tests/integration/security-followup-archive.test.ts는 후보 빌드에 쓸 증거를 얻으려고 checkout의 artifacts/를 통째로 사본에 복사한다. 같은 integration 실행에서 tests/integration/http-scenario-catalog.test.ts가 artifacts/tests/http-scenario-executions.json을 임시 파일에 쓰고 rename한다. 복사가 목록을 읽은 뒤 그 임시 파일이 rename되면 ENOENT로 실패한다. desktop FE-GATE-007(2026-11-12, load 9)에서 났다. 복사 filter가 원자적 쓰기의 임시 파일(.<이름>.<무작위>.tmp)을 건너뛴다. 그런 파일은 쓰는 중이라 증거가 아니다. fs.cp는 filter를 stat보다 먼저 부르므로, 건너뛴 파일은 사라져도 오류가 없다. 버린 것: - 필요한 증거 경로만 복사: 공급망 생성이 추적 파일(artifacts의 .gitkeep 포함)을 모두 lstat하고 build가 읽는 증거가 여러 곳이라, 목록을 따로 관리해야 한다. - 두 시험을 같이 돌지 않게 하기: integration 층 전체를 직렬로 돌려야 한다. 위험: 임시 파일이 아닌 파일을 다른 시험이 지우는 경합은 남는다. 지금 artifacts/ 아래에서 그렇게 하는 시험은 찾지 못했다. 검증(desktop): - 다른 프로세스가 artifacts/tests에 임시 파일 10개를 계속 만들고 rename하는 동안 이 시험을 돌렸다. main 6b4f703c는 3회 중 2회가 같은 ENOENT(.tmp)로 실패했고, 이 커밋은 3회 모두 통과했다. - test:unit, check:types, check:ci, lint, verify:documentation.
171 lines
6.0 KiB
TypeScript
171 lines
6.0 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { cp, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { expect, it } from "vitest";
|
|
|
|
import {
|
|
captureCiCandidateArchive,
|
|
withVerifiedCapturedCandidate,
|
|
} from "../../scripts/lib/ci-candidate-archive.ts";
|
|
import { verifyArchivedLocalEvidence } from "../../scripts/lib/local-release-evidence.ts";
|
|
import {
|
|
RELEASE_CANDIDATE_EVIDENCE_PATHS,
|
|
RELEASE_CANDIDATE_MANIFEST_PATH,
|
|
releaseCandidateManifestSchema,
|
|
} from "../../scripts/lib/release-candidate.ts";
|
|
import {
|
|
FIXTURE_PNPM_ENVIRONMENT,
|
|
linkFixtureNodeModules,
|
|
} from "../../scripts/lib/fixture-node-modules.ts";
|
|
import { selectRepositoryPaths } from "../../scripts/lib/repository-layout.ts";
|
|
|
|
/** The temporary file of an atomic write: `.<name>.<random>.tmp`. */
|
|
const IN_FLIGHT_WRITE = /^\..+\.tmp$/u;
|
|
|
|
it(
|
|
"builds a real candidate assessment and passes the default archived verifier from the captured archive",
|
|
async () => {
|
|
const sourceRoot = process.cwd();
|
|
const fixtureRoot = await mkdtemp(path.join(tmpdir(), "security-followup-producer-"));
|
|
try {
|
|
await cp(sourceRoot, fixtureRoot, {
|
|
recursive: true,
|
|
filter: (source) => {
|
|
const relative = path.relative(sourceRoot, source);
|
|
if (!relative) return true;
|
|
const first = relative.split(path.sep)[0];
|
|
return !selectRepositoryPaths("supply-chain-fixture-skip").includes(first ?? "");
|
|
},
|
|
});
|
|
// Other test files write their receipts under artifacts/ while this one
|
|
// copies it: a temporary file of an atomic write (.<name>.<uuid>.tmp) was
|
|
// renamed between the listing and the copy, and the copy failed with
|
|
// ENOENT (FE-GATE-007 on desktop, 2026-11-12). It is never evidence.
|
|
await cp(path.join(sourceRoot, "artifacts"), path.join(fixtureRoot, "artifacts"), {
|
|
recursive: true,
|
|
filter: (source) => !IN_FLIGHT_WRITE.test(path.basename(source)),
|
|
});
|
|
await rm(path.join(fixtureRoot, "artifacts/release"), {
|
|
recursive: true,
|
|
force: true,
|
|
});
|
|
await linkFixtureNodeModules(fixtureRoot, sourceRoot);
|
|
const git = spawnSync("git", ["show", "-s", "--format=%H%n%ct", "HEAD"], {
|
|
cwd: sourceRoot,
|
|
encoding: "utf8",
|
|
});
|
|
expect(git.status, git.stderr).toBe(0);
|
|
const [revision, sourceDateEpoch] = git.stdout.trim().split(/\r?\n/u);
|
|
const build = spawnSync(
|
|
"corepack",
|
|
["pnpm", "build:release-candidate"],
|
|
{
|
|
cwd: fixtureRoot,
|
|
encoding: "utf8",
|
|
timeout: 120_000,
|
|
maxBuffer: 32 * 1024 * 1024,
|
|
env: {
|
|
...process.env,
|
|
...FIXTURE_PNPM_ENVIRONMENT,
|
|
CI: "true",
|
|
VITE_BUILD_ID: "security-followup-integration",
|
|
VITE_COMMIT_SHA: revision,
|
|
RELEASE_ID: "security-followup-integration",
|
|
SOURCE_DATE_EPOCH: sourceDateEpoch,
|
|
CI_RUNNER_IMAGE: `fixture@sha256:${"a".repeat(64)}`,
|
|
},
|
|
},
|
|
);
|
|
expect(build.status, `${build.stdout}\n${build.stderr}`).toBe(0);
|
|
const manifest = releaseCandidateManifestSchema.parse(
|
|
JSON.parse(
|
|
await readFile(path.join(fixtureRoot, RELEASE_CANDIDATE_MANIFEST_PATH), "utf8"),
|
|
) as unknown,
|
|
);
|
|
const archivePath = path.join(fixtureRoot, "candidate.tar.gz");
|
|
const archived = spawnSync(
|
|
"/usr/bin/tar",
|
|
[
|
|
"--sort=name",
|
|
"--mtime=@0",
|
|
"--owner=0",
|
|
"--group=0",
|
|
"--numeric-owner",
|
|
"-czf",
|
|
archivePath,
|
|
"dist",
|
|
...RELEASE_CANDIDATE_EVIDENCE_PATHS,
|
|
RELEASE_CANDIDATE_MANIFEST_PATH,
|
|
],
|
|
{ cwd: fixtureRoot, encoding: "utf8" },
|
|
);
|
|
expect(archived.status, archived.stderr).toBe(0);
|
|
const archiveBytes = await readFile(archivePath);
|
|
const expectedSha256 = await import("node:crypto").then(({ createHash }) =>
|
|
createHash("sha256").update(archiveBytes).digest("hex"),
|
|
);
|
|
const captured = await captureCiCandidateArchive({ archivePath, expectedSha256 });
|
|
const verified = await withVerifiedCapturedCandidate({
|
|
captured,
|
|
verify: ({ extractionRoot, manifest: extractedManifest }) =>
|
|
verifyArchivedLocalEvidence({
|
|
extractionRoot,
|
|
expectedManifest: extractedManifest,
|
|
}),
|
|
});
|
|
|
|
expect(manifest.files).toContainEqual(
|
|
expect.objectContaining({
|
|
path: "artifacts/security/local-evidence-assessment.json",
|
|
}),
|
|
);
|
|
expect(verified).toEqual(
|
|
expect.objectContaining({
|
|
status: "PASS",
|
|
identity: expect.objectContaining({ sourceRevision: revision }),
|
|
failures: [],
|
|
}),
|
|
);
|
|
|
|
const outsideRoot = await mkdtemp(path.join(tmpdir(), "security-followup-outside-"));
|
|
try {
|
|
await mkdir(path.join(outsideRoot, "config/security"), { recursive: true });
|
|
await writeFile(
|
|
path.join(outsideRoot, "config/security/dependency-policy.json"),
|
|
'{"contradictoryCheckoutCanary":"FAIL"}\n',
|
|
);
|
|
const outsideVerification = spawnSync(
|
|
process.execPath,
|
|
[
|
|
path.join(sourceRoot, "scripts/verify-archived-local-evidence.ts"),
|
|
"--archive",
|
|
archivePath,
|
|
"--sha256",
|
|
expectedSha256,
|
|
],
|
|
{
|
|
cwd: outsideRoot,
|
|
encoding: "utf8",
|
|
timeout: 120_000,
|
|
maxBuffer: 32 * 1024 * 1024,
|
|
},
|
|
);
|
|
expect(
|
|
outsideVerification.status,
|
|
`${outsideVerification.stdout}\n${outsideVerification.stderr}`,
|
|
).toBe(0);
|
|
expect(outsideVerification.stdout).toContain(
|
|
"Archived local evidence verification: PASS",
|
|
);
|
|
} finally {
|
|
await rm(outsideRoot, { recursive: true, force: true });
|
|
}
|
|
} finally {
|
|
await rm(fixtureRoot, { recursive: true, force: true });
|
|
}
|
|
},
|
|
150_000,
|
|
);
|