Files
tech-log-frontend/tests/system/ci-runner/ci-evidence-freshness.test.ts
T
DongHyeonka c80320dfc7 chore: sync the frontend template from ebea300 to af3d8e6
Carries 359 template commits, tag v0.2.0 plus one documentation commit: the
generator-built feature index with its app, bounded-context and feature
declarations, the src/platform kernel and scale tooling, the 2026-09-24 src
review fixes, and the 2026-09-25 maturity review round with its CHANGELOG
[보안]/[계약] rows. 691 of the 824 template paths are applied, 85 of them
merged with product changes; 127 are not carried.

Product identity is unchanged: name, version 0.1.0, routes, design and the
TechLog domain.

Three decisions worth naming. TechLog stays composed directly, as the last
two syncs recorded; its directory carries a NOT_INSTALLED marker that says so,
and every installed-* composer takes the template's projection with TechLog
added on top. The reference sample is no longer installed: the template now
installs a feature only through feature-module.ts and context-routes.ts,
which load the screens this product deleted, so its three operations, six
schemas and one topic leave the registries, recorded as registry change
evidence. And AppRouter mounts the platform and TechLog routes only; the
template's bounded-context route gateway waits for a generator-installed
feature.

Required fixes: readSubject on the BFF session owner (without it every HTTP
Studio session would close as integration-failed), zod through the facade in
nine TechLog files, noUnusedLocals, and public/config.json written out to
match the local profile. Derived baselines were recomputed after reproducing
both sides' values: CI contract 101 commands / 106 references / 141
artifacts, gate shape c9adcf85; registry approval 2dc6c3a3; the runtime
config schema baseline equals the schema at 8210d48.

Verified here: types, lint, architecture, adapter inventory, CI contract,
i18n, design system, diagnostics, browser security, dev release manifest,
TechLog contract and build pass; 220 component, 155 integration, 15
contract, 418 TechLog, 43 reference-feature, 18 recipe and 46
release-coherence tests pass, and 2381 of 2383 unit tests. Reproduced at
8210d48 first and unchanged: check:registries (byte-identical),
test:runtime-schema, verify:documentation. Brought by the template and
escalated rather than suppressed: check:request-fanout on TechLog's cursor
pagination, check:remediation-ledger (fails upstream too), the shared-chunk
hash test, and the registry-dependent sample removal and second-feature
tests. Playwright suites were not run.

Full record, the five open questions and the follow-ups in
docs/operations/template-sync-2026-09-29.md.

(cherry picked from commit b2170cf265dea45dc9cc05d3c61e627e97f31cdb)
2026-11-12 08:28:54 +09:00

187 lines
6.9 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { loadCiGateContract } from "../../../scripts/contracts/ci-gates.ts";
import { FIXTURE_PNPM_ENVIRONMENT } from "../../../scripts/lib/fixture-node-modules.ts";
// F-12. The temp roots have a package.json but no node_modules or lockfile.
// Run directly (not under pnpm), pnpm's pre-script install check started an
// install there and failed with ERR_PNPM_IGNORED_BUILDS; the gate runner has
// to run the scripts as they are.
const temporaryRoots: string[] = [];
afterEach(async () => {
await Promise.all(
temporaryRoots.splice(0).map((root) =>
rm(root, { recursive: true, force: true }),
),
);
});
describe("CI-runner command-generated evidence freshness", () => {
it("rejects stale command-generated evidence from a successful no-op producer", async () => {
const root = await mkdtemp(path.join(tmpdir(), "ci-gate-stale-evidence-"));
temporaryRoots.push(root);
await mkdir(path.join(root, "config/ci"), { recursive: true });
await mkdir(path.join(root, "artifacts/tests"), { recursive: true });
const contract = JSON.parse(
JSON.stringify(await loadCiGateContract(process.cwd())),
) as Record<string, any>;
const command = contract.commands.find(
(entry: Record<string, any>) => entry.id === "test-runtime-schema",
);
command.script = "test:stale-evidence-noop";
const evidence = contract.artifacts.find(
(entry: Record<string, any>) =>
entry.path === "artifacts/tests/runtime-schema.xml",
);
const packageDocument = JSON.parse(
await readFile("package.json", "utf8"),
) as { scripts: Record<string, string> };
packageDocument.scripts[command.script] = "true";
await writeFile(
path.join(root, "config/ci/gates.json"),
`${JSON.stringify(contract)}\n`,
);
await writeFile(
path.join(root, "config/ci/contract-baseline.json"),
await readFile("config/ci/contract-baseline.json"),
);
await writeFile(
path.join(root, "package.json"),
`${JSON.stringify(packageDocument)}\n`,
);
await writeFile(
path.join(root, evidence.path),
'<testsuite name="stale" tests="0" failures="0"/>\n',
);
const result = spawnSync(
process.execPath,
[path.resolve("scripts/run-ci-gate.ts"), "FE-GATE-004"],
{ cwd: root, encoding: "utf8", env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT, CI: "false" } },
);
expect(result.status).toBe(1);
expect(
await readFile(
path.join(root, "artifacts/quality/gates/FE-GATE-004.txt"),
"utf8",
),
).toMatch(/not freshly produced/i);
});
it("accepts a fresh deterministic rewrite with identical evidence bytes", async () => {
const root = await mkdtemp(
path.join(tmpdir(), "ci-gate-identical-rewrite-"),
);
temporaryRoots.push(root);
await mkdir(path.join(root, "config/ci"), { recursive: true });
await mkdir(path.join(root, "artifacts/tests"), { recursive: true });
const contract = JSON.parse(
JSON.stringify(await loadCiGateContract(process.cwd())),
) as Record<string, any>;
const command = contract.commands.find(
(entry: Record<string, any>) => entry.id === "test-runtime-schema",
);
command.script = "test:identical-evidence-rewrite";
const evidence = contract.artifacts.find(
(entry: Record<string, any>) =>
entry.path === "artifacts/tests/runtime-schema.xml",
);
const evidenceBytes =
'<testsuite name="deterministic" tests="0" failures="0"/>\n';
const packageDocument = JSON.parse(
await readFile("package.json", "utf8"),
) as { scripts: Record<string, string> };
packageDocument.scripts[command.script] =
`node -e 'require("node:fs").writeFileSync("${evidence.path}", Buffer.from("${Buffer.from(evidenceBytes).toString("base64")}", "base64"))'`;
await writeFile(
path.join(root, "config/ci/gates.json"),
`${JSON.stringify(contract)}\n`,
);
await writeFile(
path.join(root, "config/ci/contract-baseline.json"),
await readFile("config/ci/contract-baseline.json"),
);
await writeFile(
path.join(root, "package.json"),
`${JSON.stringify(packageDocument)}\n`,
);
await writeFile(path.join(root, evidence.path), evidenceBytes);
const result = spawnSync(
process.execPath,
[path.resolve("scripts/run-ci-gate.ts"), "FE-GATE-004"],
{ cwd: root, encoding: "utf8", env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT, CI: "false" } },
);
expect(result.status).toBe(0);
expect(result.stdout).toMatch(/FE-GATE-004 runtime-schema: PASS/);
});
});
describe("CI-runner gate output budget", () => {
it("caps aggregate gate output at the log schema before later commands can accumulate", async () => {
const root = await mkdtemp(path.join(tmpdir(), "ci-gate-output-budget-"));
temporaryRoots.push(root);
await mkdir(path.join(root, "config/ci"), { recursive: true });
const contract = JSON.parse(
JSON.stringify(await loadCiGateContract(process.cwd())),
) as Record<string, any>;
const gate = contract.gates.find(
(entry: Record<string, any>) => entry.id === "FE-GATE-001",
);
const command = contract.commands.find(
(entry: Record<string, any>) => entry.id === gate.commandIds[0],
);
command.script = "test:huge-output";
const logArtifact = contract.artifacts.find(
(entry: Record<string, any>) => entry.id === gate.logArtifactId,
);
const logSchema = contract.artifactSchemas.find(
(entry: Record<string, any>) => entry.id === logArtifact.schemaId,
);
logSchema.maxBytes = 8_192;
const packageDocument = JSON.parse(
await readFile("package.json", "utf8"),
) as { scripts: Record<string, string> };
packageDocument.scripts["test:huge-output"] =
"node -e \"process.stdout.write('x'.repeat(20000))\"";
await writeFile(
path.join(root, "config/ci/gates.json"),
`${JSON.stringify(contract)}\n`,
);
await writeFile(
path.join(root, "config/ci/contract-baseline.json"),
await readFile("config/ci/contract-baseline.json"),
);
await writeFile(
path.join(root, "package.json"),
`${JSON.stringify(packageDocument)}\n`,
);
const result = spawnSync(
process.execPath,
[path.resolve("scripts/run-ci-gate.ts"), "FE-GATE-001"],
{
cwd: root,
encoding: "utf8",
env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT, CI: "false" },
timeout: 15_000,
},
);
expect(result.status).toBe(1);
const log = await readFile(path.join(root, logArtifact.path));
expect(log.byteLength).toBeLessThanOrEqual(8_192);
expect(log.toString("utf8")).toMatch(
/aggregate output|INFRASTRUCTURE_FAILURE/i,
);
}, 20_000);
});