Skip to content
Merged
Next Next commit
refactor: remove dead paneExt.kind and add verify arch boundaries + S…
…SOT drift triggers
  • Loading branch information
kyya committed Nov 28, 2026
commit 2f940b3f4709679acd402e47be9ff0752aaa880a
6 changes: 0 additions & 6 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ func browserURL(s string) string {
return "https://" + s
}

// browserCleanURL is the URL a browser pane keeps and shows: without the
// user info, which a layout file should not hold.

// browserCleanURL is the URL a browser pane keeps and shows: without the
// user info, which a layout file should not hold.
func browserCleanURL(u string) string {
Expand All @@ -64,6 +61,3 @@ func browserHost(s string) string {
}
return u.Host
}

// newBrowserPane makes a pane that shows url in a web view of the
// window's, with the address field given the keyboard.
1 change: 0 additions & 1 deletion extpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ func (e *extPane) updateSync(fn func()) {

// The paneExt of an extension pack's pane.

func (e *extPane) kind() string { return e.def.Kind }
func (e *extPane) program() program { return e.prog }

// label is the pane's name, or the page of its web slot, or its own
Expand Down
6 changes: 0 additions & 6 deletions panekind.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import (
// fields of the layout, and the acts a pane kind takes part in. Pane.ext
// holds it, nil for a terminal.
type paneExt interface {
// kind is the layout Kind it answers for: "note", "browser", or a
// pack's kind name.
kind() string
// program is the pane's tile and glyph.
program() program
// label is the pane's name and detail in headers and sidebars.
Expand Down Expand Up @@ -70,8 +67,6 @@ type paneKindDef struct {
program program
}

// paneKinds are the app's built-in pane kinds; allPaneKinds adds the
// packs' to them.
// paneKinds are the app's built-in pane kinds, none today: every pane
// kind is a pack's.
var paneKinds []paneKindDef
Expand Down Expand Up @@ -192,7 +187,6 @@ func (a *App) newPlaceholderPane(s *savedNode) *Pane {
return &Pane{ID: a.id(), Name: s.Name, ext: &placeholderExt{kindName: s.Kind, keep: keep}}
}

func (e *placeholderExt) kind() string { return e.kindName }
func (e *placeholderExt) program() program {
return extMissingProgram
}
Expand Down
144 changes: 144 additions & 0 deletions tools/verify/arch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package main

// Package dependency boundary enforcement for internal/** and ios/**.
//
// Reads Go import statements with go/parser (pure read-only, no code
// execution) and fails when a package imports across an architectural
// layer boundary.

import (
"errors"
"fmt"
"go/parser"
"go/token"
"io"
"io/fs"
"path/filepath"
"sort"
"strconv"
"strings"
)

const modulePrefix = "gorex/"

// leafPackages have zero internal GoRex dependencies so any layer (desktop,
// server, CLI, iOS gomobile) can import them without pulling in runtime state.
var leafPackages = map[string]bool{
"internal/atomicfile": true,
"internal/duotone": true,
"internal/ext": true,
"internal/homedir": true,
"internal/layout": true,
"internal/pairaddr": true,
"internal/rexproto": true,
"internal/tailcatpool": true,
"internal/tailnode": true,
"internal/testrex": true,
"internal/theme": true,
}

// forbiddenImports maps a package to the internal/ios prefixes it must never import.
var forbiddenImports = map[string][]string{
"internal/rex": {
"internal/rexapi",
"internal/cli",
"internal/push",
"internal/omarchy",
"internal/iconpack",
"internal/reximp",
"ios/",
},
"ios/tailnet": {
"internal/rex",
"internal/rexapi",
"internal/cli",
},
"ios/share": {
"internal/",
},
}

// archBoundariesCheck parses non-test Go files under internal/ and ios/ and
// verifies that no package violates the layer dependency rules.
func archBoundariesCheck(root string, log io.Writer) error {
var violations []string
fset := token.NewFileSet()

for _, top := range []string{"internal", "ios"} {
base := filepath.Join(root, top)
err := filepath.WalkDir(base, func(path string, d fs.DirEntry, err error) error {
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil
}
return err
}
if d.IsDir() {
name := d.Name()
if name == "testdata" || name == "Frameworks" || strings.HasPrefix(name, ".") {
return filepath.SkipDir
}
return nil
}
if !strings.HasSuffix(d.Name(), ".go") || strings.HasSuffix(d.Name(), "_test.go") {
return nil
}
rel, err := filepath.Rel(root, path)
if err != nil {
return err
}
rel = filepath.ToSlash(rel)
pkg := filepath.ToSlash(filepath.Dir(rel))

f, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly)
if err != nil {
return fmt.Errorf("parse %s: %w", rel, err)
}
for _, spec := range f.Imports {
imp, err := strconv.Unquote(spec.Path.Value)
if err != nil || !strings.HasPrefix(imp, modulePrefix) {
continue
}
target := strings.TrimPrefix(imp, modulePrefix)
if target == pkg {
// go:generate scripts (//go:build ignore) inside a package may import their own package.
continue
}
if reason := checkImportRule(pkg, target); reason != "" {
violations = append(violations, fmt.Sprintf("%s: %s imports %s (%s)", rel, pkg, target, reason))
}
}
return nil
})
if err != nil {
return err
}
}

if len(violations) > 0 {
sort.Strings(violations)
msg := "architecture boundary violations:\n " + strings.Join(violations, "\n ") + "\n"
fmt.Fprint(log, msg)
return fmt.Errorf("%d architecture boundary violation(s)", len(violations))
}
return nil
}

func checkImportRule(pkg, target string) string {
if target == "internal/testrex" {
return "non-test code must not import internal/testrex"
}
if leafPackages[pkg] && (strings.HasPrefix(target, "internal/") || strings.HasPrefix(target, "ios/")) {
return "leaf package must not import internal/ or ios/ packages"
}
for _, banned := range forbiddenImports[pkg] {
if strings.HasSuffix(banned, "/") {
if strings.HasPrefix(target, banned) {
return "forbidden dependency on " + banned + "*"
}
} else if target == banned || strings.HasPrefix(target, banned+"/") {
return "forbidden dependency on " + banned
}
}
return ""
}
64 changes: 64 additions & 0 deletions tools/verify/arch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)

func TestArchBoundariesRepo(t *testing.T) {
root, err := repoRoot(".")
if err != nil {
t.Fatalf("repoRoot: %v", err)
}
var buf bytes.Buffer
if err := archBoundariesCheck(root, &buf); err != nil {
t.Fatalf("archBoundariesCheck failed: %v\n%s", err, buf.String())
}
}

func TestArchBoundariesViolations(t *testing.T) {
dir := t.TempDir()
write := func(rel, src string) {
p := filepath.Join(dir, filepath.FromSlash(rel))
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(p, []byte(src), 0o644); err != nil {
t.Fatal(err)
}
}

// Leaf package importing internal/rex -> forbidden
write("internal/layout/bad.go", "package layout\nimport _ \"gorex/internal/rex\"\n")
// Core runtime importing rexapi -> forbidden
write("internal/rex/bad.go", "package rex\nimport _ \"gorex/internal/rexapi\"\n")
// iOS tailnet importing internal/rex -> forbidden
write("ios/tailnet/bad.go", "package tailnet\nimport _ \"gorex/internal/rex\"\n")
// Non-test importing testrex -> forbidden
write("internal/cli/bad.go", "package cli\nimport _ \"gorex/internal/testrex\"\n")
// Test file importing testrex -> allowed
write("internal/cli/ok_test.go", "package cli\nimport _ \"gorex/internal/testrex\"\n")

var buf bytes.Buffer
err := archBoundariesCheck(dir, &buf)
if err == nil {
t.Fatal("expected boundary violations, got nil")
}
out := buf.String()
for _, want := range []string{
"internal/layout/bad.go",
"internal/rex/bad.go",
"ios/tailnet/bad.go",
"internal/cli/bad.go",
} {
if !strings.Contains(out, want) {
t.Errorf("missing expected violation %q in:\n%s", want, out)
}
}
if strings.Contains(out, "ok_test.go") {
t.Errorf("test file should not trigger violation:\n%s", out)
}
}
28 changes: 22 additions & 6 deletions tools/verify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,34 @@ type facts struct {
// plan maps the changed files to the checks to run, cheapest first.
func plan(files []string, f facts) []check {
var goFiles, goDirs []string
goAll, web, ios, gh, docs := false, false, false, false, false
goAll, web, ios, gh, docs, arch := false, false, false, false, false, false
seen := map[string]bool{}
addDir := func(d string) {
if !seen[d] {
seen[d] = true
goDirs = append(goDirs, d)
}
}
for _, p := range files {
p = filepath.ToSlash(p)
switch {
case p == "go.mod" || p == "go.sum":
goAll = true
arch = true
case strings.HasSuffix(p, ".go"):
goFiles = append(goFiles, p)
d := pathDir(p)
if !seen[d] {
seen[d] = true
goDirs = append(goDirs, d)
addDir(pathDir(p))
if strings.HasPrefix(p, "internal/") || strings.HasPrefix(p, "ios/") || strings.HasPrefix(p, "tools/verify/") {
arch = true
}
}
// Trigger generated-SSOT drift tests when any input or cross-platform output changes.
switch p {
case "assets/brands.json", "programs_brands_gen.go", "web/src/programs_brands.ts", "ios/Shared/ProgramBrands.swift":
addDir("./tools/genbrands")
case "internal/rexproto/protocol.json", "web/src/rex-protocol.gen.ts", "ios/GoRex/Rex/RexProtocol.gen.swift":
addDir("./internal/rexproto")
}
web = web || strings.HasPrefix(p, "web/")
ios = ios || strings.HasPrefix(p, "ios/")
gh = gh || strings.HasPrefix(p, ".github/")
Expand All @@ -97,6 +110,9 @@ func plan(files []string, f facts) []check {
if len(goFiles) > 0 {
cs = append(cs, check{name: "gofmt", args: append([]string{"gofmt", "-l"}, goFiles...)})
}
if arch {
cs = append(cs, check{name: "arch boundaries", fn: archBoundariesCheck})
}
if docs {
cs = append(cs, check{name: "design docs", fn: designDocsCheck})
}
Expand Down Expand Up @@ -177,7 +193,7 @@ func plan(files []string, f facts) []check {
// branch's own config. A skip counts as NOT VERIFIED.
func readOnlyPlan(cs []check) []check {
for i, c := range cs {
safe := c.name == "gofmt" || c.name == "actionlint" || c.name == "design docs" ||
safe := c.name == "gofmt" || c.name == "arch boundaries" || c.name == "actionlint" || c.name == "design docs" ||
strings.HasPrefix(c.name, "vet ") || strings.HasPrefix(c.name, "build ")
if !safe && c.skip == "" {
cs[i].skip = "NOT VERIFIED: branch is not from si-mods; read-only checks only"
Expand Down
17 changes: 12 additions & 5 deletions tools/verify/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ func TestPlan(t *testing.T) {
{"nothing", nil, win, nil},
{"docs only", []string{"docs/lessons.md", "README.md"}, win, []string{"design docs"}},
{"sub package", []string{"internal/rex/server.go"}, win,
append(append([]string{"gofmt"}, goChecks...), "golangci-lint", "go test")},
append(append([]string{"gofmt", "arch boundaries"}, goChecks...), "golangci-lint", "go test")},
{"root package", []string{"app.go"}, win,
append(append([]string{"gofmt"}, goChecks...), "golangci-lint", "go test root (skip)")},
{"root package full", []string{"app.go"}, facts{goos: "linux", full: true},
append(append([]string{"gofmt"}, goChecks...), "golangci-lint", "go test root")},
{"go.mod only", []string{"go.mod"}, win,
append(append([]string{}, goChecks...), "golangci-lint", "go test root (skip)")},
append(append([]string{"arch boundaries"}, goChecks...), "golangci-lint", "go test root (skip)")},
{"brands json", []string{"assets/brands.json"}, win,
append(append([]string{}, goChecks...), "golangci-lint", "go test")},
{"rexproto json", []string{"internal/rexproto/protocol.json"}, win,
append(append([]string{}, goChecks...), "golangci-lint", "go test")},
{"web", []string{"web/src/a.ts"}, win, []string{"web typecheck", "web test"}},
{"web no node_modules", []string{"web/src/a.ts"}, facts{goos: "windows"},
[]string{"web typecheck (skip)", "web test (skip)"}},
Expand Down Expand Up @@ -252,7 +256,7 @@ func TestHookDenies(t *testing.T) {
t.Fatal(err)
}
gitT("add", "go.mod")
gitT("-c", "user.name=t", "-c", "user.email=t@example.com", "commit", "-q", "-m", "init")
gitT("-c", "user.name=t", "-c", "user.email=t@example.com", "commit", "--no-verify", "-q", "-m", "init")
gitT("update-ref", "refs/remotes/origin/main", "HEAD")
if err := os.WriteFile(filepath.Join(dir, "bad.go"), []byte("package gorex\nvar x = 1\n"), 0o644); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -284,6 +288,9 @@ func trustRepo(t *testing.T, url string) (string, func(args ...string) string) {
dir := t.TempDir()
g := func(args ...string) string {
t.Helper()
if len(args) > 0 && args[0] == "commit" {
args = append([]string{"commit", "--no-verify"}, args[1:]...)
}
out, err := git(dir, append([]string{"-c", "user.name=t", "-c", "user.email=t@example.com"}, args...)...)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -382,7 +389,7 @@ func TestTrustedBranch(t *testing.T) {
func TestPlanReadOnly(t *testing.T) {
files := []string{"internal/rex/a.go", "web/src/a.ts", "ios/App.swift", ".github/workflows/ci.yml"}
for _, c := range plan(files, facts{goos: "darwin", webNodeModules: true, iosToolsPresent: true, readOnly: true}) {
safe := c.name == "gofmt" || c.name == "actionlint" || strings.HasPrefix(c.name, "vet ") || strings.HasPrefix(c.name, "build ")
safe := c.name == "gofmt" || c.name == "arch boundaries" || c.name == "actionlint" || strings.HasPrefix(c.name, "vet ") || strings.HasPrefix(c.name, "build ")
if safe && c.skip != "" {
t.Errorf("%s skipped in read-only mode: %s", c.name, c.skip)
}
Expand Down Expand Up @@ -424,7 +431,7 @@ func checkoutFork(t *testing.T, dir string, g func(args ...string) string) {
{"init", "-q", "-b", "main"},
{"fetch", "-q", dir, "refs/remotes/origin/main"},
{"checkout", "-q", "-b", "work", "FETCH_HEAD"},
{"-c", "user.name=f", "-c", "user.email=f@example.com", "commit", "-q", "--allow-empty", "-m", "fork work"},
{"-c", "user.name=f", "-c", "user.email=f@example.com", "commit", "--no-verify", "-q", "--allow-empty", "-m", "fork work"},
} {
if _, err := git(fork, a...); err != nil {
t.Fatal(err)
Expand Down