`docsredirectscheck` validates `docs/redirects.json`, the list of redirects the documentation websites apply 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 or missing redirect is caught in the pull request that introduces it.
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 route outside the grammar above, the old `/docs/...` form, or an external destination outside the allowlist.
- **A destination that is not a page.**
An internal destination must be a route in `docs/manifest.json`.
A wildcard destination must point into a section that has pages.
- **A source that hides a live page.**
A page always wins over a redirect, and some sites apply redirects first.
A rule whose source matches a page in the manifest is therefore rejected.
- **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.
- **A rule that can never apply.**
An earlier rule whose source matches every route a later rule would.
A wildcard above a rule inside its subtree is the usual cause.
An exact rule above a wildcard on the same prefix is allowed, because it claims the bare prefix and leaves the subtree to the wildcard.
A route that worked before the change must still work after it.
Each route in the inventory must be a live route in the head manifest, or be resolved by the head rules to a live route, to `/`, or to an allowed external URL.
The list is `https://coder.com/beta-docs/@main/llms.txt` for `main` and `https://coder.com/beta-docs/vX.Y/llms.txt` for `release/X.Y`.
Only links under that version count.
The version served at the unversioned `/beta-docs` path links its pages without a version segment, so when a list has no links under its own segment, the unversioned links count instead.
When the list redirects to `/docs`, links under `/docs` count the same way.
- The `source` of every rule in `docs/redirects.json` on the base branch.
A wildcard source contributes its prefix.
A base file in the old absolute form is read as well.
A failure names the route, where it came from, and a rule to paste, for example `{"source": "path/to/page", "destination": "/"}`.
The destination is the one live page with the same last segment.
Otherwise it is the one page this change added in the same parent section, which catches a rename such as `admin/integrations/istio` to `admin/integrations/istio-mesh`.
Otherwise it is `/`.
Change the destination when a better page exists.
In GitHub Actions each failure is also an error annotation.
Both ends of the check can be missing, and the check says so and skips that part:
- **Base branch.**
In GitHub Actions on a pull request the base is the first parent of the merge commit, which is the tip of the branch the change merges into.
Elsewhere pass `-base <rev>`.
A shallow checkout that lacks the revision skips the comparison with a note.
- **Live page list.**
The target branch is `-branch`, then `GITHUB_BASE_REF` on a pull request, then `GITHUB_REF_NAME` on a push.
A branch other than `main` or `release/X.Y`, or no known branch, skips the list with a note.
A list that answers 404 skips the list with a note, because a new `release/X.Y` branch has no published docs version yet.
When `docs/manifest.json` and `docs/redirects.json` are the same as on the base branch, the list is skipped with a note, because the change cannot affect the result.
The docs site generates one page for each REST API endpoint from `coderd/apidoc/swagger.json`, at `reference/api/<section>/<endpoint>`, such as `reference/api/users/get-user-by-name`.
`docs/manifest.json` lists only the section pages, such as `reference/api/users`, so the check cannot tell which endpoint pages exist.
A route of that form in the live page list is therefore not checked while its section page is a live route, and the check prints how many it left out.
Once the section page is gone, its endpoint routes need a rule like any other route.
The endpoint part of the URL comes from the endpoint's summary and the section from its tag.
A change to either one moves the page, and the check does not notice.
It derives routes from `docs/manifest.json` as the docs websites do: strip a leading `./`, then strip the suffixes `README.md`, `index.md`, and `.md` one after another, and trim slashes.
That includes the websites' quirk of matching the suffixes as plain text rather than per path segment, so a file named `my-index.md` becomes the route `.../my-`.
Every manifest entry with a path counts as a page, whether or not it appears in the sidebar.
The empty route is the docs root, and it always exists.