Repository navigation
docs: inherit feature states from ancestor routes in the docs sidebar - #31481
coder[bot] wants to merge 5 commits into
Conversation
nickvigilante
left a comment
There was a problem hiding this comment.
Can we move AI Governance to be at the top level, as a sibling of ai-coder/ and immediately following it instead of as a child of ai-coder/?
Reviewed the Go changes in scripts/docsmanifestgen. The repeated-state check is correct on the PR tree: tests and golangci-lint pass, and adding state: [premium] to ai-gateway.yml fails check against the AI Governance ancestor, as expected. All inline comments are non-blocking. These tests run only on Linux in CI. go vet passes for Windows and macOS (GOOS=windows and GOOS=darwin), and a manual check with Windows line endings (CRLF) behaved correctly.
🤖 Review generated with Coder Agents on behalf of @nickvigilante.
There was a problem hiding this comment.
For the sections you've added to this doc, can you make it one sentence per line per the style guide?
| Follow these rules: | ||
|
|
||
| 1. Put the state on the highest route it applies to. | ||
| For a Premium feature with several pages, set `state: [premium]` on the |
There was a problem hiding this comment.
No hard wrap at 72 characters in any Markdown file anywhere in this repo. Don't change lines that weren't part of the existing diff; I'll handle that separately. Just don't hard wrap any new lines.
| } | ||
|
|
||
| func checkStateRoute(dir, name string, r docgenenv.Route, crumb []string, inherited map[string]stateOrigin, seen map[string]bool, errs *[]error) { | ||
| crumb = append(crumb[:len(crumb):len(crumb)], r.Title) |
There was a problem hiding this comment.
Nit: docgenenv does this same copy-on-append as append(slices.Clip(crumb), r.Title) (scripts/docgenenv/sources.go lines 154, 243, 264, and 330).
Matching it reads more clearly than the three-index slice.
There's no suggestion block because the change also needs a slices import.
| if _, err := docgenenv.BuildManifest(sourcesDir, *docsDir); err != nil { | ||
| errs = append(errs, err) | ||
| } | ||
| errs = append(errs, repeatedStates(sourcesDir)...) |
There was a problem hiding this comment.
This runs the second include walker even when BuildManifest has already rejected the tree.
repeatedStates resolves includes with path.Clean, not the loader's sourceRel, so on an invalid tree it follows paths the loader refuses.
I tried this in a temp tree with include: ../outside.yml.
BuildManifest rejects the path, but repeatedStates still decodes the file outside the sources directory and reports a state error for it.
On an include cycle, the per-section seen map is the only thing that stops unbounded recursion, and no test case covers it.
If the walker runs only after BuildManifest succeeds, it sees only trees where every include is local, a .yml file, and used once.
I applied this locally: go test ./scripts/docsmanifestgen/ and docsmanifestgen check on the PR tree both still pass.
The cost is that state errors show up only after structural errors are fixed.
If you take it, update the last sentence of the repeatedStates doc comment, and seen can go.
If you'd rather report both in one run, move the walker into docgenenv so it can reuse sourceRel, and add an include-cycle case to TestRepeatedStates.
| if _, err := docgenenv.BuildManifest(sourcesDir, *docsDir); err != nil { | |
| errs = append(errs, err) | |
| } | |
| errs = append(errs, repeatedStates(sourcesDir)...) | |
| if _, err := docgenenv.BuildManifest(sourcesDir, *docsDir); err != nil { | |
| errs = append(errs, err) | |
| } else { | |
| errs = append(errs, repeatedStates(sourcesDir)...) | |
| } |
| func checkStateRoute(dir, name string, r docgenenv.Route, crumb []string, inherited map[string]stateOrigin, seen map[string]bool, errs *[]error) { | ||
| crumb = append(crumb[:len(crumb):len(crumb)], r.Title) | ||
| where := strings.Join(crumb, " > ") | ||
| own := make(map[string]stateOrigin, len(inherited)+len(r.State)) |
There was a problem hiding this comment.
Nit: own holds the inherited states plus this route's, and it's what each child receives as inherited.
A name like states would match what it holds better than own, which reads as this route's states only.
| *errs = append(*errs, xerrors.Errorf("%s: %s: state %q is already set on ancestor %q in %s; remove it, because a route inherits its ancestors' states", name, where, s, o.crumb, o.file)) | ||
| continue | ||
| } | ||
| own[s] = stateOrigin{file: name, crumb: where} |
There was a problem hiding this comment.
Optional: state: [beta, beta] on a single route passes, because only inherited is checked.
That's outside the ancestor rule, so take it or leave it.
own already holds the inherited values, so a hit after the inherited check means this route lists the value twice.
I applied this locally with a StateListedTwiceOnOneRoute table case (state: [beta, beta] on Home, want home.yml: Home: state "beta" is listed more than once).
The package tests, docsmanifestgen check on the PR tree, and golangci-lint all pass.
| own[s] = stateOrigin{file: name, crumb: where} | |
| if _, ok := own[s]; ok { | |
| *errs = append(*errs, xerrors.Errorf("%s: %s: state %q is listed more than once", name, where, s)) | |
| continue | |
| } | |
| own[s] = stateOrigin{file: name, crumb: where} |
A route's state applies to all of its descendants, so a descendant that repeats an ancestor's state is redundant. docsmanifestgen check now reports each such route with its file, breadcrumb, and the ancestor that already sets the state.
Add a Feature states section to contributing/documentation.md with the inheritance rules, a YAML example of a Premium parent with an early access child, and what the sidebar and the page title show for each route. Link to it from the content guidelines.
Run repeatedStates only when BuildManifest succeeds, so it no longer needs to tolerate undecodable files or guard against repeated includes. Use slices.Clip for copy-on-append, rename the per-route state map, and report a state listed more than once on the same route.
AI Governance sets state: [premium], and External provisioners sets it on its own route, so their descendants inherit it. Remove the repeated values that docsmanifestgen check now rejects.
a797f59 to
1439340
Compare
|
Closing and reopening under a human author, as required for this repository. |
Summary
A feature
stateindocs/manifest/now applies to a route and all its descendants, so each state is set once on the highest route it applies to.docsmanifestgen checkrejects a route that repeats an ancestor's state, and the repeated states onmainare removed.State model
Changes
docsmanifestgen check(make lint/docs-manifest) fails when a route repeats an ancestor's state, following include files and overlays, or lists a state twice.It runs only after the manifest builds cleanly.
Table-driven tests in
scripts/docsmanifestgen/state_test.go.state: [premium]on AI Governance and External provisioners only.Remove the 27 states their descendants repeat in
docs/manifest/ai-governance/**anddocs/manifest/install/operate/provisioners.yml, and regeneratedocs/manifest.json.contributing/documentation.md(new "Feature states" section with a YAML example),docs/.style/content-guidelines.md, and the doc-check skill.Important
Inherited pills under the page title and the new sidebar behavior need the matching docs-engine change (DOCS-1440).
Merge this after that ships, or child pages show no state pill until it does.
Testing
go test ./scripts/docsmanifestgen/... ./scripts/docgenenv/...golangci-lint run ./scripts/docsmanifestgen/...GOOS=windowsandGOOS=darwingo vet ./scripts/docsmanifestgen/make lint/docs-manifest,make lint/markdown,make lint/docs-redirectsmake gen/docs-manifestleaves the tree clean.Decision log: rebase onto main after #31645
ai-coder/...redirects.That covered this PR's move commits, link and URL updates, and redirects, which caused the conflicts.
main: the two move commits were dropped, and the four state-tooling and guidance commits were cherry-picked.The manifest cleanup was redone as a new commit against
main's layout, using the new lint's output as the list of repeated states.state: [premium, beta]and no child states, so it needs no change.content-guidelines.mdand the doc-check skill were resolved to keepmain's newer text (Vale word-choice updates and relative redirect syntax) and apply only the feature-states lines.a797f59737.