Files
coder/scripts/docsredirectscheck
Nick Vigilante bb58916e6c ci: validate docs/redirects.json (#30209)
Adds `docsredirectscheck`, a lint for `docs/redirects.json`, the list of
redirects the documentation website applies for pages that have moved or
been removed. It runs as `make lint/docs-redirects`, part of `make lint`
and `make lint-light`, so a bad redirect is caught in the pull request
that adds it. The file does not exist yet, and the check passes while it
is absent, so this can merge before or after the file does.

## What it checks

It fails on:

- a file that is not a JSON array of well-formed rules (`source`,
`destination`, optional boolean `permanent`, no unknown fields);
- syntax outside the supported subset: a source under `/docs/`, written
as an exact path, a trailing `/:name*`, or a trailing `/:name(.*)`, with
no version segment such as `/@main`;
- an internal destination that is not a page in `docs/manifest.json`, or
a pattern destination that points into a section with no pages or uses a
parameter the source does not define;
- a source that matches a live page, which would hide it;
- duplicate sources, chains (a destination that is another rule's
source), and loops.

It warns, and never fails, when a pull request removes routes from
`docs/manifest.json` while `docs/redirects.json` is unchanged and does
not already cover them. Pages are sometimes removed on purpose. The
comparison is by route rather than by file, so a rename that keeps its
URL (for example `admin/foo/index.md` to `admin/foo.md`) does not warn.
In GitHub Actions the warning is an annotation on the manifest. The base
is the first parent of the PR merge commit, the same approach
`scripts/check_emdash.sh` uses, and the warning is skipped with a note
when it is not available.

Routes are derived from `docs/manifest.json` the way the docs website
derives them, including its plain-suffix stripping of `README.md`,
`index.md`, and `.md`, so the check and the site agree about which pages
exist. `scripts/docsredirectscheck/README.md` documents the rule format
and the limits.

## Testing

- 128 Go tests pass under Go 1.26.5: route derivation, every failing and
passing rule shape, the absent-file pass, exit codes, and the warning
logic through a fake git reader.
- I checked that the tests can fail by breaking the code 16 ways (for
example dropping the `index.md` suffix, disabling the shadow check,
reporting loops twice). All 16 were caught. That run found one gap, a
missing test for "redirects file changed", which is now covered.
- Ran against the repository's real `docs/manifest.json`: passes with no
redirects file, and a file with one of each failure class reports every
problem with the rule index, the source, and how to fix it.
- Ran the warning against real git history: it warns for an older base,
stays silent at `HEAD`, and skips with a note for an unknown revision.
- Lint: `golangci-lint` v2.0.2 built with Go 1.26.5 against the
repository config reports 0 issues. `paralleltestctx`, `intxcheck`,
`typos` 1.46.1, `gofumpt` and `gci` (through `make fmt/go`), and `go
vet` pass.

CI: `lint` (which runs this check), `fmt`, `title`, and the Go and
end-to-end test jobs pass. The `gen` job, and so `required`, fails on
this branch for a reason this PR does not touch: `main` is failing it
too. `docs/manifest/generated/cli.json` has not been regenerated for the
`coder sharing` commands that landed in the latest commit on `main`. It
should clear once `main` is fixed and merged into this branch.

Not run locally: the full `make lint` and `make pre-commit`. The local
hooks are opt-in and were off. The annotation output has been exercised
by unit tests and a local run with `GITHUB_ACTIONS=true`, but not yet on
a real pull request merge commit; this PR does not change the manifest,
so it will not exercise it either. No workflow change is needed, because
the `lint` job already runs `make lint` for any change that is not
offlinedocs-only.

---
🤖 Built with AI assistance.
2026-10-02 14:27:44 -04:00
..

docsredirectscheck

docsredirectscheck validates docs/redirects.json, the list of redirects the documentation website applies for pages that have moved or been removed. It runs as make lint/docs-redirects (part of make lint and make lint-light), so a bad redirect is caught in the pull request that introduces it.

A missing docs/redirects.json passes.

The rule file

docs/redirects.json is a JSON array of rules:

[
  {
    "source": "/docs/about/architecture",
    "destination": "/docs/about",
    "permanent": true
  },
  {
    "source": "/docs/tutorials/ai-agents/:path*",
    "destination": "/docs/ai-coder/:path*"
  }
]
  • source and destination are full site paths that start with /docs/. Write them without a version segment such as /@main; the docs website adds that itself.
  • permanent is optional and defaults to true.
  • A source is an exact path, a trailing /:name* (matches the prefix and everything beneath it), or a trailing /:name(.*) (matches everything beneath the prefix, not the prefix itself).
  • A destination is an exact path, a trailing /:name or /:name* that reuses the source's parameter, or an http(s):// URL.

What it catches

These fail the check:

  • A malformed file. Not valid JSON, not an array, an entry that is not an object, a missing or empty source or destination, a non-boolean permanent, or an unknown field.
  • Unsupported syntax. A source outside /docs/, a version segment, or any pattern beyond the forms above.
  • A destination that is not a page. An internal destination must be a route in docs/manifest.json. A pattern destination must point into a section that has pages, and may only use a parameter the source defines.
  • A source that hides a live page. Redirects apply before pages, so a rule whose source matches a page in the manifest makes that page unreachable.
  • Duplicates, chains, and loops. Two rules with the same source, a rule whose destination is another rule's source (point it at the final page instead), and cycles.

Removed-route warning

On a pull request the check also compares docs/manifest.json with the base branch. If routes were removed, docs/redirects.json was not changed, and no existing rule already covers the removed routes, it prints a warning. In GitHub Actions the warning is an annotation on the manifest. It never fails the run, because pages are sometimes removed on purpose.

The comparison is by route, not by file, so renaming admin/foo/index.md to admin/foo.md (same URL) is not a removal.

In GitHub Actions the base is the first parent of the pull request's merge commit, which is the tip of the branch the change merges into. Elsewhere pass -base <rev>; with neither, or when the revision is unavailable (a shallow checkout), the warning is skipped with a note.

How it decides which pages exist

It derives routes from docs/manifest.json exactly as the docs website does: strip a leading ./, then strip the suffixes README.md, index.md, and .md one after another, trim slashes, and prefix /docs. That includes the website's quirk of matching the suffixes as plain text rather than per path segment, so a file named my-index.md becomes the route /docs/.../my-. Every manifest entry with a path counts as a page, whether or not it appears in the sidebar. The landing page /docs always exists, and /docs/about exists when the first page is titled "About".

Usage

go run ./scripts/docsredirectscheck [-manifest path] [-redirects path] [-base rev]

Exit status is 0 when the file is valid or absent, 1 when it has problems, and 2 when the check itself could not run (for example the manifest is unreadable).

Limitations

  • Chains through a pattern destination are not followed, because where such a destination lands depends on the URL being redirected.
  • Only the three source forms above are understood. Regular-expression groups, version ranges, and mid-path parameters are rejected rather than guessed at.
  • The removed-route warning compares routes only; it does not know whether an external site links to a removed page.