FE-GATE-027은 `check:release-admission`을 먼저, `scan:dependency-advisories` 를 뒤에 돈다. `ci:gate`는 처음 실패한 명령에서 멈춘다. 그래서 공개 대상 승인이 거절된 run에는 advisory 기록(`artifacts/security/ dependency-advisories.json`)이 생기지 않는다. 운영 문서는 release 산출물이 결과와 상관없이 이 기록을 싣는다고 적는다. 명령 순서를 scan → 승인으로 바꾼다. scan은 막지 않는 신호라 항상 exit 0이고, 승인 판정과 gate 결과는 그대로다. 문서 두 곳(한국어·영어)에 올라가는 것은 그 run에 생긴 파일이고, 승인이 거절돼도 기록이 있으며, FE-GATE-015가 실패하면 FE-GATE-027이 돌지 않아 기록이 없다고 적는다. gate 모양이 바뀌어 계약 기준선의 `gateShapeSha256`을 다시 적었다(owner DongHyeonka, reason에 1106/13-01, 개수는 그대로). 생성 workflow는 명령 순서를 담지 않아 바뀌지 않는다. 버린 대안: (a) 문서만 고치기 — 거절된 run에서 신호가 한 run 늦는 것이 남는다. (c) scan을 always 단계로 따로 빼기 — 계약 단계와 workflow가 바뀌어 이 결함에 비해 크다. 위험·한계: 승인 전에 pnpm audit이 돌아 거절되는 run이 최대 120초(scan timeout) 늦게 끝난다. scan이 정책 파일을 못 읽어 죽으면 이제 승인이 돌지 않는다(전에도 gate는 실패했다). FE-GATE-015가 실패한 run에는 여전히 기록이 없다. 실제 runner의 upload가 없는 파일을 건너뛰는지는 미확인이다. 제품이 `config/ci/contract-baseline.json`을 자기 값으로 다시 적어 두었다면 받은 뒤 다시 적어야 한다. 새 digest는 jq로 계산했다. 같은 계산이 바꾸기 전 기준선(7bebafe6…)을 그대로 재현했다. 검증: desktop batch에서 확인. `node scripts/run-vitest.ts run tests/system/ci-runner/ci-evidence-freshness.test.ts tests/unit/dependency-advisories.test.ts` — 새 "writes the advisory record when the release admission refuses the candidate"와 바꾼 "runs before the release admission (FE-GATE-027) ..."가 수정 전 계약에서 실패하고 수정 뒤 통과한다. `check:ci`, 13-R1 C. Refs: 1106/13-01
250 lines
9.6 KiB
TypeScript
250 lines
9.6 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 { DEPENDENCY_ADVISORIES_RECORD_PATH } from "../../../scripts/lib/dependency-advisories.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);
|
|
});
|
|
|
|
// 1106/13-01. ci:gate stops at the first command that fails. FE-GATE-027 ran
|
|
// the admission first, so a refused candidate left no advisory record, and the
|
|
// release evidence the operations guide points to had none. The two package
|
|
// scripts are stand-ins: the admission refuses, the scan writes its record.
|
|
describe("CI-runner FE-GATE-027 advisory record", () => {
|
|
it("writes the advisory record when the release admission refuses the candidate", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "ci-gate-refused-admission-"));
|
|
temporaryRoots.push(root);
|
|
await mkdir(path.join(root, "config/ci"), { recursive: true });
|
|
await mkdir(path.join(root, path.dirname(DEPENDENCY_ADVISORIES_RECORD_PATH)), {
|
|
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-027",
|
|
);
|
|
const logArtifact = contract.artifacts.find(
|
|
(entry: Record<string, any>) => entry.id === gate.logArtifactId,
|
|
);
|
|
const packageDocument = JSON.parse(
|
|
await readFile("package.json", "utf8"),
|
|
) as { scripts: Record<string, string> };
|
|
packageDocument.scripts["check:release-admission"] =
|
|
`node -e "process.stderr.write('release admission refused for production: fixture'),process.exit(1)"`;
|
|
packageDocument.scripts["scan:dependency-advisories"] =
|
|
`node -e 'require("node:fs").writeFileSync(${JSON.stringify(DEPENDENCY_ADVISORIES_RECORD_PATH)}, "fixture record")'`;
|
|
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-027"],
|
|
{
|
|
cwd: root,
|
|
encoding: "utf8",
|
|
env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT, CI: "false" },
|
|
timeout: 15_000,
|
|
},
|
|
);
|
|
|
|
expect(result.status, result.stderr).toBe(1);
|
|
expect(
|
|
await readFile(path.join(root, logArtifact.path), "utf8"),
|
|
).toContain("release admission refused for production: fixture");
|
|
expect(
|
|
await readFile(path.join(root, DEPENDENCY_ADVISORIES_RECORD_PATH), "utf8"),
|
|
).toBe("fixture record");
|
|
}, 20_000);
|
|
});
|