test(landing): guard _redirects against catalog drift (#575)

Exports a pure buildRedirects() from generate-redirects.mjs and adds a unit test asserting the committed apps/landing/public/_redirects matches it, so tool additions can't silently leave the generated redirects stale (see #573).
This commit is contained in:
SnapOtter
2026-07-19 16:36:33 +08:00
committed by GitHub
parent 6339370093
commit 84c18eb82c
2 changed files with 54 additions and 9 deletions
@@ -0,0 +1,24 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import {
buildRedirects,
REDIRECTS_PATH,
} from "../../../apps/landing/scripts/generate-redirects.mjs";
/**
* Drift guard: apps/landing/public/_redirects is generated from the shared
* TOOLS catalog by scripts/generate-redirects.mjs (runs in the landing
* prebuild) but is committed, so it silently goes stale whenever a tool is
* added without regenerating it (that is how remove-gif-background's redirects
* went missing, PR #573). Adding a tool touches @snapotter/shared and runs this
* suite, so the drift fails here at PR time instead of shipping.
*/
describe("landing _redirects drift", () => {
it("committed public/_redirects matches the generator output", () => {
const committed = readFileSync(REDIRECTS_PATH, "utf8");
expect(
committed,
"apps/landing/public/_redirects is stale. Regenerate it with `pnpm --filter @snapotter/landing prebuild` and commit the file.",
).toBe(buildRedirects());
});
});