carlos / platform Public

cli: corpus refuses git ancestors; default skips honoured

Task 3 review P2s. runGoldenCases now refuses to run when a .git sits
above the cases' directory (canary runs git, whose discovery walks up),
with a focused gitAbove test. Branch cases that DefaultOn would send to
a default carrying Golden.Skip become skipped records (SkipBare: the bare
case only), for named and unnamed defaults; the generator fixture covers
both. Re-recorded from 7f4bdf3a: corpus unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7c74e4dbe5591bd4988b5fdc27cfc5330f0c4c3e parent decd103
2 files changed, +273 −4
  • clireg_golden_test.go +254 −4
  • docs/superpowers/plans/CODEX-FINDINGS-cli-registry-words-T3.md +19 −0

CI failed — run details

Intent

Human

<task-notification> <task-id>af3796f4b37feb4de</task-id> <tool-use-id>toolu_01PTkv6NfMr878mazxRk2u3E</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/27979b8d-cc90-4f50-88f6-87ba41433627/tasks/af3796f4b37feb4de.output</output-file> <status>completed</status> <summary>Agent "Implement Task 4 apps/config words" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Task 4 is done in one commit, `decd1033756a918e431bda2d4372d88f270c39fb` ("cli: apps, config and settings words in the registry"). Every dispatcher converted byte for byte, none had to stay a leaf, and the corpus replays with zero differences. Git printed the `packed-refs.lock` error; `git log -1` confirms the commit and the tree is clean. I made one commit for the whole task rather than one per dispatcher group, because the corpus file and `parity/cli.tsv` were regenerated once for all of them. **Nodes created.** Every leaf is `raw(...)` unless noted. Unless marked operator, nodes are Customer. - **`apps`** (`appsCommand`, apps.go): no default. Fallback prints `appsUsage` to stderr and exits 1. Children: `create`, `place`, `region`, `build-probe`, `set`, `show` (Operator), `delete`, `restore`, `ttl`, `keep`, `list`. `RunApps` stays as a wrapper for fleets_cli_test. - **`apps source`** (`appsSourceCommand`, apps_source.go): no default. Fallback is `log.Fatal(sourcePullUsage)`. One child, `pull`. - **`env`** (`envCommand`, appconfig_cli.go): Fallback prints `envUsage` to stderr and exits 1. Children: `set`, `unset`, `list`, `environments`, `exec-delivery`, `sync`, `adopt`, `release`, `fork`. `RunEnv` is deleted. - **`secrets`** (`secretsCommand`): Fallback prints `secretsUsage` to stderr and exits 1. Children: `set`, `unset`, `list`, `genkey` (Golden.Skip: "prints a freshly generated key pair: no two runs agree"), `fingerprint`. `RunSecrets` stays as a wrapper. - **`features`**: Fallback `log.Fatal(featuresUsage)`. Children `set`, `list`. `runFeatures` is deleted. - **`assets`**: Fallback `log.Fatal(assetsUsage)`. Children `purge`, `status`. Old dispatcher deleted. - **`domains`**: Fallback `log.Fatal(domainsUsage)`. Children: `check`, `buy`, `attach`, `verify`, `detach`, `list`, `paths`, `placements`. `runDomains` stays as a wrapper. - **`gate`**: Fallback `log.Fatal(gateUsage)`. Children `set`, `clear`, `list`. Old dispatcher deleted. - **`ratelimit`**: Fallback `log.Fatal(ratelimitUsage)`. Children `show`, `set`, `clear`. Old dispatcher deleted. - **`config`** (`configCommand`): Fallback prints `configUsage` to stderr and exits 1. OnError is `configError(path[1], err)`, which is RunConfig's mapping moved verbatim: ErrHelp returns, a flag error exits 2, anything else prints `carlos config &lt;word&gt;: &lt;err&gt;` and exits 1. `RunConfig` is deleted. - **`config destinations`** (`configDestinationsCommand(out io.Writer, errp *error)`): `Default: "list"` on `OnAbsent|OnFlag`. Children: `list` (alias `ls`), `add`, `set`, `default`, `remove` (alias `rm`), `rename`. The Fallback handles `help` by printing `destinationsUsage` to `out`; any other word builds the `no verb %q` error. `configDestinations(out, args) error` is now the three-line wrapper the plan describes, and config_cli_test.go is unchanged. - **`accounts`**: Fallback prints `accountsUsage` to stderr and exits 1. Children: `create`, `list`, `migrate` (Operator), `plan` (Operator). There is no OnError, because `runAccountsPlan` already maps its own errors. `RunAccounts` is deleted. - **`auth`**: Fallback prints `authUsage` to stderr and exits 1. Leaves `login`, `whoami`, `logout`, `default` are closures calling `f(os.Stdout, inv.Raw)`. OnError is RunAuth's mapping verbatim, printing `carlos auth &lt;path[1]&gt;:` and exiting 1. `RunAuth` is deleted. - **`route`, `routes`, `protection`**: no change, still leaves. They choose behaviour by flags, not words. **Corpus.** - It went from 155 cases to 333. The re-record from `7f4bdf3a` shows 178 lines added and 0 removed or changed in `git diff`. - I read every new line. Each matches the old behaviour, including `auth login -h` (exit 1, "flag: help requested"), `config destinations help` (stdout, exit 0) and `config destinations zz` (stderr, exit 1). - Replay with no flags passes. **Explicit cases.** I added a `goldenExtras` list to `clireg_golden_test.go`, keyed `"&lt;argv&gt; | extra"` with an optional `(note)` suffix. It is applied in `TestCLIGolden` only, so the generator fixture test is untouched. It holds the three cases the generator doesn't produce: `config destinations --global`, `config destinations zz` and `apps source delete`. The other three you listed come from the generator: `config destinations` bare, `auth login -h` and `apps source` bare. **Tests, all passing:** - The 31 related root-package test files (apps*, appconfig*, accounts*, auth*, config_cli, domains*, features, assets, gate, ratelimit, fleets_cli, fleets_secrets_key_cli). - `TestCommandTreeIsValid`, `TestCLIProjection`, `TestTopLevelWordsUnchanged`, `TestUpdateHintSkippedPerPath`, `TestGoldenCasesGenerator` and `TestCLIGolden` replay. - `internal/parity`, `internal/docsite`, `internal/clireg` and `internal/domains`. - `go vet .`, `gofmt -l` (clean), `go build ./...`, and `make parity-doc` (regenerated `parity/cli.tsv`). **Decisions the plan didn't settle:** 1. **`apps source pull`** (apps_source.go:26-41): `pull` had to become a node, so I split `runAppsSource` into a branch plus a new handler, `runAppsSourcePull(args)`. Its body is the old one, parsing `args` instead of `args[1:]`. That makes this the one handler whose body changed, which A0 requires. 2. **`errp` semantics** (config_cli.go:93-140): when `errp` is set, a verb's error goes to `*errp` through the node's OnError, the fallback stores its error there too, and nothing exits. When `errp` is nil (production), verb errors go to `config`'s OnError and the fallback calls `configError("destinations", err)` itself, because a Fallback cannot return an error. 3. **`config` OnError word** (config_cli.go:63): it uses `path[1]`, which is always `destinations`. That matches the old `args[0]`, since that word has no alias. 4. **`accounts plan`**: no OnError, because the ErrHelp mapping already lives inside `runAccountsPlan`, as the spec's step-1 note allows. 5. **Audiences** come from parity.tsv: `apps show`, `accounts migrate` and `accounts plan` are Operator; the rest are Customer. 6. **Stale comments**: a few still name the deleted functions (pipeline.go:63, appconfig_cli.go:2, cli.go:3469). I left them, apart from one fix at config_cli.go:212. The files changed are under `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/cli-registry-words/`: `apps.go`, `apps_source.go`, `appconfig_cli.go`, `features_cli.go`, `assets_cli.go`, `domains_cli.go`, `gate_cli.go`, `ratelimit_cli.go`, `config_cli.go`, `accounts.go`, `auth.go`, `commands.go`, `clireg_golden_test.go`, `parity/cli.tsv` and `testdata/clireg-golden.jsonl`. My scratch directory under `$TMPDIR` is removed.</result> <usage><subagent_tokens>160285</subagent_tokens><tool_uses>48</tool_uses><duration_ms>508435</duration_ms></usage> </task-notification>

Attributed to this commit: 11.7 g CO₂e (1,408,347 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on cli-registry-words, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/clireg_golden_test.go b/clireg_golden_test.go
index 47656a083..4a3f1fa55 100644
--- a/clireg_golden_test.go
+++ b/clireg_golden_test.go
@@ -116,7 +116,10 @@ func goldenKindArgs(kind string) []string {
// word (the word alone is the bare one), plus the word twice;
// - every When node: its cases with whenEnv's switch on and off; its
// descendants with it on;
-// - a node with Golden.Skip: one skipped case and nothing below it.
+// - a node with Golden.Skip: one skipped case and nothing below it;
+// - a branch whose default (named or unnamed) has Golden.Skip: each case
+// DefaultOn would send to it is a skipped case instead; with
+// Golden.SkipBare, the bare one only.
//
// A case is keyed "<typed words> | <kind>", "<root>" for no words, with "
// (when on)" or " (when off)" after a When node's kinds.
@@ -239,10 +242,91 @@ func (g *goldenGen) nodeCases(n *clireg.Node, s goldenSpelling) {
}
}
-// branchCases adds the six branch kinds at spelling s; skipBare, when set,
-// replaces the bare case with a skipped one.
+// branchCases adds the six branch kinds at spelling s. A kind is a skipped
+// record instead when skipBare is set (bare only), or when it would reach
+// n's default and that default carries Golden.Skip (any kind) or
+// Golden.SkipBare (bare only).
func (g *goldenGen) branchCases(n *clireg.Node, s goldenSpelling, skipBare string) {
- g.kindCases(goldenBranchKinds, s, skipBare)
+ for _, kind := range goldenBranchKinds {
+ if why := goldenDefaultSkip(n, goldenKindArgs(kind)); why != "" {
+ g.add(s.typed, kind, s.suffix, nil, nil, why)
+ continue
+ }
+ if kind == "bare" && skipBare != "" {
+ g.add(s.typed, kind, s.suffix, nil, nil, skipBare)
+ continue
+ }
+ g.add(s.typed, kind, s.suffix, append(append([]string{}, s.typed...), goldenKindArgs(kind)...), s.env, "")
+ }
+}
+
+// goldenDefault is the node n's default runs: its unnamed DefaultLeaf or
+// the child Default names; nil when it has neither.
+func goldenDefault(n *clireg.Node) *clireg.Node {
+ if n.DefaultLeaf != nil {
+ return n.DefaultLeaf
+ }
+ if n.Default == "" {
+ return nil
+ }
+ for _, c := range n.Children {
+ if c != nil && !c.Transparent && c.Name == n.Default {
+ return c
+ }
+ }
+ return nil
+}
+
+// goldenDefaultSkip is why a case whose arguments after n's words are args
+// must not run because it would reach n's default ("" when it may run). A
+// word that a child always matches (no When) never reaches the default;
+// one a When child matches might, so it counts.
+func goldenDefaultSkip(n *clireg.Node, args []string) string {
+ d := goldenDefault(n)
+ if d == nil {
+ return ""
+ }
+ var on clireg.On
+ switch {
+ case len(args) == 0:
+ on = clireg.OnAbsent
+ case strings.HasPrefix(args[0], "-"):
+ on = clireg.OnFlag
+ default:
+ on = clireg.OnWord
+ if goldenChildAlwaysMatches(n, args[0]) {
+ return ""
+ }
+ }
+ if n.DefaultOn&on == 0 {
+ return ""
+ }
+ if d.Golden.Skip != "" {
+ return d.Golden.Skip
+ }
+ if on == clireg.OnAbsent {
+ return d.Golden.SkipBare
+ }
+ return ""
+}
+
+// goldenChildAlwaysMatches reports whether a non-transparent child of n
+// with no When condition is spelled word.
+func goldenChildAlwaysMatches(n *clireg.Node, word string) bool {
+ for _, c := range n.Children {
+ if c == nil || c.Transparent || c.When != nil {
+ continue
+ }
+ if c.Name == word {
+ return true
+ }
+ for _, a := range c.Aliases {
+ if a == word {
+ return true
+ }
+ }
+ }
+ return false
}
func (g *goldenGen) kindCases(kinds []string, s goldenSpelling, skipBare string) {
@@ -284,6 +368,11 @@ func (g *goldenGen) visit(n *clireg.Node, typed, canon []string, env map[string]
g.branchCases(n, s, c.Golden.SkipBare)
w := s.typed[len(s.typed)-1]
twice := append(append([]string{}, s.typed...), w)
+ // The second word is not dropped again: it reaches n as a word.
+ if why := goldenDefaultSkip(n, []string{w}); why != "" {
+ g.add(twice, "bare", s.suffix, nil, nil, why)
+ continue
+ }
g.add(twice, "bare", s.suffix, twice, s.env, "")
}
}
@@ -383,6 +472,33 @@ func runGoldenCase(bin, parent string, c goldenCase) goldenResult {
return r
}
+// gitAbove is the first .git (directory or file) at dir or above it, over
+// the path as written and with its symlinks resolved; "" when there is
+// none. Anything but "does not exist" counts as there.
+func gitAbove(dir string) string {
+ if abs, err := filepath.Abs(dir); err == nil {
+ dir = abs
+ }
+ starts := []string{dir}
+ if resolved, err := filepath.EvalSymlinks(dir); err == nil && resolved != dir {
+ starts = append(starts, resolved)
+ }
+ for _, d := range starts {
+ for {
+ path := filepath.Join(d, ".git")
+ if _, err := os.Lstat(path); !errors.Is(err, os.ErrNotExist) {
+ return path
+ }
+ parent := filepath.Dir(d)
+ if parent == d {
+ break
+ }
+ d = parent
+ }
+ }
+ return ""
+}
+
// runGoldenCases runs every non-skipped case, at most goldenConcurrency at
// once, and returns the results by case.
func runGoldenCases(t *testing.T, bin string, cases []goldenCase) map[string]goldenResult {
@@ -393,6 +509,13 @@ func runGoldenCases(t *testing.T, bin string, cases []goldenCase) map[string]gol
if p := configAbove(parent); p != "" {
t.Fatalf("%s is above the cases' directory %s", p, parent)
}
+ // Some commands (canary) run git, whose discovery also walks up: a
+ // repository above the cases would change what they print, and the
+ // corpus was recorded outside one. Refused rather than fenced with
+ // GIT_CEILING_DIRECTORIES, which would change the cases' environment.
+ if p := gitAbove(parent); p != "" {
+ t.Fatalf("%s is above the cases' directory %s: git would find that repository; set TMPDIR to a directory outside any git checkout", p, parent)
+ }
out := map[string]goldenResult{}
var mu sync.Mutex
var wg sync.WaitGroup
@@ -702,6 +825,40 @@ func TestGoldenCasesGenerator(t *testing.T) {
Children: []*clireg.Node{leaf("y")},
Golden: clireg.Golden{SkipBare: "starts a daemon"},
},
+ // A named default with Skip, admitting absent and word: the
+ // help child takes "help" before the default can.
+ {
+ Name: "e",
+ Fallback: func(args, consumed []string) {},
+ Children: []*clireg.Node{
+ {Name: "run", Run: run, Golden: clireg.Golden{Skip: "opens a browser"}},
+ leaf("help"),
+ {Name: "t", Transparent: true},
+ },
+ Default: "run",
+ DefaultOn: clireg.OnAbsent | clireg.OnWord,
+ },
+ // An unnamed default with Skip, admitting absent and flag.
+ {
+ Name: "f",
+ Fallback: func(args, consumed []string) {},
+ Children: []*clireg.Node{leaf("g")},
+ DefaultLeaf: &clireg.Node{Run: run, Golden: clireg.Golden{Skip: "prompts"}},
+ DefaultOn: clireg.OnAbsent | clireg.OnFlag,
+ },
+ // A named default with SkipBare, admitting everything.
+ {
+ Name: "h",
+ Children: []*clireg.Node{{Name: "k", Run: run, Golden: clireg.Golden{SkipBare: "waits on stdin"}}},
+ Default: "k",
+ DefaultOn: clireg.OnAbsent | clireg.OnFlag | clireg.OnWord,
+ },
+ // An unnamed default with SkipBare, admitting everything.
+ {
+ Name: "u",
+ DefaultLeaf: &clireg.Node{Run: run, Golden: clireg.Golden{SkipBare: "tails a log"}},
+ DefaultOn: clireg.OnAbsent | clireg.OnFlag | clireg.OnWord,
+ },
},
}
got, err := goldenCases(root, map[string]map[string]string{"w": {"W_ON": "1"}})
@@ -788,6 +945,8 @@ func TestGoldenCasesGenerator(t *testing.T) {
wantCounts := map[string]int{
"<root>": 6, "a": 2, "aa": 2, "b": 6, "b c": 2, "b r": 6, "b r r": 1,
"d": 6, "d list": 2, "d ls": 2, "w": 12, "w x": 2, "s": 1, "q": 6, "q y": 2,
+ "e": 6, "e run": 1, "e help": 2, "e t": 6, "e t t": 1, "f": 7, "f g": 2,
+ "h": 6, "h k": 2, "u": 6,
}
if !reflect.DeepEqual(counts, wantCounts) {
t.Errorf("cases per spelling: %v, want %v", counts, wantCounts)
@@ -798,12 +957,103 @@ func TestGoldenCasesGenerator(t *testing.T) {
}
}
+ // Defaults' skips, exactly: every case under e, f, h and u, with the
+ // reason when it is skipped ("" when it runs).
+ defaultCases := map[string]string{
+ "e | bare": "opens a browser",
+ "e | help": "", // the help child, not the default
+ "e | -h": "",
+ "e | --help": "",
+ "e | zz-unknown": "opens a browser",
+ "e | --zz-unknown-flag": "",
+ "e run | skipped": "opens a browser",
+ "e help | -h": "",
+ "e help | --zz-unknown-flag": "",
+ "e t | bare": "opens a browser",
+ "e t | help": "",
+ "e t | -h": "",
+ "e t | --help": "",
+ "e t | zz-unknown": "opens a browser",
+ "e t | --zz-unknown-flag": "",
+ "e t t | bare": "opens a browser",
+ "f | bare": "prompts",
+ "f | help": "",
+ "f | -h": "prompts",
+ "f | --help": "prompts",
+ "f | zz-unknown": "",
+ "f | --zz-unknown-flag": "prompts",
+ "f | default skipped": "prompts",
+ "f g | -h": "",
+ "f g | --zz-unknown-flag": "",
+ "h | bare": "waits on stdin",
+ "h | help": "",
+ "h | -h": "",
+ "h | --help": "",
+ "h | zz-unknown": "",
+ "h | --zz-unknown-flag": "",
+ "h k | -h": "",
+ "h k | --zz-unknown-flag": "",
+ "u | bare": "tails a log",
+ "u | help": "",
+ "u | -h": "",
+ "u | --help": "",
+ "u | zz-unknown": "",
+ "u | --zz-unknown-flag": "",
+ }
+ gotDefault := map[string]string{}
+ for _, c := range got {
+ switch strings.SplitN(c.Case, " ", 2)[0] {
+ case "e", "f", "h", "u":
+ gotDefault[c.Case] = c.Skipped
+ if (c.Skipped == "") == (c.Argv == nil) {
+ t.Errorf("%q: skipped %q with argv %q", c.Case, c.Skipped, c.Argv)
+ }
+ }
+ }
+ if !reflect.DeepEqual(gotDefault, defaultCases) {
+ t.Errorf("default-skip cases:\n got %v\nwant %v", gotDefault, defaultCases)
+ }
+
// A When node with no switch is an error, not a silent pair of cases.
if _, err := goldenCases(root, nil); err == nil {
t.Error("goldenCases: no error for a When node missing from whenEnv")
}
}
+// gitAbove finds a .git (a directory, or a worktree's file) above a nested
+// directory, and nothing when there is none.
+func TestGoldenCasesGitAbove(t *testing.T) {
+ root := t.TempDir()
+ if p := gitAbove(root); p != "" {
+ t.Fatalf("gitAbove(%s) = %q before any .git exists (the temp root is inside a repository)", root, p)
+ }
+ nested := filepath.Join(root, "repo", "a", "b")
+ if err := os.MkdirAll(nested, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if p := gitAbove(nested); p != "" {
+ t.Errorf("gitAbove(%s) = %q, want none", nested, p)
+ }
+ for _, asDir := range []bool{true, false} {
+ git := filepath.Join(root, "repo", ".git")
+ var err error
+ if asDir {
+ err = os.Mkdir(git, 0o755)
+ } else {
+ err = os.WriteFile(git, []byte("gitdir: elsewhere\n"), 0o644)
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ if p := gitAbove(nested); p != git {
+ t.Errorf("gitAbove(%s) with .git (dir %v) = %q, want %q", nested, asDir, p, git)
+ }
+ if err := os.RemoveAll(git); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
func TestGoldenNormalise(t *testing.T) {
dir := "/var/tmp/x/case-1"
in := "2026/11/09 10:11:12 open " + dir + "/data/registry.db: no\nkept 2026/11/09 10:11:12 mid-line\n"
diff --git a/docs/superpowers/plans/CODEX-FINDINGS-cli-registry-words-T3.md b/docs/superpowers/plans/CODEX-FINDINGS-cli-registry-words-T3.md
new file mode 100644
index 000000000..4f47458d2
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-FINDINGS-cli-registry-words-T3.md
@@ -0,0 +1,19 @@
+No P1 findings. Two P2 findings:
+
+1. **P2 — Git discovery can escape the case directory.**
+ **Evidence:** [clireg_golden_test.go:353](clireg_golden_test.go:353) checks ancestors for `.carlos/config`, but not an enclosing Git repository. `canary.go:518–520` invokes Git before checking authentication.
+ **Failure scenario:** After Task 5 exposes canary’s branch cases, `canary zz-unknown` and `canary help` reach that Git lookup. With temporary directories inside a checkout without `.carlos/config`, they read its Git state and produce a different error from cases recorded outside a repository. Recording twice in the same environment does not detect this.
+ **Fix:** Reject or relocate case directories inside a Git repository, checking resolved paths. Add a focused isolation test.
+ **Fault family:** Corpus isolation from ancestor state.
+
+2. **P2 — Default-leaf skips do not suppress invocations reaching that leaf.**
+ **Evidence:** [clireg_golden_test.go:191](clireg_golden_test.go:191) emits executable branch cases before inspecting `DefaultLeaf.Golden.Skip`; it then adds a separate skipped record without removing those cases. Named defaults’ skip annotations are likewise not consulted by `branchCases`.
+ **Failure scenario:** A skipped default admitting `OnAbsent|OnFlag|OnWord` still runs through the branch’s bare, help, and unknown-input cases. The corpus can therefore execute a handler explicitly marked unsafe to run. No current corpus row exercises this configuration.
+ **Fix:** Honor the selected default’s skip annotations when generating branch cases, or reject conflicting annotations before launching processes. Cover named and unnamed defaults with focused fixtures.
+ **Fault family:** Skip enforcement across default dispatch.
+
+No P3 findings.
+
+Validation: all 155 corpus rows are sorted and unique; all 146 runnable rows contain exit, stdout, and stderr expectations. `git diff --check` passed. Targeted generator and normalization tests could not start because the read-only sandbox prevented Go from creating its build directory. No files changed; no full suites ran.
+
+READY AFTER FIXES (no P1)
\ No newline at end of file