Merge remote-tracking branch 'origin/main' into fix/r9-form-and-primitives
This commit is contained in:
@@ -1,50 +1,38 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
function requiredPnpmCli(): string {
|
||||
const executable = process.env.npm_execpath;
|
||||
if (!executable) {
|
||||
throw new Error(
|
||||
"check:browser-file-storage-boundaries must run through pnpm",
|
||||
);
|
||||
import { ESLint } from "eslint";
|
||||
|
||||
/** A lint run's verdict as `eslint --no-ignore --max-warnings=0` would exit, and its report. */
|
||||
type LintOutcome = Readonly<{ status: number; output: string }>;
|
||||
|
||||
// One ESLint instance lints every fixture. The check used to start
|
||||
// `pnpm exec eslint` once per fixture (about 30 processes), and loading the
|
||||
// flat config each time was most of FE-GATE-010's minute. The options match
|
||||
// that command line: --no-ignore is `ignore: false`, --max-warnings=0 makes a
|
||||
// warning fail like an error.
|
||||
const eslint = new ESLint({ ignore: false });
|
||||
const formatter = await eslint.loadFormatter("stylish");
|
||||
|
||||
async function lintOutcome(results: ESLint.LintResult[]): Promise<LintOutcome> {
|
||||
const failed = results.some((result) => result.errorCount > 0 || result.warningCount > 0);
|
||||
return { status: failed ? 1 : 0, output: await formatter.format(results) };
|
||||
}
|
||||
|
||||
async function runEslint(target: string): Promise<LintOutcome> {
|
||||
try {
|
||||
return await lintOutcome(await eslint.lintFiles([target]));
|
||||
} catch (error) {
|
||||
// The CLI exits 2 when nothing matches or the config fails to load.
|
||||
return { status: 2, output: `${error instanceof Error ? error.message : String(error)}\n` };
|
||||
}
|
||||
return executable;
|
||||
}
|
||||
|
||||
function runEslint(path: string) {
|
||||
return spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
requiredPnpmCli(),
|
||||
"exec",
|
||||
"eslint",
|
||||
path,
|
||||
"--no-ignore",
|
||||
"--max-warnings=0",
|
||||
],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
async function runEslintSource(source: string, virtualPath: string): Promise<LintOutcome> {
|
||||
return lintOutcome(await eslint.lintText(source, { filePath: virtualPath, warnIgnored: true }));
|
||||
}
|
||||
|
||||
function runEslintSource(source: string, virtualPath: string) {
|
||||
return spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
requiredPnpmCli(),
|
||||
"exec",
|
||||
"eslint",
|
||||
"--stdin",
|
||||
"--stdin-filename",
|
||||
virtualPath,
|
||||
"--no-ignore",
|
||||
"--max-warnings=0",
|
||||
],
|
||||
{ encoding: "utf8", input: source },
|
||||
);
|
||||
}
|
||||
|
||||
const allowed = runEslint(
|
||||
const allowed = await runEslint(
|
||||
"tests/fixtures/browser-file-storage-boundaries/allowed",
|
||||
);
|
||||
const forbiddenRoot =
|
||||
@@ -54,10 +42,10 @@ const forbiddenFiles = (
|
||||
)
|
||||
.filter((entry) => entry.isFile() && /\.tsx?$/u.test(entry.name))
|
||||
.map((entry) => path.join(forbiddenRoot, entry.name));
|
||||
const forbiddenResults = forbiddenFiles.map((file) => ({
|
||||
file,
|
||||
result: runEslint(file),
|
||||
}));
|
||||
const forbiddenResults: Array<{ file: string; result: LintOutcome }> = [];
|
||||
for (const file of forbiddenFiles) {
|
||||
forbiddenResults.push({ file, result: await runEslint(file) });
|
||||
}
|
||||
const acceptedForbidden = forbiddenResults.filter(
|
||||
({ result }) => result.status === 0,
|
||||
);
|
||||
@@ -102,28 +90,28 @@ const protectedSourceFixtures = await Promise.all(
|
||||
const approvedAdapterResults = [
|
||||
{
|
||||
file: "src/adapters/storage/indexeddb/boundary-fixture.ts",
|
||||
result: runEslintSource(
|
||||
result: await runEslintSource(
|
||||
indexedDbBypassSource,
|
||||
"src/adapters/storage/indexeddb/boundary-fixture.ts",
|
||||
),
|
||||
},
|
||||
{
|
||||
file: "src/adapters/cross-context-invalidation/boundary-fixture.ts",
|
||||
result: runEslintSource(
|
||||
result: await runEslintSource(
|
||||
crossContextAdapterSource,
|
||||
"src/adapters/cross-context-invalidation/boundary-fixture.ts",
|
||||
),
|
||||
},
|
||||
{
|
||||
file: "src/adapters/storage/boundary-fixture.ts",
|
||||
result: runEslintSource(
|
||||
result: await runEslintSource(
|
||||
browserStorageAdapterSource,
|
||||
"src/adapters/storage/boundary-fixture.ts",
|
||||
),
|
||||
},
|
||||
{
|
||||
file: "src/adapters/browser-transfer/boundary-fixture.ts",
|
||||
result: runEslintSource(
|
||||
result: await runEslintSource(
|
||||
blobBypassSource,
|
||||
"src/adapters/browser-transfer/boundary-fixture.ts",
|
||||
),
|
||||
@@ -135,40 +123,40 @@ const rejectedApprovedAdapters = approvedAdapterResults.filter(
|
||||
const misplacedAdapterResults = [
|
||||
{
|
||||
file: "src/adapters/http/boundary-fixture.ts",
|
||||
result: runEslintSource(
|
||||
result: await runEslintSource(
|
||||
indexedDbBypassSource,
|
||||
"src/adapters/http/boundary-fixture.ts",
|
||||
),
|
||||
},
|
||||
{
|
||||
file: "src/features/fixture-feature/adapters/boundary-fixture.ts",
|
||||
result: runEslintSource(
|
||||
result: await runEslintSource(
|
||||
objectUrlBypassSource,
|
||||
"src/features/fixture-feature/adapters/boundary-fixture.ts",
|
||||
),
|
||||
},
|
||||
{
|
||||
file: "src/adapters/http/cross-context-boundary-fixture.ts",
|
||||
result: runEslintSource(
|
||||
result: await runEslintSource(
|
||||
crossContextAdapterSource,
|
||||
"src/adapters/http/cross-context-boundary-fixture.ts",
|
||||
),
|
||||
},
|
||||
{
|
||||
file: "src/adapters/http/browser-storage-boundary-fixture.ts",
|
||||
result: runEslintSource(
|
||||
result: await runEslintSource(
|
||||
browserStorageAdapterSource,
|
||||
"src/adapters/http/browser-storage-boundary-fixture.ts",
|
||||
),
|
||||
},
|
||||
...protectedSourceFixtures.map(({ file, source }) => {
|
||||
const virtualPath = `src/presentation/${file}`;
|
||||
return {
|
||||
file: virtualPath,
|
||||
result: runEslintSource(source, virtualPath),
|
||||
};
|
||||
}),
|
||||
];
|
||||
for (const { file, source } of protectedSourceFixtures) {
|
||||
const virtualPath = `src/presentation/${file}`;
|
||||
misplacedAdapterResults.push({
|
||||
file: virtualPath,
|
||||
result: await runEslintSource(source, virtualPath),
|
||||
});
|
||||
}
|
||||
const acceptedMisplacedAdapters = misplacedAdapterResults.filter(
|
||||
({ result }) => result.status === 0,
|
||||
);
|
||||
@@ -180,24 +168,24 @@ if (
|
||||
acceptedForbidden.length > 0 ||
|
||||
acceptedMisplacedAdapters.length > 0
|
||||
) {
|
||||
process.stderr.write(allowed.stderr || allowed.stdout);
|
||||
process.stderr.write(allowed.output);
|
||||
for (const { file, result } of rejectedApprovedAdapters) {
|
||||
process.stderr.write(
|
||||
`${file}: owned browser capability adapter was rejected\n`,
|
||||
);
|
||||
process.stderr.write(result.stderr || result.stdout);
|
||||
process.stderr.write(result.output);
|
||||
}
|
||||
for (const { file, result } of acceptedForbidden) {
|
||||
process.stderr.write(
|
||||
`${file}: forbidden browser API fixture was accepted\n`,
|
||||
);
|
||||
process.stderr.write(result.stderr || result.stdout);
|
||||
process.stderr.write(result.output);
|
||||
}
|
||||
for (const { file, result } of acceptedMisplacedAdapters) {
|
||||
process.stderr.write(
|
||||
`${file}: native browser storage access outside its owned adapter was accepted\n`,
|
||||
);
|
||||
process.stderr.write(result.stderr || result.stdout);
|
||||
process.stderr.write(result.output);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { readdir } from "node:fs/promises";
|
||||
import { readdir, readFile } from "node:fs/promises";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
import { declaredCspProblems } from "./lib/csp-policy.ts";
|
||||
|
||||
function requiredPnpmCli(): string {
|
||||
const executable = process.env.npm_execpath;
|
||||
if (!executable) {
|
||||
@@ -35,15 +37,28 @@ const forbidden = runPnpm([
|
||||
const distFiles = await readdir("dist", { recursive: true });
|
||||
const publicSourceMaps = distFiles.filter((file) => String(file).endsWith(".map"));
|
||||
|
||||
if (allowed.status !== 0 || forbidden.status === 0 || publicSourceMaps.length > 0) {
|
||||
const SECURITY_HEADERS = "config/hosting/security-headers.json";
|
||||
const cspProblems = declaredCspProblems(await readFile(SECURITY_HEADERS, "utf8"));
|
||||
|
||||
if (
|
||||
allowed.status !== 0 ||
|
||||
forbidden.status === 0 ||
|
||||
publicSourceMaps.length > 0 ||
|
||||
cspProblems.length > 0
|
||||
) {
|
||||
process.stderr.write(allowed.stderr || allowed.stdout);
|
||||
process.stderr.write(forbidden.stderr || forbidden.stdout);
|
||||
if (publicSourceMaps.length > 0) {
|
||||
process.stderr.write(`Public source maps found: ${publicSourceMaps.join(", ")}\n`);
|
||||
}
|
||||
if (cspProblems.length > 0) {
|
||||
process.stderr.write(
|
||||
`${SECURITY_HEADERS} Content-Security-Policy: ${cspProblems.join("; ")}\n`,
|
||||
);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
"Browser security fixtures: injection rejected, public source maps absent\n",
|
||||
"Browser security fixtures: injection rejected, public source maps absent, declared CSP allows no unsafe source\n",
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import { loadCiGateContract } from "./contracts/ci-gates.ts";
|
||||
import { loadProductCiOverlay } from "./contracts/product-ci-overlay.ts";
|
||||
import {
|
||||
gatedTestPaths,
|
||||
gatedTestTargets,
|
||||
listTestFiles,
|
||||
parseUngatedTestExclusions,
|
||||
ungatedTestFailures,
|
||||
@@ -38,7 +39,7 @@ try {
|
||||
failures.push(
|
||||
...ungatedTestFailures({
|
||||
testFiles: await listTestFiles(process.cwd()),
|
||||
gatedPaths: gatedTestPaths(
|
||||
gatedPaths: gatedTestTargets(
|
||||
packageScripts,
|
||||
[...contract.commands.map(({ script }) => script), ...productGateScripts],
|
||||
(file) => readFileSync(file, "utf8"),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import {
|
||||
checkDeclaredCspFixtures,
|
||||
checkNonmatchingSecurityIncludeFixture,
|
||||
checkSecurityFixtures,
|
||||
} from "./lib/security-fixture-check.ts";
|
||||
|
||||
await checkNonmatchingSecurityIncludeFixture();
|
||||
await checkSecurityFixtures();
|
||||
await checkDeclaredCspFixtures();
|
||||
process.stdout.write(
|
||||
"Security fixtures: unmatched include rejected; 3 forbidden files detected\n",
|
||||
"Security fixtures: unmatched include rejected; 3 forbidden files detected; unsafe CSP fixture rejected\n",
|
||||
);
|
||||
|
||||
@@ -88,14 +88,24 @@ export async function findSystemTestPrerequisiteFailures(
|
||||
}
|
||||
|
||||
if (executable.get(BWRAP)) {
|
||||
const probe = host.spawn(BWRAP, NAMESPACE_PROBE_ARGUMENTS, PROBE_TIMEOUT_MS);
|
||||
if (probe.error || probe.status !== 0) {
|
||||
failures.push(await namespaceFailure(host, probe));
|
||||
}
|
||||
const failure = await findProviderSandboxNamespaceFailure(host);
|
||||
if (failure !== undefined) failures.push(failure);
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1101/13-03. Whether this host lets the provider sandbox create its
|
||||
* namespaces, and if not, why and what to do. The release provider jobs run
|
||||
* it before the provider (scripts/run-and-validate-provider.ts).
|
||||
*/
|
||||
export async function findProviderSandboxNamespaceFailure(
|
||||
host: SystemTestHost = nodeSystemTestHost,
|
||||
): Promise<string | undefined> {
|
||||
const probe = host.spawn(BWRAP, NAMESPACE_PROBE_ARGUMENTS, PROBE_TIMEOUT_MS);
|
||||
return probe.error || probe.status !== 0 ? namespaceFailure(host, probe) : undefined;
|
||||
}
|
||||
|
||||
async function namespaceFailure(
|
||||
host: SystemTestHost,
|
||||
probe: ReturnType<SystemTestHost["spawn"]>,
|
||||
|
||||
@@ -299,6 +299,14 @@ const gateSchema = z
|
||||
* contract baseline, like any other change to what a gate demands.
|
||||
*/
|
||||
hostRequirements: z.array(nonEmpty.max(512)).min(1).max(8).optional(),
|
||||
/**
|
||||
* Where the gate runs when the job container cannot meet its host
|
||||
* requirements. "system-container": scripts/run-in-system-container.sh
|
||||
* runs the gate in a disposable privileged systemd container
|
||||
* (config/ci/system-container.Dockerfile), in CI through the runner's
|
||||
* Docker daemon and on desktop through scripts/verify.sh.
|
||||
*/
|
||||
hostEnvironment: z.enum(["system-container"]).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -325,7 +333,18 @@ const environmentBindingSchema = z
|
||||
const checkoutStep = z.object({ kind: z.literal("checkout") }).strict();
|
||||
const setupNodeStep = z.object({ kind: z.literal("setup-node") }).strict();
|
||||
const frozenInstallStep = z.object({ kind: z.literal("frozen-install") }).strict();
|
||||
const browserInstallStep = z.object({ kind: z.literal("browser-install") }).strict();
|
||||
/**
|
||||
* `image`: the job runs in Playwright's own image for the pinned
|
||||
* @playwright/test version, which already holds the browsers and their OS
|
||||
* libraries (tests/unit/ci-browser-image.test.ts keeps the versions equal).
|
||||
* Without it the step downloads them, about 900 MB and 3 to 4 minutes a job.
|
||||
*/
|
||||
export const PLAYWRIGHT_JOB_IMAGE_PATTERN =
|
||||
/^mcr\.microsoft\.com\/playwright:v(\d+\.\d+\.\d+)-noble@sha256:[0-9a-f]{64}$/u;
|
||||
const browserInstallStep = z.object({
|
||||
kind: z.literal("browser-install"),
|
||||
image: z.string().regex(PLAYWRIGHT_JOB_IMAGE_PATTERN).optional(),
|
||||
}).strict();
|
||||
const runGateStep = z.object({ kind: z.literal("run-gate") }).strict();
|
||||
const archiveCandidateStep = z
|
||||
.object({
|
||||
@@ -413,6 +432,9 @@ const jobSchema = z
|
||||
browserGateIds: z.array(id).max(64),
|
||||
environment: z.array(environmentBindingSchema).max(32),
|
||||
steps: z.array(jobStepSchema).min(1).max(64),
|
||||
// 1101/13-03. What the runner of a job without a gate needs (the provider
|
||||
// jobs' sandbox). Rendered beside its runner label like a gate's.
|
||||
hostRequirements: z.array(nonEmpty.max(512)).min(1).max(8).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
@@ -467,7 +489,7 @@ export type CiGateContractIndex = Readonly<{
|
||||
export const RETIRED_GATE_IDS: readonly string[] = Object.freeze(["FE-GATE-016"]);
|
||||
|
||||
export const CANONICAL_GATE_IDS: readonly string[] = Object.freeze(
|
||||
Array.from({ length: 29 }, (_, index) => `FE-GATE-${String(index + 1).padStart(3, "0")}`)
|
||||
Array.from({ length: 30 }, (_, index) => `FE-GATE-${String(index + 1).padStart(3, "0")}`)
|
||||
.filter((gateId) => !RETIRED_GATE_IDS.includes(gateId)),
|
||||
);
|
||||
|
||||
@@ -745,7 +767,7 @@ function validateContractSemantics(
|
||||
|
||||
const expectedGateIds = CANONICAL_GATE_IDS;
|
||||
if (JSON.stringify(contract.gates.map(({ id }) => id)) !== JSON.stringify(expectedGateIds)) {
|
||||
issue(`gate registry must contain FE-GATE-001..029 without retired ${RETIRED_GATE_IDS.join(", ")} in canonical order`);
|
||||
issue(`gate registry must contain FE-GATE-001..030 without retired ${RETIRED_GATE_IDS.join(", ")} in canonical order`);
|
||||
}
|
||||
const expectedStages: ReadonlyArray<readonly [string, string, readonly string[], readonly string[]]> = [
|
||||
["merge", "MERGE_READY", [], PROMOTION_FORMULA.MERGE_READY],
|
||||
@@ -837,9 +859,26 @@ function validateContractSemantics(
|
||||
field_gate: ["FE-GATE-018"],
|
||||
documentation_gate: ["FE-GATE-017"],
|
||||
// F2. The checkers' own negative fixtures and the gating coverage check
|
||||
// run after a merge to main, not on every pull request.
|
||||
main_gate: ["FE-GATE-029"],
|
||||
// run after a merge to main, not on every pull request. So do the optional
|
||||
// runtime removal drills (FE-GATE-030, owner decision 2026-11-12 p): about
|
||||
// seven of a pull request's thirty runner minutes, the same shape as the
|
||||
// paired backend's nightly lanes.
|
||||
main_gate: ["FE-GATE-029", "FE-GATE-030"],
|
||||
};
|
||||
// 1101/13-03. The provider jobs run FE-GATE-013's sandbox (systemd-run
|
||||
// scope, bwrap with the same namespace options), so they need its host.
|
||||
const sandboxRequirements = JSON.stringify(
|
||||
contract.gates.find(({ id: gateId }) => gateId === "FE-GATE-013")?.hostRequirements ?? [],
|
||||
);
|
||||
for (const job of contract.jobs) {
|
||||
if (job.kind === "provider") {
|
||||
if (JSON.stringify(job.hostRequirements ?? []) !== sandboxRequirements) {
|
||||
issue(`provider job host requirements must equal FE-GATE-013's: ${job.id}`);
|
||||
}
|
||||
} else if (job.hostRequirements !== undefined) {
|
||||
issue(`only a provider job declares host requirements of its own: ${job.id}`);
|
||||
}
|
||||
}
|
||||
if (JSON.stringify(contract.jobs.map(({ id }) => id)) !== JSON.stringify(Object.keys(expectedJobOwnership))) {
|
||||
issue("job registry must contain the exact thirteen canonical jobs in semantic order");
|
||||
}
|
||||
@@ -993,6 +1032,9 @@ function validateContractSemantics(
|
||||
const browserSteps = job.steps.filter(({ kind }) => kind === "browser-install").length;
|
||||
const expected = job.browserGateIds.length > 0 ? 1 : 0;
|
||||
if (browserSteps !== expected) issue(`browser install step drift: ${job.id}`);
|
||||
// A matrix job's non-browser lanes would run in the browser image too.
|
||||
const imaged = job.steps.some((step) => step.kind === "browser-install" && step.image !== undefined);
|
||||
if (imaged && job.kind !== "gate-sequence") issue(`browser job image outside a gate sequence: ${job.id}`);
|
||||
}
|
||||
for (const cycle of findCycles(contract.jobs.map((job) => [job.id, job.needs] as const))) {
|
||||
issue(`job dependency cycle: ${cycle.join(" -> ")}`);
|
||||
|
||||
@@ -139,7 +139,7 @@ function baseOf(id: string): string {
|
||||
: id;
|
||||
}
|
||||
|
||||
function namesOf(id: string) {
|
||||
export function namesOf(id: string) {
|
||||
const base = baseOf(id);
|
||||
const pascal = base
|
||||
.split("-")
|
||||
@@ -884,6 +884,7 @@ export type ${pascal}CreateCommand = Readonly<{ name: string }>;
|
||||
`
|
||||
: "";
|
||||
return `import type {} from "../../../application/ports/in/application-api.ts";
|
||||
import { isAbortFailure } from "../../../contracts/errors.ts";
|
||||
${write ? `import type { MutationIntent } from "../../../contracts/mutation-intent.ts";\n` : ""}import type { Result } from "../../../contracts/result.ts";
|
||||
import {
|
||||
failOpenTelemetryPort,
|
||||
@@ -938,7 +939,8 @@ export function create${pascal}FeatureInput(
|
||||
// scale-architecture.md §24, §26: telemetry is best-effort and never changes the result.
|
||||
const events = failOpenTelemetryPort(telemetry);
|
||||
function reported<Value>(kind: string, result: Result<Value>): Result<Value> {
|
||||
if (!result.ok && result.error.kind !== "REQUEST_ABORTED") {
|
||||
// An aborted or fenced request did not fail (isAbortFailure).
|
||||
if (!result.ok && !isAbortFailure(result.error)) {
|
||||
void events.emit({
|
||||
kind,
|
||||
severity: "warning",
|
||||
@@ -1279,6 +1281,18 @@ describe("${names.id} application input", () => {
|
||||
await expect(input.listItems()).resolves.toEqual({ ok: false, error: failure });
|
||||
expect(emit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not report a load a scope fence ended", async () => {
|
||||
const failure = createFailure("SCOPE_GENERATION_CHANGED", "${operationId}", 0);
|
||||
const emit = vi.fn<TelemetryPort["emit"]>();
|
||||
const input = create${pascal}FeatureInput(
|
||||
gatewayListing(async () => ({ ok: false, error: failure })),
|
||||
{ telemetry: { emit } },
|
||||
);
|
||||
|
||||
await expect(input.listItems()).resolves.toEqual({ ok: false, error: failure });
|
||||
expect(emit).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,10 @@ import {
|
||||
registrySnapshotArtifactSchema,
|
||||
supplyChainVerificationArtifactSchema,
|
||||
} from "./contracts/release-artifacts.ts";
|
||||
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
||||
import {
|
||||
type ValidatedJsonArtifactInput,
|
||||
writeValidatedJsonArtifact,
|
||||
} from "./lib/validated-json-artifact.ts";
|
||||
|
||||
const ARTIFACT_SCHEMA_DEFINITIONS = Object.freeze([
|
||||
{
|
||||
@@ -39,6 +42,13 @@ const ARTIFACT_SCHEMA_DEFINITIONS = Object.freeze([
|
||||
type GenerateArtifactSchemasOptions = Readonly<{
|
||||
root?: string;
|
||||
check?: boolean;
|
||||
/**
|
||||
* Publishes one schema document. The default writes durably (fsync of the
|
||||
* file and its directory). A test that only checks the generated bytes in a
|
||||
* temporary root passes a writer without fsync: four fsync pairs were most
|
||||
* of its time and grew to seconds under the parallel suite's disk load.
|
||||
*/
|
||||
writeArtifact?: (input: ValidatedJsonArtifactInput) => Promise<void>;
|
||||
}>;
|
||||
|
||||
function canonicalize(value: unknown): unknown {
|
||||
@@ -90,7 +100,7 @@ export async function generateArtifactSchemas(
|
||||
continue;
|
||||
}
|
||||
await mkdir(path.dirname(destination), { recursive: true });
|
||||
await writeValidatedJsonArtifact({
|
||||
await (options.writeArtifact ?? writeValidatedJsonArtifact)({
|
||||
path: destination,
|
||||
schema: jsonSchemaDocumentArtifactSchema,
|
||||
value: document,
|
||||
|
||||
@@ -77,6 +77,21 @@ const PRODUCT_GATE_JOB = "product_merge_gate";
|
||||
*/
|
||||
const PRODUCT_GATES_HOLD = "release_gate";
|
||||
|
||||
/**
|
||||
* A newer run in the same group cancels the older one. Gitea 1.27 cancels the
|
||||
* older run's waiting and blocked jobs always and its running jobs only when
|
||||
* cancel-in-progress is true. A pull request run has the ref
|
||||
* `refs/pull/<number>/head`, so one group per pull request; a branch push is
|
||||
* one group per branch; a release tag has its own ref. A manual run is one
|
||||
* group per ref and stage and does not cancel a running run: a later release
|
||||
* dispatch must not stop an earlier one between verification and promotion.
|
||||
*/
|
||||
const CONCURRENCY_LINES = Object.freeze([
|
||||
"concurrency:",
|
||||
" group: frontend-quality-gates-${{ gitea.event_name }}-${{ gitea.ref }}-${{ inputs.stage }}",
|
||||
" cancel-in-progress: ${{ gitea.event_name != 'workflow_dispatch' }}",
|
||||
]);
|
||||
|
||||
export function renderCiWorkflow(
|
||||
contract: CiGateContract,
|
||||
productGates: readonly ProductGate[] = [],
|
||||
@@ -117,6 +132,8 @@ export function renderCiWorkflow(
|
||||
"permissions:",
|
||||
" contents: read",
|
||||
"",
|
||||
...CONCURRENCY_LINES,
|
||||
"",
|
||||
"env:",
|
||||
' CI: "true"',
|
||||
' VITE_BUILD_ID: "gitea-${{ gitea.run_id }}-${{ gitea.run_attempt }}"',
|
||||
@@ -190,6 +207,8 @@ function renderJob(
|
||||
" runs-on: ubuntu-latest",
|
||||
` timeout-minutes: ${job.timeoutMinutes}`,
|
||||
);
|
||||
const image = jobImage(job);
|
||||
if (image) lines.push(" container:", ` image: ${yamlScalar(image)}`);
|
||||
if (job.kind === "immutable") {
|
||||
const archive = job.steps.find((step) => step.kind === "archive-candidate");
|
||||
if (!archive || archive.kind !== "archive-candidate") throw new TypeError("immutable job lacks archive step");
|
||||
@@ -213,12 +232,13 @@ function renderJob(
|
||||
lines.push(" outputs:", " deployed: ${{ steps.deploy.outputs.deployed }}");
|
||||
}
|
||||
const jobEnvironment = job.environment.filter((binding) => !isStepScopedSecret(job, binding));
|
||||
if (jobEnvironment.length > 0) {
|
||||
lines.push(" env:");
|
||||
for (const binding of jobEnvironment) {
|
||||
lines.push(` ${binding.name}: ${yamlScalar(binding.value)}`);
|
||||
}
|
||||
}
|
||||
// The build records the image it ran in (scripts/lib/build-environment.ts):
|
||||
// a job in its own image names that one, not the runner label's.
|
||||
const environmentLines = [
|
||||
...(image ? [` CI_RUNNER_IMAGE: ${yamlScalar(image)}`] : []),
|
||||
...jobEnvironment.map((binding) => ` ${binding.name}: ${yamlScalar(binding.value)}`),
|
||||
];
|
||||
if (environmentLines.length > 0) lines.push(" env:", ...environmentLines);
|
||||
if (job.kind === "gate-matrix") {
|
||||
lines.push(" strategy:", " fail-fast: false", " matrix:", " include:");
|
||||
const includesBrowser = job.steps.some(({ kind }) => kind === "browser-install");
|
||||
@@ -247,11 +267,34 @@ function renderHostRequirements(
|
||||
job: CiWorkflowJob,
|
||||
index: ReturnType<typeof indexCiGateContract>,
|
||||
): string[] {
|
||||
return job.gateIds.flatMap((gateId) =>
|
||||
(index.gates.get(gateId)?.hostRequirements ?? []).map(
|
||||
(requirement) => ` # ${gateId} runner requirement: ${requirement}`,
|
||||
return [
|
||||
...job.gateIds.flatMap((gateId) =>
|
||||
(index.gates.get(gateId)?.hostRequirements ?? []).map(
|
||||
(requirement) => ` # ${gateId} runner requirement: ${requirement}`,
|
||||
),
|
||||
),
|
||||
);
|
||||
// 1101/13-03. A provider job runs the provider sandbox and has no gate.
|
||||
...(job.hostRequirements ?? []).map(
|
||||
(requirement) => ` # provider sandbox runner requirement: ${requirement}`,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* A gate whose host requirements the job container cannot meet runs in the
|
||||
* environment its contract names (`hostEnvironment`). FE-GATE-013's provider
|
||||
* sandbox needs systemd and bubblewrap, which the runner's job image lacks.
|
||||
*/
|
||||
function gateHostPrefix(gate: Readonly<{ hostEnvironment?: "system-container" | undefined }> | undefined): string {
|
||||
return gate?.hostEnvironment === "system-container" ? "scripts/run-in-system-container.sh " : "";
|
||||
}
|
||||
|
||||
/** The Playwright image a browser job runs in (`browser-install.image`), if any. */
|
||||
function jobImage(job: CiWorkflowJob): string | undefined {
|
||||
for (const step of job.steps) {
|
||||
if (step.kind === "browser-install" && step.image) return step.image;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function renderStep(
|
||||
@@ -281,6 +324,16 @@ function renderStep(
|
||||
" corepack pnpm install --frozen-lockfile --ignore-scripts",
|
||||
];
|
||||
case "browser-install":
|
||||
if (step.image) {
|
||||
// The job image holds the browsers and their OS libraries; the goldens'
|
||||
// faces are still OS packages it lacks, and it ships no package lists.
|
||||
return [
|
||||
" - name: Install visual-test fonts",
|
||||
" run: |",
|
||||
" $(command -v sudo || true) apt-get update",
|
||||
` $(command -v sudo || true) ${VISUAL_TEST_FONT_INSTALL_ARGUMENTS}`,
|
||||
];
|
||||
}
|
||||
return [
|
||||
" - name: Install Playwright browsers",
|
||||
...(job.kind === "gate-matrix" ? [" if: ${{ matrix.browser }}"] : []),
|
||||
@@ -303,7 +356,7 @@ function renderStep(
|
||||
return job.gateIds.flatMap((gateId) => [
|
||||
` - name: ${yamlScalar(`${gateId} / ${index.gates.get(gateId)?.name ?? ""}`)}`,
|
||||
" if: ${{ !cancelled() }}",
|
||||
` run: corepack pnpm ci:gate -- ${gateId}`,
|
||||
` run: ${gateHostPrefix(index.gates.get(gateId))}corepack pnpm ci:gate -- ${gateId}`,
|
||||
]);
|
||||
}
|
||||
// 12-02: every gate the job owns runs, in order. Rendering only the first
|
||||
@@ -533,9 +586,11 @@ export function workflowGateExecutionFailures(
|
||||
) {
|
||||
productFailures.push(`product gates do not hold the release stage: ${PRODUCT_GATES_HOLD} does not need ${PRODUCT_GATE_JOB}`);
|
||||
}
|
||||
const hostPrefixes = new Map(contract.gates.map((gate) => [gate.id, gateHostPrefix(gate)]));
|
||||
for (const job of jobs) {
|
||||
for (const match of job.matchAll(/^ +run: corepack pnpm ci:gate -- (FE-GATE-\d{3})$/gmu)) {
|
||||
executed.add(match[1]!);
|
||||
for (const match of job.matchAll(/^ +run: (\S+ )?corepack pnpm ci:gate -- (FE-GATE-\d{3})$/gmu)) {
|
||||
// A gate runs through the prefix its contract names, and only that one.
|
||||
if ((match[1] ?? "") === hostPrefixes.get(match[2]!)) executed.add(match[2]!);
|
||||
}
|
||||
if (/^ +run: corepack pnpm ci:gate -- \$\{\{ matrix\.gate \}\}$/mu.test(job)) {
|
||||
for (const match of job.matchAll(/^ +- \{ gate: (FE-GATE-\d{3}),/gmu)) {
|
||||
|
||||
@@ -25,8 +25,8 @@ Bash 직후 ──> post-bash ──> desktop에서 pnpm·게이트를 돌
|
||||
| N2 | 같은 때, `*.md` | `scripts/check-work-docs.py`를 돌린다(작업 매뉴얼의 분량·이력 ID·뼈대·상대 링크) | 실패 줄. 고친 문서를 가리키는 줄이 있으면 그것만 |
|
||||
| N5 | Stop | 이 세션에서 desktop만 확인할 수 있는 파일(아래 밖의 모든 파일)을 고친 뒤 desktop 실행이 없으면 턴을 한 번 막고 이유를 준다 | `decision: block`, 다음 편집 전까지 한 번 |
|
||||
|
||||
- N5가 "desktop 실행"으로 치는 것: `ssh <desktop 호스트> …`로 pnpm·`ci:gate`·`verify.sh`·vitest·playwright·`node scripts/…`를 돌린 명령, 또는 `scripts/verify.sh`를 `docs`·`hooks` 밖 단계로(`--on here` 없이) 돌린 명령.
|
||||
- N5가 세지 않는 파일(노트북에서 확인되는 것): `.claude/`, `scripts/hooks/`, `scripts/tests/`, `scripts/check-work-docs.py`, `docs/ledger/`, `CLAUDE.md`, `src/**/AGENTS.md`·`CLAUDE.md`. 이것들은 `scripts/verify.sh docs`·`hooks`가 노트북에서 본다.
|
||||
- N5가 "desktop 실행"으로 치는 것: `ssh <desktop 호스트> …`로 pnpm·`ci:gate`·`verify.sh`·vitest·playwright·`node scripts/…`를 돌린 명령(로그를 읽기만 하는 `cat`·`grep`·`tail` 등은 빼고), 또는 `scripts/verify.sh`를 명령으로 `docs`·`hooks` 밖 단계로(`--on here`·`--dry-run` 없이) 돌린 명령. 앞의 `VAR=값`과 `timeout`·`nohup`·`bash` 같은 감싸는 낱말, ssh 옵션과 그 값(`-o BatchMode=yes`, `-p 22`)은 건너뛴다. `verify.sh`를 읽는 명령(`sed`, `grep`, `git log -- scripts/verify.sh`)은 세지 않는다.
|
||||
- N5가 세지 않는 파일(노트북에서 확인되는 것): `.claude/`의 설정·훅 상태, `scripts/hooks/`·`scripts/tests/`의 코드, `scripts/check-work-docs.py`, `docs/ledger/`의 장부. 이것들은 `scripts/verify.sh docs`·`hooks`가 노트북에서 본다. 그 폴더의 문서(`.md`)와 `CLAUDE.md`, `src/**/AGENTS.md`·`CLAUDE.md`는 desktop `verify:documentation`도 보므로 센다.
|
||||
- N5가 기억하는 것은 `.claude/hook-state/<session_id>.json`이다(git이 무시한다).
|
||||
- 권한 쪽 차단: `.claude/settings.json`의 `permissions.deny`가 실제 `.env`·`.env.local`·`.env.*.local`·`.env.<mode>` 읽기·쓰기를 막는다. `.env.example`은 막지 않는다.
|
||||
|
||||
|
||||
+70
-18
@@ -70,21 +70,32 @@ DOC_CHECK = ("scripts/check-work-docs.py",)
|
||||
DOC_TIMEOUT = 20
|
||||
|
||||
# --- N5: an edit that only the desktop can check, until a desktop run --------------------------------------
|
||||
# Laptop-checkable on their own: the hooks and their tests, the work-manual checker, the ledger, Claude
|
||||
# settings, CLAUDE.md and the folder rule books under src/ (scripts/check-work-docs.py checks them). Everything else is checked by gates that need pnpm.
|
||||
# Laptop-checkable on their own: the hooks and their tests, the work-manual checker, the ledger and the
|
||||
# Claude settings, documents left out. Everything else is checked by gates that need pnpm, documents
|
||||
# included: verify:documentation reads CLAUDE.md, the folder rule books under src/, .claude/**/*.md and
|
||||
# the module READMEs of scripts/hooks/ and docs/ledger/ too (1112/08-04).
|
||||
LAPTOP_ONLY = (
|
||||
re.compile(r"^\.claude/"),
|
||||
re.compile(r"^scripts/hooks/"),
|
||||
re.compile(r"^scripts/tests/"),
|
||||
re.compile(r"^\.claude/(?!.*\.md$)"),
|
||||
re.compile(r"^scripts/hooks/(?!.*\.md$)"),
|
||||
re.compile(r"^scripts/tests/(?!.*\.md$)"),
|
||||
re.compile(r"^scripts/check-work-docs\.py$"),
|
||||
re.compile(r"^docs/ledger/"),
|
||||
re.compile(r"^CLAUDE\.md$"),
|
||||
re.compile(r"^src/(?:.+/)?(?:AGENTS|CLAUDE)\.md$"),
|
||||
re.compile(r"^docs/ledger/(?!.*\.md$)"),
|
||||
)
|
||||
DESKTOP_HOST = re.compile(r"desktop")
|
||||
DESKTOP_WORK = re.compile(r"\b(?:pnpm|ci:gate|verify\.sh|vitest|playwright)\b|\bnode\s+scripts/")
|
||||
VERIFY = re.compile(r"(?:^|[\s;&|(])(?:\./)?scripts/verify\.sh\s+(\S+)(.*)")
|
||||
LAPTOP_STAGES = {"docs", "hooks"}
|
||||
# 1112/08-09. One command of a shell line: what follows ;, &&, ||, |, ( or a newline.
|
||||
COMMAND_SEPARATOR = re.compile(r"&&|\|\||;|\||\(|\)|\n")
|
||||
# Words that run the next command: `timeout 900 scripts/verify.sh …`, `bash scripts/verify.sh …`.
|
||||
WRAPPERS = {"timeout": 1, "nohup": 0, "setsid": 0, "env": 0, "time": 0, "exec": 0, "bash": 0, "sh": 0}
|
||||
# ssh options that take the next word as their value (`ssh -o BatchMode=yes desktop …`).
|
||||
SSH_VALUE_OPTIONS = {"-B", "-b", "-c", "-D", "-E", "-e", "-F", "-I", "-i", "-J", "-L", "-l", "-m", "-O",
|
||||
"-o", "-P", "-p", "-Q", "-R", "-S", "-W", "-w"}
|
||||
# A remote command made only of these reads logs; it runs nothing.
|
||||
READ_ONLY = {"cat", "grep", "tail", "head", "less", "ls", "sed", "awk", "wc", "find", "stat", "echo",
|
||||
"printf", "date", "uptime", "ps", "test", "true", "for", "do", "done", "if", "then", "fi"}
|
||||
ASSIGNMENT = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*=")
|
||||
STEP_WORD = re.compile(r"^[a-z][a-z0-9-]*$")
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@@ -277,20 +288,61 @@ def needs_desktop(path: str) -> bool:
|
||||
return not any(pattern.search(path) for pattern in LAPTOP_ONLY)
|
||||
|
||||
|
||||
def ran_on_desktop(command: str) -> bool:
|
||||
"""An `ssh <desktop> …` running pnpm or a gate, or scripts/verify.sh with a stage that goes there."""
|
||||
def split_words(text: str) -> list[str]:
|
||||
try:
|
||||
words = shlex.split(command)
|
||||
return shlex.split(text)
|
||||
except ValueError:
|
||||
words = command.split()
|
||||
return text.split()
|
||||
|
||||
|
||||
def command_words(segment: str) -> list[str]:
|
||||
"""The words of one command, its leading `VAR=value` and wrapper words dropped."""
|
||||
words = split_words(segment)
|
||||
while words:
|
||||
if ASSIGNMENT.match(words[0]):
|
||||
words = words[1:]
|
||||
elif words[0] in WRAPPERS:
|
||||
words = words[1 + WRAPPERS[words[0]]:]
|
||||
else:
|
||||
break
|
||||
return words
|
||||
|
||||
|
||||
def ssh_host_and_remote(words: list[str]) -> tuple[str | None, str]:
|
||||
"""The host and the remote command of the words after `ssh`, its options and their values skipped."""
|
||||
position = 0
|
||||
while position < len(words) and words[position].startswith("-"):
|
||||
position += 2 if words[position] in SSH_VALUE_OPTIONS else 1
|
||||
if position >= len(words):
|
||||
return None, ""
|
||||
return words[position], " ".join(words[position + 1:])
|
||||
|
||||
|
||||
def runs_only_reads(remote: str) -> bool:
|
||||
segments = [command_words(part) for part in COMMAND_SEPARATOR.split(remote)]
|
||||
return all(not words or words[0] in READ_ONLY for words in segments)
|
||||
|
||||
|
||||
def ran_on_desktop(command: str) -> bool:
|
||||
"""An `ssh <desktop> …` running pnpm or a gate, or scripts/verify.sh running a step that goes there.
|
||||
|
||||
1112/08-09. Reading verify.sh (`sed`, `grep`, `git log -- scripts/verify.sh`), `--dry-run` and
|
||||
an ssh that only reads logs run nothing on the desktop.
|
||||
"""
|
||||
words = split_words(command)
|
||||
for position, word in enumerate(words):
|
||||
if word.endswith("ssh"):
|
||||
hosts = [w for w in words[position + 1:position + 5] if not w.startswith("-")][:2]
|
||||
if any(DESKTOP_HOST.search(host) for host in hosts) and DESKTOP_WORK.search(command):
|
||||
host, remote = ssh_host_and_remote(words[position + 1:])
|
||||
if (host is not None and DESKTOP_HOST.search(host) and DESKTOP_WORK.search(remote)
|
||||
and not runs_only_reads(remote)):
|
||||
return True
|
||||
for match in VERIFY.finditer(command):
|
||||
stage, rest = match.group(1), match.group(2)
|
||||
if stage not in LAPTOP_STAGES and not re.search(r"--on\s+here\b", rest):
|
||||
for segment in COMMAND_SEPARATOR.split(command):
|
||||
words = command_words(segment)
|
||||
if len(words) < 2 or not re.search(r"(?:^|/)scripts/verify\.sh$", words[0]):
|
||||
continue
|
||||
step, flags = words[1], words[2:]
|
||||
if (STEP_WORD.match(step) and step not in LAPTOP_STAGES and "--dry-run" not in flags
|
||||
and not re.search(r"--on\s+here\b", " ".join(flags))):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ export const ciContractReportSchema = z
|
||||
.object({
|
||||
schemaVersion: z.literal(2),
|
||||
nodeVersion: z.string().regex(/^\d+\.\d+\.\d+$/u),
|
||||
gateCount: z.literal(28),
|
||||
gateCount: z.literal(29),
|
||||
commandDefinitionCount: z.number().int().positive(),
|
||||
commandReferenceCount: z.number().int().positive(),
|
||||
artifactCount: z.number().int().positive(),
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 1112/08-13. What a failed `ci:gate` prints to stderr: the gate, the command
|
||||
* that failed (or that none did), the log with the whole output, and the end
|
||||
* of that output, where the cause usually is.
|
||||
*/
|
||||
export function formatGateFailure(input: Readonly<{
|
||||
gateId: string;
|
||||
gateName: string;
|
||||
logPath: string;
|
||||
failedCommand?: string | undefined;
|
||||
output: readonly string[];
|
||||
tailLines?: number;
|
||||
}>): string {
|
||||
const tail = input.output
|
||||
.flatMap((chunk) => chunk.split(/\r?\n/u))
|
||||
.filter((line) => line.trim() !== "")
|
||||
.slice(-(input.tailLines ?? 20));
|
||||
return [
|
||||
`${input.gateId} ${input.gateName}: FAIL`,
|
||||
` failed command: ${input.failedCommand ?? "none (a check outside the commands)"}`,
|
||||
` log: ${input.logPath}`,
|
||||
" last lines of the log:",
|
||||
...tail.map((line) => ` ${line}`),
|
||||
].join("\n");
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import path from "node:path";
|
||||
|
||||
/**
|
||||
* Vitest matches `coverage.include` and `coverage.exclude` against each
|
||||
* module's absolute path with picomatch `contains: true`, so a relative
|
||||
* pattern may match anywhere in that path. `src/**` also matched
|
||||
* `<checkout>/vite.config.ts` when the checkout sat in a folder whose name
|
||||
* ends in `src` (`~/work/app-src/`), and risk coverage then failed on rows
|
||||
* outside the repository inventory. A pattern that starts with the root
|
||||
* matches only inside it.
|
||||
*
|
||||
* The root is escaped with the expression Vitest's glob library (tinyglobby
|
||||
* 0.2) uses for a cwd, so a root with glob characters still matches itself
|
||||
* literally and the untested-file glob resolves the pattern back to
|
||||
* `src/...` under that cwd. A Windows root is turned into forward slashes
|
||||
* first; for a valid Windows path that escape equals tinyglobby's Windows one.
|
||||
*/
|
||||
const UNESCAPED_GLOB_SYMBOLS =
|
||||
/(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/gu;
|
||||
|
||||
export function rootAnchoredGlobs(
|
||||
root: string,
|
||||
patterns: readonly string[],
|
||||
): string[] {
|
||||
const normalizedRoot = path.resolve(root).split(path.sep).join("/");
|
||||
const escapedRoot = normalizedRoot.replace(UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
||||
return patterns.map((pattern) => {
|
||||
if (
|
||||
pattern.length === 0 ||
|
||||
pattern.startsWith("/") ||
|
||||
pattern.startsWith("!") ||
|
||||
pattern.includes("\\") ||
|
||||
pattern.split("/").includes("..")
|
||||
) {
|
||||
throw new TypeError(
|
||||
`coverage pattern must be a forward-slash path inside the root: ${pattern}`,
|
||||
);
|
||||
}
|
||||
return `${escapedRoot.replace(/\/$/u, "")}/${pattern}`;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 0929/13-04. What the declared Content-Security-Policy
|
||||
* (config/hosting/security-headers.json) may not allow.
|
||||
* scripts/verify-hosting-headers.ts compares a host's answer with it; this
|
||||
* reads what it allows. check:browser-security (FE-GATE-013) runs it, and
|
||||
* check:security:fixtures (FE-GATE-029) holds it to a rejected fixture.
|
||||
*/
|
||||
const UNSAFE_SOURCES = new Set(["'unsafe-inline'", "'unsafe-eval'", "*"]);
|
||||
/** Directives whose sources decide what script or plugin code may run or style may apply. */
|
||||
const CODE_DIRECTIVES = new Set([
|
||||
"default-src",
|
||||
"script-src",
|
||||
"script-src-elem",
|
||||
"script-src-attr",
|
||||
"style-src",
|
||||
"style-src-elem",
|
||||
"style-src-attr",
|
||||
"object-src",
|
||||
]);
|
||||
/** A scheme-only source (`https:`) lets any host on it run script. */
|
||||
const SCHEME_ONLY = /^[a-z][a-z0-9+.-]*:$/u;
|
||||
const SCRIPT_DIRECTIVES = new Set(["default-src", "script-src", "script-src-elem", "object-src"]);
|
||||
|
||||
/**
|
||||
* The directives as a browser reads them (CSP3): names and keywords in any
|
||||
* case, and the first of a repeated directive, the later ones ignored.
|
||||
*/
|
||||
function directivesOf(policy: string): Map<string, readonly string[]> {
|
||||
const directives = new Map<string, readonly string[]>();
|
||||
for (const part of policy.split(";")) {
|
||||
const [name, ...sources] = part.trim().split(/\s+/u);
|
||||
const key = name?.toLowerCase();
|
||||
if (key && !directives.has(key)) {
|
||||
directives.set(key, sources.map((source) => source.toLowerCase()));
|
||||
}
|
||||
}
|
||||
return directives;
|
||||
}
|
||||
|
||||
export function cspPolicyProblems(policy: string): string[] {
|
||||
const directives = directivesOf(policy);
|
||||
const problems: string[] = [];
|
||||
if (!directives.has("script-src") && !directives.has("default-src")) {
|
||||
problems.push("no script-src and no default-src");
|
||||
}
|
||||
for (const [name, sources] of directives) {
|
||||
if (!CODE_DIRECTIVES.has(name)) continue;
|
||||
for (const source of sources) {
|
||||
if (UNSAFE_SOURCES.has(source)) problems.push(`${name} allows ${source}`);
|
||||
else if (SCRIPT_DIRECTIVES.has(name) && SCHEME_ONLY.test(source)) {
|
||||
problems.push(`${name} allows the whole scheme ${source}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
/**
|
||||
* The problems of the policy a security-headers document (the shape of
|
||||
* config/hosting/security-headers.json) declares, its header name in any case.
|
||||
*/
|
||||
export function declaredCspProblems(securityHeadersJson: string): string[] {
|
||||
const document = JSON.parse(securityHeadersJson) as { headers?: Record<string, unknown> };
|
||||
const policy = Object.entries(document.headers ?? {}).find(
|
||||
([name]) => name.toLowerCase() === "content-security-policy",
|
||||
)?.[1];
|
||||
return typeof policy === "string"
|
||||
? cspPolicyProblems(policy)
|
||||
: ["no Content-Security-Policy header"];
|
||||
}
|
||||
+129
-12
@@ -9,8 +9,16 @@ import path from "node:path";
|
||||
* - `src/`: any file whose path or text still names the feature ID or its
|
||||
* folder. Platform source never names a product feature, so a name left
|
||||
* there is a reference the type checker cannot see (a catalog key, a
|
||||
* runtime override, a link).
|
||||
* - `tests/`: a file named after the feature, or one that imports from the
|
||||
* runtime override, a link). The name counts as a whole name only: in the
|
||||
* text, case-sensitive with no identifier character (`[A-Za-z0-9_-]`) on
|
||||
* either side; in the path, a segment equal to it or whose part before the
|
||||
* first `.` is. A substring search counted ten template files for
|
||||
* `product-feature` (`product-features.ts`, `product-features-port.ts` and
|
||||
* their importers). `src/.generated/` is derived from the feature list and
|
||||
* left out. A one-word ID that is an ordinary word in the template
|
||||
* (`search`) can still be found in its text.
|
||||
* - `tests/`: a file named after the feature (the same path rule; the
|
||||
* template's `product-feature-switch.test.tsx` is not), or one that imports from the
|
||||
* feature's `src/features/<dir>/` or `tests/features/<dir>/`. A vitest
|
||||
* test's text is not searched for the bare name: the template's own tests
|
||||
* use example IDs as data (`tests/unit/create-feature.test.ts` writes
|
||||
@@ -25,14 +33,24 @@ import path from "node:path";
|
||||
* searched for the ID or folder name as written, case-sensitive, with no
|
||||
* identifier character (`[A-Za-z0-9_-]`) on either side. A longer name
|
||||
* that contains it (`generate-product-feature-index.ts` for
|
||||
* `product-feature`, `KO_MESSAGES` for `messages`) does not count. A spec
|
||||
* that names only the feature's routes or URLs is not found; 03's hand list
|
||||
* removes the feature's specs.
|
||||
* `product-feature`, `KO_MESSAGES` for `messages`) does not count.
|
||||
* Diff review DR-02: only a name with a hyphen is searched. A one-word ID
|
||||
* or folder (`status`, `reports`, `messages`) is an ordinary word in the
|
||||
* template's own specs (`status: 200`, `getByRole("status")`, "reports" in
|
||||
* a test title), and no text rule tells that from a reference, so a spec
|
||||
* that names only a one-word ID is not found either.
|
||||
* a test title), and no text rule tells that from a reference.
|
||||
* - 0925 FOLLOW-UP 09-07. A spec that opens the feature by its URL alone
|
||||
* (`page.goto("/invoices")`) failed only in FE-GATE-008, after the drill
|
||||
* passed. `routes.paths` are the removed feature's route paths: a spec, or
|
||||
* another file in a Playwright `testDir` that is not a vitest test (a page
|
||||
* object), with a string that opens one is residue. A string opens a route
|
||||
* when it starts with the route's fixed prefix (`/invoices` of
|
||||
* `/invoices/:id` or `/invoices/edit?`) followed by the string's end, `/`,
|
||||
* `?`, `#` or `${`, and no route left behind (`routes.remainingPaths`) has
|
||||
* a longer prefix that fits it. A prefix that is `/` is not searched.
|
||||
* `routes.ids`, the feature's route IDs, are searched in `src` text by the
|
||||
* whole-name rule. What is still not found: a spec that names only a
|
||||
* one-word ID, or builds the URL from parts. 03's hand list removes the
|
||||
* feature's specs.
|
||||
*
|
||||
* The drill applies the same rule to a sample a project lists in
|
||||
* scripts/lib/removable-template-features.ts.
|
||||
@@ -41,6 +59,18 @@ function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* The feature ID or folder as a whole name: case-sensitive, with no
|
||||
* identifier character (`[A-Za-z0-9_-]`) on either side. The drill searches
|
||||
* `src` text and the built `dist` with it; the template's own bundle holds
|
||||
* `data-product-feature` and `product-features`, which a substring search
|
||||
* counted for a feature named `product-feature`.
|
||||
*/
|
||||
export function featureNamePattern(featureId: string, directory: string): RegExp {
|
||||
const names = [...new Set([featureId, directory])].map(escapeRegExp).join("|");
|
||||
return new RegExp(`(?<![A-Za-z0-9_-])(?:${names})(?![A-Za-z0-9_-])`, "u");
|
||||
}
|
||||
|
||||
async function filesUnder(directory: string): Promise<string[]> {
|
||||
const entries = await readdir(directory, { withFileTypes: true }).catch(() => []);
|
||||
const nested = await Promise.all(
|
||||
@@ -52,13 +82,73 @@ async function filesUnder(directory: string): Promise<string[]> {
|
||||
return nested.flat();
|
||||
}
|
||||
|
||||
/**
|
||||
* The part of a route path before its first parameter, wildcard or optional
|
||||
* segment (`/invoices` of `/invoices/:id` or `/invoices/edit?`), or null when
|
||||
* that is `/`.
|
||||
*/
|
||||
function staticRoutePrefix(routePath: string): string | null {
|
||||
const segments: string[] = [];
|
||||
for (const segment of routePath.split("/").filter(Boolean)) {
|
||||
if (segment.startsWith(":") || segment.includes("*") || segment.endsWith("?")) break;
|
||||
segments.push(segment);
|
||||
}
|
||||
return segments.length === 0 ? null : `/${segments.join("/")}`;
|
||||
}
|
||||
|
||||
const prefixesOf = (routePaths: readonly string[]) =>
|
||||
new Set(routePaths.map(staticRoutePrefix).filter((prefix): prefix is string => prefix !== null));
|
||||
|
||||
/** `/invoices`, `/invoices/7`, `/invoices?tab=1`, `/invoices#x`, `/invoices${query}` open `/invoices`. */
|
||||
function opens(value: string, prefix: string): boolean {
|
||||
if (!value.startsWith(prefix)) return false;
|
||||
const rest = value.slice(prefix.length);
|
||||
return rest === "" || /^[/?#]/u.test(rest) || rest.startsWith("${");
|
||||
}
|
||||
|
||||
/** The Playwright `testDir`s the repository's `playwright*.config.ts` files name. */
|
||||
async function browserTestDirectories(root: string): Promise<string[]> {
|
||||
const configs = (await readdir(root).catch(() => [])).filter((name) =>
|
||||
/^playwright(?:\.[\w-]+)?\.config\.[cm]?[jt]s$/u.test(name),
|
||||
);
|
||||
const directories = await Promise.all(
|
||||
configs.map(async (config) =>
|
||||
/testDir:\s*["']\.?\/?([^"']+)["']/u.exec(await readFile(path.join(root, config), "utf8"))?.[1]
|
||||
?.replace(/\/$/u, ""),
|
||||
),
|
||||
);
|
||||
return directories.filter((directory): directory is string => directory !== undefined);
|
||||
}
|
||||
|
||||
export type FeatureRoutes = Readonly<{
|
||||
/** The removed feature's route paths. */
|
||||
paths?: readonly string[];
|
||||
/** Every route path left after the removal, platform routes included. */
|
||||
remainingPaths?: readonly string[];
|
||||
/** The removed feature's route IDs, platform IDs it took over left out. */
|
||||
ids?: readonly string[];
|
||||
}>;
|
||||
|
||||
export async function productFeatureResidue(
|
||||
root: string,
|
||||
featureId: string,
|
||||
directory: string,
|
||||
routes: FeatureRoutes = {},
|
||||
): Promise<string[]> {
|
||||
const names = [...new Set([featureId, directory])].map(escapeRegExp).join("|");
|
||||
const named = new RegExp(names, "iu");
|
||||
const nameSet = new Set([featureId, directory]);
|
||||
const names = [...nameSet].map(escapeRegExp).join("|");
|
||||
const wholeAnyName = featureNamePattern(featureId, directory);
|
||||
// A route ID left in platform source (a catalog key, `route.INVOICES_LIST`)
|
||||
// is found by its whole name too.
|
||||
const routeIds = [...new Set(routes.ids ?? [])].map(escapeRegExp);
|
||||
const wholeRouteId =
|
||||
routeIds.length === 0
|
||||
? null
|
||||
: new RegExp(`(?<![A-Za-z0-9_-])(?:${routeIds.join("|")})(?![A-Za-z0-9_-])`, "u");
|
||||
const pathNames = (relativePath: string) =>
|
||||
relativePath
|
||||
.split("/")
|
||||
.some((segment) => nameSet.has(segment) || nameSet.has(segment.split(".")[0] ?? ""));
|
||||
const imported = new RegExp(
|
||||
String.raw`(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\bmock\s*\(\s*)["'][^"'\n]*/features/(?:${names})/`,
|
||||
"u",
|
||||
@@ -70,20 +160,47 @@ export async function productFeatureResidue(
|
||||
specNames.length === 0
|
||||
? null
|
||||
: new RegExp(`(?<![A-Za-z0-9_-])(?:${specNames.join("|")})(?![A-Za-z0-9_-])`, "u");
|
||||
// A URL opens the route whose fixed prefix is the longest that fits it, so
|
||||
// a sibling feature's `/invoices/lines` in the same context is not the
|
||||
// removed `/invoices`. When a route left behind has the same prefix
|
||||
// (`/invoices` beside a removed `/invoices/:id`), the URL is not counted.
|
||||
const removed = prefixesOf(routes.paths ?? []);
|
||||
const remaining = prefixesOf(routes.remainingPaths ?? []);
|
||||
const candidates = [...new Set([...removed, ...remaining])].sort((a, b) => b.length - a.length);
|
||||
const opensRemovedRoute = (text: string) => {
|
||||
if (removed.size === 0) return false;
|
||||
for (const match of text.matchAll(/["'`](\/[^"'`\s]*)/gu)) {
|
||||
const best = candidates.find((prefix) => opens(match[1]!, prefix));
|
||||
if (best !== undefined && removed.has(best) && !remaining.has(best)) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const browserDirectories = await browserTestDirectories(root);
|
||||
const playwrightSpec = /\.spec\.[cm]?[jt]sx?$/u;
|
||||
// A page object or helper beside the specs (`tests/e2e/support/*.ts`) runs
|
||||
// only in a browser too; a vitest test (`*.test.*`) does not.
|
||||
const browserFile = (name: string) =>
|
||||
playwrightSpec.test(name) ||
|
||||
(!/\.test\.[cm]?[jt]sx?$/u.test(name) &&
|
||||
browserDirectories.some((directory) => name.startsWith(`${directory}/`)));
|
||||
const residue: string[] = [];
|
||||
const relative = (file: string) => path.relative(root, file).split(path.sep).join("/");
|
||||
for (const file of await filesUnder(path.join(root, "src"))) {
|
||||
const name = relative(file);
|
||||
if (named.test(`${name}\n${await readFile(file, "utf8")}`)) residue.push(name);
|
||||
if (name.startsWith("src/.generated/")) continue;
|
||||
const text = await readFile(file, "utf8");
|
||||
if (pathNames(name) || wholeAnyName.test(text) || (wholeRouteId !== null && wholeRouteId.test(text))) {
|
||||
residue.push(name);
|
||||
}
|
||||
}
|
||||
for (const file of await filesUnder(path.join(root, "tests"))) {
|
||||
const name = relative(file);
|
||||
const text = await readFile(file, "utf8");
|
||||
if (
|
||||
named.test(name) ||
|
||||
pathNames(name) ||
|
||||
imported.test(text) ||
|
||||
(wholeName !== null && playwrightSpec.test(name) && wholeName.test(text))
|
||||
(playwrightSpec.test(name) && wholeName !== null && wholeName.test(text)) ||
|
||||
(browserFile(name) && opensRemovedRoute(text))
|
||||
) {
|
||||
residue.push(name);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,29 @@ const BROWSER =
|
||||
const DRILL =
|
||||
"a removal drill copies the repository again. The drill runs the generated " +
|
||||
"feature's own removal instead (feature-removal).";
|
||||
/**
|
||||
* The drill runs FE-GATE-005's test:coverage in the same copy, and its paths
|
||||
* hold every path of these suites (tests/unit/removal-drill-test-paths.test.ts).
|
||||
* Running them plain as well found nothing more and cost about 80 s a drill.
|
||||
*/
|
||||
const COVERED =
|
||||
"test:coverage runs the same test files in this copy " +
|
||||
"(tests/unit/removal-drill-test-paths.test.ts checks the paths).";
|
||||
export const SCAFFOLD_DRILL_COVERED_SUITES: readonly string[] = Object.freeze([
|
||||
"test:runtime-schema",
|
||||
"test:unit",
|
||||
"test:contract",
|
||||
"test:component",
|
||||
"test:integration",
|
||||
]);
|
||||
/**
|
||||
* What a removal drill runs next to test:coverage so that every test:all path
|
||||
* still runs once in the copy (scripts/test-sample-removal.ts). The rest of
|
||||
* test:all, check:release-coherence included, is inside coverage's paths.
|
||||
*/
|
||||
export const REMOVAL_DRILL_SUITES_OUTSIDE_COVERAGE: readonly string[] = Object.freeze([
|
||||
"test:recipes",
|
||||
]);
|
||||
|
||||
export const SCAFFOLD_DRILL_EXCLUDED_SCRIPTS: Readonly<Record<string, string>> = Object.freeze({
|
||||
"verify:lockfile":
|
||||
@@ -38,11 +61,9 @@ export const SCAFFOLD_DRILL_EXCLUDED_SCRIPTS: Readonly<Record<string, string>> =
|
||||
"needs the CI runner's bubblewrap, systemd and cgroup v2 " +
|
||||
"(scripts/check-system-test-prerequisites.ts). It tests the provider " +
|
||||
"sandbox, which a feature does not reach.",
|
||||
...Object.fromEntries(SCAFFOLD_DRILL_COVERED_SUITES.map((script) => [script, COVERED])),
|
||||
"test:sample-removal": DRILL,
|
||||
"test:feature-scaffold": "is this drill.",
|
||||
"test:optional-recipe-removal": DRILL,
|
||||
"test:browser-file-storage-removal": DRILL,
|
||||
"test:realtime-removal": DRILL,
|
||||
});
|
||||
|
||||
export type ScaffoldDrillCommand = Readonly<{
|
||||
@@ -65,6 +86,14 @@ export function scaffoldDrillCommands(
|
||||
const mergeScripts = new Set<string>();
|
||||
const seen = new Set<string>();
|
||||
const selected: ScaffoldDrillCommand[] = [];
|
||||
// A covered suite is left out only while the drill runs test:coverage. A
|
||||
// copy whose merge stage lost it runs the suites plain again.
|
||||
const runsCoverage = !Object.hasOwn(excluded, "test:coverage") && merge.gateIds.some((gateId) =>
|
||||
contract.gates.find(({ id }) => id === gateId)?.commandIds.some((commandId) =>
|
||||
commands.get(commandId)?.script === "test:coverage"));
|
||||
const leftOut = (script: string) =>
|
||||
Object.hasOwn(excluded, script) &&
|
||||
(runsCoverage || !SCAFFOLD_DRILL_COVERED_SUITES.includes(script) || excluded[script] !== COVERED);
|
||||
for (const gateId of merge.gateIds) {
|
||||
const gate = contract.gates.find(({ id }) => id === gateId);
|
||||
if (!gate) throw new TypeError(`the merge stage names an undefined gate: ${gateId}`);
|
||||
@@ -72,7 +101,7 @@ export function scaffoldDrillCommands(
|
||||
const command = commands.get(commandId);
|
||||
if (!command) throw new TypeError(`${gateId} names an undefined command: ${commandId}`);
|
||||
mergeScripts.add(command.script);
|
||||
if (seen.has(commandId) || Object.hasOwn(excluded, command.script)) continue;
|
||||
if (seen.has(commandId) || leftOut(command.script)) continue;
|
||||
seen.add(commandId);
|
||||
selected.push(Object.freeze({
|
||||
name: `${gateId}:${commandId}`,
|
||||
|
||||
@@ -5,9 +5,11 @@ import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
import { namesOf } from "../create-feature.ts";
|
||||
import { localBuildEnvironment } from "./build-environment.ts";
|
||||
import { linkFixtureNodeModules } from "./fixture-node-modules.ts";
|
||||
import { REMOVAL_FIXTURE_COPY_TARGETS } from "./removal-fixture.ts";
|
||||
import { TEMPLATE_PROBE_PREFIX } from "./template-probe-features.ts";
|
||||
|
||||
/**
|
||||
* 2026-11-07. The template ships no feature. What needs one in a real build
|
||||
@@ -19,8 +21,19 @@ import { REMOVAL_FIXTURE_COPY_TARGETS } from "./removal-fixture.ts";
|
||||
* (scripts/scale/browser-soak.ts, `buildWithGeneratedFeature`). A change of
|
||||
* the generator's output fails there. The `--keyed` write slice is the widest
|
||||
* one the command makes.
|
||||
*
|
||||
* 1112/08-02. The id begins with the reserved probe prefix: the copy holds
|
||||
* the product's own features, and a product that had built `order-feature`
|
||||
* made create:feature refuse this one.
|
||||
*/
|
||||
export const GENERATED_FEATURE_ID = "order-feature";
|
||||
export const GENERATED_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}order-feature`;
|
||||
|
||||
const NAMES = namesOf(GENERATED_FEATURE_ID);
|
||||
|
||||
/** The key of one of the feature's words (`<camel>.list.title`). */
|
||||
export function generatedMessageKey(suffix: string): string {
|
||||
return `${NAMES.camel}.${suffix}`;
|
||||
}
|
||||
|
||||
export type GeneratedRoute = Readonly<{
|
||||
routeId: string;
|
||||
@@ -48,7 +61,7 @@ function node(root: string, args: readonly string[]): string {
|
||||
return result.stdout;
|
||||
}
|
||||
|
||||
/** The edit of a fixture build: `corepack pnpm create:feature order-feature --with-create --keyed`. */
|
||||
/** The edit of a fixture build: `corepack pnpm create:feature <GENERATED_FEATURE_ID> --with-create --keyed`. */
|
||||
export async function addGeneratedFeature(root: string): Promise<void> {
|
||||
node(root, ["scripts/generate-product-feature-index.ts"]);
|
||||
node(root, ["scripts/create-feature.ts", GENERATED_FEATURE_ID, "--with-create", "--keyed"]);
|
||||
@@ -62,23 +75,24 @@ export async function addGeneratedFeature(root: string): Promise<void> {
|
||||
export function generatedFeature(root: string): GeneratedFeature {
|
||||
const feature = path.join(root, "src/features", GENERATED_FEATURE_ID);
|
||||
const module = (file: string) => JSON.stringify(pathToFileURL(path.join(feature, file)).href);
|
||||
const { base, upper } = NAMES;
|
||||
const source = `
|
||||
const { ORDER_FEATURE_CONTRACT } = await import(${module("contracts/order-feature-contract.ts")});
|
||||
const { ORDER_MESSAGE_CATALOGS } = await import(${module("contracts/order-message-catalog.ts")});
|
||||
const { ORDER_LIST_ITEMS_CONTRACT } = await import(${module("contracts/order-contract-contribution.ts")});
|
||||
const { ${upper}_FEATURE_CONTRACT: CONTRACT } = await import(${module(`contracts/${GENERATED_FEATURE_ID}-contract.ts`)});
|
||||
const { ${upper}_MESSAGE_CATALOGS: CATALOGS } = await import(${module(`contracts/${base}-message-catalog.ts`)});
|
||||
const { ${upper}_LIST_ITEMS_CONTRACT: LIST_ITEMS } = await import(${module(`contracts/${base}-contract-contribution.ts`)});
|
||||
const { API_BASE_URL } = JSON.parse(await (await import("node:fs/promises")).readFile("config/runtime/local.json", "utf8"));
|
||||
const route = (id) => ({
|
||||
routeId: id,
|
||||
path: ORDER_FEATURE_CONTRACT.routes[id].path,
|
||||
chunkId: ORDER_FEATURE_CONTRACT.routes[id].chunkId,
|
||||
moduleId: ORDER_FEATURE_CONTRACT.routeRuntimeContracts[id].moduleId,
|
||||
path: CONTRACT.routes[id].path,
|
||||
chunkId: CONTRACT.routes[id].chunkId,
|
||||
moduleId: CONTRACT.routeRuntimeContracts[id].moduleId,
|
||||
});
|
||||
process.stdout.write(JSON.stringify({
|
||||
list: route("ORDER_LIST"),
|
||||
detail: route("ORDER_DETAIL"),
|
||||
create: route("ORDER_CREATE"),
|
||||
messages: ORDER_MESSAGE_CATALOGS,
|
||||
api: new URL(ORDER_LIST_ITEMS_CONTRACT.contract.pathTemplate.slice(1), API_BASE_URL).href,
|
||||
list: route("${upper}_LIST"),
|
||||
detail: route("${upper}_DETAIL"),
|
||||
create: route("${upper}_CREATE"),
|
||||
messages: CATALOGS,
|
||||
api: new URL(LIST_ITEMS.contract.pathTemplate.slice(1), API_BASE_URL).href,
|
||||
}));
|
||||
`;
|
||||
return JSON.parse(node(root, ["--input-type=module", "-e", source])) as GeneratedFeature;
|
||||
|
||||
@@ -43,7 +43,10 @@ export const PROMOTION_FORMULA = Object.freeze({
|
||||
// F2 (design-docs repo-structure/03-ci.md 7.3). The checkers' negative
|
||||
// fixtures and the gating coverage check run after a merge to main. They
|
||||
// test the checkers, not the change, so they hold no promotion.
|
||||
MAIN_READY: Object.freeze(["FE-GATE-029"]),
|
||||
// FE-GATE-030 (owner decision 2026-11-12 p): the optional runtime removal
|
||||
// drills moved here from FE-GATE-020. A failure turns main red, and the next
|
||||
// pull request fixes it before it merges.
|
||||
MAIN_READY: Object.freeze(["FE-GATE-029", "FE-GATE-030"]),
|
||||
});
|
||||
|
||||
export type GateResult = "PASS" | "FAIL" | "UNVERIFIED";
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { constants, type Dirent, type Stats } from "node:fs";
|
||||
import {
|
||||
lstat,
|
||||
open,
|
||||
readdir,
|
||||
realpath,
|
||||
} from "node:fs/promises";
|
||||
closeSync,
|
||||
constants,
|
||||
type Dirent,
|
||||
fstatSync,
|
||||
lstatSync,
|
||||
openSync,
|
||||
readdirSync,
|
||||
readFileSync,
|
||||
realpathSync,
|
||||
type Stats,
|
||||
} from "node:fs";
|
||||
import path from "node:path";
|
||||
import babelParser from "@babel/eslint-parser";
|
||||
import { parseSync } from "@babel/core";
|
||||
|
||||
import {
|
||||
COVERAGE_SUMMARY_METRICS as coverageMetrics,
|
||||
@@ -422,23 +427,35 @@ function statementIsCoverageCounterBearing(value: unknown): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
function directiveIsCoverageCounterBearing(value: unknown): boolean {
|
||||
if (!isRecord(value) || !isRecord(value.value) || typeof value.value.value !== "string") {
|
||||
throw new TypeError("TypeScript parser returned an invalid directive");
|
||||
}
|
||||
return value.value.value !== "use strict";
|
||||
}
|
||||
|
||||
export function hasCoverageCounterBearingStatements(
|
||||
source: string,
|
||||
relativePath: string,
|
||||
): boolean {
|
||||
// Babel's own parser and AST. @babel/eslint-parser ran the same parser and
|
||||
// then converted the whole tree and its tokens to ESTree, about 2.8 times
|
||||
// the cost over the repository, and the top-level statement types and
|
||||
// flags read here are the same in both trees. Every production module is
|
||||
// parsed once per inventory, and the inventory is built in the gate and in
|
||||
// its tests.
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = babelParser.parse(source, {
|
||||
parsed = parseSync(source, {
|
||||
filename: relativePath,
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
sourceType: "module",
|
||||
requireConfigFile: false,
|
||||
filePath: relativePath,
|
||||
babelOptions: {
|
||||
parserOpts: {
|
||||
plugins: [
|
||||
"typescript",
|
||||
...(relativePath.endsWith(".tsx") ? ["jsx"] : []),
|
||||
],
|
||||
},
|
||||
parserOpts: {
|
||||
plugins: [
|
||||
"typescript",
|
||||
...(relativePath.endsWith(".tsx") ? (["jsx"] as const) : []),
|
||||
],
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -446,10 +463,21 @@ export function hasCoverageCounterBearingStatements(
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
if (!isRecord(parsed) || !Array.isArray(parsed.body)) {
|
||||
const program = isRecord(parsed) ? parsed.program : undefined;
|
||||
if (
|
||||
!isRecord(program) ||
|
||||
!Array.isArray(program.body) ||
|
||||
!Array.isArray(program.directives)
|
||||
) {
|
||||
throw new TypeError("TypeScript parser returned an invalid program");
|
||||
}
|
||||
return parsed.body.some(statementIsCoverageCounterBearing);
|
||||
// Babel keeps the directive prologue in `directives`, not `body` (ESTree
|
||||
// put it in `body`). V8 coverage counts a directive as a statement, all but
|
||||
// "use strict" (check:v8-coverage-counter-semantics runs both).
|
||||
return (
|
||||
program.directives.some(directiveIsCoverageCounterBearing) ||
|
||||
program.body.some(statementIsCoverageCounterBearing)
|
||||
);
|
||||
}
|
||||
|
||||
export async function buildProductionModuleInventory(
|
||||
@@ -457,12 +485,25 @@ export async function buildProductionModuleInventory(
|
||||
): Promise<ProductionModuleInventory> {
|
||||
const repositoryRoot = path.resolve(options.repositoryRoot ?? process.cwd());
|
||||
const sourceRoot = path.join(repositoryRoot, "src");
|
||||
// The default file system makes the same calls in the same order as the
|
||||
// fs/promises one, synchronously. The walk awaits about six calls per
|
||||
// module one after another; through the thread pool each waited for an
|
||||
// event-loop turn, and on a loaded CI machine that wait, not the work, made
|
||||
// the inventory take seconds. Injected file systems keep the async shape.
|
||||
const readDirectory = options.readDirectory ??
|
||||
((target: string) => readdir(target, { withFileTypes: true }));
|
||||
const lstatPath = options.lstatPath ?? lstat;
|
||||
const realpathPath = options.realpathPath ?? realpath;
|
||||
(async (target: string) => readdirSync(target, { withFileTypes: true }));
|
||||
const lstatPath = options.lstatPath ?? (async (target: string) => lstatSync(target));
|
||||
const realpathPath = options.realpathPath ??
|
||||
(async (target: string) => realpathSync.native(target));
|
||||
const openFile = options.openFile ??
|
||||
((target: string, flags: number) => open(target, flags));
|
||||
(async (target: string, flags: number): Promise<ReadableFileHandle> => {
|
||||
const descriptor = openSync(target, flags);
|
||||
return {
|
||||
stat: async () => fstatSync(descriptor),
|
||||
readFile: async (encoding) => readFileSync(descriptor, encoding),
|
||||
close: async () => closeSync(descriptor),
|
||||
};
|
||||
});
|
||||
const generatedPaths = uniquePaths(options.generatedPaths ?? [], "generatedPaths");
|
||||
const generated = new Set(generatedPaths);
|
||||
const repositoryRealpath = await realpathPath(repositoryRoot);
|
||||
|
||||
@@ -3,6 +3,8 @@ import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { declaredCspProblems } from "./csp-policy.ts";
|
||||
|
||||
type ScanResult = Readonly<{
|
||||
error?: Error;
|
||||
status: number | null;
|
||||
@@ -168,3 +170,25 @@ export async function checkNonmatchingSecurityIncludeFixture(
|
||||
await cleanup(directory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 0929/13-04. The policy check check:browser-security runs rejects its
|
||||
* fixture (a keyword in another case, in the first of two script-src) and
|
||||
* accepts the declared policy.
|
||||
*/
|
||||
export async function checkDeclaredCspFixtures(): Promise<void> {
|
||||
const fixture = "tests/fixtures/security/csp/rejected-security-headers.json";
|
||||
const rejected = declaredCspProblems(await readFile(fixture, "utf8"));
|
||||
const expected = ["script-src allows 'unsafe-inline'"];
|
||||
if (JSON.stringify(rejected) !== JSON.stringify(expected)) {
|
||||
throw new Error(
|
||||
`${fixture}: expected ${expected.join(", ")}; received ${rejected.join(", ") || "no problem"}`,
|
||||
);
|
||||
}
|
||||
const declared = declaredCspProblems(
|
||||
await readFile("config/hosting/security-headers.json", "utf8"),
|
||||
);
|
||||
if (declared.length > 0) {
|
||||
throw new Error(`config/hosting/security-headers.json: ${declared.join("; ")}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { namesOf } from "../create-feature.ts";
|
||||
|
||||
/**
|
||||
* 1112/08-02. Feature ids the template's own tests and drills create in a
|
||||
* copy of the repository. The copy holds the product's features, and
|
||||
* create:feature refuses an id a feature there already has, or one with the
|
||||
* same prefix. A template test that used the manual's example
|
||||
* (`invoice-feature`) or a plain business word (`order-feature`) therefore
|
||||
* failed FE-GATE-005 and FE-GATE-008 in every product that had built a
|
||||
* feature by that name. Each id here begins with the prefix the template
|
||||
* reserves for its probes; docs/manual/reference/create-feature.md tells a
|
||||
* product not to use it.
|
||||
*/
|
||||
export const TEMPLATE_PROBE_PREFIX = "typecheck-probe-";
|
||||
|
||||
/** The feature the manual's code blocks are written for (docs/manual/01-add-a-feature.md). */
|
||||
export const MANUAL_EXAMPLE_FEATURE_ID = "invoice-feature";
|
||||
/** What tests/unit/manual-code-blocks.test.ts creates and renames the blocks to. */
|
||||
export const MANUAL_PROBE_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}${MANUAL_EXAMPLE_FEATURE_ID}`;
|
||||
/** The sample tests/unit/template-feature-removal-documents.test.ts lists and deletes. */
|
||||
export const LISTED_SAMPLE_PROBE_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}listed-sample-feature`;
|
||||
/** What FE-GATE-020's scaffold drill (scripts/test-feature-scaffold.ts, test:sample-removal) creates. */
|
||||
export const SCAFFOLD_PROBE_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}scaffold-feature`;
|
||||
/** The scaffold drill's `--with-create --keyed` feature. */
|
||||
export const SCAFFOLD_WRITE_PROBE_FEATURE_ID = `${TEMPLATE_PROBE_PREFIX}scaffold-write-feature`;
|
||||
|
||||
function escape(text: string): string {
|
||||
return text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* `text` written for feature `fromId`, with every spelling create:feature
|
||||
* derives from an id (`INVOICE_`, `Invoice`, `invoice-`, `invoice`) moved to
|
||||
* the spelling it derives from `toId`. Prose that uses the word moves too;
|
||||
* what matters is that the names a block defines and the names it imports
|
||||
* from the generated feature move together.
|
||||
*/
|
||||
export function renameFeatureText(text: string, fromId: string, toId: string): string {
|
||||
const from = namesOf(fromId);
|
||||
const to = namesOf(toId);
|
||||
const spellings = new Map<string, string>([
|
||||
[from.upper, to.upper],
|
||||
[from.pascal, to.pascal],
|
||||
[`${from.base}-`, `${to.base}-`],
|
||||
[from.camel, to.camel],
|
||||
]);
|
||||
const pattern = new RegExp([...spellings.keys()].map(escape).join("|"), "gu");
|
||||
return text.replace(pattern, (match) => spellings.get(match) ?? match);
|
||||
}
|
||||
@@ -16,6 +16,15 @@ import { reachablePackageScripts } from "./package-script-graph.ts";
|
||||
export const UNGATED_TESTS_PATH = "config/ci/ungated-tests.json";
|
||||
|
||||
const TEST_FILE = /\.(?:test|spec)\.tsx?$/u;
|
||||
// vitest.config.ts includes only the `*.test.ts` and `*.test.tsx` files below tests.
|
||||
const VITEST_TEST_FILE = /\.test\.tsx?$/u;
|
||||
|
||||
/**
|
||||
* 0929/12-06. A gated path and the runner that reaches it. A Vitest path
|
||||
* runs its `*.test.*` files only; a Playwright `testDir` runs what the
|
||||
* Playwright default `testMatch` takes, `*.spec.*` and `*.test.*`.
|
||||
*/
|
||||
export type GatedTestTarget = Readonly<{ path: string; runner: "vitest" | "playwright" }>;
|
||||
|
||||
const ungatedTestsSchema = z
|
||||
.object({
|
||||
@@ -54,14 +63,26 @@ export function gatedTestPaths(
|
||||
entryScripts: readonly string[],
|
||||
readConfig: (file: string) => string,
|
||||
): string[] {
|
||||
const paths = new Set<string>();
|
||||
return [...new Set(gatedTestTargets(scripts, entryScripts, readConfig).map(({ path: target }) => target))].sort();
|
||||
}
|
||||
|
||||
export function gatedTestTargets(
|
||||
scripts: Readonly<Record<string, string>>,
|
||||
entryScripts: readonly string[],
|
||||
readConfig: (file: string) => string,
|
||||
): GatedTestTarget[] {
|
||||
const targets = new Map<string, GatedTestTarget>();
|
||||
const add = (target: string, runner: GatedTestTarget["runner"]) => {
|
||||
const normalized = target.replace(/\/$/u, "");
|
||||
targets.set(`${runner} ${normalized}`, { path: normalized, runner });
|
||||
};
|
||||
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, ""));
|
||||
if (!token.startsWith("-")) add(token, "vitest");
|
||||
}
|
||||
};
|
||||
for (const script of reachablePackageScripts(scripts, entryScripts)) {
|
||||
@@ -79,20 +100,30 @@ export function gatedTestPaths(
|
||||
const configFlag = tokens.indexOf("--config");
|
||||
const config = configFlag >= 0 ? tokens[configFlag + 1]! : "playwright.config.ts";
|
||||
const testDir = /testDir:\s*["']\.?\/?([^"']+)["']/u.exec(readConfig(config))?.[1];
|
||||
if (testDir) paths.add(testDir.replace(/\/$/u, ""));
|
||||
if (testDir) add(testDir, "playwright");
|
||||
}
|
||||
}
|
||||
}
|
||||
return [...paths].sort();
|
||||
return [...targets.values()].sort(
|
||||
(left, right) => left.path.localeCompare(right.path) || left.runner.localeCompare(right.runner),
|
||||
);
|
||||
}
|
||||
|
||||
export function ungatedTestFailures(input: Readonly<{
|
||||
testFiles: readonly string[];
|
||||
gatedPaths: readonly string[];
|
||||
/** A bare string is a Vitest path. */
|
||||
gatedPaths: readonly (string | GatedTestTarget)[];
|
||||
exclusions: readonly UngatedTestExclusion[];
|
||||
}>): string[] {
|
||||
const targets = input.gatedPaths.map((target): GatedTestTarget =>
|
||||
typeof target === "string" ? { path: target, runner: "vitest" } : target,
|
||||
);
|
||||
const gated = (file: string) =>
|
||||
input.gatedPaths.some((gatedPath) => file === gatedPath || file.startsWith(`${gatedPath}/`));
|
||||
targets.some(
|
||||
({ path: gatedPath, runner }) =>
|
||||
(file === gatedPath || file.startsWith(`${gatedPath}/`)) &&
|
||||
(runner === "playwright" || VITEST_TEST_FILE.test(file)),
|
||||
);
|
||||
const excluded = new Set(input.exclusions.map(({ path: file }) => file));
|
||||
const failures = input.testFiles
|
||||
.filter((file) => !gated(file) && !excluded.has(file))
|
||||
|
||||
@@ -10,6 +10,8 @@ import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { rootAnchoredGlobs } from "./coverage-scope.ts";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const coverageMetrics = [
|
||||
"lines",
|
||||
@@ -17,8 +19,13 @@ const coverageMetrics = [
|
||||
"functions",
|
||||
"branches",
|
||||
] as const;
|
||||
const runtimeModule = "src/runtime.ts";
|
||||
/** Modules V8 gives at least one counter: code, and a directive prologue. */
|
||||
const counterBearingModules = Object.freeze([
|
||||
"src/directive-use-client.ts",
|
||||
"src/runtime.ts",
|
||||
] as const);
|
||||
const counterlessModules = Object.freeze([
|
||||
"src/directive-use-strict.ts",
|
||||
"src/import-empty.ts",
|
||||
"src/import-side-effect.ts",
|
||||
"src/import-type-empty.ts",
|
||||
@@ -27,15 +34,25 @@ const counterlessModules = Object.freeze([
|
||||
"src/reexport-star.ts",
|
||||
"src/type-only.ts",
|
||||
] as const);
|
||||
const expectedModules = Object.freeze(
|
||||
[runtimeModule, ...counterlessModules].sort(),
|
||||
const expectedModules: readonly string[] = Object.freeze(
|
||||
[...counterBearingModules, ...counterlessModules].sort(),
|
||||
);
|
||||
const childOutputLimit = 1_800;
|
||||
/**
|
||||
* The fixture is copied into a folder whose name ends in `src` and has glob
|
||||
* characters. Vitest matches coverage patterns anywhere in an absolute path,
|
||||
* so an unanchored `src/**` also counts the fixture's root-level
|
||||
* `outside-src.ts`, which the row-set check then reports as additional. The
|
||||
* repository's own coverage patterns are anchored the same way
|
||||
* (vitest.config.ts, scripts/lib/coverage-scope.ts).
|
||||
*/
|
||||
const fixtureCheckoutName = "checkout (copy)-src";
|
||||
|
||||
type ChildOutput = Readonly<{ stdout: string; stderr: string }>;
|
||||
type ChildInput = Readonly<{
|
||||
repositoryRoot: string;
|
||||
ownedRoot: string;
|
||||
fixtureRoot: string;
|
||||
configPath: string;
|
||||
}>;
|
||||
type CheckerOptions = Readonly<{
|
||||
@@ -144,9 +161,11 @@ export function assertV8CoverageCounterSemantics(
|
||||
`V8 coverage row set mismatch; missing: ${missing.join(", ") || "none"}; additional: ${additional.join(", ") || "none"}`,
|
||||
);
|
||||
}
|
||||
const runtimeRow = rows.get(runtimeModule)!;
|
||||
if (!coverageMetrics.some((metric) => runtimeRow[metric].total > 0)) {
|
||||
throw new Error(`V8 runtime module is not counter-bearing: ${runtimeModule}`);
|
||||
for (const modulePath of counterBearingModules) {
|
||||
const row = rows.get(modulePath)!;
|
||||
if (!coverageMetrics.some((metric) => row[metric].total > 0)) {
|
||||
throw new Error(`V8 module is not counter-bearing: ${modulePath}`);
|
||||
}
|
||||
}
|
||||
for (const modulePath of counterlessModules) {
|
||||
const row = rows.get(modulePath)!;
|
||||
@@ -166,7 +185,7 @@ export function assertV8CoverageCounterSemantics(
|
||||
}
|
||||
}
|
||||
return Object.freeze({
|
||||
counterBearingModules: Object.freeze([runtimeModule]),
|
||||
counterBearingModules: Object.freeze([...counterBearingModules]),
|
||||
counterlessModules: Object.freeze([...counterlessModules]),
|
||||
});
|
||||
}
|
||||
@@ -195,7 +214,7 @@ async function defaultRunVitest(input: ChildInput): Promise<ChildOutput> {
|
||||
"--no-color",
|
||||
],
|
||||
{
|
||||
cwd: input.ownedRoot,
|
||||
cwd: input.fixtureRoot,
|
||||
encoding: "utf8",
|
||||
timeout: 30_000,
|
||||
maxBuffer: 256 * 1024,
|
||||
@@ -232,15 +251,16 @@ export async function checkV8CoverageCounterSemantics(
|
||||
repositoryRoot,
|
||||
"tests/fixtures/v8-coverage-counter-semantics",
|
||||
);
|
||||
const configPath = path.join(ownedRoot, "vitest.config.mjs");
|
||||
const fixtureRoot = path.join(ownedRoot, fixtureCheckoutName);
|
||||
const configPath = path.join(fixtureRoot, "vitest.config.mjs");
|
||||
const reportsDirectory = path.join(ownedRoot, "coverage");
|
||||
try {
|
||||
await cp(fixtureSource, ownedRoot, { recursive: true });
|
||||
await cp(fixtureSource, fixtureRoot, { recursive: true });
|
||||
await writeFile(
|
||||
configPath,
|
||||
`export default ${JSON.stringify(
|
||||
{
|
||||
root: ownedRoot,
|
||||
root: fixtureRoot,
|
||||
test: {
|
||||
globals: true,
|
||||
include: ["counter-semantics.fixture.ts"],
|
||||
@@ -249,7 +269,7 @@ export async function checkV8CoverageCounterSemantics(
|
||||
provider: "v8",
|
||||
reportsDirectory,
|
||||
reporter: ["json-summary"],
|
||||
include: ["src/**/*.ts"],
|
||||
include: rootAnchoredGlobs(fixtureRoot, ["src/**/*.ts"]),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -259,7 +279,7 @@ export async function checkV8CoverageCounterSemantics(
|
||||
"utf8",
|
||||
);
|
||||
try {
|
||||
await runVitest({ repositoryRoot, ownedRoot, configPath });
|
||||
await runVitest({ repositoryRoot, ownedRoot, fixtureRoot, configPath });
|
||||
} catch (error) {
|
||||
const record = isRecord(error) ? error : {};
|
||||
throw new Error(
|
||||
@@ -287,7 +307,7 @@ export async function checkV8CoverageCounterSemantics(
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
return assertV8CoverageCounterSemantics(summary, ownedRoot);
|
||||
return assertV8CoverageCounterSemantics(summary, fixtureRoot);
|
||||
} finally {
|
||||
await rm(ownedRoot, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
type ProviderGuardianLease,
|
||||
} from "./lib/provider-guardian-client.ts";
|
||||
import { createProviderOutputLimiter } from "./lib/provider-output-limiter.ts";
|
||||
import { findProviderSandboxNamespaceFailure } from "./check-system-test-prerequisites.ts";
|
||||
import { PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS } from "./lib/provider-sandbox-namespaces.ts";
|
||||
import {
|
||||
providerProcessTraceEnvironment,
|
||||
@@ -125,6 +126,13 @@ await access("/usr/bin/systemd-run", constants.X_OK).catch(() => {
|
||||
await access("/usr/bin/systemctl", constants.X_OK).catch(() => {
|
||||
throw new Error("provider cgroup unavailable: /usr/bin/systemctl is required");
|
||||
});
|
||||
// 1101/13-03. A runner that refuses the sandbox's unprivileged user and
|
||||
// network namespaces fails here, by name and with its host settings, instead
|
||||
// of later with bwrap's raw error.
|
||||
const namespaceFailure = await findProviderSandboxNamespaceFailure();
|
||||
if (namespaceFailure !== undefined) {
|
||||
throw new Error(`provider sandbox unavailable: ${namespaceFailure}`);
|
||||
}
|
||||
await assertProviderCgroupManagerAvailable();
|
||||
const trust = await readProviderTrust(workspaceRoot, publicKeyPath, keyId);
|
||||
if (!trust) throw new TypeError("provider supervisor trust key is invalid");
|
||||
|
||||
+12
-1
@@ -11,6 +11,7 @@ import {
|
||||
import { classifyGateStepResult } from "./lib/ci-step-result.ts";
|
||||
import { withCiGatePreflight } from "./contracts/ci-gates.ts";
|
||||
import { validateCiArtifact } from "./lib/ci-artifact-validator.ts";
|
||||
import { formatGateFailure } from "./lib/ci-gate-failure.ts";
|
||||
import { writeCiGateLogAtomic } from "./lib/ci-gate-log.ts";
|
||||
|
||||
const requestedGateId = process.argv
|
||||
@@ -111,6 +112,7 @@ for (const variable of gate.requiresEnvironment ?? []) {
|
||||
}
|
||||
}
|
||||
|
||||
let failedCommand: string | undefined;
|
||||
if (passed) {
|
||||
for (const commandId of gate.commandIds) {
|
||||
const step = contractIndex.commands.get(commandId);
|
||||
@@ -174,6 +176,7 @@ if (passed) {
|
||||
});
|
||||
if (!appendOutput(`classification: ${classification.kind}`)) passed = false;
|
||||
if (!classification.expectationMet) {
|
||||
failedCommand = commandLine;
|
||||
appendOutput(
|
||||
`expectation failed: expected ${step.expect}, exit=${result.status}, signal=${result.signal ?? "none"}`,
|
||||
...(step.expect === "fail"
|
||||
@@ -241,7 +244,15 @@ if (passed) {
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
process.stderr.write(`${gateId} ${gate.name}: FAIL\n`);
|
||||
process.stderr.write(
|
||||
`${formatGateFailure({
|
||||
gateId,
|
||||
gateName: gate.name,
|
||||
logPath: logArtifact.path,
|
||||
failedCommand,
|
||||
output,
|
||||
})}\n`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
process.stdout.write(
|
||||
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env bash
|
||||
# Runs one command in a disposable systemd container, for a gate whose host requirements a CI job
|
||||
# container or a developer shell does not meet (config/ci/gates.json `hostEnvironment: "system-container"`,
|
||||
# FE-GATE-013's provider sandbox: bubblewrap, a systemd user manager, delegated cgroup v2).
|
||||
#
|
||||
# scripts/run-in-system-container.sh <command…> e.g. corepack pnpm ci:gate -- FE-GATE-013
|
||||
#
|
||||
# The container is privileged with its own cgroup namespace and boots systemd (config/ci/system-container.Dockerfile).
|
||||
# The command runs as root there, so bubblewrap needs no unprivileged user namespace from the host kernel
|
||||
# (Ubuntu 23.10+ refuses those to unconfined processes). Node and pnpm come from the caller, copied in with the
|
||||
# working tree and its git history; artifacts/ is copied back and the container removed, whatever the result.
|
||||
# Docker: the CI job reaches the runner's own daemon through its Docker proxy
|
||||
# (platform-core infrastructure/ci/gitea-runner); on desktop it is the host daemon.
|
||||
# Environment: SYSTEM_CONTAINER_DOCKER (default docker), SYSTEM_CONTAINER_KEEP=1 keeps the container for debugging.
|
||||
# Exit code: the command's, or 3 when the container could not be prepared.
|
||||
set -euo pipefail
|
||||
|
||||
[ $# -gt 0 ] || { sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//' >&2; exit 2; }
|
||||
docker=${SYSTEM_CONTAINER_DOCKER:-docker}
|
||||
root=$(git rev-parse --show-toplevel)
|
||||
cd "$root"
|
||||
dockerfile=config/ci/system-container.Dockerfile
|
||||
tag="fe-system-container:$(sha256sum "$dockerfile" | cut -c1-16)"
|
||||
node_root=$(dirname "$(dirname "$(command -v node)")")
|
||||
corepack_home=${COREPACK_HOME:-$HOME/.cache/node/corepack}
|
||||
# The environment the gate reads (scripts/verify.sh ci_env, the workflow's global env).
|
||||
pass_env=(CI VITE_BUILD_ID VITE_COMMIT_SHA RELEASE_ID CI_RUNNER_IMAGE SOURCE_DATE_EPOCH APP_PROFILE RELEASE_TARGET)
|
||||
|
||||
say() { echo "system-container: $*" >&2; }
|
||||
fail() { say "$*"; exit 3; }
|
||||
|
||||
if ! $docker image inspect "$tag" > /dev/null 2>&1; then
|
||||
say "building $tag"
|
||||
$docker build -q -t "$tag" -f "$dockerfile" config/ci > /dev/null || fail "image build failed"
|
||||
fi
|
||||
cid=$($docker run -d --privileged --cgroupns=private --tmpfs /run --tmpfs /run/lock "$tag") \
|
||||
|| fail "container did not start"
|
||||
cleanup() {
|
||||
if [ "${SYSTEM_CONTAINER_KEEP:-0}" = 1 ]; then say "kept container $cid"; else $docker rm -f "$cid" > /dev/null 2>&1 || :; fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# systemd reaches a final state, then root's lingering user manager opens its bus. Until PID 1 has its own
|
||||
# bus up, systemctl cannot connect and answers nothing, so ask again for up to a minute.
|
||||
state=""
|
||||
for _ in $(seq 1 120); do
|
||||
state=$($docker exec "$cid" systemctl is-system-running --wait 2>/dev/null || :)
|
||||
case "$state" in running | degraded) break ;; esac
|
||||
sleep 0.5
|
||||
done
|
||||
case "$state" in running | degraded) ;; *) fail "systemd did not start (state: ${state:-none})" ;; esac
|
||||
$docker exec "$cid" sh -c 'for i in $(seq 1 120); do [ -S /run/user/0/bus ] && exit 0; sleep 0.5; done; exit 1' \
|
||||
|| fail "the root user manager did not start"
|
||||
|
||||
# The working tree as it is (node_modules included) and its history. A linked worktree's .git is a file
|
||||
# naming a directory outside the tree, so the history goes in as a bundle of HEAD instead.
|
||||
tar -C "$root" --exclude=./.git --exclude=./.tmp -cf - . | $docker exec -i "$cid" sh -c 'mkdir -p /work && tar -C /work --no-same-owner -xf -' \
|
||||
|| fail "copying the working tree failed"
|
||||
if [ -d .git ]; then
|
||||
tar -C "$root" -cf - .git | $docker exec -i "$cid" tar -C /work --no-same-owner -xf - || fail "copying .git failed"
|
||||
else
|
||||
bundle=$(mktemp)
|
||||
git bundle create -q "$bundle" HEAD
|
||||
$docker exec -i "$cid" sh -c 'cat > /tmp/head.bundle' < "$bundle"
|
||||
rm -f "$bundle"
|
||||
$docker exec -w /work "$cid" sh -c 'git init -q . && git fetch -q /tmp/head.bundle HEAD && git update-ref HEAD FETCH_HEAD && git reset -q' \
|
||||
|| fail "restoring the git history failed"
|
||||
fi
|
||||
tar -C "$node_root" -cf - . | $docker exec -i "$cid" sh -c 'mkdir -p /opt/node && tar -C /opt/node --no-same-owner -xf -' \
|
||||
|| fail "copying node failed"
|
||||
if [ -d "$corepack_home" ]; then
|
||||
tar -C "$corepack_home" -cf - . | $docker exec -i "$cid" sh -c 'mkdir -p /opt/corepack && tar -C /opt/corepack --no-same-owner -xf -' \
|
||||
|| fail "copying the corepack cache failed"
|
||||
fi
|
||||
|
||||
exec_env=(-e PATH=/opt/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
-e COREPACK_HOME=/opt/corepack -e HOME=/root
|
||||
-e XDG_RUNTIME_DIR=/run/user/0 -e DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus)
|
||||
for name in "${pass_env[@]}"; do
|
||||
[ -z "${!name+x}" ] || exec_env+=(-e "$name=${!name}")
|
||||
done
|
||||
rc=0
|
||||
$docker exec -w /work "${exec_env[@]}" "$cid" "$@" || rc=$?
|
||||
# The gate's log and evidence come back even when it failed.
|
||||
mkdir -p artifacts
|
||||
$docker exec "$cid" sh -c '[ -d /work/artifacts ] && tar -C /work -cf - artifacts' | tar -C "$root" -xf - \
|
||||
|| say "copying artifacts back failed"
|
||||
exit "$rc"
|
||||
@@ -4,6 +4,10 @@ import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { loadCiGateContract } from "./contracts/ci-gates.ts";
|
||||
import {
|
||||
SCAFFOLD_PROBE_FEATURE_ID,
|
||||
SCAFFOLD_WRITE_PROBE_FEATURE_ID,
|
||||
} from "./lib/template-probe-features.ts";
|
||||
import {
|
||||
runScaffoldDrillCommand,
|
||||
scaffoldDrillCommands,
|
||||
@@ -37,9 +41,10 @@ import {
|
||||
* test:sample-removal repeats the generation after deleting the sample
|
||||
* (decision 4), which proves the command needs nothing from it.
|
||||
*/
|
||||
const FEATURE_ID = "scaffold-feature";
|
||||
/** 1112/08-02. Reserved probe ids: the copy holds the product's own features. */
|
||||
const FEATURE_ID = SCAFFOLD_PROBE_FEATURE_ID;
|
||||
/** 1103/09-06. The `--with-create --keyed` slice, in its own context. */
|
||||
const WRITE_FEATURE_ID = "scaffold-write-feature";
|
||||
const WRITE_FEATURE_ID = SCAFFOLD_WRITE_PROBE_FEATURE_ID;
|
||||
const REPORT = "artifacts/tests/feature-scaffold.xml";
|
||||
|
||||
const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath");
|
||||
|
||||
@@ -10,10 +10,11 @@ import { spawnSync } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { ROUTE_FEATURE_OWNER } from "../src/features/installed-feature-contracts.ts";
|
||||
import { PLATFORM_ROUTE_REGISTRY } from "../src/contracts/routes.ts";
|
||||
import { ROUTE_FEATURE_OWNER, routePath } from "../src/features/installed-feature-contracts.ts";
|
||||
import { loadCiGateContract } from "./contracts/ci-gates.ts";
|
||||
import { createFileSystemDeclarationSource } from "./generate-product-feature-index.ts";
|
||||
import { productFeatureResidue } from "./lib/feature-residue.ts";
|
||||
import { featureNamePattern, type FeatureRoutes, productFeatureResidue } from "./lib/feature-residue.ts";
|
||||
import { isProductionModulePath } from "./lib/risk-coverage.ts";
|
||||
import {
|
||||
createRemovalFixtureRoot,
|
||||
@@ -31,7 +32,9 @@ import {
|
||||
sealRemovalFixtureRepository,
|
||||
type RemovalCheck,
|
||||
} from "./lib/removal-fixture.ts";
|
||||
import { REMOVAL_DRILL_SUITES_OUTSIDE_COVERAGE } from "./lib/feature-scaffold-drill.ts";
|
||||
import { REMOVABLE_TEMPLATE_FEATURES } from "./lib/removable-template-features.ts";
|
||||
import { SCAFFOLD_PROBE_FEATURE_ID } from "./lib/template-probe-features.ts";
|
||||
|
||||
/**
|
||||
* 09-07 (D-10). Removes one installed feature, `--feature=<id>`, from a copy
|
||||
@@ -162,6 +165,22 @@ const located = await locateFeature(featureId);
|
||||
const featureRouteIds = Object.entries(ROUTE_FEATURE_OWNER)
|
||||
.filter(([, owner]) => owner === featureId)
|
||||
.map(([routeId]) => routeId);
|
||||
// 0925 FOLLOW-UP 09-07. A browser test that opens the feature by one of these
|
||||
// paths is residue (scripts/lib/feature-residue.ts). A platform route the
|
||||
// feature took over (its home) goes back to the platform with the removal.
|
||||
const platformRoutePaths = new Set<string>(
|
||||
Object.values(PLATFORM_ROUTE_REGISTRY).map((route) => route.path),
|
||||
);
|
||||
const featureRoutes: FeatureRoutes = Object.freeze({
|
||||
paths: featureRouteIds.map(routePath).filter((candidate) => !platformRoutePaths.has(candidate)),
|
||||
remainingPaths: [
|
||||
...platformRoutePaths,
|
||||
...Object.keys(ROUTE_FEATURE_OWNER)
|
||||
.filter((routeId) => !featureRouteIds.includes(routeId))
|
||||
.map(routePath),
|
||||
],
|
||||
ids: featureRouteIds.filter((routeId) => !Object.hasOwn(PLATFORM_ROUTE_REGISTRY, routeId)),
|
||||
});
|
||||
|
||||
const fixtureRoot = await createRemovalFixtureRoot(`${featureId}-removal`);
|
||||
const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath");
|
||||
@@ -453,11 +472,17 @@ try {
|
||||
|
||||
// 1105/16-04. Template tests use example feature IDs as data; only what
|
||||
// still points at the removed feature counts (scripts/lib/feature-residue.ts).
|
||||
const residue = await productFeatureResidue(fixtureRoot, featureId, located.directory);
|
||||
const builtResiduePattern = new RegExp(
|
||||
`${escapeRegExp(featureId)}|${escapeRegExp(located.directory)}`,
|
||||
"i",
|
||||
// 0925 FOLLOW-UP 09-07. The drill runs no Playwright spec; one that still
|
||||
// opens the feature's URL is found here instead of in FE-GATE-008.
|
||||
const residue = await productFeatureResidue(
|
||||
fixtureRoot,
|
||||
featureId,
|
||||
located.directory,
|
||||
featureRoutes,
|
||||
);
|
||||
// 1105/16-04. The same whole-name rule as `src`: the template's bundle
|
||||
// holds `data-product-feature`, which a substring search counted.
|
||||
const builtResiduePattern = featureNamePattern(featureId, located.directory);
|
||||
|
||||
const missingCommonTests: string[] = [];
|
||||
for (const testPath of commonTestPaths) {
|
||||
@@ -476,8 +501,13 @@ try {
|
||||
check(`${prefix}design-system`, "check:design-system"),
|
||||
check(`${prefix}architecture`, "check:architecture"),
|
||||
check(`${prefix}registries`, "check:registries"),
|
||||
check(`${prefix}unit-integration`, "test:all"),
|
||||
// test:all ran here before coverage and ran its files twice. coverage
|
||||
// holds every test:all path but the optional recipes'
|
||||
// (tests/unit/removal-drill-test-paths.test.ts), so those run on their own.
|
||||
check(`${prefix}coverage`, "test:coverage"),
|
||||
...REMOVAL_DRILL_SUITES_OUTSIDE_COVERAGE
|
||||
.filter((script) => Object.hasOwn(fixturePackage.scripts, script))
|
||||
.map((script) => check(`${prefix}${script.replace(/^test:/u, "")}`, script)),
|
||||
check(`${prefix}test-evidence-source`, "check:test-evidence:source"),
|
||||
check(`${prefix}ci-contract`, "check:ci"),
|
||||
check(`${prefix}home-smoke`, "exec", [
|
||||
@@ -528,7 +558,7 @@ try {
|
||||
// 1103/09-06. With the write slice (NEVER), which needs nothing from
|
||||
// the sample either.
|
||||
const created = check("scaffold-create-feature", "create:feature", [
|
||||
"scaffold-feature",
|
||||
SCAFFOLD_PROBE_FEATURE_ID,
|
||||
"--with-create",
|
||||
]);
|
||||
checks.push(created);
|
||||
|
||||
@@ -234,6 +234,30 @@ class TurnEndNudgeTest(RepositoryTestCase):
|
||||
self.bash(command)
|
||||
self.assertIsNone(self.stop())
|
||||
|
||||
def test_reading_verify_sh_or_a_dry_run_does_not_count(self) -> None:
|
||||
# 1112/08-09. Only a command that runs a desktop step clears the reminder.
|
||||
for command in ("scripts/verify.sh merge --dry-run",
|
||||
"sed -n 1,80p scripts/verify.sh && ls",
|
||||
"grep -n foo scripts/verify.sh config/ci/gates.json",
|
||||
"git log -- scripts/verify.sh docs/work",
|
||||
"ssh desktop 'cat /tmp/claude-gates/x/FE-GATE-005.log | grep vitest'"):
|
||||
with self.subTest(command=command):
|
||||
self.edit("src/domain/order.ts", "export const a = 5;\n")
|
||||
self.bash(command)
|
||||
self.assertIsNotNone(self.stop())
|
||||
|
||||
def test_a_wrapped_desktop_step_counts(self) -> None:
|
||||
for command in ("timeout 900 scripts/verify.sh exec --log x -- node scripts/run-vitest.ts run tests/unit/a.test.ts",
|
||||
"VERIFY_SNAPSHOT=1 scripts/verify.sh merge --log r9",
|
||||
# round9 confirm review: a shell that runs the script, and ssh options with a value.
|
||||
"bash scripts/verify.sh merge --log r9",
|
||||
"ssh -o BatchMode=yes desktop 'cd ~/workspace/x && corepack pnpm -s lint'",
|
||||
"ssh -p 22 desktop 'corepack pnpm -s lint'"):
|
||||
with self.subTest(command=command):
|
||||
self.edit("src/domain/order.ts", "export const a = 6;\n")
|
||||
self.bash(command)
|
||||
self.assertIsNone(self.stop())
|
||||
|
||||
def test_laptop_commands_and_other_hosts_do_not_count(self) -> None:
|
||||
for command in ("corepack pnpm lint", "ssh build-box 'corepack pnpm lint'", "scripts/verify.sh docs",
|
||||
"scripts/verify.sh hooks", "scripts/verify.sh gate FE-GATE-005 --on here",
|
||||
@@ -244,13 +268,22 @@ class TurnEndNudgeTest(RepositoryTestCase):
|
||||
self.assertIsNotNone(self.stop())
|
||||
|
||||
def test_files_the_laptop_checks_do_not_need_the_desktop(self) -> None:
|
||||
for path in (".claude/rules/x.md", "scripts/hooks/hooks.py", "scripts/tests/test_x.py", "CLAUDE.md",
|
||||
"docs/ledger/estimates.jsonl", "scripts/check-work-docs.py", "src/adapters/AGENTS.md",
|
||||
"src/features/CLAUDE.md"):
|
||||
for path in (".claude/settings.json", "scripts/hooks/hooks.py", "scripts/tests/test_x.py",
|
||||
"docs/ledger/estimates.jsonl", "scripts/check-work-docs.py"):
|
||||
self.repo.write(path, "x\n")
|
||||
run_event("post-edit", self.repo.payload(path))
|
||||
self.assertIsNone(self.stop())
|
||||
|
||||
def test_living_instruction_documents_need_the_desktop(self) -> None:
|
||||
# 1112/08-04. verify:documentation, a desktop gate, checks these documents too.
|
||||
for path in (".claude/rules/x.md", ".claude/skills/fe-x/SKILL.md", "CLAUDE.md",
|
||||
"src/adapters/AGENTS.md", "src/features/CLAUDE.md",
|
||||
# round9 confirm review: living module READMEs beside laptop-checked files.
|
||||
"scripts/hooks/README.md", "docs/ledger/README.md"):
|
||||
with self.subTest(path=path):
|
||||
self.edit(path, "x\n")
|
||||
self.assertIsNotNone(self.stop())
|
||||
|
||||
def test_a_new_edit_after_the_reminder_reminds_again(self) -> None:
|
||||
self.edit("src/domain/order.ts", "export const a = 4;\n")
|
||||
self.stop()
|
||||
|
||||
@@ -45,12 +45,90 @@ class StagePlanTest(unittest.TestCase):
|
||||
|
||||
def test_parts_runs_each_command_of_the_gate(self) -> None:
|
||||
contract = gates()
|
||||
gate = next(g for g in contract["gates"] if g["id"] == "FE-GATE-013")
|
||||
gate = next(g for g in contract["gates"] if g["id"] == "FE-GATE-005")
|
||||
scripts = {c["id"]: c["script"] for c in contract["commands"]}
|
||||
result = sh([str(VERIFY), "parts", "FE-GATE-013", "--dry-run"], cwd=REPO)
|
||||
result = sh([str(VERIFY), "parts", "FE-GATE-005", "--dry-run"], cwd=REPO)
|
||||
self.assertEqual([line.split(": ", 1)[1] for line in result.stdout.splitlines()],
|
||||
[f"corepack pnpm -s {scripts[c]}" for c in gate["commandIds"]])
|
||||
|
||||
def test_a_gate_with_a_host_environment_runs_in_it_as_in_the_workflow(self) -> None:
|
||||
# FE-GATE-013 needs systemd and bubblewrap; the workflow and verify.sh both run it through
|
||||
# scripts/run-in-system-container.sh (config/ci/gates.json hostEnvironment).
|
||||
contract = gates()
|
||||
hosted = [g for g in contract["gates"] if g.get("hostEnvironment") == "system-container"]
|
||||
self.assertEqual([g["id"] for g in hosted], ["FE-GATE-013"])
|
||||
scripts = {c["id"]: c["script"] for c in contract["commands"]}
|
||||
wrapper = "scripts/run-in-system-container.sh"
|
||||
result = sh([str(VERIFY), "gate", "FE-GATE-013", "FE-GATE-005", "--dry-run"], cwd=REPO)
|
||||
self.assertEqual(result.stdout.splitlines(), [f"FE-GATE-013: {wrapper} corepack pnpm -s ci:gate FE-GATE-013",
|
||||
"FE-GATE-005: corepack pnpm -s ci:gate FE-GATE-005"])
|
||||
result = sh([str(VERIFY), "parts", "FE-GATE-013", "--dry-run"], cwd=REPO)
|
||||
self.assertEqual([line.split(": ", 1)[1] for line in result.stdout.splitlines()],
|
||||
[f"{wrapper} corepack pnpm -s {scripts[c]}" for c in hosted[0]["commandIds"]])
|
||||
workflow = (REPO / ".gitea/workflows/quality-gates.yml").read_text(encoding="utf-8")
|
||||
self.assertIn(f"run: {wrapper} corepack pnpm ci:gate -- FE-GATE-013", workflow)
|
||||
# A host that cannot start the container runs the gate here (gates.md 3절).
|
||||
result = sh([str(VERIFY), "gate", "FE-GATE-013", "--dry-run"], cwd=REPO, env={"VERIFY_HOST_ENVIRONMENT": "off"})
|
||||
self.assertEqual(result.stdout.splitlines(), ["FE-GATE-013: corepack pnpm -s ci:gate FE-GATE-013"])
|
||||
|
||||
def test_parts_passes_each_command_its_arguments_as_ci_gate_does(self) -> None:
|
||||
# run-ci-gate.ts runs `pnpm <script> ...args`. Without the args FE-GATE-009's
|
||||
# `review:a11y-manual -- --format-only` checked the release evidence instead and failed.
|
||||
contract = gates()
|
||||
commands = {c["id"]: c for c in contract["commands"]}
|
||||
with_args = [g for g in contract["gates"]
|
||||
if any(commands[c].get("args") for c in g["commandIds"])]
|
||||
self.assertTrue(with_args, "the contract has no command with arguments to check")
|
||||
for gate in with_args:
|
||||
with self.subTest(gate=gate["id"]):
|
||||
result = sh([str(VERIFY), "parts", gate["id"], "--dry-run"], cwd=REPO)
|
||||
expected = []
|
||||
prefix = ["scripts/run-in-system-container.sh"] if gate.get("hostEnvironment") else []
|
||||
for command_id in gate["commandIds"]:
|
||||
command = commands[command_id]
|
||||
words = [*prefix, "corepack", "pnpm", "-s", command["script"], *command.get("args", [])]
|
||||
expected.append(" ".join(words))
|
||||
self.assertEqual([line.split(": ", 1)[1] for line in result.stdout.splitlines()], expected)
|
||||
|
||||
def test_parts_passes_a_negative_fixture_only_with_its_registered_diagnostic(self) -> None:
|
||||
# run-ci-gate.ts passes an expect=fail command only when it exits with its code and prints its
|
||||
# diagnostic. parts saw the exit code alone, so a checker broken into an unrelated exit 1 (a
|
||||
# TypeError) still counted as its negative fixture passing.
|
||||
contract = gates()
|
||||
commands = {c["id"]: c for c in contract["commands"]}
|
||||
gate = next(g for g in contract["gates"] if g["id"] == "FE-GATE-029")
|
||||
negatives = [commands[c] for c in gate["commandIds"] if commands[c].get("expect") == "fail"]
|
||||
self.assertTrue(any(c.get("expectedDiagnosticId") for c in negatives))
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
fake = Path(tmp) / "corepack"
|
||||
# Answers `corepack pnpm -s <script> ...args` as the contract registers that command:
|
||||
# pass commands exit 0, negative fixtures exit with their code and print DIAGNOSTIC_MODE.
|
||||
fake.write_text(f"""#!/usr/bin/env python3
|
||||
import json, os, sys
|
||||
script, args = sys.argv[3], sys.argv[4:]
|
||||
for command in json.load(open({str(REPO / "config/ci/gates.json")!r}))["commands"]:
|
||||
if command["script"] == script and command.get("args", []) == args:
|
||||
break
|
||||
else:
|
||||
sys.exit(97)
|
||||
if command.get("expect") != "fail":
|
||||
sys.exit(0)
|
||||
if os.environ["DIAGNOSTIC_MODE"] == "registered":
|
||||
print("checker refused the fixture:", command.get("expectedDiagnosticId", ""))
|
||||
else:
|
||||
print("TypeError: Cannot read properties of undefined")
|
||||
sys.exit(command.get("expectedExitCode", 1))
|
||||
""", encoding="utf-8")
|
||||
fake.chmod(0o755)
|
||||
env = {"PATH": f"{tmp}:{os.environ['PATH']}"}
|
||||
wrong = sh([str(VERIFY), "parts", "FE-GATE-029", "--on", "here"], cwd=REPO, check=False,
|
||||
env={**env, "DIAGNOSTIC_MODE": "unrelated"})
|
||||
self.assertEqual(wrong.returncode, 1, wrong.stdout + wrong.stderr)
|
||||
self.assertIn("diagnostic", wrong.stderr)
|
||||
right = sh([str(VERIFY), "parts", "FE-GATE-029", "--on", "here"], cwd=REPO, check=False,
|
||||
env={**env, "DIAGNOSTIC_MODE": "registered"})
|
||||
self.assertEqual(right.returncode, 0, right.stdout + right.stderr)
|
||||
|
||||
def test_arguments_after_the_separator_go_to_the_one_script_or_command_as_given(self) -> None:
|
||||
result = sh([str(VERIFY), "script", "test:sample-removal", "--dry-run", "--", "--feature=invoice-feature"],
|
||||
cwd=REPO)
|
||||
|
||||
@@ -131,7 +131,20 @@ if (liveTarget?.passed && !slotEmpty) {
|
||||
const fixture = await readDocument(
|
||||
"tests/fixtures/hosting/response-headers.json",
|
||||
);
|
||||
responses = responseHeaders(fixture.responses);
|
||||
// 0929/13-04. The fixture host answers with the declared security headers
|
||||
// wherever the fixture names none, so a policy change is one file. A value
|
||||
// the fixture names is compared like a host's answer.
|
||||
const declaredAnswer = Object.fromEntries(
|
||||
Object.entries(securityHeaders).map(([header, value]) => [header.toLowerCase(), value]),
|
||||
);
|
||||
responses = Object.fromEntries(
|
||||
Object.entries(responseHeaders(fixture.responses)).map(([surface, headers]) => [
|
||||
surface,
|
||||
recordValue(cacheSurfaces[surface]).securityHeaders === true
|
||||
? { ...declaredAnswer, ...headers }
|
||||
: headers,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
const results: ProbeResult[] = [...probeResults];
|
||||
|
||||
+61
-13
@@ -22,7 +22,8 @@
|
||||
# 환경 변수: VERIFY_HOST(desktop 단계의 --on 기본값, 기본 desktop), VERIFY_REMOTE_REPO(원격 checkout, 기본
|
||||
# workspace/<repo 이름>, 홈 기준), VERIFY_BASE_REF(기본 origin/main), VERIFY_LOCK(기본 /tmp/claude-gates/heavy.lock),
|
||||
# VERIFY_LOG_ROOT(원격 로그 폴더, 기본 /tmp/claude-gates), VERIFY_SSH(기본 ssh), VERIFY_NODE_BIN(원격 node 폴더,
|
||||
# 기본 ~/.nvm/versions/node/v<.nvmrc>/bin), VERIFY_INSTALL(0이면 원격 의존성 설치를 건너뛴다).
|
||||
# 기본 ~/.nvm/versions/node/v<.nvmrc>/bin), VERIFY_INSTALL(0이면 원격 의존성 설치를 건너뛴다),
|
||||
# VERIFY_HOST_ENVIRONMENT(off면 hostEnvironment 게이트도 시스템 컨테이너 없이 이 호스트에서 돈다).
|
||||
# 종료 코드: 0 통과, 1 실패, 2 사용법, 4 원격 준비 실패.
|
||||
set -euo pipefail
|
||||
|
||||
@@ -34,7 +35,7 @@ DRY_RUN=0
|
||||
APPLY_BACK=0
|
||||
|
||||
usage() {
|
||||
sed -n '2,26p' "$0" | sed 's/^# \{0,1\}//' >&2
|
||||
sed -n '2,27p' "$0" | sed 's/^# \{0,1\}//' >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
@@ -55,6 +56,11 @@ elif kind == "stage":
|
||||
elif kind == "gate":
|
||||
if not any(gate["id"] == names[0] for gate in contract["gates"]):
|
||||
sys.exit(1)
|
||||
elif kind == "host":
|
||||
gate = next((gate for gate in contract["gates"] if gate["id"] == names[0]), None)
|
||||
if gate is None:
|
||||
sys.exit(1)
|
||||
print(gate.get("hostEnvironment", ""))
|
||||
elif kind == "scripts":
|
||||
gate = next((gate for gate in contract["gates"] if gate["id"] == names[0]), None)
|
||||
if gate is None:
|
||||
@@ -62,7 +68,10 @@ elif kind == "scripts":
|
||||
commands = {command["id"]: command for command in contract["commands"]}
|
||||
for command_id in gate["commandIds"]:
|
||||
command = commands[command_id]
|
||||
print(f'{command["script"]}\t{command.get("expect", "pass")}\t{command.get("expectedExitCode", "")}')
|
||||
# \x1f between fields keeps an empty exit code a field; \x1e between the command's args.
|
||||
args = "\x1e".join(command.get("args", []))
|
||||
print(f'{command["script"]}\x1f{command.get("expect", "pass")}\x1f{command.get("expectedExitCode", "")}'
|
||||
f'\x1f{args}\x1f{command.get("expectedDiagnosticId", "")}')
|
||||
PY
|
||||
}
|
||||
|
||||
@@ -111,33 +120,72 @@ step() {
|
||||
start=$(date +%s)
|
||||
log=${VERIFY_STEP_LOGS:+$VERIFY_STEP_LOGS/$(printf '%s' "$name" | tr ' /:' '___').log}
|
||||
set +e
|
||||
if [ -n "$log" ]; then "$@" > "$log" 2>&1; else "$@"; fi
|
||||
rc=$?
|
||||
# STEP_CAPTURE: also keep the output in that file (run_parts reads a negative fixture's diagnostic).
|
||||
if [ -n "$log" ]; then
|
||||
"$@" > "$log" 2>&1
|
||||
rc=$?
|
||||
[ -z "${STEP_CAPTURE:-}" ] || cp "$log" "$STEP_CAPTURE"
|
||||
elif [ -n "${STEP_CAPTURE:-}" ]; then
|
||||
"$@" 2>&1 | tee "$STEP_CAPTURE"
|
||||
rc=${PIPESTATUS[0]}
|
||||
else
|
||||
"$@"
|
||||
rc=$?
|
||||
fi
|
||||
set -e
|
||||
echo "$name rc=$rc $(( $(date +%s) - start ))s" | tee -a "${VERIFY_SUMMARY:-/dev/null}"
|
||||
return "$rc"
|
||||
}
|
||||
|
||||
# 계약이 hostEnvironment를 정한 게이트(FE-GATE-013)는 workflow와 같이 그 환경에서 돈다.
|
||||
# VERIFY_HOST_ENVIRONMENT=off면 이 호스트에서 바로 돈다(컨테이너를 띄울 수 없는 호스트, gates.md 3절).
|
||||
host_prefix() {
|
||||
[ "${VERIFY_HOST_ENVIRONMENT:-on}" != off ] || return 0
|
||||
case "$(gates_json host "$1")" in
|
||||
system-container) echo scripts/run-in-system-container.sh ;;
|
||||
esac
|
||||
}
|
||||
|
||||
run_gates() {
|
||||
local failed=0 gate
|
||||
local failed=0 gate prefix
|
||||
[ "$DRY_RUN" = 1 ] || ci_env
|
||||
for gate in "$@"; do
|
||||
gates_json gate "$gate" || { echo "verify: config/ci/gates.json에 없는 게이트: $gate" >&2; return 2; }
|
||||
step "$gate" corepack pnpm -s ci:gate "$gate" || failed=1
|
||||
prefix=$(host_prefix "$gate")
|
||||
# shellcheck disable=SC2086 # 접두어는 공백 없는 경로 하나이거나 비어 있다
|
||||
step "$gate" $prefix corepack pnpm -s ci:gate "$gate" || failed=1
|
||||
done
|
||||
return "$failed"
|
||||
}
|
||||
|
||||
run_parts() {
|
||||
local gate=$1 failed=0 script expect code rc
|
||||
local gate=$1 failed=0 script expect code argtext diagnostic rc args prefix capture
|
||||
[ "$DRY_RUN" = 1 ] || ci_env
|
||||
gates_json scripts "$gate" > /dev/null || { echo "verify: config/ci/gates.json에 없는 게이트: $gate" >&2; return 2; }
|
||||
while IFS=$'\t' read -r script expect code; do
|
||||
prefix=$(host_prefix "$gate")
|
||||
while IFS=$'\x1f' read -r script expect code argtext diagnostic; do
|
||||
rc=0
|
||||
step "$gate $script" corepack pnpm -s "$script" || rc=$?
|
||||
# expect=fail인 명령(음성 fixture)은 정해진 종료 코드로 실패해야 통과다.
|
||||
args=()
|
||||
# The command's args, as run-ci-gate.ts passes them (`pnpm <script> ...args`).
|
||||
[ -z "$argtext" ] || IFS=$'\x1e' read -r -a args <<< "$argtext"
|
||||
capture=""
|
||||
if [ "$expect" = fail ] && [ "$DRY_RUN" != 1 ]; then
|
||||
capture=$(mktemp)
|
||||
TMP_FILES+=("$capture")
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
STEP_CAPTURE=$capture step "$gate $script" $prefix corepack pnpm -s "$script" ${args[@]+"${args[@]}"} || rc=$?
|
||||
# expect=fail인 명령(음성 fixture)은 run-ci-gate.ts처럼 정해진 종료 코드로 실패하고 정해진 진단 문구를
|
||||
# 출력해야 통과다. 종료 코드만 보면 엉뚱한 원인의 exit 1(깨진 검사기)도 통과로 센다.
|
||||
if [ "$expect" = fail ]; then
|
||||
[ "$DRY_RUN" = 1 ] || [ "$rc" = "${code:-1}" ] || failed=1
|
||||
[ "$DRY_RUN" = 1 ] && continue
|
||||
if [ "$rc" != "${code:-1}" ]; then
|
||||
echo "verify: $gate $script: expected exit ${code:-1}, got $rc" >&2
|
||||
failed=1
|
||||
elif [ -n "$diagnostic" ] && ! grep -qF -- "$diagnostic" "$capture"; then
|
||||
echo "verify: $gate $script: exit $rc without the registered diagnostic: $diagnostic" >&2
|
||||
failed=1
|
||||
fi
|
||||
elif [ "$rc" != 0 ]; then
|
||||
failed=1
|
||||
fi
|
||||
@@ -266,7 +314,7 @@ if [ $install = 1 ]; then
|
||||
|| CI=true corepack pnpm install --frozen-lockfile >> "\$logs/install.log" 2>&1 \
|
||||
|| { echo "의존성 설치 실패: \$logs/install.log" >&2; exit 4; }
|
||||
fi
|
||||
export VERIFY_SUMMARY="\$logs/summary.txt" VERIFY_STEP_LOGS="\$logs" VERIFY_REF="$ref"
|
||||
export VERIFY_SUMMARY="\$logs/summary.txt" VERIFY_STEP_LOGS="\$logs" VERIFY_REF="$ref" VERIFY_HOST_ENVIRONMENT="${VERIFY_HOST_ENVIRONMENT:-on}"
|
||||
flock $lock ./scripts/verify.sh $args 2>&1 | tee "\$logs/run.log"
|
||||
rc=\${PIPESTATUS[0]}
|
||||
git status --porcelain > "\$logs/status-after.txt"
|
||||
|
||||
Reference in New Issue
Block a user