fix: release QA hardening across processing, media, security, and CI gates (#649)

A release-readiness QA pass over the whole product. The commits split into
defects a user would hit and gates that were reporting green while measuring
nothing.

## Fixes that change behaviour

Rate limiting was bypassable on every install: TRUST_PROXY defaulted to true, so
request.ip came from a client-set header and a forged X-Forwarded-For got past
the login limiter. The default is now a private-network trust list.

A transient Postgres outage stranded in-flight jobs, leaving finished output on
disk with no row pointing at it. A reconciler now resolves those rows and adopts
the bytes rather than dropping the work.

A Redis connection that moved to a new address wedged every read-blocked
consumer, so completions stopped signalling while health still answered 200.
Socket timeouts plus subscriber pings recover it.

Installing more than one AI bundle left the shared venv multi-versioned and
silently broke three tools. The installer now reconciles distributions to one
version each.

Converting an image to JXL at quality 1 through 4 returned a 500, because
libjxl 0.7 rejects the distance those values compute. The quality is floored at
what the encoder honours. A missing ffmpeg was also reported to the user as a
corrupt upload; it now says the engine is unavailable.

RAW uploads reached an unpatched LibRaw on arm64, so it is built from source at
0.22.2, and the release scan was split so it can fail on an unfixed critical
instead of hiding it behind ignore-unfixed.

## Gates that could not fail

Two mutation lanes ran zero mutants because Stryker crawled the gitignored docs
build; coverage discarded its whole report on any failing test; the lint gate
skipped root tests, scripts, and two workspaces; and several generated matrices
counted a host missing ffmpeg as a passing tool. Each now measures what it
claims.

Full evidence and the outstanding release items are tracked locally and are not
part of this branch.
This commit is contained in:
SnapOtter
2026-07-27 15:37:30 +08:00
committed by GitHub
parent bc32f86a07
commit d10d0f544f
855 changed files with 54564 additions and 13092 deletions
@@ -0,0 +1,119 @@
import { execFileSync } from "node:child_process";
import { existsSync, readFileSync } from "node:fs";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { describe, expect, it } from "vitest";
const root = process.cwd();
const scriptPath = path.resolve(root, "scripts/check-production-licenses.mjs");
const policyPath = path.resolve(root, "config/production-license-policy.json");
const noticesPath = path.resolve(root, "THIRD_PARTY_NOTICES.md");
type Inventory = Record<
string,
Array<{ name: string; versions: string[]; license: string; homepage?: string }>
>;
type Policy = {
allowedExpressions: string[];
deniedExpressions: string[];
};
async function loadChecker(): Promise<{
renderNotices: (inventory: Inventory) => string;
validateInventory: (inventory: Inventory, policy: Policy) => string[];
}> {
expect(existsSync(scriptPath), "production license checker is missing").toBe(true);
return import(pathToFileURL(scriptPath).href);
}
describe("production Node dependency license policy", () => {
it("rejects unknown and explicitly denied license expressions", async () => {
const { validateInventory } = await loadChecker();
const policy = { allowedExpressions: ["MIT"], deniedExpressions: ["BUSL-1.1"] };
expect(
validateInventory(
{
MIT: [{ name: "allowed", versions: ["1.0.0"], license: "MIT" }],
Unknown: [{ name: "mystery", versions: ["0.1.0"], license: "Unknown" }],
"BUSL-1.1": [{ name: "denied", versions: ["2.0.0"], license: "BUSL-1.1" }],
},
policy,
),
).toEqual([
"denied license expression BUSL-1.1: denied@2.0.0",
"unknown license expression Unknown: mystery@0.1.0",
]);
});
it("rejects every expression not present in the reviewed allowlist", async () => {
const { validateInventory } = await loadChecker();
expect(
validateInventory(
{
MIT: [{ name: "allowed", versions: ["1.0.0"], license: "MIT" }],
"LicenseRef-Unreviewed": [
{ name: "unreviewed", versions: ["3.0.0"], license: "LicenseRef-Unreviewed" },
],
},
{ allowedExpressions: ["MIT"], deniedExpressions: [] },
),
).toEqual(["unapproved license expression LicenseRef-Unreviewed: unreviewed@3.0.0"]);
});
it("renders deterministic notices without machine-specific install paths", async () => {
const { renderNotices } = await loadChecker();
const inventory = {
MIT: [
{
name: "z-package",
versions: ["2.0.0", "1.0.0"],
license: "MIT",
homepage: "https://example.test/z",
},
{ name: "a-package", versions: ["1.0.0"], license: "MIT" },
],
};
const notices = renderNotices(inventory);
expect(notices).toContain("# Third-Party Production Node Dependency Notices");
expect(notices).toContain("## MIT");
expect(notices.indexOf("a-package@1.0.0")).toBeLessThan(
notices.indexOf("z-package@1.0.0,2.0.0"),
);
expect(notices).toContain("https://example.test/z");
expect(notices).not.toContain(root);
});
it("keeps the reviewed policy, generated notices, package script, and release gates current", () => {
expect(existsSync(policyPath), "production license policy is missing").toBe(true);
expect(existsSync(noticesPath), "production third-party notices are missing").toBe(true);
const packageJson = JSON.parse(readFileSync(path.resolve(root, "package.json"), "utf8"));
expect(packageJson.scripts["check:production-node-licenses"]).toBe(
"node scripts/check-production-licenses.mjs",
);
expect(packageJson.scripts["check:production-licenses"]).toContain(
"check:production-node-licenses",
);
expect(packageJson.pnpm.overrides["exceljs>unzipper"]).toBe("0.12.5");
const ci = readFileSync(path.resolve(root, ".github/workflows/ci.yml"), "utf8");
const release = readFileSync(path.resolve(root, ".github/workflows/release.yml"), "utf8");
expect(ci).toContain("pnpm check:production-node-licenses");
expect(release).toContain("pnpm check:production-node-licenses");
expect(release.indexOf("pnpm check:production-node-licenses")).toBeLessThan(
release.indexOf("Run semantic-release"),
);
expect(() =>
execFileSync("pnpm", ["check:production-node-licenses"], {
cwd: root,
encoding: "utf8",
stdio: "pipe",
}),
).not.toThrow();
});
});
+43
View File
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { beforeEach, describe, expect, it } from "vitest";
import { createDocsAdapter } from "../../../../scripts/i18n/adapters/docs-md.mjs";
import { hash } from "../../../../scripts/i18n/lib/hash.mjs";
let root: string;
@@ -122,6 +123,48 @@ describe("docs-md adapter", () => {
expect(e?.text).toContain("# Iks {#x}");
});
it("hashes the canonical post-render document and detects later edits", async () => {
await seed(
"guide/x.md",
"---\ndescription: Install: quickly\n---\n# X {#x}\n\nSee [Config](/guide/configuration).",
);
const adapter = createDocsAdapter({ root });
const units = await adapter.extract();
const entry = {
text: units[0].sourceText.replace("Install: quickly", "Installieren: schnell"),
sourceHash: "abc123def456",
provenance: "machine" as const,
outputHash: "0".repeat(12),
stale: false,
};
await adapter.write("de", new Map([[units[0].id, entry]]));
const written = await readFile(join(root, "de/guide/x.md"), "utf8");
expect(written).toContain("i18n_hash_version: 2");
expect(written).toContain("[Config](/de/guide/configuration)");
const stored = await adapter.load("de");
const loaded = stored.get("guide/x.md");
expect(loaded?.text).not.toContain("i18n_output_hash");
expect(loaded?.outputHash).toBe(hash(loaded?.text ?? ""));
await writeFile(join(root, "de/guide/x.md"), written.replace("schnell", "bearbeitet"));
const edited = (await adapter.load("de")).get("guide/x.md");
expect(edited?.outputHash).not.toBe(hash(edited?.text ?? ""));
});
it("migrates legacy machine hashes without misclassifying rendered output as human", async () => {
await seed("guide/x.md", "# X {#x}\n");
await seed(
"de/guide/x.md",
"---\ni18n_source_hash: oldsource001\ni18n_provenance: machine\ni18n_output_hash: 000000000000\n---\n# Iks {#x}\n",
);
const adapter = createDocsAdapter({ root });
const loaded = (await adapter.load("de")).get("guide/x.md");
expect(loaded?.provenance).toBe("machine");
expect(loaded?.outputHash).toBe(hash(loaded?.text ?? ""));
});
it("writeFallback emits an English copy flagged for a missing translation", async () => {
await seed("guide/x.md", "---\ndescription: Install it\n---\n# X {#x}\n\nBody.");
const adapter = createDocsAdapter({ root });
@@ -0,0 +1,151 @@
import { execFileSync } from "node:child_process";
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { expect, test } from "vitest";
const root = process.cwd();
const scriptPath = path.resolve(root, "scripts/manage-release-notes.mjs");
test("archives custom release notes byte-for-byte and permits an identical retry", async () => {
expect(existsSync(scriptPath), "release-note manager is missing").toBe(true);
const { archiveCustomReleaseNotes } = await import(pathToFileURL(scriptPath).href);
const fixtureRoot = mkdtempSync(path.join(tmpdir(), "snapotter-release-notes-"));
const source = "# SnapOtter 3.0.0\n\nUnicode: 水獺\n\nTrailing line.\n";
try {
writeFileSync(path.join(fixtureRoot, ".release-notes.md"), source);
expect(archiveCustomReleaseNotes(fixtureRoot, "3.0.0")).toBe(true);
const archived = path.join(fixtureRoot, ".release-notes/v3.0.0.md");
expect(readFileSync(archived, "utf8")).toBe(source);
expect(existsSync(path.join(fixtureRoot, ".release-notes.md"))).toBe(false);
writeFileSync(path.join(fixtureRoot, ".release-notes.md"), source);
expect(archiveCustomReleaseNotes(fixtureRoot, "3.0.0")).toBe(true);
expect(readFileSync(archived, "utf8")).toBe(source);
expect(existsSync(path.join(fixtureRoot, ".release-notes.md"))).toBe(false);
} finally {
rmSync(fixtureRoot, { force: true, recursive: true });
}
});
test("materializes archived custom notes byte-for-byte for a retry", async () => {
expect(existsSync(scriptPath), "release-note manager is missing").toBe(true);
const releaseNotes = await import(pathToFileURL(scriptPath).href);
expect(typeof releaseNotes.materializeReleaseNotes).toBe("function");
const fixtureRoot = mkdtempSync(path.join(tmpdir(), "snapotter-release-notes-"));
const source = "## Highlights\n\nExact custom body.\n";
try {
writeFileSync(path.join(fixtureRoot, ".release-notes.md"), source);
releaseNotes.archiveCustomReleaseNotes(fixtureRoot, "3.0.0");
const output = path.join(fixtureRoot, "materialized.md");
expect(releaseNotes.materializeReleaseNotes(fixtureRoot, "3.0.0", output)).toBe(true);
expect(readFileSync(output, "utf8")).toBe(source);
} finally {
rmSync(fixtureRoot, { force: true, recursive: true });
}
});
test("recovers generated release notes from the committed changelog", async () => {
expect(existsSync(scriptPath), "release-note manager is missing").toBe(true);
const { materializeReleaseNotes } = await import(pathToFileURL(scriptPath).href);
const fixtureRoot = mkdtempSync(path.join(tmpdir(), "snapotter-release-notes-"));
const expected = "# [3.0.0](https://example.test/v3.0.0)\n\n### Fixes\n\n* repaired retries\n";
try {
writeFileSync(
path.join(fixtureRoot, "CHANGELOG.md"),
`${expected}\n# [2.9.0](https://example.test/v2.9.0)\n\nOlder notes.\n`,
);
const output = path.join(fixtureRoot, "materialized.md");
expect(materializeReleaseNotes(fixtureRoot, "3.0.0", output)).toBe(false);
expect(readFileSync(output, "utf8")).toBe(expected);
} finally {
rmSync(fixtureRoot, { force: true, recursive: true });
}
});
test("inserts an exact custom-note entry after the published changelog heading once", async () => {
expect(existsSync(scriptPath), "release-note manager is missing").toBe(true);
const releaseNotes = await import(pathToFileURL(scriptPath).href);
expect(typeof releaseNotes.syncDocsChangelog).toBe("function");
const fixtureRoot = mkdtempSync(path.join(tmpdir(), "snapotter-release-notes-"));
const notes = [
"# SnapOtter 3.0.0",
"",
"## Highlights",
"",
"Retry-safe release.",
"",
"## Upgrade",
"",
"Use the new image.",
"",
"---",
"",
].join("\n");
try {
mkdirSync(path.join(fixtureRoot, ".release-notes"));
writeFileSync(path.join(fixtureRoot, ".release-notes/v3.0.0.md"), notes);
writeFileSync(
path.join(fixtureRoot, "apps-docs-changelog.md"),
"---\ndescription: History.\n---\n\n# Changelog {#changelog}\n\n## v2.9.0\n\nOlder.\n",
);
expect(
releaseNotes.syncDocsChangelog(fixtureRoot, "3.0.0", "2.9.0", "apps-docs-changelog.md"),
).toBe(true);
expect(
releaseNotes.syncDocsChangelog(fixtureRoot, "3.0.0", "2.9.0", "apps-docs-changelog.md"),
).toBe(false);
const changelog = readFileSync(path.join(fixtureRoot, "apps-docs-changelog.md"), "utf8");
expect(changelog.match(/^## v3\.0\.0$/gm)).toHaveLength(1);
expect(changelog).toContain(
"# Changelog {#changelog}\n\n## v3.0.0\n\nRetry-safe release.\n\n" +
"[Full diff on GitHub](https://github.com/snapotter-hq/SnapOtter/compare/v2.9.0...v3.0.0)\n\n---\n",
);
} finally {
rmSync(fixtureRoot, { force: true, recursive: true });
}
});
test("CLI exposes archive, materialize, and changelog preparation for release automation", () => {
const fixtureRoot = mkdtempSync(path.join(tmpdir(), "snapotter-release-notes-"));
const notes = "## Highlights\n\nCLI release.\n";
try {
mkdirSync(path.join(fixtureRoot, "apps/docs"), { recursive: true });
writeFileSync(path.join(fixtureRoot, ".release-notes.md"), notes);
writeFileSync(
path.join(fixtureRoot, "CHANGELOG.md"),
"# [3.0.0](https://example.test/v3.0.0)\n\nGenerated.\n",
);
writeFileSync(path.join(fixtureRoot, "apps/docs/changelog.md"), "# Changelog {#changelog}\n");
expect(
execFileSync(process.execPath, [scriptPath, "archive", "3.0.0", "--root", fixtureRoot], {
encoding: "utf8",
}),
).toBe("custom=true\n");
const materialized = path.join(fixtureRoot, "expected.md");
expect(
execFileSync(
process.execPath,
[scriptPath, "materialize", "3.0.0", materialized, "--root", fixtureRoot],
{ encoding: "utf8" },
),
).toBe("custom=true\n");
expect(readFileSync(materialized, "utf8")).toBe(notes);
expect(
execFileSync(
process.execPath,
[scriptPath, "sync-docs", "3.0.0", "2.9.0", "--root", fixtureRoot],
{ encoding: "utf8" },
),
).toBe("changed=true\n");
} finally {
rmSync(fixtureRoot, { force: true, recursive: true });
}
});
@@ -0,0 +1,115 @@
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import {
acquireFuzzLock,
buildFuzzEnvironment,
fuzzLockPath,
parseFuzzArguments,
} from "../../../scripts/run-fuzz-gate.mjs";
test("parses canonical fuzz runner arguments", () => {
assert.deepEqual(parseFuzzArguments(["--runs", "50", "--seed=1234"]), {
help: false,
runs: 50,
seed: 1234,
});
assert.deepEqual(parseFuzzArguments(["--help"]), {
help: true,
runs: undefined,
seed: undefined,
});
assert.deepEqual(parseFuzzArguments(["--", "--runs", "25"]), {
help: false,
runs: 25,
seed: undefined,
});
assert.throws(() => parseFuzzArguments(["--runs", "0"]), /--runs.*between 1 and 10000/i);
assert.throws(() => parseFuzzArguments(["--seed", "NaN"]), /--seed.*integer/i);
assert.throws(() => parseFuzzArguments(["--unknown"]), /unknown argument/i);
});
test("forces the canonical single-fork fuzz environment", () => {
assert.deepEqual(
buildFuzzEnvironment(
{
FC_SEED: "5678",
FUZZ: "0",
FUZZ_RUNS: "10",
FUZZ_SEED: "8765",
VITEST_MAX_FORKS: "8",
},
{ help: false, runs: 50, seed: 1234 },
),
{
FUZZ: "1",
FUZZ_RUNS: "50",
FUZZ_SEED: "1234",
VITEST_MAX_FORKS: "1",
},
);
assert.deepEqual(buildFuzzEnvironment({ FC_SEED: "5678" }, { help: false }), {
FC_SEED: "5678",
FUZZ: "1",
VITEST_MAX_FORKS: "1",
});
});
test("derives a stable repo-scoped lock path", () => {
const firstRepo = mkdtempSync(join(tmpdir(), "snapotter-fuzz-repo-a-"));
const secondRepo = mkdtempSync(join(tmpdir(), "snapotter-fuzz-repo-b-"));
const nested = join(firstRepo, "nested");
try {
execFileSync("git", ["init", "--quiet"], { cwd: firstRepo });
execFileSync("git", ["init", "--quiet"], { cwd: secondRepo });
mkdirSync(nested);
assert.equal(fuzzLockPath(firstRepo), fuzzLockPath(nested));
assert.notEqual(fuzzLockPath(firstRepo), fuzzLockPath(secondRepo));
assert.match(fuzzLockPath(firstRepo), /snapotter-fuzz-[a-f0-9]{64}\.lock$/);
} finally {
rmSync(firstRepo, { force: true, recursive: true });
rmSync(secondRepo, { force: true, recursive: true });
}
});
test("refuses a second fuzz campaign and only releases its own lock", () => {
const root = mkdtempSync(join(tmpdir(), "snapotter-fuzz-lock-test-"));
const lockPath = join(root, "fuzz.lock");
try {
const first = acquireFuzzLock(lockPath, {
pid: process.pid,
startedAt: "2026-07-25T00:00:00.000Z",
token: "first-owner",
});
assert.equal(existsSync(lockPath), true);
assert.throws(
() =>
acquireFuzzLock(lockPath, {
pid: process.pid,
startedAt: "2026-07-25T00:00:01.000Z",
token: "second-owner",
}),
/another fuzz campaign is already running/i,
);
assert.equal(existsSync(lockPath), true);
first.release();
assert.equal(existsSync(lockPath), false);
const next = acquireFuzzLock(lockPath, {
pid: process.pid,
startedAt: "2026-07-25T00:00:02.000Z",
token: "next-owner",
});
next.release();
assert.equal(existsSync(lockPath), false);
} finally {
rmSync(root, { force: true, recursive: true });
}
});