carlos / platform Public

parity: CLI coverage from the command registry

TestParityCLIPaths, TestParityCLIAudience and TestParityMCPColumn replace
TestParityCLITopLevel and check every row against parity/cli.tsv (spec D2
to D5). LoadCLI reads the projection. Rows fixed: steering, channels
digests (operator), system-box gains runsc-ensure and
exec-sandbox-allows-prev. AGENTS.md and parity/README.md say a word that
selects code is a clireg node.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9ca0f62bef96658f5073dc54fa542547737f5486 parent 250668a
12 files changed, +487 −64
  • AGENTS.md +13 −9
  • docs/parity.md +8 −9
  • internal/parity/cli.go +229 −0
  • internal/parity/cli_test.go +184 −0
  • internal/parity/page.go +1 −1
  • internal/parity/page_test.go +2 −2
  • internal/parity/repo_test.go +33 −31
  • internal/parity/rules.go +5 −1
  • internal/parity/table.go +2 −4
  • internal/parity/table_test.go +5 −2
  • parity/README.md +1 −1
  • parity/parity.tsv +4 −4

Intent

Human

<task-notification> <task-id>bot3ag9gf</task-id> <tool-use-id>toolu_01GHbSr4W5KdxK6MhfXVAihX</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/27979b8d-cc90-4f50-88f6-87ba41433627/tasks/bot3ag9gf.output</output-file> <status>completed</status> <summary>Background command "Wait for Astra T7 review" completed (exit code 0)</summary> </task-notification>

diff --git a/AGENTS.md b/AGENTS.md
index 1c9e2b64c..a34bccdde 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -421,10 +421,10 @@ unchanged.
- **When a storage shape changes, the consumer list is everything that PARSES
the shape** — not everything that calls the API. (Learned three times.)
- **A new `carlos` command is not done until `docs/site/cli.md` names it.**
- `internal/docsite` reads main.go's dispatch switch and fails the gate over a
- command with no heading on the CLI page, over a fenced example running a verb
- that no longer exists, and over a `/docs` link whose page or `#fragment` does
- not resolve. The check is a heading and not a substring on purpose: `route` is
+ `internal/docsite` reads the command tree's projection (`parity/cli.tsv`)
+ and fails the gate over a command with no heading on the CLI page, over a
+ fenced example running a verb that no longer exists, and over a `/docs`
+ link whose page or `#fragment` does not resolve. The check is a heading and not a substring on purpose: `route` is
a prefix of `routes`, and a substring check let a deleted section pass. The
corpus is rendered by `carlosframework/website`, which vendors a copy — so a
change here reaches the site only after that repo re-syncs and ships.
@@ -433,11 +433,15 @@ unchanged.
or subcommand and a new `routeDecls` entry in
`internal/console/routedecls.go`; the row lands in the same branch. When a
branch closes a gap, move its row to `both`.
- `TestParityTableCoversConsoleRoutes`, `TestParityCLITopLevel`,
- `TestParityTableIsValid` and `TestParityPageIsCurrent` enforce this. Run
- `make parity-doc` after editing the table. `TestParityCLITopLevel` checks
- only top-level CLI commands against main.go. Keep subcommand rows by hand
- until slice 4's registry.
+ `TestParityTableCoversConsoleRoutes`, `TestParityCLIPaths`,
+ `TestParityCLIAudience`, `TestParityMCPColumn`, `TestParityTableIsValid`
+ and `TestParityPageIsCurrent` enforce this. Run `make parity-doc` after
+ editing the table or the command tree. The CLI tests check every command
+ in the registry's projection, `parity/cli.tsv`.
+- **A word that selects code is a `clireg` node** in `commands.go` or its
+ package's subtree, with its `parity/parity.tsv` row in the same branch. A
+ leaf compares arguments only to its declared enum values, flag spellings
+ or ordinary value checks, never to a word that picks different behaviour.
- **Wire-shape changes are additive**: live pointers/manifests exist in
production buckets; anything written before your change must still parse.
- **Production channel names are pinned in tests**
diff --git a/docs/parity.md b/docs/parity.md
index 83a97cb96..2bf12513b 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -6,16 +6,16 @@ This page is generated from `parity/parity.tsv` and `parity/packages.tsv` by `ma
Only customer rows are counted. Rows outside customer parity appear at the end.
-Only top-level CLI commands are checked against main.go. Subcommand rows stay hand-maintained until slice 4's registry.
+CLI rows are checked against the command registry (`parity/cli.tsv`).
| Status | Rows |
|---|---:|
| both | 42 |
| partial | 9 |
-| gap | 63 |
+| gap | 62 |
| cli-only | 15 |
| console-only | 17 |
-| Total | 146 |
+| Total | 145 |
## account
@@ -153,7 +153,7 @@ Only top-level CLI commands are checked against main.go. Subcommand rows stay ha
| instances-updates | both | `instances set [--updates,--major,--pin]` | `POST /a/{sqid}/apps/{app}/instances/{host}/updates` | | |
| instances-update | both | `instances update` | `POST /a/{sqid}/apps/{app}/instances/{host}/updates/install` | | |
| instances-retry | both | `instances retry` | `POST /a/{sqid}/apps/{app}/instances/{host}/retry` | | |
-| steering | gap | `steering latency`<br>`steering off` | | [wp-instances](#wp-instances) | |
+| steering | gap | `steering` | | [wp-instances](#wp-instances) | |
| routes | partial | `routes` | `GET /a/{sqid}/apps/{app}/instances`<br>`GET /a/{sqid}/apps/{app}/settings/{section}` | | The console shows host and channel but no environment or replication column. |
| restart | partial | `restart` | `POST /a/{sqid}/apps/{app}/restart`<br>`POST /a/{sqid}/apps/{app}/instances/{host}/restart` | | The console has no environment scope and no dry-run list. |
| move | gap | `move`<br>`move status`<br>`move cut`<br>`move abort`<br>`move resolve [--retry]`<br>`move offline stage`<br>`move offline start`<br>`move offline seal`<br>`move offline flip`<br>`move offline open`<br>`move offline finish`<br>`move offline abort`<br>`move offline status` | | [wp-instances](#wp-instances) | Region moves; the instance page shows only that a move is running. |
@@ -195,7 +195,6 @@ Only top-level CLI commands are checked against main.go. Subcommand rows stay ha
| canary-retire | console-only | | `POST /a/{sqid}/apps/{app}/canary/retire` | | Retires the canary's channel and refuses while any host follows it. No CLI verb retires a channel: canary rm deletes the instance and leaves the channel. |
| channels | both | `channels` | `GET /a/{sqid}/apps/{app}/releases` | | |
| channels-resign | gap | `channels resign` | | [wp-settings](#wp-settings) | |
-| channels-digests | gap | `channels digests` | | [wp-settings](#wp-settings) | Shows whether channel pointers are digest-signed. |
| pipeline | both | `pipeline show`<br>`pipeline init`<br>`pipeline set`<br>`pipeline add`<br>`pipeline remove` | `GET /a/{sqid}/apps/{app}/pipeline`<br>`POST /a/{sqid}/apps/{app}/pipeline`<br>`GET /a/{sqid}/apps/{app}/settings/{section}` | | |
| releases | both | `releases` | `GET /a/{sqid}/apps/{app}/releases`<br>`GET /a/{sqid}/apps/{app}/deployments` | | |
| releases-retention | partial | `releases retention` | `GET /a/{sqid}/apps/{app}/releases` | | The console shows the keep count only; it cannot set it or do a dry run. |
@@ -264,7 +263,7 @@ Discussion #734.
- `instances-set-environment` (instances), CLI has `instances set-environment`
- `instances-set-assets` (instances), CLI has `instances set-assets`
- `instances-set-pages` (instances), CLI has `instances set-pages`
-- `steering` (instances), CLI has `steering latency`, `steering off`
+- `steering` (instances), CLI has `steering`
- `move` (instances), CLI has `move`, `move status`, `move cut`, `move abort`, `move resolve [--retry]`, `move offline stage`, `move offline start`, `move offline seal`, `move offline flip`, `move offline open`, `move offline finish`, `move offline abort`, `move offline status`
<a id="wp-settings"></a>
@@ -278,7 +277,6 @@ Discussion #735.
- `apps-copies` (apps), CLI has `apps set [--copies]`
- `apps-update-defaults` (apps), CLI has `apps set [--instance-control,--default-updates,--default-major,--default-channel]`
- `channels-resign` (releases), CLI has `channels resign`
-- `channels-digests` (releases), CLI has `channels digests`
- `version-target` (releases), CLI has `version target`
- `env-new-bundle` (config), CLI has `env set [--environment, new bundle]`
- `env-exec-delivery` (config), CLI has `env exec-delivery`
@@ -398,7 +396,8 @@ Discussion #742.
| op-billing | operator | `billing problems`<br>`billing close`<br>`billing house` | | Billing problems and house accounts. |
| op-instance-policy | operator | `apps set [--egress-allow,--size]`<br>`instances set [--size]` | | Instance policy is set by an operator. |
| op-upstreams | operator | `instances set-upstreams`<br>`instances create [--addr]` | | TCP backends are set by an operator. |
-| op-digests | operator | `channels digests on`<br>`channels digests off` | | The digest signing switch. |
+| op-digests | operator | `channels digests [on, off]` | | The digest signing switch. |
+| channels-digests | operator | `channels digests [report]` | | Operator only: the report needs a system operator (apiSystemRoller). Shows which channel pointers are digest-signed. |
| op-releases-authorize | operator | `releases authorize` | | Signs a promotion record for an old build. |
| op-relay-rotate | operator | `relay rotate` | | Rotates a region's relay master. |
| op-move-lost | operator | `move resolve [--declare-lost]` | | Declares a box lost in the middle of a move. |
@@ -425,7 +424,7 @@ Discussion #742.
| release-keygen | box | `release-keygen` | | Mints signing keys; the private key stays local. |
| proof | box | `proof keygen`<br>`proof get`<br>`proof put`<br>`proof history` | | Dev proofs a box needs to adopt. |
| relay-box | box | `relay serve`<br>`relay keygen` | | Runs the relay, or mints a region master key. |
-| system-box | box | `system apply`<br>`system files`<br>`system guard-arm`<br>`system guard-exec`<br>`system floor-allows-prev`<br>`system install-channel`<br>`system host-env`<br>`system named-units`<br>`system db-worker`<br>`system journal-migrate`<br>`system group-maintenance`<br>`system box publish-record` | | Root oneshots and units on a box. |
+| system-box | box | `system apply`<br>`system files`<br>`system guard-arm`<br>`system guard-exec`<br>`system floor-allows-prev`<br>`system exec-sandbox-allows-prev`<br>`system runsc-ensure`<br>`system install-channel`<br>`system host-env`<br>`system named-units`<br>`system db-worker`<br>`system journal-migrate`<br>`system group-maintenance`<br>`system box publish-record` | | Root oneshots and units on a box. |
| status-dry-run | box | `status [--dry-run]` | | A leak check against a fixture fleet, run locally. |
| devbox-serve | box | `devbox serve` | | The devbox service under systemd. |
diff --git a/internal/parity/cli.go b/internal/parity/cli.go
new file mode 100644
index 000000000..f715c53ea
--- /dev/null
+++ b/internal/parity/cli.go
@@ -0,0 +1,229 @@
+package parity
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "strings"
+)
+
+// CLIEntry is one line of parity/cli.tsv, the command tree's projection
+// (package main's TestCLIProjection writes it): one runnable command.
+// Tool is "" and Flags and Enums are nil where the file has "-".
+type CLIEntry struct {
+ ID string
+ Audience string
+ Tool string
+ Flags, Enums []string
+ Line int
+}
+
+// The audiences a command declares. Customer commands count towards
+// parity; the rest are outside it (spec D5).
+const (
+ AudienceCustomer = "customer"
+ AudienceOperator = "operator"
+ AudienceBoxLocal = "box-local"
+ AudienceInternal = "internal"
+)
+
+const cliHeader = "id\taudience\teffect\tscope\ttool\tflags\tenums"
+
+// cliFile is how problems against the projection name it.
+const cliFile = "parity/cli.tsv"
+
+// ParseCLI reads a command projection. Flags and enums are
+// comma-separated; "-" means none.
+func ParseCLI(r io.Reader) ([]CLIEntry, error) {
+ var out []CLIEntry
+ seen := map[string]int{}
+ err := lines(r, cliHeader, func(n int, line string) error {
+ f := strings.Split(line, "\t")
+ if len(f) != 7 {
+ return fmt.Errorf("want 7 tab-separated columns (%s), got %d", strings.ReplaceAll(cliHeader, "\t", ", "), len(f))
+ }
+ e := CLIEntry{ID: f[0], Audience: f[1], Line: n}
+ if msg := checkCLIMember(e.ID); msg != "" {
+ return fmt.Errorf("id %q: %s", e.ID, msg)
+ }
+ if prev, ok := seen[e.ID]; ok {
+ return fmt.Errorf("%s is already listed on line %d", e.ID, prev)
+ }
+ seen[e.ID] = n
+ switch e.Audience {
+ case AudienceCustomer, AudienceOperator, AudienceBoxLocal, AudienceInternal:
+ default:
+ return fmt.Errorf("%s: unknown audience %q", e.ID, e.Audience)
+ }
+ if f[4] != "-" {
+ e.Tool = f[4]
+ }
+ e.Flags, e.Enums = cliList(f[5]), cliList(f[6])
+ out = append(out, e)
+ return nil
+ })
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
+// cliList splits a flags or enums field; "-" is none.
+func cliList(field string) []string {
+ if field == "-" || field == "" {
+ return nil
+ }
+ var out []string
+ for _, s := range strings.Split(field, ",") {
+ if s = strings.TrimSpace(s); s != "" {
+ out = append(out, s)
+ }
+ }
+ return out
+}
+
+// LoadCLI reads the command projection at path (parity/cli.tsv).
+func LoadCLI(path string) ([]CLIEntry, error) {
+ f, err := os.Open(path)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ es, err := ParseCLI(f)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", path, err)
+ }
+ return es, nil
+}
+
+// entryProblem reports against the projection, not a row: RowID is empty
+// and Line is the entry's line in parity/cli.tsv.
+func entryProblem(e CLIEntry, format string, args ...any) Problem {
+ return Problem{Line: e.Line, Msg: fmt.Sprintf(format, args...)}
+}
+
+// CheckCLIPaths is spec D2 and D3. Every non-internal command in entries
+// is some row's CLI member; every row's CLI member is a command in
+// entries (a __ member an internal one). A qualifier component starting
+// with "-" names a flag the command declares, once it declares any.
+func CheckCLIPaths(rows []Row, entries []CLIEntry) []Problem {
+ var probs []Problem
+ byID := map[string]CLIEntry{}
+ for _, e := range entries {
+ byID[e.ID] = e
+ }
+ named := map[string]bool{}
+ for _, r := range rows {
+ for _, m := range r.CLI {
+ named[m.Text] = true
+ e, ok := byID[m.Text]
+ switch {
+ case !ok && strings.HasPrefix(m.Text, "__"):
+ probs = append(probs, rowProblem(r, "CLI member %q is not a plumbing word the binary runs (%s); remove it or fix the spelling", m.String(), cliFile))
+ continue
+ case !ok:
+ probs = append(probs, rowProblem(r, "CLI member %q is not a command the binary runs (%s); name a command as the tree has it, with any mode or argument in a [qualifier]", m.String(), cliFile))
+ continue
+ case strings.HasPrefix(m.Text, "__") && e.Audience != AudienceInternal:
+ probs = append(probs, rowProblem(r, "CLI member %q starts with __ but is not an internal command in %s", m.String(), cliFile))
+ }
+ for _, flag := range undeclaredFlags(m.Qualifier, e.Flags) {
+ probs = append(probs, rowProblem(r, "CLI member %q: %s does not declare the flag %s; name a declared flag or drop it from the qualifier", m.String(), e.ID, flag))
+ }
+ }
+ }
+ for _, e := range entries {
+ if e.Audience == AudienceInternal || named[e.ID] {
+ continue
+ }
+ probs = append(probs, entryProblem(e, "the binary runs `%s` (%s) but no row in parity/parity.tsv names it: add it to a row, or add a row", e.ID, e.Audience))
+ }
+ return probs
+}
+
+// undeclaredFlags returns the components of qual that look like flags
+// (start with "-") and are not in declared. With no declared flags the
+// command has no argument model yet and nothing is checked.
+func undeclaredFlags(qual string, declared []string) []string {
+ if qual == "" || len(declared) == 0 {
+ return nil
+ }
+ have := map[string]bool{}
+ for _, f := range declared {
+ have[strings.TrimLeft(f, "-")] = true
+ }
+ var out []string
+ for _, c := range strings.Split(qual, ",") {
+ c = strings.TrimSpace(c)
+ if strings.HasPrefix(c, "-") && !have[strings.TrimLeft(c, "-")] {
+ out = append(out, c)
+ }
+ }
+ return out
+}
+
+// CheckCLIAudience is spec D5: a customer command is in at least one row
+// with a customer status; an operator, box-local or internal command is
+// only in rows with outside statuses (which one is the row's call).
+func CheckCLIAudience(rows []Row, entries []CLIEntry) []Problem {
+ var probs []Problem
+ byID := map[string]CLIEntry{}
+ for _, e := range entries {
+ byID[e.ID] = e
+ }
+ inCustomer := map[string]bool{}
+ for _, r := range rows {
+ for _, m := range r.CLI {
+ e, ok := byID[m.Text]
+ if !ok {
+ continue // CheckCLIPaths reports it
+ }
+ if r.Status.Customer() {
+ inCustomer[e.ID] = true
+ if e.Audience != AudienceCustomer {
+ probs = append(probs, rowProblem(r, "CLI member %q has audience %s, so it cannot be in a %s row; move it to a row with an outside status (operator, box-local, internal)", m.String(), e.Audience, r.Status))
+ }
+ }
+ }
+ }
+ for _, e := range entries {
+ if e.Audience == AudienceCustomer && !inCustomer[e.ID] {
+ probs = append(probs, entryProblem(e, "`%s` is a customer command but no row with a customer status (both, partial, gap, cli-only) names it", e.ID))
+ }
+ }
+ return probs
+}
+
+// MCPColumn returns what row r's mcp column must hold: the tool names of
+// its CLI members' commands, in member order, each once, joined by
+// commas; "" when none has a tool.
+func MCPColumn(r Row, entries []CLIEntry) string {
+ tool := map[string]string{}
+ for _, e := range entries {
+ tool[e.ID] = e.Tool
+ }
+ var out []string
+ seen := map[string]bool{}
+ for _, m := range r.CLI {
+ if t := tool[m.Text]; t != "" && !seen[t] {
+ seen[t] = true
+ out = append(out, t)
+ }
+ }
+ return strings.Join(out, ",")
+}
+
+// CheckMCPColumn is spec D4: every row's mcp column equals MCPColumn.
+func CheckMCPColumn(rows []Row, entries []CLIEntry) []Problem {
+ var probs []Problem
+ for _, r := range rows {
+ if want := MCPColumn(r, entries); r.MCP != want {
+ probs = append(probs, rowProblem(r, "mcp column is %q, want %q (the tools of its CLI members in %s)", r.MCP, want, cliFile))
+ }
+ }
+ return probs
+}
+
+func rowProblem(r Row, format string, args ...any) Problem {
+ return Problem{Line: r.Line, RowID: r.ID, Msg: fmt.Sprintf(format, args...)}
+}
diff --git a/internal/parity/cli_test.go b/internal/parity/cli_test.go
new file mode 100644
index 000000000..c9f87bacc
--- /dev/null
+++ b/internal/parity/cli_test.go
@@ -0,0 +1,184 @@
+package parity
+
+import (
+ "strings"
+ "testing"
+)
+
+// entry is one line of a cli.tsv fixture: id, audience, tool, flags, with
+// "-" for none as in the real file.
+func entry(id, audience, tool, flags string) string {
+ return strings.Join([]string{id, audience, "-", "-", tool, flags, "-"}, "\t")
+}
+
+func mustParseCLI(t *testing.T, lines ...string) []CLIEntry {
+ t.Helper()
+ es, err := ParseCLI(strings.NewReader("# fixture\n" + cliHeader + "\n" + strings.Join(lines, "\n") + "\n"))
+ if err != nil {
+ t.Fatalf("ParseCLI: %v", err)
+ }
+ return es
+}
+
+// wantEntryProblem asserts one projection problem (no row) contains every
+// fragment.
+func wantEntryProblem(t *testing.T, probs []Problem, fragments ...string) {
+ t.Helper()
+ for _, p := range probs {
+ if p.RowID != "" {
+ continue
+ }
+ ok := true
+ for _, f := range fragments {
+ ok = ok && strings.Contains(p.Msg, f)
+ }
+ if ok {
+ if !strings.HasPrefix(p.String(), "parity/cli.tsv:") {
+ t.Fatalf("String() %q does not name parity/cli.tsv", p.String())
+ }
+ return
+ }
+ }
+ t.Fatalf("no projection problem containing %q; got %v", fragments, probs)
+}
+
+func cliRows(t *testing.T, lines ...string) []Row {
+ t.Helper()
+ return mustParse(t, tsv(lines...))
+}
+
+func TestParseCLI(t *testing.T) {
+ es := mustParseCLI(t,
+ entry("__demo-snapshot", "internal", "-", "-"),
+ entry("apps set", "customer", "apps_set", "--swap,--copies"),
+ )
+ if len(es) != 2 || es[0].ID != "__demo-snapshot" || es[0].Tool != "" || es[0].Flags != nil || es[0].Line != 3 {
+ t.Fatalf("first entry = %+v", es[0])
+ }
+ if es[1].Tool != "apps_set" || strings.Join(es[1].Flags, " ") != "--swap --copies" || es[1].Audience != AudienceCustomer {
+ t.Fatalf("second entry = %+v", es[1])
+ }
+}
+
+func TestParseCLIErrors(t *testing.T) {
+ for name, src := range map[string]string{
+ "header": "id\taudience\n",
+ "columns": cliHeader + "\napps list\tcustomer\n",
+ "audience": cliHeader + "\n" + entry("apps list", "staff", "-", "-") + "\n",
+ "duplicate": cliHeader + "\n" + entry("apps list", "customer", "-", "-") + "\n" + entry("apps list", "customer", "-", "-") + "\n",
+ "shape": cliHeader + "\n" + entry("Apps list", "customer", "-", "-") + "\n",
+ } {
+ t.Run(name, func(t *testing.T) {
+ if _, err := ParseCLI(strings.NewReader(src)); err == nil {
+ t.Fatal("ParseCLI succeeded, want an error")
+ }
+ })
+ }
+}
+
+// A leaf whose row is removed fails even though its parent's row stays
+// (the R3-2 case).
+func TestCLIPathsLeafRowRemoved(t *testing.T) {
+ es := mustParseCLI(t,
+ entry("move", "customer", "-", "-"),
+ entry("move status", "customer", "-", "-"),
+ )
+ rows := cliRows(t, row("move", "instances", "gap", "move", "", "wp-instances", "", ""))
+ wantEntryProblem(t, CheckCLIPaths(rows, es), "`move status`", "no row")
+ rows = cliRows(t, row("move", "instances", "gap", "move ; move status", "", "wp-instances", "", ""))
+ wantClean(t, CheckCLIPaths(rows, es))
+}
+
+// A row naming a command the tree does not have fails (the R3-3 case).
+func TestCLIPathsUnknownCommand(t *testing.T) {
+ es := mustParseCLI(t, entry("apps source pull", "customer", "-", "-"))
+ rows := cliRows(t,
+ row("pull", "apps", "both", "apps source pull", "GET /x", "", "", ""),
+ row("del", "apps", "cli-only", "apps source delete", "", "", "", "why"),
+ )
+ wantProblem(t, CheckCLIPaths(rows, es), "del", `"apps source delete"`, "not a command")
+}
+
+func TestCLIPathsInternal(t *testing.T) {
+ es := mustParseCLI(t,
+ entry("__demo-snapshot", "internal", "-", "-"),
+ entry("apps list", "customer", "-", "-"),
+ )
+ rows := cliRows(t,
+ row("apps", "apps", "cli-only", "apps list", "", "", "", "why"),
+ row("plumbing", "platform", "internal", "__demo-snapshot ; __does-not-exist", "", "", "", "why"),
+ )
+ probs := CheckCLIPaths(rows, es)
+ wantProblem(t, probs, "plumbing", `"__does-not-exist"`, "plumbing word")
+ if len(probs) != 1 {
+ t.Fatalf("want only the __does-not-exist problem, got %v", probs)
+ }
+ // An internal command needs no row.
+ wantClean(t, CheckCLIPaths(rows[:1], es))
+}
+
+func TestCLIPathsQualifierFlags(t *testing.T) {
+ declared := mustParseCLI(t, entry("env set", "customer", "-", "--environment,--app"))
+ mixed := cliRows(t,
+ row("env", "config", "both", "env set [--environment, existing bundle]", "GET /x", "", "", ""),
+ row("env-new", "config", "gap", "env set [--environment, new bundle]", "", "wp-instances", "", ""),
+ )
+ wantClean(t, CheckCLIPaths(mixed, declared))
+
+ bad := cliRows(t, row("env", "config", "cli-only", "env set [--bundle, new bundle]", "", "", "", "why"))
+ wantProblem(t, CheckCLIPaths(bad, declared), "env", `"env set [--bundle, new bundle]"`, "--bundle")
+
+ // No declared flags yet: the command has no argument model, so flag
+ // components are not checked.
+ undeclared := mustParseCLI(t, entry("env set", "customer", "-", "-"))
+ wantClean(t, CheckCLIPaths(bad, undeclared))
+}
+
+// The status leaf is operator; its flag-selected modes sit in two outside
+// statuses, which is the rows' call (spec D5).
+func TestCLIAudienceStatusRows(t *testing.T) {
+ es := mustParseCLI(t, entry("status", "operator", "-", "-"))
+ rows := cliRows(t,
+ row("op-architecture", "operator", "operator", "status [--instances,--layout]", "GET /fleet/boxes", "", "", "why"),
+ row("op-status-live", "operator", "operator", "status [--live]", "GET /fleet/boxes", "", "", "why"),
+ row("status-dry-run", "box", "box-local", "status [--dry-run]", "", "", "", "why"),
+ )
+ wantClean(t, CheckCLIAudience(rows, es))
+ wantClean(t, CheckCLIPaths(rows, es))
+ wantClean(t, Check(rows, testPkgs))
+}
+
+func TestCLIAudienceCustomerOnlyInOperatorRow(t *testing.T) {
+ es := mustParseCLI(t, entry("apps set", "customer", "-", "-"))
+ rows := cliRows(t, row("op", "operator", "operator", "apps set [--size]", "", "", "", "why"))
+ wantEntryProblem(t, CheckCLIAudience(rows, es), "`apps set`", "customer")
+ rows = cliRows(t,
+ row("op", "operator", "operator", "apps set [--size]", "", "", "", "why"),
+ row("swap", "apps", "cli-only", "apps set [--swap]", "", "", "", "why"),
+ )
+ wantClean(t, CheckCLIAudience(rows, es))
+}
+
+func TestCLIAudienceOperatorInCustomerRow(t *testing.T) {
+ es := mustParseCLI(t, entry("apps show", "operator", "-", "-"))
+ rows := cliRows(t, row("show", "apps", "both", "apps show", "GET /x", "", "", ""))
+ wantProblem(t, CheckCLIAudience(rows, es), "show", `"apps show"`, "operator", "both")
+}
+
+func TestMCPColumn(t *testing.T) {
+ es := mustParseCLI(t,
+ entry("gate set", "customer", "gate_set", "-"),
+ entry("gate clear", "customer", "-", "-"),
+ entry("gate list", "customer", "gate_list", "-"),
+ )
+ good := cliRows(t, row("gate", "domains", "cli-only", "gate set ; gate clear ; gate list", "", "", "gate_set,gate_list", "why"))
+ wantClean(t, CheckMCPColumn(good, es))
+ stale := cliRows(t, row("gate", "domains", "cli-only", "gate set ; gate clear ; gate list", "", "", "gate_set", "why"))
+ wantProblem(t, CheckMCPColumn(stale, es), "gate", `want "gate_set,gate_list"`)
+
+ none := mustParseCLI(t, entry("gate set", "customer", "-", "-"))
+ empty := cliRows(t, row("gate", "domains", "cli-only", "gate set", "", "", "", "why"))
+ wantClean(t, CheckMCPColumn(empty, none))
+ filled := cliRows(t, row("gate", "domains", "cli-only", "gate set", "", "", "gate_set", "why"))
+ wantProblem(t, CheckMCPColumn(filled, none), "gate", `want ""`)
+}
diff --git a/internal/parity/page.go b/internal/parity/page.go
index 947180407..fd2d04685 100644
--- a/internal/parity/page.go
+++ b/internal/parity/page.go
@@ -27,7 +27,7 @@ func Render(rows []Row, pkgs []Package) []byte {
}
p("## Counts\n\n")
p("Only customer rows are counted. Rows outside customer parity appear at the end.\n\n")
- p("Only top-level CLI commands are checked against main.go. Subcommand rows stay hand-maintained until slice 4's registry.\n\n")
+ p("CLI rows are checked against the command registry (`parity/cli.tsv`).\n\n")
p("| Status | Rows |\n|---|---:|\n")
for _, s := range customerStatuses {
p("| %s | %d |\n", s, counts[s])
diff --git a/internal/parity/page_test.go b/internal/parity/page_test.go
index d66ad65af..806f7f28e 100644
--- a/internal/parity/page_test.go
+++ b/internal/parity/page_test.go
@@ -46,10 +46,10 @@ func TestRenderCountsCustomerOnly(t *testing.T) {
if strings.Contains(counts, "auth") || strings.Contains(counts, "internal") {
t.Errorf("counts include a non-customer status:\n%s", counts)
}
- line := "Only top-level CLI commands are checked against main.go. Subcommand rows stay hand-maintained until slice 4's registry."
+ line := "CLI rows are checked against the command registry (`parity/cli.tsv`)."
i, j := strings.Index(counts, line), strings.Index(counts, "| Status |")
if i < 0 || j < 0 || i > j {
- t.Errorf("the slice 4 line is not above the counts table:\n%s", counts)
+ t.Errorf("the registry line is not above the counts table:\n%s", counts)
}
}
diff --git a/internal/parity/repo_test.go b/internal/parity/repo_test.go
index 998244f4d..2e48040bd 100644
--- a/internal/parity/repo_test.go
+++ b/internal/parity/repo_test.go
@@ -3,10 +3,7 @@ package parity
import (
"bytes"
"os"
- "strings"
"testing"
-
- "github.com/carlosframework/platform/internal/docsite"
)
// The checked-in table, its packages and its page, read by the tests
@@ -50,40 +47,45 @@ func TestParityTableIsValid(t *testing.T) {
}
}
-// TestParityCLITopLevel is spec C5: every top-level command the binary
-// dispatches (the first words of parity/cli.tsv, internal ones aside)
-// starts some row's CLI member, and every CLI member starts with one of
-// them, except the __ plumbing words, which Check holds to shape only.
-func TestParityCLITopLevel(t *testing.T) {
- rows, _ := loadRepo(t)
- words, err := docsite.TopLevelNames(repoCLI)
+func loadRepoCLI(t *testing.T) []CLIEntry {
+ t.Helper()
+ es, err := LoadCLI(repoCLI)
if err != nil {
t.Fatal(err)
}
- if len(words) == 0 {
- t.Fatal("docsite.TopLevelNames found no commands in parity/cli.tsv")
+ if len(es) < 100 {
+ t.Fatalf("parity/cli.tsv lists %d commands, want at least 100; run make parity-doc", len(es))
}
- dispatched := map[string]bool{}
- for _, w := range words {
- dispatched[w] = true
+ return es
+}
+
+// TestParityCLIPaths is registry spec D2 and D3: every command the binary
+// runs (parity/cli.tsv, internal ones aside) is some row's CLI member,
+// every CLI member is a command it runs, and flags in qualifiers are
+// flags the command declares.
+func TestParityCLIPaths(t *testing.T) {
+ rows, _ := loadRepo(t)
+ for _, p := range CheckCLIPaths(rows, loadRepoCLI(t)) {
+ t.Error(p)
}
- first := map[string]bool{}
- for _, r := range rows {
- for _, m := range r.CLI {
- w, _, _ := strings.Cut(m.Text, " ")
- first[w] = true
- if strings.HasPrefix(w, "__") {
- continue
- }
- if !dispatched[w] {
- t.Errorf("parity/parity.tsv:%d: row %s: `%s` is not a command the binary dispatches (parity/cli.tsv)", r.Line, r.ID, w)
- }
- }
+}
+
+// TestParityCLIAudience is registry spec D5: customer commands are in a
+// customer row, operator, box-local and internal ones only in outside
+// rows.
+func TestParityCLIAudience(t *testing.T) {
+ rows, _ := loadRepo(t)
+ for _, p := range CheckCLIAudience(rows, loadRepoCLI(t)) {
+ t.Error(p)
}
- for _, w := range words {
- if !first[w] {
- t.Errorf("the binary dispatches `%s` but no row's CLI member starts with it: add a row", w)
- }
+}
+
+// TestParityMCPColumn is registry spec D4: each row's mcp column is the
+// tools of its CLI members.
+func TestParityMCPColumn(t *testing.T) {
+ rows, _ := loadRepo(t)
+ for _, p := range CheckMCPColumn(rows, loadRepoCLI(t)) {
+ t.Error(p)
}
}
diff --git a/internal/parity/rules.go b/internal/parity/rules.go
index 3a73c7830..a6a3e2e71 100644
--- a/internal/parity/rules.go
+++ b/internal/parity/rules.go
@@ -13,8 +13,12 @@ type Problem struct {
RowID, Msg string
}
-// String names the file, line and row, then says what to fix.
+// String names the file, line and row, then says what to fix. A problem
+// with no row is against the command projection, parity/cli.tsv.
func (p Problem) String() string {
+ if p.RowID == "" {
+ return fmt.Sprintf("%s:%d: %s", cliFile, p.Line, p.Msg)
+ }
return fmt.Sprintf("parity/parity.tsv:%d: row %s: %s", p.Line, p.RowID, p.Msg)
}
diff --git a/internal/parity/table.go b/internal/parity/table.go
index abc0b6edf..0ecbeb9d4 100644
--- a/internal/parity/table.go
+++ b/internal/parity/table.go
@@ -141,7 +141,8 @@ func lines(r io.Reader, header string, fn func(n int, line string) error) error
}
// Parse reads a parity table. It checks syntax only (columns, id and area
-// shape, member syntax, an empty mcp column); Check applies the rules.
+// shape, member syntax); Check applies the rules, and CheckMCPColumn holds
+// the mcp column to the command projection.
func Parse(r io.Reader) ([]Row, error) {
var rows []Row
err := lines(r, tableHeader, func(n int, line string) error {
@@ -156,9 +157,6 @@ func Parse(r io.Reader) ([]Row, error) {
if !areaRE.MatchString(row.Area) {
return fmt.Errorf("row %s: area %q must be lower-case letters and hyphens, starting with a letter", row.ID, row.Area)
}
- if row.MCP != "" {
- return fmt.Errorf("row %s: the mcp column must be empty for now", row.ID)
- }
var err error
if row.CLI, err = parseMembers(f[3]); err != nil {
return fmt.Errorf("row %s: cli: %w", row.ID, err)
diff --git a/internal/parity/table_test.go b/internal/parity/table_test.go
index afee74730..1e107da41 100644
--- a/internal/parity/table_test.go
+++ b/internal/parity/table_test.go
@@ -99,8 +99,11 @@ func TestParseBadMembers(t *testing.T) {
}
}
-func TestParseMCPMustBeEmpty(t *testing.T) {
- parseErr(t, tsv(row("x", "apps", "cli-only", "apps", "", "", "apps_list", "why")), "mcp")
+func TestParseKeepsMCP(t *testing.T) {
+ rows := mustParse(t, tsv(row("x", "apps", "cli-only", "apps", "", "", "apps_list", "why")))
+ if rows[0].MCP != "apps_list" {
+ t.Fatalf("MCP = %q, want apps_list", rows[0].MCP)
+ }
}
func TestParseBadIDAndArea(t *testing.T) {
diff --git a/parity/README.md b/parity/README.md
index 81968388b..e25bb44d8 100644
--- a/parity/README.md
+++ b/parity/README.md
@@ -2,6 +2,6 @@
`parity.tsv` lists every CLI command and console route, one row per capability, with its status (`both`, `partial`, `gap`, `cli-only`, `console-only`, or a status outside customer parity). `packages.tsv` lists the work packages that close the `gap` rows.
-The rule: a branch that adds a CLI command or subcommand, or a console route declaration, adds its row here in the same branch. Tests in `internal/parity` and `internal/console` fail when the table and the code disagree.
+The rule: a branch that adds a CLI command or subcommand, or a console route declaration, adds its row here in the same branch. Tests in `internal/parity` and `internal/console` fail when the table and the code disagree. A word that selects code is a `clireg` node with its row here; a leaf never compares an argument to a word that picks different behaviour. The CLI rows are checked against `cli.tsv`, the command registry's projection.
After editing either file, run `make parity-doc` to regenerate `docs/parity.md`.
diff --git a/parity/parity.tsv b/parity/parity.tsv
index bb8613896..5354217d6 100644
--- a/parity/parity.tsv
+++ b/parity/parity.tsv
@@ -39,7 +39,6 @@ canary-rm releases gap canary rm wp-instances Deletes the canary's instance an
canary-retire releases console-only POST /a/{sqid}/apps/{app}/canary/retire Retires the canary's channel and refuses while any host follows it. No CLI verb retires a channel: canary rm deletes the instance and leaves the channel.
channels releases both channels GET /a/{sqid}/apps/{app}/releases
channels-resign releases gap channels resign wp-settings
-channels-digests releases gap channels digests wp-settings Shows whether channel pointers are digest-signed.
pipeline releases both pipeline show ; pipeline init ; pipeline set ; pipeline add ; pipeline remove GET /a/{sqid}/apps/{app}/pipeline ; POST /a/{sqid}/apps/{app}/pipeline ; GET /a/{sqid}/apps/{app}/settings/{section}
releases releases both releases GET /a/{sqid}/apps/{app}/releases ; GET /a/{sqid}/apps/{app}/deployments
releases-retention releases partial releases retention GET /a/{sqid}/apps/{app}/releases The console shows the keep count only; it cannot set it or do a dry run.
@@ -72,7 +71,7 @@ instances-set-pages instances gap instances set-pages wp-instances Page cachin
instances-updates instances both instances set [--updates,--major,--pin] POST /a/{sqid}/apps/{app}/instances/{host}/updates
instances-update instances both instances update POST /a/{sqid}/apps/{app}/instances/{host}/updates/install
instances-retry instances both instances retry POST /a/{sqid}/apps/{app}/instances/{host}/retry
-steering instances gap steering latency ; steering off wp-instances
+steering instances gap steering wp-instances
routes instances partial routes GET /a/{sqid}/apps/{app}/instances ; GET /a/{sqid}/apps/{app}/settings/{section} The console shows host and channel but no environment or replication column.
restart instances partial restart POST /a/{sqid}/apps/{app}/restart ; POST /a/{sqid}/apps/{app}/instances/{host}/restart The console has no environment scope and no dry-run list.
move instances gap move ; move status ; move cut ; move abort ; move resolve [--retry] ; move offline stage ; move offline start ; move offline seal ; move offline flip ; move offline open ; move offline finish ; move offline abort ; move offline status wp-instances Region moves; the instance page shows only that a move is running.
@@ -198,7 +197,8 @@ op-accounts-migrate operator operator accounts migrate A one-off migration of
op-billing operator operator billing problems ; billing close ; billing house Billing problems and house accounts.
op-instance-policy operator operator apps set [--egress-allow,--size] ; instances set [--size] Instance policy is set by an operator.
op-upstreams operator operator instances set-upstreams ; instances create [--addr] TCP backends are set by an operator.
-op-digests operator operator channels digests on ; channels digests off The digest signing switch.
+op-digests operator operator channels digests [on, off] The digest signing switch.
+channels-digests operator operator channels digests [report] Operator only: the report needs a system operator (apiSystemRoller). Shows which channel pointers are digest-signed.
op-releases-authorize operator operator releases authorize Signs a promotion record for an old build.
op-relay-rotate operator operator relay rotate Rotates a region's relay master.
op-move-lost operator operator move resolve [--declare-lost] Declares a box lost in the middle of a move.
@@ -222,7 +222,7 @@ box-ops box box-local ops litestream ; ops restore-verify ; ops hibernate-verify
release-keygen box box-local release-keygen Mints signing keys; the private key stays local.
proof box box-local proof keygen ; proof get ; proof put ; proof history Dev proofs a box needs to adopt.
relay-box box box-local relay serve ; relay keygen Runs the relay, or mints a region master key.
-system-box box box-local system apply ; system files ; system guard-arm ; system guard-exec ; system floor-allows-prev ; system install-channel ; system host-env ; system named-units ; system db-worker ; system journal-migrate ; system group-maintenance ; system box publish-record Root oneshots and units on a box.
+system-box box box-local system apply ; system files ; system guard-arm ; system guard-exec ; system floor-allows-prev ; system exec-sandbox-allows-prev ; system runsc-ensure ; system install-channel ; system host-env ; system named-units ; system db-worker ; system journal-migrate ; system group-maintenance ; system box publish-record Root oneshots and units on a box.
status-dry-run box box-local status [--dry-run] A leak check against a fixture fleet, run locally.
devbox-serve box box-local devbox serve The devbox service under systemd.