Merge lane K: CI, guardrails and release fixes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 12-11. One violation line names the rule, the edge and the import specifier
|
||||
* as written, then the rule's `comment` from .dependency-cruiser.json: why the
|
||||
* edge is forbidden and where the code should go instead.
|
||||
*/
|
||||
export function formatArchitectureViolation(
|
||||
violation: Readonly<{ rule: string; source: string; target: string; cycle?: readonly string[] }>,
|
||||
specifiers: readonly string[],
|
||||
comment: string | undefined,
|
||||
): string {
|
||||
const imports = specifiers.length > 0
|
||||
? ` (import ${specifiers.map((specifier) => JSON.stringify(specifier)).join(", ")})`
|
||||
: "";
|
||||
const cycle = violation.cycle ? ` (cycle group: ${violation.cycle.join(", ")})` : "";
|
||||
const why = comment ? ` why: ${comment}\n` : "";
|
||||
return `Architecture violation [${violation.rule}]: ${violation.source} -> ${violation.target}${imports}${cycle}\n${why}`;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { chmod, readdir, stat } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
/**
|
||||
* 13-02. dist is published as-is to a web server that may run as another OS
|
||||
* user, so every file in it must be readable by others. The validated JSON
|
||||
* writer creates files 0600 on purpose (evidence under artifacts/ stays
|
||||
* private); the build adds read bits to what it publishes instead of loosening
|
||||
* that writer.
|
||||
*/
|
||||
export async function makeDistFilesPublic(directory: string): Promise<void> {
|
||||
for (const entry of await readdir(directory, { recursive: true, withFileTypes: true })) {
|
||||
if (!entry.isFile()) continue;
|
||||
const file = path.join(entry.parentPath, entry.name);
|
||||
const { mode } = await stat(file);
|
||||
if ((mode & 0o004) === 0) await chmod(file, (mode & 0o7777) | 0o444);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import {
|
||||
PROMOTION_VERIFIER_ID,
|
||||
PROMOTION_VERIFIER_VERSION,
|
||||
PROVIDER_FUTURE_SKEW_MS,
|
||||
assertDistinctProviderTrust,
|
||||
evaluatePromotionEvidence,
|
||||
providerVerificationArtifactSchema,
|
||||
@@ -35,6 +36,29 @@ export type ExactPromotionExpectedContext = Readonly<{
|
||||
lockfileSha256?: string;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* 13-04. `current` checks provider evidence against the clock, as a new
|
||||
* promotion must. `archived` re-verifies a release promoted earlier (deploying
|
||||
* it later, or rolling back to it): signatures, digests and members are checked
|
||||
* the same way, but freshness is judged at the promotion's recorded
|
||||
* `verifiedAt`, which may not lie in the future. Promotion itself
|
||||
* (promotion-stager.ts) never passes `archived`.
|
||||
*/
|
||||
export type PromotionFreshness = "current" | "archived";
|
||||
|
||||
export function promotionEvidenceTime(
|
||||
freshness: PromotionFreshness,
|
||||
verifiedAt: string,
|
||||
now: number,
|
||||
): number {
|
||||
if (freshness === "current") return now;
|
||||
const verified = Date.parse(verifiedAt);
|
||||
if (!Number.isFinite(verified) || verified > now + PROVIDER_FUTURE_SKEW_MS) {
|
||||
throw new Error("archived promotion verifiedAt is in the future or invalid");
|
||||
}
|
||||
return verified;
|
||||
}
|
||||
|
||||
export async function verifyExactPromotionBundle(
|
||||
files: ExactPromotionBundle,
|
||||
options: Readonly<{
|
||||
@@ -42,6 +66,7 @@ export async function verifyExactPromotionBundle(
|
||||
provenanceTrust: ProviderTrust;
|
||||
expected: ExactPromotionExpectedContext;
|
||||
nowEpochMs?: () => number;
|
||||
freshness?: PromotionFreshness;
|
||||
}>,
|
||||
): Promise<Readonly<{ status: "PASS" }>> {
|
||||
assertDistinctProviderTrust(options);
|
||||
@@ -286,7 +311,12 @@ export async function verifyExactPromotionBundle(
|
||||
provenanceAttestation: provenance,
|
||||
vulnerabilityTrust: options.vulnerabilityTrust,
|
||||
provenanceTrust: options.provenanceTrust,
|
||||
nowEpochMs: options.nowEpochMs,
|
||||
nowEpochMs: () =>
|
||||
promotionEvidenceTime(
|
||||
options.freshness ?? "current",
|
||||
promotion.verifiedAt,
|
||||
(options.nowEpochMs ?? Date.now)(),
|
||||
),
|
||||
});
|
||||
if (
|
||||
reevaluated.status !== "PASS" ||
|
||||
|
||||
@@ -1,6 +1,33 @@
|
||||
import type { InstalledServiceWorkerSelection } from "../../src/contracts/service-worker.ts";
|
||||
|
||||
const LOOPBACK_IPV4 = /^127(?:\.\d{1,3}){3}$/;
|
||||
|
||||
export type HostingMode = "live" | "invalid-live" | "fixture";
|
||||
export type HostingVerdict = "PASS" | "FAIL" | "UNVERIFIED";
|
||||
|
||||
/**
|
||||
* 13-05 (D-14). The fixture compares the declared headers with a copy of
|
||||
* themselves, so it can only find a contradiction, never prove hosting. Only a
|
||||
* live probe of the deployed release can PASS.
|
||||
*/
|
||||
export function hostingVerdict(mode: HostingMode, passed: boolean): HostingVerdict {
|
||||
if (!passed) return "FAIL";
|
||||
return mode === "live" ? "PASS" : "UNVERIFIED";
|
||||
}
|
||||
|
||||
/**
|
||||
* 13-05. The live probe requests the entry script the served index.html names,
|
||||
* so it checks the release that is deployed rather than the first asset of a
|
||||
* local build, which the deployed release may not contain.
|
||||
*/
|
||||
export function servedEntryScript(indexHtml: string): string | null {
|
||||
for (const tag of indexHtml.match(/<script\b[^>]*>/gu) ?? []) {
|
||||
if (!/\btype=["']module["']/u.test(tag)) continue;
|
||||
const source = /\bsrc=["']([^"']+\.js)["']/u.exec(tag)?.[1];
|
||||
if (source) return source;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const PUBLIC_SERVICE_WORKER = /(?:^|\/)(?:service-worker|sw)(?:[.-][^/]*)?\.js$/i;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,8 +15,20 @@ const REVIEW_FIELDS = Object.freeze([
|
||||
"Screen reader",
|
||||
]);
|
||||
|
||||
export function validateManualA11yEvidence(content: string) {
|
||||
const fields = Object.fromEntries(
|
||||
const IDENTITY_FIELDS = Object.freeze([
|
||||
"Status",
|
||||
"Route ID",
|
||||
"Release ID",
|
||||
"Reviewer",
|
||||
"Reviewed at",
|
||||
"Signature",
|
||||
"Attestation",
|
||||
]);
|
||||
|
||||
const NOT_APPLICABLE = /^not-applicable \(.+\)$/;
|
||||
|
||||
function parseRecordFields(content: string): Record<string, string> {
|
||||
return Object.fromEntries(
|
||||
content
|
||||
.split(/\r?\n/)
|
||||
.map((line) => /^([^:]+):\s*(.*)$/.exec(line))
|
||||
@@ -26,6 +38,37 @@ export function validateManualA11yEvidence(content: string) {
|
||||
match[2].trim(),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 08-06. The merge-stage check: the record for `routeId` keeps the template's
|
||||
* fields and vocabulary, whether or not a human has reviewed it yet. A record
|
||||
* that claims `reviewed` must also be complete. Returns the offending fields.
|
||||
*/
|
||||
export function validateManualA11yRecordFormat(content: string, routeId: string): string[] {
|
||||
const fields = parseRecordFields(content);
|
||||
const failures = [...IDENTITY_FIELDS, ...REVIEW_FIELDS].filter(
|
||||
(field) => !(field in fields),
|
||||
);
|
||||
if (fields.Status !== undefined && !["pending-manual-review", "reviewed"].includes(fields.Status)) {
|
||||
failures.push("Status");
|
||||
}
|
||||
if (fields["Route ID"] !== undefined && fields["Route ID"] !== routeId) failures.push("Route ID");
|
||||
if (fields.Attestation !== undefined && !["pending", "accepted"].includes(fields.Attestation)) {
|
||||
failures.push("Attestation");
|
||||
}
|
||||
for (const field of REVIEW_FIELDS) {
|
||||
const verdict = fields[field];
|
||||
if (verdict !== undefined && verdict !== "pass" && verdict !== "pending" && !NOT_APPLICABLE.test(verdict)) {
|
||||
failures.push(field);
|
||||
}
|
||||
}
|
||||
if (fields.Status === "reviewed") failures.push(...validateManualA11yEvidence(content).failures);
|
||||
return [...new Set(failures)];
|
||||
}
|
||||
|
||||
export function validateManualA11yEvidence(content: string) {
|
||||
const fields = parseRecordFields(content);
|
||||
const failures: string[] = [];
|
||||
if (fields.Status !== "reviewed") failures.push("Status");
|
||||
if (!fields["Route ID"]) failures.push("Route ID");
|
||||
@@ -44,7 +87,7 @@ export function validateManualA11yEvidence(content: string) {
|
||||
const result = fields[field];
|
||||
if (
|
||||
result !== "pass" &&
|
||||
!/^not-applicable \(.+\)$/.test(result ?? "")
|
||||
!NOT_APPLICABLE.test(result ?? "")
|
||||
) {
|
||||
failures.push(field);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/**
|
||||
* Package-script graph for the CI contract (D-12, 12-10). Kept after checking
|
||||
* whether `--ignore-scripts` on the workflow install and `allowBuilds` in
|
||||
* pnpm-workspace.yaml already close the same risks. They do not:
|
||||
*
|
||||
* - Gate commands run installs themselves (`verify:lockfile`, removal
|
||||
* fixtures). `allowBuilds` limits dependency build scripts under pnpm only;
|
||||
* the root project's own install hooks and npm/yarn installs still run
|
||||
* unless the command says `--ignore-scripts`.
|
||||
* - A gate names a root package script. `--prefix`, `--filter`, `-C`, npm
|
||||
* pre/post hooks and `npm_config_*` scope variables can make that name run a
|
||||
* different manifest's script, which no install flag affects.
|
||||
* - `reachablePackageScripts` is also how the ungated-test check (12-04) finds
|
||||
* which Vitest paths a gate runs.
|
||||
*/
|
||||
type PackageManager = "pnpm" | "npm" | "yarn";
|
||||
|
||||
type ManagerParseResult = Readonly<{
|
||||
|
||||
@@ -18,14 +18,19 @@ export const PROMOTION_FORMULA = Object.freeze({
|
||||
"FE-GATE-012",
|
||||
"FE-GATE-014",
|
||||
"FE-GATE-015",
|
||||
"FE-GATE-019",
|
||||
"FE-GATE-026",
|
||||
// FE-GATE-027. A candidate is only release-ready once it has been admitted
|
||||
// to a named environment; coherence alone never proved it belonged there.
|
||||
"FE-GATE-027",
|
||||
// FE-GATE-028 (08-06). The signed human accessibility review belongs to a
|
||||
// release candidate, so it gates release; merge checks the record format.
|
||||
"FE-GATE-028",
|
||||
]),
|
||||
PROD_PROMOTION_READY: Object.freeze([
|
||||
"FE-GATE-016",
|
||||
// FE-GATE-019 (13-05, D-14). Live hosting headers of the deployed promoted
|
||||
// release; the declared-header fixture alone is UNVERIFIED, not PASS.
|
||||
"FE-GATE-019",
|
||||
// FE-GATE-016 is retired (D-14): it repeated FE-GATE-025's FE-RB-005 drill.
|
||||
"FE-GATE-021",
|
||||
"FE-GATE-022",
|
||||
"FE-GATE-023",
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
// Importing the realtime or Web Push adapter from the composition root is the
|
||||
// graph rule unselected-realtime-runtime-is-not-composed (12-10). This scan
|
||||
// keeps what an import graph cannot see: native API calls and timers.
|
||||
export type RealtimeBoundaryRuleId =
|
||||
| "NATIVE_REALTIME_API_OUTSIDE_ADAPTER"
|
||||
| "PRESENTATION_INTERVAL_OWNER"
|
||||
| "UNSELECTED_REALTIME_RUNTIME_COMPOSED";
|
||||
| "PRESENTATION_INTERVAL_OWNER";
|
||||
|
||||
export type RealtimeBoundaryViolation = Readonly<{
|
||||
ruleId: RealtimeBoundaryRuleId;
|
||||
@@ -17,8 +19,6 @@ const OWNED_NATIVE_ROOTS = [
|
||||
"src/adapters/realtime/",
|
||||
"src/adapters/web-push/",
|
||||
] as const;
|
||||
const REALTIME_ADAPTER_IMPORT =
|
||||
/(?:from\s*|import\s*\()\s*["'][^"']*\/adapters\/(?:realtime|web-push)(?:\/[^"']*)?["']/gu;
|
||||
const NATIVE_REALTIME_PATTERNS = [
|
||||
/\bnew\s+(?:WebSocket|EventSource|Notification)\s*\(/gu,
|
||||
/\bNotification\s*\.\s*requestPermission\s*\(/gu,
|
||||
@@ -62,9 +62,6 @@ function inspectFile(
|
||||
const presentationOwned =
|
||||
logicalFile.startsWith("src/presentation/") ||
|
||||
/^src\/features\/[^/]+\/presentation\//u.test(logicalFile);
|
||||
const compositionBoundary =
|
||||
logicalFile.startsWith("src/bootstrap/") ||
|
||||
/^src\/features\/installed-feature-/u.test(logicalFile);
|
||||
|
||||
const report = (
|
||||
ruleId: RealtimeBoundaryRuleId,
|
||||
@@ -92,11 +89,6 @@ function inspectFile(
|
||||
report("PRESENTATION_INTERVAL_OWNER", match.index);
|
||||
}
|
||||
}
|
||||
if (compositionBoundary) {
|
||||
for (const match of source.matchAll(REALTIME_ADAPTER_IMPORT)) {
|
||||
report("UNSELECTED_REALTIME_RUNTIME_COMPOSED", match.index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function collectSourceFiles(
|
||||
|
||||
@@ -3,12 +3,14 @@ import path from "node:path";
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
import { SCALE_TIERS, type ScaleTier } from "../scale/run-scale-profile.ts";
|
||||
import { reachablePackageScripts } from "./package-script-graph.ts";
|
||||
|
||||
/**
|
||||
* 12-04. A test file protects nothing unless a CI gate runs it. The gated set
|
||||
* is read from the package scripts the CI contract's commands reach: Vitest
|
||||
* path filters (`run-vitest.ts run <paths>`) and Playwright config `testDir`s.
|
||||
* path filters (`run-vitest.ts run <paths>`), the Vitest steps of a scale tier
|
||||
* (`run-scale-profile.ts <tier>`) and Playwright config `testDir`s.
|
||||
* A test outside that set needs a reasoned entry in config/ci/ungated-tests.json.
|
||||
*/
|
||||
export const UNGATED_TESTS_PATH = "config/ci/ungated-tests.json";
|
||||
@@ -53,17 +55,22 @@ export function gatedTestPaths(
|
||||
readConfig: (file: string) => string,
|
||||
): string[] {
|
||||
const paths = new Set<string>();
|
||||
const addVitestPaths = (tokens: readonly string[]) => {
|
||||
const vitestRun = tokens.findIndex(
|
||||
(token, index) => token === "run" && /(?:run-vitest\.ts|vitest)$/u.test(tokens[index - 1] ?? ""),
|
||||
);
|
||||
if (vitestRun < 0) return;
|
||||
for (const token of tokens.slice(vitestRun + 1)) {
|
||||
if (!token.startsWith("-")) paths.add(token.replace(/\/$/u, ""));
|
||||
}
|
||||
};
|
||||
for (const script of reachablePackageScripts(scripts, entryScripts)) {
|
||||
for (const segment of scripts[script]!.split("&&")) {
|
||||
const tokens = segment.trim().split(/\s+/u);
|
||||
const vitestRun = tokens.findIndex(
|
||||
(token, index) => token === "run" && /(?:run-vitest\.ts|vitest)$/u.test(tokens[index - 1] ?? ""),
|
||||
);
|
||||
if (vitestRun >= 0) {
|
||||
for (const token of tokens.slice(vitestRun + 1)) {
|
||||
if (token.startsWith("-")) break;
|
||||
paths.add(token.replace(/\/$/u, ""));
|
||||
}
|
||||
addVitestPaths(tokens);
|
||||
const scaleProfile = tokens.findIndex((token) => /run-scale-profile\.ts$/u.test(token));
|
||||
if (scaleProfile >= 0) {
|
||||
for (const step of SCALE_TIERS[tokens[scaleProfile + 1] as ScaleTier] ?? []) addVitestPaths(step.command);
|
||||
}
|
||||
const playwrightTest = tokens.findIndex(
|
||||
(token, index) => token === "test" && tokens[index - 1] === "playwright",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
import type { Plugin } from "vite";
|
||||
@@ -39,6 +40,7 @@ export function viteModuleInventoryPlugin(
|
||||
{
|
||||
schemaVersion: 1,
|
||||
chunks,
|
||||
packages: bundledPackages(chunks),
|
||||
},
|
||||
null,
|
||||
2,
|
||||
@@ -48,7 +50,41 @@ export function viteModuleInventoryPlugin(
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeModuleId(
|
||||
/**
|
||||
* 13-12. The `name@version` of every package with at least one module in the
|
||||
* emitted bundle: what the public release actually ships, as opposed to the
|
||||
* SBOM, which lists the whole installed graph.
|
||||
*/
|
||||
export function bundledPackages(chunks: readonly ModuleInventoryChunk[]): string[] {
|
||||
const packages = new Set<string>();
|
||||
for (const chunk of chunks) {
|
||||
for (const module of chunk.modules) {
|
||||
const match = /^npm:((?:@[^/]+\/)?[^/@]+@[^/]+)\//u.exec(module);
|
||||
if (match?.[1]) packages.add(match[1]);
|
||||
}
|
||||
}
|
||||
return [...packages].sort();
|
||||
}
|
||||
|
||||
const packageManifests = new Map<string, Readonly<{ name: string; version: string }>>();
|
||||
|
||||
function installedPackage(directory: string): Readonly<{ name: string; version: string }> {
|
||||
let manifest = packageManifests.get(directory);
|
||||
if (!manifest) {
|
||||
const parsed = JSON.parse(readFileSync(path.join(directory, "package.json"), "utf8")) as {
|
||||
name?: unknown;
|
||||
version?: unknown;
|
||||
};
|
||||
if (typeof parsed.name !== "string" || typeof parsed.version !== "string") {
|
||||
throw new TypeError(`bundled package has no name/version: ${directory}`);
|
||||
}
|
||||
manifest = Object.freeze({ name: parsed.name, version: parsed.version });
|
||||
packageManifests.set(directory, manifest);
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
export function normalizeModuleId(
|
||||
moduleId: string,
|
||||
repositoryRoot: string,
|
||||
): string {
|
||||
@@ -56,6 +92,18 @@ function normalizeModuleId(
|
||||
if (!path.isAbsolute(withoutQuery)) {
|
||||
return withoutQuery.replaceAll("\\", "/");
|
||||
}
|
||||
// 13-12: a dependency module keeps its package identity, read from the
|
||||
// package.json of the directory it was resolved into.
|
||||
const file = withoutQuery.replaceAll("\\", "/");
|
||||
const marker = "/node_modules/";
|
||||
const at = file.lastIndexOf(marker);
|
||||
if (at >= 0) {
|
||||
const segments = file.slice(at + marker.length).split("/");
|
||||
const nameLength = segments[0]?.startsWith("@") ? 2 : 1;
|
||||
const directory = file.slice(0, at + marker.length) + segments.slice(0, nameLength).join("/");
|
||||
const { name, version } = installedPackage(directory);
|
||||
return `npm:${name}@${version}/${segments.slice(nameLength).join("/")}`;
|
||||
}
|
||||
const relative = path.relative(repositoryRoot, withoutQuery);
|
||||
return relative.startsWith("..")
|
||||
? `external:${path.basename(withoutQuery)}`
|
||||
|
||||
Reference in New Issue
Block a user