package docsite import "testing" // mainFile is the CLI's dispatch, relative to this package. const mainFile = "../../main.go" // cliPage is the page that must document all of it. const cliPage = "cli" // TestTopLevelCommandsReadsTheDispatch checks the scanner before the // gate that depends on it. A scanner that silently returns nothing // turns the gate below into a test that always passes. func TestTopLevelCommandsReadsTheDispatch(t *testing.T) { cmds, err := TopLevelCommands(mainFile) if err != nil { t.Fatalf("scan: %v", err) } if len(cmds) < 20 { t.Fatalf("found %d commands (%v) — the scanner is broken, not the docs", len(cmds), cmds) } for _, want := range []string{"ship", "promote", "deploy", "domains", "logs", "fleets"} { if !contains(cmds, want) { t.Errorf("scanner missed the %q command", want) } } for _, unwanted := range []string{"-h", "--help", ""} { if contains(cmds, unwanted) { t.Errorf("scanner kept %q, which is not a command", unwanted) } } } func contains(xs []string, s string) bool { for _, x := range xs { if x == s { return true } } return false } // TestCLICommandsAreDocumented is the gate. It reads the dispatch // switch rather than the usage text on purpose: usage text is prose // someone can forget to update, so gating against it would only prove // the docs match a second copy of the docs. The switch is the CLI. // // It asks for a HEADING, not a substring of the body, and that is not // a stylistic preference. A substring check is defeated by prefixes: // "route" is a prefix of "routes", so the literal text "carlos routes" // anywhere on the page satisfies a Contains check for "route" — the // whole `### carlos route` section can be deleted with every test // still green (a reviewer did exactly that, 2026-08-25). The same // check also counts a mention inside another command's example fence, // or in a link, as documentation. A heading is the thing a reader can // actually land on, and `#carlos-route` and `#carlos-routes` are // distinct anchors. Do not "simplify" this back to Contains. func TestCLICommandsAreDocumented(t *testing.T) { site, err := Load(root) if err != nil { t.Fatalf("load: %v", err) } page, ok := site.BySlug[cliPage] if !ok { t.Fatalf("no %s page — every command has to be documented somewhere", cliPage) } cmds, err := TopLevelCommands(mainFile) if err != nil { t.Fatalf("scan: %v", err) } for _, cmd := range cmds { if !hasAnchor(page, Anchor("carlos "+cmd)) { t.Errorf("%s.md has no heading for %q (expected a heading anchoring #%s)", cliPage, cmd, Anchor("carlos "+cmd)) } } }