1package cli
2
3import (
4 "go/ast"
5 "go/parser"
6 "go/token"
7 "os"
8 "strings"
9 "testing"
10)
11
12type uiAdoptionExpectation struct {
13 family string
14 file string
15 functions []string
16}
17
18var uiAdoptionExpectations = []uiAdoptionExpectation{
19 {
20 family: "server",
21 file: "serve.go",
22 functions: []string{"newStartCmd"},
23 },
24 {
25 family: "root/server",
26 file: "root.go",
27 functions: []string{"newVersionCmd", "runReloadRemote", "runLogsRemote", "streamLogsRemote", "showContainerLogsLocal"},
28 },
29 {
30 family: "backups",
31 file: "backup.go",
32 functions: []string{"newBackupListCmd", "newBackupRunCmd", "newBackupDetectCmd", "newBackupStatusCmd"},
33 },
34 {
35 family: "images",
36 file: "images.go",
37 functions: []string{"runImagesList", "runImagesPrune"},
38 },
39}
40
41func TestLocalParityMatrix(t *testing.T) {
42 checks := []struct {
43 file string
44 legacyText string
45 command string
46 }{
47 {file: "push.go", legacyText: "push requires remote mode", command: "gordon push"},
48 {file: "rollback.go", legacyText: "rollback requires remote mode", command: "gordon rollback"},
49 {file: "backup.go", legacyText: "backup commands require a configured remote target", command: "gordon backups"},
50 {file: "routes.go", legacyText: "status command requires --remote flag or GORDON_REMOTE env var", command: "gordon status"},
51 {file: "restart.go", legacyText: "local restart does not support --with-attachments; use --remote", command: "gordon restart --with-attachments"},
52 }
53
54 for _, check := range checks {
55 content, err := os.ReadFile(check.file)
56 if err != nil {
57 t.Fatalf("failed to read %s: %v", check.file, err)
58 }
59 if strings.Contains(string(content), check.legacyText) {
60 t.Fatalf("local parity gap: %s still blocks local mode (%q found in %s)", check.command, check.legacyText, check.file)
61 }
62 }
63}
64
65func TestUIAdoptionMatrixCoverage(t *testing.T) {
66 for _, expect := range uiAdoptionExpectations {
67 expect := expect
68 t.Run(expect.family, func(t *testing.T) {
69 if len(expect.functions) == 0 {
70 t.Fatalf("ui adoption matrix for %s is empty", expect.family)
71 }
72
73 fset := token.NewFileSet()
74 fileNode, err := parser.ParseFile(fset, expect.file, nil, parser.AllErrors)
75 if err != nil {
76 t.Fatalf("failed to parse %s: %v", expect.file, err)
77 }
78
79 found := make(map[string]bool, len(expect.functions))
80 ast.Inspect(fileNode, func(n ast.Node) bool {
81 fn, ok := n.(*ast.FuncDecl)
82 if !ok {
83 return true
84 }
85 found[fn.Name.Name] = true
86 return true
87 })
88
89 for _, fn := range expect.functions {
90 if !found[fn] {
91 t.Fatalf("ui adoption matrix references missing function %s in %s", fn, expect.file)
92 }
93 }
94 })
95 }
96}