Files
clean-architecture-frontend…/tests/unit/dependency-advisories.test.ts
T
DongHyeonka c5ab7a3983 fix(ci): FE-GATE-027이 advisory 검사를 승인보다 먼저 돌린다
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
2026-11-06 05:18:09 +09:00

116 lines
4.4 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import { summarizeDependencyAdvisories } from "../../scripts/lib/dependency-advisories.ts";
/**
* 1103/13-03. The lockfile broke the template's own vulnerability policy
* (high and above, no exception) and nothing said so before the production
* promotion provider, which a template copy may not have. The summary applies
* that policy to `pnpm audit --json`.
*/
const POLICY = { blockAtSeverity: "high" };
const NO_EXCEPTIONS = { schemaVersion: 1, exceptions: [] };
const LOCKFILE = "a".repeat(64);
const advisory = (
id: string,
module: string,
severity: string,
findings: readonly Readonly<{ version: string; dev: boolean }>[],
) => ({
github_advisory_id: id,
module_name: module,
severity,
patched_versions: ">=9.9.9",
findings: findings.map((finding) => ({ ...finding, paths: [`.>${module}`] })),
});
const audit = (...advisories: ReturnType<typeof advisory>[]) => ({
advisories: Object.fromEntries(advisories.map((entry, index) => [String(index), entry])),
metadata: { vulnerabilities: {} },
});
describe("dependency advisory summary (1103/13-03)", () => {
it("names what the policy would block at promotion, in production and development", () => {
const summary = summarizeDependencyAdvisories(
audit(
advisory("GHSA-prod-high", "zod", "high", [{ version: "4.4.3", dev: false }]),
advisory("GHSA-dev-critical", "storybook", "critical", [{ version: "10.5.4", dev: true }]),
advisory("GHSA-dev-moderate", "postcss", "moderate", [{ version: "8.5.22", dev: true }]),
),
POLICY,
NO_EXCEPTIONS,
LOCKFILE,
);
expect(summary.status).toBe("POLICY_VIOLATION");
expect(summary.blocking).toEqual([
"GHSA-prod-high:zod@4.4.3:high",
"GHSA-dev-critical:storybook@10.5.4:critical",
]);
expect(summary.counts.production).toMatchObject({ high: 1, critical: 0 });
expect(summary.counts.development).toMatchObject({ critical: 1, moderate: 1 });
});
it("passes when nothing reaches the blocking severity", () => {
const summary = summarizeDependencyAdvisories(
audit(advisory("GHSA-dev-moderate", "postcss", "moderate", [{ version: "8.5.22", dev: true }])),
POLICY,
NO_EXCEPTIONS,
LOCKFILE,
);
expect(summary).toMatchObject({ status: "PASS", blocking: [] });
});
it("honours a valid exception the way the promotion verdict does", () => {
const exceptions = {
schemaVersion: 1,
exceptions: [
{
vulnerabilityId: "GHSA-prod-high",
packageName: "zod",
owner: "frontend-platform",
reviewer: "security-review",
reason: "not reachable",
expiresAt: "2027-01-01T00:00:00.000Z",
},
],
};
expect(
summarizeDependencyAdvisories(
audit(advisory("GHSA-prod-high", "zod", "high", [{ version: "4.4.3", dev: false }])),
POLICY,
exceptions,
LOCKFILE,
new Date("2026-11-04T00:00:00.000Z"),
),
).toMatchObject({ status: "PASS", blocking: [] });
});
it("is UNVERIFIED, not PASS, when the audit returned no report", () => {
for (const output of [null, {}, { error: { code: "ENOTFOUND" } }]) {
expect(summarizeDependencyAdvisories(output, POLICY, NO_EXCEPTIONS, LOCKFILE)).toMatchObject({
status: "UNVERIFIED",
reason: expect.stringContaining("pnpm audit"),
});
}
});
// 1106/13-01. ci:gate stops at the first command that fails. With the scan
// after the admission, a refused run had no advisory record, while the
// operations guide says the release evidence carries it. The scan never
// fails, so running it first leaves the admission verdict as it was.
it("runs before the release admission (FE-GATE-027) and never fails the gate by itself", async () => {
const contract = JSON.parse(await readFile("config/ci/gates.json", "utf8")) as {
gates: { id: string; commandIds: string[] }[];
commands: { id: string; script: string }[];
};
const scripts = (contract.gates.find(({ id }) => id === "FE-GATE-027")?.commandIds ?? []).map(
(commandId) => contract.commands.find(({ id }) => id === commandId)?.script,
);
expect(scripts).toEqual(["scan:dependency-advisories", "check:release-admission"]);
const source = await readFile("scripts/scan-dependency-advisories.ts", "utf8");
expect(source).not.toMatch(/process\.exit(?:Code)?\s*(?:=|\()\s*[1-9]/u);
});
});