Merge lane/J: test system (10-02, 10-04~10-07, 11-04~11-08, F-2, F-4, F-12, 00-03)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,20 @@ import path from "node:path";
|
||||
* the linked directories. It is rewritten to name the fixture root instead:
|
||||
* the packages are the repository's own, already validated.
|
||||
*/
|
||||
/**
|
||||
* F-4. The environment for every `pnpm` a linked fixture runs. pnpm verifies
|
||||
* the install before a script and, when the fixture's copied state disagrees
|
||||
* with its own settings (for example `CI=true` against an install made
|
||||
* without it), installs. `.pnpm` and `.bin` are links into the repository's
|
||||
* node_modules, so that install rewrote the shared `.pnpm/lock.yaml` and bin
|
||||
* shims. A fixture started through `pnpm <script>` inherits this setting from
|
||||
* pnpm; one started directly (`node scripts/run-vitest.ts run <file>`) did not.
|
||||
* The fixture uses the repository's packages as they are; it never installs.
|
||||
*/
|
||||
export const FIXTURE_PNPM_ENVIRONMENT = Object.freeze({
|
||||
pnpm_config_verify_deps_before_run: "false",
|
||||
});
|
||||
|
||||
export async function linkFixtureNodeModules(
|
||||
fixtureRoot: string,
|
||||
sourceRoot: string = process.cwd(),
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* 11-07. The pieces of the lab performance gate (`scripts/test-performance.ts`)
|
||||
* that decide what is measured and whether the numbers can be trusted.
|
||||
*/
|
||||
|
||||
export const DEFAULT_LAB_PORT = 4173;
|
||||
export const DEFAULT_LAB_RUNS = 5;
|
||||
|
||||
/**
|
||||
* `vite preview` arguments. Without `--strictPort` vite moved to the next free
|
||||
* port when the requested one was taken, and the gate measured whatever server
|
||||
* already listened there.
|
||||
*/
|
||||
export function previewArguments(port: number): readonly string[] {
|
||||
return [
|
||||
"pnpm",
|
||||
"preview",
|
||||
"--host",
|
||||
"127.0.0.1",
|
||||
"--port",
|
||||
String(port),
|
||||
"--strictPort",
|
||||
];
|
||||
}
|
||||
|
||||
export type SampleSummary = Readonly<{
|
||||
median: number;
|
||||
min: number;
|
||||
max: number;
|
||||
samples: readonly number[];
|
||||
}>;
|
||||
|
||||
export function summarizeSamples(samples: readonly number[]): SampleSummary {
|
||||
if (samples.length === 0) throw new RangeError("no samples to summarize");
|
||||
const sorted = [...samples].sort((left, right) => left - right);
|
||||
const middle = Math.floor(sorted.length / 2);
|
||||
const median =
|
||||
sorted.length % 2 === 1
|
||||
? sorted[middle]!
|
||||
: (sorted[middle - 1]! + sorted[middle]!) / 2;
|
||||
return Object.freeze({
|
||||
median,
|
||||
min: sorted[0]!,
|
||||
max: sorted.at(-1)!,
|
||||
samples: Object.freeze([...samples]),
|
||||
});
|
||||
}
|
||||
|
||||
/** Fails when anything already answers where the preview server will listen. */
|
||||
export async function assertPortUnused(
|
||||
baseUrl: string,
|
||||
fetchImpl: typeof fetch = fetch,
|
||||
): Promise<void> {
|
||||
let answered = false;
|
||||
try {
|
||||
await fetchImpl(baseUrl, { signal: AbortSignal.timeout(1_000) });
|
||||
answered = true;
|
||||
} catch {
|
||||
// Nothing is listening: the expected state.
|
||||
}
|
||||
if (answered) {
|
||||
throw new Error(
|
||||
`${baseUrl} already answers before the preview server starts; another server holds the port.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the release the server actually serves with the local build that
|
||||
* is being measured, so the numbers belong to that build.
|
||||
*/
|
||||
export async function assertServedRelease(
|
||||
baseUrl: string,
|
||||
expected: Readonly<{ buildId: string; releaseId: string }>,
|
||||
fetchImpl: typeof fetch = fetch,
|
||||
): Promise<void> {
|
||||
const response = await fetchImpl(new URL("/release-manifest.json", baseUrl), {
|
||||
cache: "no-store",
|
||||
});
|
||||
const served = response.ok
|
||||
? ((await response.json()) as Partial<Record<"buildId" | "releaseId", unknown>>)
|
||||
: {};
|
||||
if (served.buildId !== expected.buildId || served.releaseId !== expected.releaseId) {
|
||||
throw new Error(
|
||||
`${baseUrl} serves build ${String(served.buildId)}/${String(served.releaseId)}, ` +
|
||||
`not the measured ${expected.buildId}/${expected.releaseId}.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,10 @@ import {
|
||||
loadCiGateContract,
|
||||
parseCiGateContract,
|
||||
} from "../contracts/ci-gates.ts";
|
||||
import { linkFixtureNodeModules } from "./fixture-node-modules.ts";
|
||||
import {
|
||||
FIXTURE_PNPM_ENVIRONMENT,
|
||||
linkFixtureNodeModules,
|
||||
} from "./fixture-node-modules.ts";
|
||||
import { generateCiWorkflow } from "../generate-ci-workflow.ts";
|
||||
import { updateCiContractBaseline } from "../update-ci-contract-baseline.ts";
|
||||
|
||||
@@ -189,7 +192,7 @@ export function runRemovalFixtureCheck(
|
||||
const status = spawnSync(process.execPath, [pnpmCli, script, ...extra], {
|
||||
cwd: root,
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT },
|
||||
}).status;
|
||||
return status === 0
|
||||
? { name, passed: true }
|
||||
@@ -243,7 +246,7 @@ export function runRemovalFixturePnpm(
|
||||
return spawnSync(process.execPath, [pnpmCli, script, ...extra], {
|
||||
cwd: root,
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, ...env },
|
||||
env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT, ...env },
|
||||
}).status === 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user