The product was materialized from the template at `4dc033c` and has stayed on it through 43 template commits, so it was missing all three rounds of adapter remediation — including files it never had, such as the shared `abortable-operation` primitive and the `exact-snapshot` decoder that later fixes are written against. Taking only the newest round was not possible for that reason: the delta is coherent only as a whole. The product had not touched `src/adapters` at all since materialization, so the 140-file delta applied with a three-way merge and no conflicts. `package.json` was the single overlap and merged cleanly: the product owns `name`, the template contributed `check:adapter-inventory`, `check:remediation-ledger` and the image-resolve-signal type fixture. All 24 product-owned files — README, index.html, CI workflow, i18n catalog, home page, generated schemas, evidence scripts, component and visual snapshots — are byte-identical to `main`. `template.lock.json` now pins the synced revision and tree. Verified in this repository, not inherited from the template: six type projects, lint, nine gates (adapter inventory, remediation ledger, registries, diagnostics, realtime boundaries, architecture, browser file/storage boundaries, optional recipes, documentation), the production build, and 2,054 of 2,073 tests. The 19 failures are all in `tests/unit/ci-artifact-contract.test.ts` and are the same pre-existing sandbox RLIMIT, EMFILE, umask and `/tmp` permission behaviour the template records; four suites that failed once under parallel load pass in isolation. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
163 lines
5.5 KiB
TypeScript
163 lines
5.5 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 { linkFixtureNodeModules } from "../../scripts/lib/fixture-node-modules.ts";
|
|
|
|
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 ![
|
|
".release",
|
|
"artifacts",
|
|
"dist",
|
|
"node_modules",
|
|
].includes(first ?? "");
|
|
},
|
|
});
|
|
await cp(path.join(sourceRoot, "artifacts"), path.join(fixtureRoot, "artifacts"), {
|
|
recursive: true,
|
|
});
|
|
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,
|
|
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,
|
|
);
|