## Summary A feature `state` in `docs/manifest/` now applies to a route and all its descendants, so each state is set once on the highest route it applies to. `docsmanifestgen check` rejects a route that repeats an ancestor's state, and the repeated states on `main` are removed. ## State model - Put a state on the highest route it applies to. - Add a state to a descendant only when it is new, such as an early access page inside a Premium section. - The sidebar shows a pill on the route that sets the state and on descendants whose state differs. - Every page shows its full state, own plus inherited, under the title. ## 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`. - Keep `state: [premium]` on AI Governance and External provisioners only. Remove the 27 states their descendants repeat in `docs/manifest/ai-governance/**` and `docs/manifest/install/operate/provisioners.yml`, and regenerate `docs/manifest.json`. - Document the model in `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](https://linear.app/codercom/issue/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=windows` and `GOOS=darwin` `go vet ./scripts/docsmanifestgen/` - `make lint/docs-manifest`, `make lint/markdown`, `make lint/docs-redirects` - `make gen/docs-manifest` leaves the tree clean. <details> <summary>Decision log: rebase onto main after #31645</summary> - #31645 (merged 2026-11-04) moved AI Governance to a top-level section with Agent Firewall and AI Gateway nested under it, and added the `ai-coder/...` redirects. That covered this PR's move commits, link and URL updates, and redirects, which caused the conflicts. - The branch was rebuilt on `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. - Agent Relay is now top-level with `state: [premium, beta]` and no child states, so it needs no change. - Conflicts in `content-guidelines.md` and the doc-check skill were resolved to keep `main`'s newer text (Vale word-choice updates and relative redirect syntax) and apply only the feature-states lines. - The pre-rebase head was `a797f59737`. </details> > Generated by Coder Agents on behalf of @nickvigilante. Supersedes #31481, reopened under a human author for attribution. --------- Co-authored-by: default <default@example.com>
126 lines
4.6 KiB
Go
126 lines
4.6 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/scripts/docgenenv"
|
|
)
|
|
|
|
func TestRepeatedStates(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
const index = "versions: [main]\nsections:\n - home.yml\n"
|
|
for _, tc := range []struct {
|
|
name string
|
|
files map[string]string
|
|
want []string // Error substrings, one per expected error.
|
|
}{
|
|
{
|
|
name: "NoStates",
|
|
files: map[string]string{
|
|
"home.yml": "title: Home\npath: ./index.md\nchildren:\n - title: A\n path: ./a.md\n",
|
|
},
|
|
},
|
|
{
|
|
name: "DifferentStateOnDescendant",
|
|
files: map[string]string{
|
|
"home.yml": "title: Home\npath: ./index.md\nstate: [premium]\nchildren:\n - title: A\n path: ./a.md\n state: [early access]\n",
|
|
},
|
|
},
|
|
{
|
|
name: "SameStateOnSiblings",
|
|
files: map[string]string{
|
|
"home.yml": "title: Home\npath: ./index.md\nchildren:\n - title: A\n path: ./a.md\n state: [beta]\n - title: B\n path: ./b.md\n state: [beta]\n",
|
|
},
|
|
},
|
|
{
|
|
name: "ChildRepeatsParent",
|
|
files: map[string]string{
|
|
"home.yml": "title: Home\npath: ./index.md\nstate: [premium]\nchildren:\n - title: A\n path: ./a.md\n state: [premium]\n",
|
|
},
|
|
want: []string{`home.yml: Home > A: state "premium" is already set on ancestor "Home" in home.yml`},
|
|
},
|
|
{
|
|
name: "OnlyRepeatedValueReported",
|
|
files: map[string]string{
|
|
"home.yml": "title: Home\npath: ./index.md\nstate: [premium]\nchildren:\n - title: A\n path: ./a.md\n state: [premium, beta]\n",
|
|
},
|
|
want: []string{`home.yml: Home > A: state "premium"`},
|
|
},
|
|
{
|
|
name: "StateListedTwiceOnOneRoute",
|
|
files: map[string]string{
|
|
"home.yml": "title: Home\npath: ./index.md\nstate: [beta, beta]\n",
|
|
},
|
|
want: []string{`home.yml: Home: state "beta" is listed more than once`},
|
|
},
|
|
{
|
|
name: "IncludedFileRepeatsAncestor",
|
|
files: map[string]string{
|
|
"home.yml": "title: Home\npath: ./index.md\nstate: [premium]\nchildren:\n - include: home/sub.yml\n",
|
|
"home/sub.yml": "title: Sub\npath: ./sub/index.md\nchildren:\n - include: home/sub/x.yml\n",
|
|
"home/sub/x.yml": "title: X\npath: ./sub/x.md\nstate: [premium]\n",
|
|
},
|
|
want: []string{`home/sub/x.yml: Home > Sub > X: state "premium" is already set on ancestor "Home" in home.yml`},
|
|
},
|
|
{
|
|
name: "EachRepeatReportedAgainstFirstAncestor",
|
|
files: map[string]string{
|
|
"home.yml": "title: Home\npath: ./index.md\nstate: [beta]\nchildren:\n - include: home/sub.yml\n",
|
|
"home/sub.yml": "title: Sub\npath: ./sub/index.md\nstate: [beta]\nchildren:\n - title: X\n path: ./sub/x.md\n state: [beta]\n",
|
|
},
|
|
want: []string{
|
|
`home/sub.yml: Home > Sub: state "beta" is already set on ancestor "Home" in home.yml`,
|
|
`home/sub.yml: Home > Sub > X: state "beta" is already set on ancestor "Home" in home.yml`,
|
|
},
|
|
},
|
|
{
|
|
name: "OverlayRepeatsAncestor",
|
|
files: map[string]string{
|
|
"home.yml": "title: Home\npath: ./index.md\nstate: [premium]\nchildren_from: generated/home.yml\nchildren:\n - title: A\n state: [premium]\n",
|
|
},
|
|
want: []string{`home.yml: Home > A: state "premium" is already set on ancestor "Home" in home.yml`},
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
dir := t.TempDir()
|
|
files := map[string]string{docgenenv.ManifestIndexFile: index}
|
|
for name, body := range tc.files {
|
|
files[name] = body
|
|
}
|
|
for name, body := range files {
|
|
p := filepath.Join(dir, filepath.FromSlash(name))
|
|
require.NoError(t, os.MkdirAll(filepath.Dir(p), 0o755))
|
|
require.NoError(t, os.WriteFile(p, []byte(body), 0o600))
|
|
}
|
|
|
|
errs := repeatedStates(dir)
|
|
require.Len(t, errs, len(tc.want), "errors: %v", errs)
|
|
for i, want := range tc.want {
|
|
require.ErrorContains(t, errs[i], want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCheckReportsRepeatedStates(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
docsDir := t.TempDir()
|
|
sources := filepath.Join(docsDir, docgenenv.ManifestSourcesDir)
|
|
require.NoError(t, os.MkdirAll(sources, 0o755))
|
|
for _, page := range []string{"index.md", "a.md"} {
|
|
require.NoError(t, os.WriteFile(filepath.Join(docsDir, page), []byte("# page\n"), 0o600))
|
|
}
|
|
require.NoError(t, os.WriteFile(filepath.Join(sources, docgenenv.ManifestIndexFile), []byte("versions: [main]\nsections:\n - home.yml\n"), 0o600))
|
|
require.NoError(t, os.WriteFile(filepath.Join(sources, "home.yml"), []byte("title: Home\npath: ./index.md\nstate: [premium]\nchildren:\n - title: A\n path: ./a.md\n state: [premium]\n"), 0o600))
|
|
|
|
err := run([]string{"check", "-docs", docsDir})
|
|
require.ErrorContains(t, err, `home.yml: Home > A: state "premium" is already set on ancestor "Home" in home.yml`)
|
|
}
|