Merge remote-tracking branch 'origin/main' into fix/r9-living-docs-sync
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Canceled after 0s
frontend-quality-gates / merge / static checks (pull_request) Canceled after 0s
frontend-quality-gates / merge / tests (pull_request) Canceled after 0s
frontend-quality-gates / merge / browser tests (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Canceled after 0s
frontend-quality-gates / external-vulnerability-provider (pull_request) Canceled after 0s
frontend-quality-gates / external-provenance-provider (pull_request) Canceled after 0s
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Canceled after 0s
frontend-quality-gates / deploy-promoted-release (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Canceled after 0s
frontend-quality-gates / main / self-tests and removal drills (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Canceled after 0s
frontend-quality-gates / merge / static checks (pull_request) Canceled after 0s
frontend-quality-gates / merge / tests (pull_request) Canceled after 0s
frontend-quality-gates / merge / browser tests (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Canceled after 0s
frontend-quality-gates / external-vulnerability-provider (pull_request) Canceled after 0s
frontend-quality-gates / external-provenance-provider (pull_request) Canceled after 0s
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Canceled after 0s
frontend-quality-gates / deploy-promoted-release (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Canceled after 0s
frontend-quality-gates / main / self-tests and removal drills (pull_request) Canceled after 0s
# Conflicts: # AGENTS.md # docs/work/reference/decisions.md
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);
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
@@ -467,7 +486,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 +764,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,8 +856,11 @@ 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"],
|
||||
};
|
||||
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 +1015,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(" -> ")}`);
|
||||
|
||||
@@ -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");
|
||||
@@ -254,6 +274,23 @@ function renderHostRequirements(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
job: CiWorkflowJob,
|
||||
step: CiWorkflowStep,
|
||||
@@ -281,6 +318,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 +350,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 +580,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)) {
|
||||
|
||||
@@ -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,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}`;
|
||||
});
|
||||
}
|
||||
@@ -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}`,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
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"
|
||||
@@ -31,6 +31,7 @@ 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";
|
||||
|
||||
/**
|
||||
@@ -476,8 +477,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", [
|
||||
|
||||
@@ -45,12 +45,51 @@ 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_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)
|
||||
|
||||
+33
-9
@@ -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,9 @@ 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", "")}\x1f{args}')
|
||||
PY
|
||||
}
|
||||
|
||||
@@ -118,23 +126,39 @@ step() {
|
||||
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 rc args prefix
|
||||
[ "$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; do
|
||||
rc=0
|
||||
step "$gate $script" corepack pnpm -s "$script" || rc=$?
|
||||
args=()
|
||||
# The command's args, as run-ci-gate.ts passes them (`pnpm <script> ...args`).
|
||||
[ -z "$argtext" ] || IFS=$'\x1e' read -r -a args <<< "$argtext"
|
||||
# shellcheck disable=SC2086
|
||||
step "$gate $script" $prefix corepack pnpm -s "$script" ${args[@]+"${args[@]}"} || rc=$?
|
||||
# expect=fail인 명령(음성 fixture)은 정해진 종료 코드로 실패해야 통과다.
|
||||
if [ "$expect" = fail ]; then
|
||||
[ "$DRY_RUN" = 1 ] || [ "$rc" = "${code:-1}" ] || failed=1
|
||||
@@ -266,7 +290,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