Files
clean-architecture-frontend…/scripts/scan-dependency-advisories.ts
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

82 lines
3.2 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import {
DEPENDENCY_ADVISORIES_RECORD_PATH,
summarizeDependencyAdvisories,
} from "./lib/dependency-advisories.ts";
/**
* 1103/13-03. Release-stage signal for known dependency advisories
* (FE-GATE-027, before the release admission of the candidate, so a refused
* candidate still leaves the record: 1106/13-01). It runs
* `pnpm audit --json` over the lockfile and applies
* config/security/vulnerability-policy.json with its exceptions, the policy the
* production promotion provider is held to. The result is a line in the gate
* log and artifacts/security/dependency-advisories.json.
*
* It never fails the gate. An advisory database that changes under unchanged
* code would otherwise break a release run, and without the registry the
* result is UNVERIFIED, not PASS. The signed verdict of the vulnerability
* provider stays the only one that decides a promotion.
*/
const RECORD_PATH = DEPENDENCY_ADVISORIES_RECORD_PATH;
const [policy, exceptions, lockfile] = await Promise.all([
readFile("config/security/vulnerability-policy.json", "utf8").then((text) => JSON.parse(text) as Record<string, unknown>),
readFile("config/security/vulnerability-exceptions.json", "utf8").then((text) => JSON.parse(text) as Record<string, unknown>),
readFile("pnpm-lock.yaml"),
]);
const lockfileSha256 = createHash("sha256").update(lockfile).digest("hex");
// pnpm audit exits 1 when it finds advisories; the JSON on stdout is the result.
const run = spawnSync("corepack", ["pnpm", "audit", "--json"], {
encoding: "utf8",
maxBuffer: 64 * 1024 * 1024,
timeout: 120_000,
});
let audit: unknown;
try {
audit = JSON.parse(run.stdout ?? "");
} catch {
audit = null;
}
const summary = summarizeDependencyAdvisories(audit, policy, exceptions, lockfileSha256);
await mkdir("artifacts/security", { recursive: true });
await writeFile(
RECORD_PATH,
`${JSON.stringify(
{
schemaVersion: 1,
generatedAt: new Date().toISOString(),
source: "pnpm audit --json",
authoritative: false,
lockfileSha256,
blockAtSeverity: policy["blockAtSeverity"] ?? null,
...summary,
},
null,
2,
)}\n`,
);
const count = (scope: Readonly<Record<string, number>>) =>
`critical ${scope["critical"]}, high ${scope["high"]}, moderate ${scope["moderate"]}, low ${scope["low"]}`;
process.stdout.write(
`Dependency advisories: ${summary.status} (production: ${count(summary.counts.production)}; ` +
`development: ${count(summary.counts.development)}); record at ${RECORD_PATH}. ` +
"Not blocking: the production promotion provider decides.\n",
);
if (summary.status === "POLICY_VIOLATION") {
process.stderr.write(
`WARNING: the vulnerability policy (block at ${String(policy["blockAtSeverity"])}) would refuse this lockfile at production promotion:\n` +
summary.blocking.map((finding) => ` ${finding}\n`).join("") +
"Update the dependency or record a reviewed exception in config/security/vulnerability-exceptions.json.\n",
);
}
if (summary.status === "UNVERIFIED") {
process.stderr.write(`WARNING: dependency advisories UNVERIFIED: ${summary.reason}\n`);
}