fix(site): make an unusable base path impossible, not merely documented - #589
Merged
Conversation
The base was guarded by a comment saying it must never be "/". A comment stops nobody, and "/" is the obvious thing to reach for when moving a site to a domain root. The failure it prevents is worse than a broken link. rehypeBaseLinks prefixes every root-absolute href/src with the base, so a base of "/" rewrites "/diagrams/x.svg" into "//diagrams/x.svg" — a protocol-relative URL that resolves against a DIFFERENT HOST. Nothing 404s: the build succeeds and the link audit passes, because the target still parses as a valid reference. The page just quietly fetches from somewhere else. base.mjs now validates at import time and throws. Verified by mutation — setting the base to "/" fails the Astro build, the link audit, and the test suite, because every one of them imports the module. There is no path that ships it. The invariant is "" or a root-absolute path with no trailing slash, so the same guard also catches "/codeArbiter/" and "codeArbiter". test/base.test.ts pins the rejected forms and, rather than describing the hazard in prose, asserts the corruption directly: prefixing under a base of "/" produces a value starting with "//". 511/511 vitest, tsc clean, build green, 20,057 links resolve.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Turns the
BASEcomment into an enforced gate.The failure it prevents
rehypeBaseLinksprefixes every root-absolutehref/srcwith the base. A base of"/"rewrites/diagrams/x.svginto//diagrams/x.svg— a protocol-relative URL that resolves against a different host.Nothing 404s. The build succeeds. The link audit passes, because the target still parses as a valid reference. The page just quietly fetches from somewhere else. That is why this needed to be an error rather than a comment:
"/"is the obvious thing to reach for when moving a site to a domain root, and every existing check would have waved it through.What changed
site/base.mjsvalidates at import time and throws. The invariant is""(apex) or a root-absolute path with no trailing slash, so the same guard also catches"/codeArbiter/"and"codeArbiter".Verified by mutation, not by assertion
Setting the base to
"/"fails all three independently, because each imports the module:RAW_BASE = "/"npm run buildnpm run link-auditvitestThere is no path that ships it.
test/base.test.tspins the rejected forms and, rather than describing the hazard in prose, asserts the corruption directly: prefixing under a base of"/"produces a value starting with//.Gate
511/511 vitest (48 files), tsc clean, build green, link-audit resolves 20,057 links across 140 pages. All four run locally this time —
npm testalone is vitest only, which is what let the previous two CI failures through.