chore(review): 1106 테스트 기반 조치 브랜치를 합친다

This commit is contained in:
DongHyeonka
2026-11-06 07:02:34 +09:00
19 changed files with 636 additions and 278 deletions
@@ -396,7 +396,7 @@ mutation이 400·409·422로 실패하면 프론트는 그 요청이 적용됐
- 위 표에서 "쓰기 뒤 가능"인 플랫폼 code(`BAD_PARAMETER`, `MAPPING_FAILED`, `DB_*` 8개,
`LOCK_ACQUISITION_TIMEOUT`, fileserver code)도 적을 수 없다(1105/03-01). 계약 조립이
거절하고 실행기도 무시한다. 목록은 `src/contracts/external-contract-runtime.ts`의
`PLATFORM_CODES_POSSIBLY_AFTER_WRITE`이고, `tests/unit/backend-contract-pin.test.ts`가
`PLATFORM_CODES_POSSIBLY_AFTER_WRITE`이고, `tests/unit/backend-contract-pin-document.test.ts`가
이 표의 "쓰기 뒤 가능" 행과 대조한다. 참조 도메인 code와 web-advanced patch code는
엔드포인트가 단계를 정하므로 그 엔드포인트를 확인한 기능 작성자가 적을 수 있다. 이 표에
"쓰기 뒤 가능" 플랫폼 code를 더하면 그 목록도 같은 변경에서 고친다.
@@ -1026,7 +1026,7 @@ TEST_RUN_ID=a playwright test
| 변수 | 누가 읽나 | 없을 때 |
|---|---|---|
| `TEST_RUN_ID` | 다섯 Playwright 설정, `tests/e2e/preload-use.spec.ts` | `dist`, `artifacts/tests/<이름>/` |
| `RUN_OUTPUT_ROOT` | 빌드 단계 전부(`scripts/build-frontend.ts`가 부르는 것), `vite.config.ts`. 설정이 web server에만 넘긴다 | `.` |
| `RUN_OUTPUT_ROOT` | 빌드 단계 전부(`scripts/build-frontend.ts`가 부르는 것), `vite.config.ts`. 설정이 web server에만 넘긴다. 빌드 뒤 검사(`scripts/generate-supply-chain.ts`, `scripts/check-bundle.ts`)는 `.`이 아니면 멈춘다 | `.` |
| `TEST_E2E_PORT`, `TEST_VISUAL_PORT`, `TEST_CAPABILITIES_PORT`, `TEST_STORYBOOK_PORT`, `TEST_DEV_PORT` | 각 설정 | 빈 포트 |
- run ID는 글자·숫자·`.`·`_`·`-` 64자 이하이고 글자나 숫자로 시작한다.
@@ -1035,6 +1035,9 @@ TEST_RUN_ID=a playwright test
- `RUN_OUTPUT_ROOT`는 직접 export하지 않는다. 설정이 run ID에서 만든다. 빌드
코드는 `TEST_RUN_ID`를 읽지 않는다. e2e가 저장소 복사본을 빌드할 때 그
빌드는 복사본 자기 `dist`에 써야 하기 때문이다.
- 빌드 뒤 검사는 checkout의 `dist`와 `artifacts/`만 읽는다. 그래서
`RUN_OUTPUT_ROOT`가 셸에 있으면 `check:bundle`은 변수 이름을 적고 실패한다.
빌드는 `.tmp/` 아래에 쓰고 검사는 이전 빌드를 재서 통과했기 때문이다(1106/12-02).
- 규칙은 `scripts/lib/run-isolation.ts` 한 곳에 있다.
두 e2e 실행을 동시에 돌리는 예:
+11
View File
@@ -9,6 +9,7 @@ import {
bundlePerformanceArtifactSchema,
} from "./contracts/release-artifacts.ts";
import { classifyViteJavascript } from "./lib/classify-vite-bundle.ts";
import { checkoutBuildReadFailure } from "./lib/run-isolation.ts";
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
type ViteManifest = Record<
@@ -21,6 +22,16 @@ type BundleBudgets = {
lazyChunkGzipBytes: number;
};
// 1106/12-02. This reads dist/.vite/manifest.json and the inventory
// scripts/generate-supply-chain.ts made of dist. Under RUN_OUTPUT_ROOT the
// build wrote elsewhere, and this passed a build over budget on the earlier
// one the checkout still held.
const outputRootFailure = checkoutBuildReadFailure("scripts/check-bundle.ts");
if (outputRootFailure !== undefined) {
process.stderr.write(`${outputRootFailure}\n`);
process.exit(1);
}
const report = bundleOutputInventoryArtifactSchema.parse(
JSON.parse(await readFile("artifacts/performance/bundle.json", "utf8")) as unknown,
);
+10
View File
@@ -39,8 +39,18 @@ import {
parseRepositoryFileInventoryPolicy,
} from "./lib/repository-file-inventory.ts";
import { collectDistOutputs, distSha256 } from "./lib/release-candidate.ts";
import { checkoutBuildReadFailure } from "./lib/run-isolation.ts";
import { deterministicSupplyChainGeneratedAt } from "./lib/supply-chain-time.ts";
// 1106/12-02. This reads artifacts/release/build-manifest.json and dist where
// the checkout keeps them. Under RUN_OUTPUT_ROOT the build wrote elsewhere,
// and this recorded the earlier build the checkout still held.
const outputRootFailure = checkoutBuildReadFailure("scripts/generate-supply-chain.ts");
if (outputRootFailure !== undefined) {
process.stderr.write(`${outputRootFailure}\n`);
process.exit(1);
}
type Document = Record<string, unknown>;
function isRecord(value: unknown): value is Document {
+9 -3
View File
@@ -66,13 +66,19 @@ export const REMOVAL_FIXTURE_DOCUMENT_TARGETS = Object.freeze([
* CHANGELOG.md, whatever the removal did. prepareRemovalFixture deletes them
* from such a fixture, and the repository's own test:unit keeps running them.
* This is the only list; the sample drill used to keep the exclusion to itself.
*
* 1106/12-01. The unit is a file, so every test in a listed file reads the
* documents. A test that reads none goes in another file: listing a file for
* one document test took the file's other tests out of those drills too.
*/
export const REMOVAL_FIXTURE_DOCUMENT_TESTS = Object.freeze([
"tests/unit/changelog-review-ids.test.ts",
"tests/unit/documentation-readiness.test.ts",
// 1105/03-01. Reads the 6.1 table of the frontend contract document.
"tests/unit/backend-contract-pin.test.ts",
// 1105/16-01. Reads the 03 manual and docs/architecture/starter-experience.md.
// 1105/03-01. Reads the 6.1 table of the frontend contract document; the
// pin checks that read none are in backend-contract-pin.test.ts.
"tests/unit/backend-contract-pin-document.test.ts",
// 1105/16-01. Reads the 03 manual and docs/architecture/starter-experience.md;
// the generator's list is checked in feature-tracked-file-rewrites.test.ts.
"tests/unit/feature-tracked-files.test.ts",
// 1105/14-01
"tests/unit/template-feature-removal-documents.test.ts",
+28
View File
@@ -82,6 +82,34 @@ export function runOutputPath(
return path.posix.join(runOutputRoot(environment), relativePath);
}
/**
* 1106/12-02. Why `step`, which reads the build where the checkout keeps it
* (`dist/`, the build manifest and the evidence under `artifacts/`), must not
* run in this environment; `undefined` when it may. With RUN_OUTPUT_ROOT set
* the build writes under that folder, so such a step would judge whatever
* build the checkout still holds: check:bundle passed an over-budget build
* that way, on the earlier one. `.` is the checkout itself, which is what a
* Playwright config hands its web server without a run ID.
*/
export function checkoutBuildReadFailure(
step: string,
environment: Environment = process.env,
): string | undefined {
let root: string;
try {
root = runOutputRoot(environment);
} catch (error) {
return `${step}: ${error instanceof Error ? error.message : String(error)}`;
}
if (root === ".") return undefined;
return (
`${step} reads the build at this checkout's paths (dist/, artifacts/), but ` +
`${RUN_OUTPUT_ROOT_VARIABLE}=${root} makes the build write under ${root}/, so it ` +
`would judge an earlier build. Unset ${RUN_OUTPUT_ROOT_VARIABLE}, build again and ` +
`run ${step} again.`
);
}
/**
* The port variable of each Playwright config's web server. Unset, the config
* picks a free port; set, it uses that one (to pin a port while debugging).
@@ -131,9 +131,16 @@ try {
}
await writeFile(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`);
await rm(path.join(fixtureRoot, "playwright.capabilities.config.ts"), {
force: true,
});
// 1106/10-01. The capabilities config goes with this runtime, and so do its
// run-isolation checks, by name: the template's test:unit runs them, this
// copy has nothing for them to check. Without `force`, so a renamed file
// stops the drill here instead of failing its typecheck later.
for (const capabilityConfigFile of [
"playwright.capabilities.config.ts",
"tests/unit/playwright-capabilities-run-isolation.test.ts",
]) {
await rm(path.join(fixtureRoot, capabilityConfigFile));
}
await rm(
path.join(fixtureRoot, "scripts/check-browser-file-storage-boundaries.ts"),
{ force: true },
+2 -1
View File
@@ -633,7 +633,8 @@ const IDEMPOTENCY_CODE = /^IDEMPOTEN(?:T|CY)_/;
* fileserver module. Their stage is the template's knowledge, not the
* feature's, so no operation may declare them as refused before its write.
* Business codes stay the feature author's to declare.
* tests/unit/backend-contract-pin.test.ts holds this list to the 6.1 table.
* tests/unit/backend-contract-pin-document.test.ts holds this list to the 6.1
* table.
*/
export const PLATFORM_CODES_POSSIBLY_AFTER_WRITE: readonly string[] =
Object.freeze([
+197
View File
@@ -0,0 +1,197 @@
import { createServer, type Server } from "node:net";
import path from "node:path";
import type { PlaywrightTestConfig } from "@playwright/test";
import { describe, expect, it, vi } from "vitest";
/**
* 1105/12-04. The run-isolation checks every Playwright config shares, for
* tests/unit/playwright-run-isolation.test.ts (the four configs every project
* has) and tests/unit/playwright-capabilities-run-isolation.test.ts (the
* capabilities config, which goes with the browser file/storage runtime).
*
* 1106/10-01. Each file imports its configs by name and passes them here, so
* no check depends on which config files a checkout happens to have.
*/
export type ConfigName = "e2e" | "visual" | "capabilities" | "storybook" | "dev";
export type ConfigLoaders = Readonly<
Partial<Record<ConfigName, () => Promise<{ default: PlaywrightTestConfig }>>>
>;
const PORT_VARIABLES: Readonly<Record<ConfigName, string>> = {
e2e: "TEST_E2E_PORT",
visual: "TEST_VISUAL_PORT",
capabilities: "TEST_CAPABILITIES_PORT",
storybook: "TEST_STORYBOOK_PORT",
dev: "TEST_DEV_PORT",
};
const RUN_VARIABLES = ["TEST_RUN_ID", "RUN_OUTPUT_ROOT", ...Object.values(PORT_VARIABLES)];
const held: Server[] = [];
/** For afterEach: forgets the loaded configs and frees the ports `hold` took. */
export async function releaseRuns(): Promise<void> {
vi.resetModules();
await Promise.all(
held.splice(0).map((server) => new Promise<void>((resolve) => server.close(() => resolve()))),
);
}
type ConfigProcess = Readonly<{
config: PlaywrightTestConfig;
after: Readonly<Record<string, string | undefined>>;
}>;
export type ConfigRuns = Readonly<{
/** The config as one process sees it, and what it left in that environment. */
loadProcess(
name: ConfigName,
environment?: Readonly<Record<string, string>>,
): Promise<ConfigProcess>;
load(name: ConfigName, environment?: Readonly<Record<string, string>>): Promise<PlaywrightTestConfig>;
}>;
/** Each load evaluates the config again with the environment of one process. */
export function configRuns(loaders: ConfigLoaders): ConfigRuns {
async function loadProcess(
name: ConfigName,
environment: Readonly<Record<string, string>> = {},
): Promise<ConfigProcess> {
const loader = loaders[name];
if (loader === undefined) throw new TypeError(`no loader for the ${name} config`);
const saved = RUN_VARIABLES.map((variable) => [variable, process.env[variable]] as const);
for (const variable of RUN_VARIABLES) delete process.env[variable];
Object.assign(process.env, environment);
vi.resetModules();
try {
const config = (await loader()).default;
return {
config,
after: Object.fromEntries(RUN_VARIABLES.map((variable) => [variable, process.env[variable]])),
};
} finally {
for (const [variable, value] of saved) {
if (value === undefined) delete process.env[variable];
else process.env[variable] = value;
}
}
}
return {
loadProcess,
load: async (name, environment = {}) => (await loadProcess(name, environment)).config,
};
}
export function portOf(config: PlaywrightTestConfig): number {
return Number(new URL(String(config.use?.baseURL)).port);
}
/** Listens on `port` the way the first run's server does. */
export async function hold(port: number): Promise<void> {
const server = createServer();
held.push(server);
await new Promise<void>((resolve, reject) => {
server.once("error", reject);
server.listen(port, "127.0.0.1", () => resolve());
});
}
function reporterOption(config: PlaywrightTestConfig, reporter: string, option: string): string {
const reporters: readonly unknown[] = Array.isArray(config.reporter) ? config.reporter : [];
const entry = reporters.find(
(candidate) => Array.isArray(candidate) && candidate[0] === reporter,
) as readonly [string, Record<string, unknown>] | undefined;
return String(entry?.[1][option]);
}
function outputs(config: PlaywrightTestConfig) {
return {
results: path.resolve(String(config.outputDir)),
report: path.resolve(reporterOption(config, "html", "outputFolder")),
junit: path.resolve(reporterOption(config, "junit", "outputFile")),
};
}
export function webServer(config: PlaywrightTestConfig) {
const server = config.webServer;
if (!server || Array.isArray(server)) throw new TypeError("expected one web server");
return server;
}
/** Each config's results, report and JUnit file, by its folder under artifacts/tests. */
export function describeResultFolders(
runs: ConfigRuns,
folders: readonly (readonly [ConfigName, string])[],
): void {
describe.each(folders)("the %s config", (name, folder) => {
const expected = (root: string) => ({
results: path.resolve(root, `artifacts/tests/${folder}/results`),
report: path.resolve(root, `artifacts/tests/${folder}/report`),
junit: path.resolve(root, `artifacts/tests/${folder}/results.xml`),
});
it("writes where the gates read without a run ID", async () => {
expect(outputs(await runs.load(name as ConfigName))).toEqual(expected("."));
});
it("gives each run ID its own results, report and JUnit file", async () => {
const a = outputs(await runs.load(name as ConfigName, { TEST_RUN_ID: "a" }));
const b = outputs(await runs.load(name as ConfigName, { TEST_RUN_ID: "b" }));
expect(a).toEqual(expected(".tmp/runs/a"));
expect(b).toEqual(expected(".tmp/runs/b"));
});
});
}
/** Inside "the build a run serves": the dev servers' Vite cache. */
export function itKeepsTheViteCacheInTheRun(runs: ConfigRuns, names: readonly ConfigName[]): void {
it.each(names)("keeps the dev server's Vite cache in the run's folder (%s)", async (name) => {
expect(webServer(await runs.load(name)).env?.["RUN_OUTPUT_ROOT"]).toBe(".");
expect(webServer(await runs.load(name, { TEST_RUN_ID: "a" })).env?.["RUN_OUTPUT_ROOT"]).toBe(
".tmp/runs/a",
);
});
}
export function describeServerPorts(runs: ConfigRuns, names: readonly ConfigName[]): void {
describe.each(names)("the %s server port", (name) => {
it("is a free port the runner hands to its workers", async () => {
const runner = await runs.loadProcess(name);
const port = portOf(runner.config);
const server = webServer(runner.config);
// Playwright evaluates the config again in each worker, which inherits
// the runner's environment: the port is there, so baseURL agrees.
expect(runner.after[PORT_VARIABLES[name]]).toBe(String(port));
expect(portOf(await runs.load(name, { [PORT_VARIABLES[name]]: String(port) }))).toBe(port);
expect(server.url).toBe(`http://127.0.0.1:${port}`);
expect(server.command).toMatch(new RegExp(` (?:--port )?${port}(?: |$)`, "u"));
expect(server.reuseExistingServer).toBe(false);
});
it("moves for a second run while the first run's server holds its port", async () => {
const first = portOf(await runs.load(name));
await hold(first);
expect(portOf(await runs.load(name))).not.toBe(first);
});
it("is the one its variable pins", async () => {
const pinned = await runs.load(name, { [PORT_VARIABLES[name]]: "40123" });
expect(portOf(pinned)).toBe(40123);
expect(webServer(pinned).url).toBe("http://127.0.0.1:40123");
});
});
}
/** Inside "vite servers": the configs whose server is vite. */
export function itExitsWhenItsPortIsTaken(runs: ConfigRuns, names: readonly ConfigName[]): void {
it.each(names)(
"exit instead of moving to the next port when theirs is taken (%s)",
async (name) => {
// Without --strictPort vite moved on, and Playwright, waiting on the
// configured URL, tested whatever already listened there.
expect(webServer(await runs.load(name)).command).toMatch(/ --port \d+ --strictPort(?: |$)/u);
},
);
}
@@ -0,0 +1,67 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { z } from "zod";
import { PLATFORM_CODES_POSSIBLY_AFTER_WRITE } from "../../src/contracts/external-contract-runtime.ts";
/**
* 1106/12-01. The one paired-backend pin check that reads a document. It has
* its own file because the removal drills that copy no documents leave whole
* files out (REMOVAL_FIXTURE_DOCUMENT_TESTS in scripts/lib/removal-fixture.ts):
* in tests/unit/backend-contract-pin.test.ts it took that file's fourteen
* checks of config and code out of those drills with it. The pin names the
* document; it is a repository document (`docs/`), which is why this file is
* on that list.
*/
const pin = z
.object({
frontend: z.object({ contractDocument: z.string().startsWith("docs/") }),
})
.parse(JSON.parse(readFileSync("config/contracts/backend-contract-pin.json", "utf8")));
/**
* 1105/03-01. The codes of the contract 6.1 table rows whose stage is "쓰기 뒤
* 가능" (possibly after the write), read from the document the pin names.
*/
function codesPossiblyAfterWrite(): ReadonlySet<string> {
const text = readFileSync(pin.frontend.contractDocument, "utf8");
const section = text.split("### 6.1 ")[1]?.split(/\n#{2,3} /u)[0] ?? "";
const codes = new Set<string>();
for (const line of section.split("\n")) {
const cells = line.split("|").map((cell) => cell.trim());
if (!line.startsWith("|") || cells[3] !== "쓰기 뒤 가능") continue;
for (const [, code = ""] of (cells[1] ?? "").matchAll(/`([A-Z0-9_]+)`/gu)) {
codes.add(code);
}
}
return codes;
}
/**
* Rows of that table whose stage the endpoint decides: the reference domain's
* codes and web-advanced's patch codes ("부르는 코드가 단계를 정한다"). A
* feature author who checked the endpoint may declare them.
*/
const FEATURE_DECIDED_CODES: readonly string[] = [
"WORKLOG_INVALID",
"POSTER_INVALID_STATE",
"POSTER_IMAGE_REQUIRED",
"WORKLOG_CONFLICT",
"POSTER_ALREADY_EXISTS",
"POSTER_IMAGE_ALREADY_PUBLISHED",
"PATCH_REJECTED",
"PATCH_TEST_FAILED",
];
describe("platform codes no operation may declare as refused before its write", () => {
it("are the 6.1 table's possibly-after-write codes outside the feature-decided rows", () => {
const table61 = codesPossiblyAfterWrite();
for (const code of FEATURE_DECIDED_CODES) {
expect(table61.has(code), code).toBe(true);
}
expect([...PLATFORM_CODES_POSSIBLY_AFTER_WRITE].sort()).toEqual(
[...table61].filter((code) => !FEATURE_DECIDED_CODES.includes(code)).sort(),
);
});
});
+4 -50
View File
@@ -13,7 +13,6 @@ import {
maybeAppliedAnswerRows,
refusedBeforeWriteRows,
} from "../../src/adapters/http/backend-envelope.ts";
import { PLATFORM_CODES_POSSIBLY_AFTER_WRITE } from "../../src/contracts/external-contract-runtime.ts";
/**
* 1103/12-06. The paired backend's contract is pinned in a file a machine
@@ -27,6 +26,10 @@ import { PLATFORM_CODES_POSSIBLY_AFTER_WRITE } from "../../src/contracts/externa
* copied word for word at the pin (`tables.backendExcerpt`), so a mistyped
* status or a row left out fails here without a backend checkout.
* `check:backend-contract-drift` holds that copy to the backend document.
*
* 1106/12-01. This file reads config and code only, so every removal drill
* runs it. The check of the contract 6.1 table reads a document and is in
* tests/unit/backend-contract-pin-document.test.ts.
*/
const COMMIT = /^[0-9a-f]{40}$/u;
@@ -252,52 +255,3 @@ describe("paired backend contract pin", () => {
}
});
});
/**
* 1105/03-01. The codes of the contract 6.1 table rows whose stage is "쓰기 뒤
* 가능" (possibly after the write), read from the document the pin names
* (docs/architecture/backend-api-and-server-state-contract.md). Because this
* file reads that document, the removal drills that copy no documents leave
* it out (REMOVAL_FIXTURE_DOCUMENT_TESTS in scripts/lib/removal-fixture.ts).
*/
function codesPossiblyAfterWrite(): ReadonlySet<string> {
const text = readFileSync(pin.frontend.contractDocument, "utf8");
const section = text.split("### 6.1 ")[1]?.split(/\n#{2,3} /u)[0] ?? "";
const codes = new Set<string>();
for (const line of section.split("\n")) {
const cells = line.split("|").map((cell) => cell.trim());
if (!line.startsWith("|") || cells[3] !== "쓰기 뒤 가능") continue;
for (const [, code = ""] of (cells[1] ?? "").matchAll(/`([A-Z0-9_]+)`/gu)) {
codes.add(code);
}
}
return codes;
}
/**
* Rows of that table whose stage the endpoint decides: the reference domain's
* codes and web-advanced's patch codes ("부르는 코드가 단계를 정한다"). A
* feature author who checked the endpoint may declare them.
*/
const FEATURE_DECIDED_CODES: readonly string[] = [
"WORKLOG_INVALID",
"POSTER_INVALID_STATE",
"POSTER_IMAGE_REQUIRED",
"WORKLOG_CONFLICT",
"POSTER_ALREADY_EXISTS",
"POSTER_IMAGE_ALREADY_PUBLISHED",
"PATCH_REJECTED",
"PATCH_TEST_FAILED",
];
describe("platform codes no operation may declare as refused before its write", () => {
it("are the 6.1 table's possibly-after-write codes outside the feature-decided rows", () => {
const table61 = codesPossiblyAfterWrite();
for (const code of FEATURE_DECIDED_CODES) {
expect(table61.has(code), code).toBe(true);
}
expect([...PLATFORM_CODES_POSSIBLY_AFTER_WRITE].sort()).toEqual(
[...table61].filter((code) => !FEATURE_DECIDED_CODES.includes(code)).sort(),
);
});
});
+71 -12
View File
@@ -24,6 +24,8 @@ async function checkBundle(
outputs: readonly Output[];
manifest: Record<string, unknown>;
budgets: Record<string, number>;
/** RUN_OUTPUT_ROOT for the run, and the build written under it. */
runOutput?: Readonly<{ root: string; outputs: readonly Output[] }>;
}>,
) {
const root = await mkdtemp(path.join(tmpdir(), "check-bundle-output-"));
@@ -32,22 +34,28 @@ async function checkBundle(
await mkdir(path.dirname(path.join(root, file)), { recursive: true });
await writeFile(path.join(root, file), `${JSON.stringify(value, null, 2)}\n`);
};
const writeBuild = async (buildRoot: string, outputs: readonly Output[]) => {
await write(path.posix.join(buildRoot, "dist/.vite/manifest.json"), options.manifest);
await write(path.posix.join(buildRoot, "artifacts/performance/bundle.json"), {
schemaVersion: 1,
generatedAt: "2026-11-04T00:00:00.000Z",
context: { nodeVersion: "v24.14.0", packageManager: "pnpm@11.17.0", runnerImage: "fixture" },
outputs: outputs.map((output) => ({
path: `dist/${output.path}`,
bytes: output.gzipBytes * 3,
gzipBytes: output.gzipBytes,
sha256: "a".repeat(64),
})),
});
};
await write("config/performance/budgets.json", { schemaVersion: 1, bundle: options.budgets });
await write("dist/.vite/manifest.json", options.manifest);
await write("artifacts/performance/bundle.json", {
schemaVersion: 1,
generatedAt: "2026-11-04T00:00:00.000Z",
context: { nodeVersion: "v24.14.0", packageManager: "pnpm@11.17.0", runnerImage: "fixture" },
outputs: options.outputs.map((output) => ({
path: `dist/${output.path}`,
bytes: output.gzipBytes * 3,
gzipBytes: output.gzipBytes,
sha256: "a".repeat(64),
})),
});
await writeBuild(".", options.outputs);
if (options.runOutput) await writeBuild(options.runOutput.root, options.runOutput.outputs);
const result = spawnSync(process.execPath, [path.resolve("scripts/check-bundle.ts")], {
cwd: root,
encoding: "utf8",
// Empty is unset (scripts/lib/run-isolation.ts), whatever the runner has.
env: { ...process.env, RUN_OUTPUT_ROOT: options.runOutput?.root ?? "" },
});
return { status: result.status, stdout: result.stdout, stderr: result.stderr };
}
@@ -126,3 +134,54 @@ describe("check:bundle failure output (1103/15-03)", () => {
expect(result.stderr).not.toContain("Bundle budget failed");
});
});
/**
* 1106/12-02. Under RUN_OUTPUT_ROOT scripts/build-frontend.ts writes the build
* below that folder, and check:bundle (scripts/generate-supply-chain.ts, then
* scripts/check-bundle.ts) read the checkout's dist/ and artifacts/ anyway: a
* build over budget under .tmp/ passed on the checkout's earlier build
* (review run 12-R2). Both stop and name the variable instead.
*/
describe("check:bundle with RUN_OUTPUT_ROOT (1106/12-02)", () => {
it("does not pass the checkout's earlier build while the build writes elsewhere", async () => {
const result = await checkBundle({
outputs: OUTPUTS,
manifest: MANIFEST,
budgets: BUDGETS,
runOutput: {
root: ".tmp/runs/other",
outputs: OUTPUTS.map((output) => ({ ...output, gzipBytes: output.gzipBytes * 4 })),
},
});
expect(result.stdout).not.toContain("Bundle budget: PASS");
expect(result.status).toBe(1);
expect(result.stderr).toContain("RUN_OUTPUT_ROOT=.tmp/runs/other");
});
it("measures the checkout's build when the output root is the checkout", async () => {
const result = await checkBundle({
outputs: OUTPUTS,
manifest: MANIFEST,
budgets: BUDGETS,
runOutput: { root: ".", outputs: OUTPUTS },
});
expect(result.stderr).toBe("");
expect(result.status).toBe(0);
expect(result.stdout).toContain("initial JS 900 / 1000 gzip bytes");
});
it("stops scripts/generate-supply-chain.ts before it reads the checkout's build", async () => {
const root = await mkdtemp(path.join(tmpdir(), "generate-supply-chain-output-root-"));
roots.push(root);
const result = spawnSync(process.execPath, [path.resolve("scripts/generate-supply-chain.ts")], {
cwd: root,
encoding: "utf8",
env: { ...process.env, RUN_OUTPUT_ROOT: ".tmp/runs/other" },
});
expect(result.status).toBe(1);
expect(result.stderr).toContain(
"scripts/generate-supply-chain.ts reads the build at this checkout's paths",
);
expect(result.stderr).toContain("RUN_OUTPUT_ROOT=.tmp/runs/other");
});
});
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { FEATURE_TRACKED_FILE_REWRITES } from "../../scripts/create-feature.ts";
/**
* 1105/16-01. The tracked template files every added feature changes, each
* with the command that rewrites it. tests/unit/feature-tracked-files.test.ts
* holds the documents to this list.
*
* 1106/12-01. This check reads no document, so it is not in that file: the
* removal drills that copy no documents leave that file out
* (REMOVAL_FIXTURE_DOCUMENT_TESTS in scripts/lib/removal-fixture.ts) and run
* this one.
*/
describe("tracked files a feature changes (1105/16-01)", () => {
it("lists the generator's tracked rewrites", () => {
expect(FEATURE_TRACKED_FILE_REWRITES.map((file) => file.path)).toEqual([
"public/release-manifest.json",
"config/scale/feature-shape-ceilings.json",
]);
});
});
+5 -7
View File
@@ -13,6 +13,11 @@ import { FEATURE_TRACKED_FILE_REWRITES } from "../../scripts/create-feature.ts";
* had neither, and nothing said what to do when two feature branches change
* the same `setDigest` line. The documents name each file with the command
* that rewrites it, which is also how a merge conflict on it is resolved.
*
* 1106/12-01. Every test here reads a document, so the removal drills that
* copy no documents leave this file out (REMOVAL_FIXTURE_DOCUMENT_TESTS in
* scripts/lib/removal-fixture.ts). The generator's own list is checked in
* tests/unit/feature-tracked-file-rewrites.test.ts, which every drill runs.
*/
function between(text: string, start: string, end: string): string {
const from = text.indexOf(start);
@@ -22,13 +27,6 @@ function between(text: string, start: string, end: string): string {
}
describe("tracked files a feature changes (1105/16-01)", () => {
it("lists the generator's tracked rewrites", () => {
expect(FEATURE_TRACKED_FILE_REWRITES.map((file) => file.path)).toEqual([
"public/release-manifest.json",
"config/scale/feature-shape-ceilings.json",
]);
});
it("names each file and its rewrite command in the 03 manual's section A", async () => {
const section = between(
await readFile("docs/manual/03-outside-feature-folder.md", "utf8"),
@@ -0,0 +1,51 @@
import { afterEach, describe, expect, it } from "vitest";
import {
configRuns,
describeResultFolders,
describeServerPorts,
hold,
itExitsWhenItsPortIsTaken,
itKeepsTheViteCacheInTheRun,
portOf,
releaseRuns,
} from "../helpers/playwright-run-isolation.ts";
/**
* 1105/12-04 for the capabilities config; why each check exists is in
* tests/unit/playwright-run-isolation.test.ts.
*
* 1106/10-01. This config goes with the browser file/storage runtime:
* test:browser-file-storage-removal deletes it, and deletes this file by
* name with it. Its eight checks used to sit with the other configs and were
* defined only while `existsSync` found the config. test:unit fails on a
* skipped test (1101/10-04), but a test that is never defined is not
* reported: the checks left that drill's copy unnoticed, and a renamed config
* would have taken them out of the template the same way. Imported by name, a
* renamed config fails check:types and this file instead.
*/
const runs = configRuns({
capabilities: () => import("../../playwright.capabilities.config.ts"),
visual: () => import("../../playwright.visual.config.ts"),
});
afterEach(releaseRuns);
describeResultFolders(runs, [["capabilities", "browser-capabilities"]]);
describe("the build a run serves", () => {
itKeepsTheViteCacheInTheRun(runs, ["capabilities"]);
});
describeServerPorts(runs, ["capabilities"]);
describe("vite servers", () => {
itExitsWhenItsPortIsTaken(runs, ["capabilities"]);
it("no longer share one port between the visual preview and the capability dev server", async () => {
const visual = portOf(await runs.load("visual"));
await hold(visual);
expect(portOf(await runs.load("capabilities"))).not.toBe(visual);
});
});
+31 -192
View File
@@ -1,9 +1,16 @@
import { existsSync, readFileSync } from "node:fs";
import { createServer, type Server } from "node:net";
import path from "node:path";
import { readFileSync } from "node:fs";
import type { PlaywrightTestConfig } from "@playwright/test";
import { afterEach, describe, expect, it, vi } from "vitest";
import { afterEach, describe, expect, it } from "vitest";
import {
configRuns,
describeResultFolders,
describeServerPorts,
itExitsWhenItsPortIsTaken,
itKeepsTheViteCacheInTheRun,
releaseRuns,
webServer,
} from "../helpers/playwright-run-isolation.ts";
/**
* 1105/12-04. Every Playwright config wrote its results, report and JUnit
@@ -20,151 +27,36 @@ import { afterEach, describe, expect, it, vi } from "vitest";
*
* Each load evaluates the config again with the environment of one process.
*
* test:browser-file-storage-removal deletes the capabilities config with the
* capability it runs, so a project without it checks the other four. Its path
* is a variable so that typecheck does not need the file.
* 1106/10-01. The capabilities config is checked in
* tests/unit/playwright-capabilities-run-isolation.test.ts: it goes with the
* browser file/storage runtime, and test:browser-file-storage-removal deletes
* the config and that file by name. This file has the four configs every
* project has.
*/
const CAPABILITIES_CONFIG = "playwright.capabilities.config.ts";
const HAS_CAPABILITIES = existsSync(CAPABILITIES_CONFIG);
const LOADERS = {
const runs = configRuns({
e2e: () => import("../../playwright.config.ts"),
visual: () => import("../../playwright.visual.config.ts"),
capabilities: () =>
import(/* @vite-ignore */ `../../${CAPABILITIES_CONFIG}`) as Promise<{
default: PlaywrightTestConfig;
}>,
storybook: () => import("../../playwright.storybook.config.ts"),
dev: () => import("../../playwright.dev.config.ts"),
} as const;
type ConfigName = keyof typeof LOADERS;
/** The names among `names` whose config file this checkout has. */
function installed<T extends ConfigName>(names: readonly T[]): T[] {
return names.filter((name) => name !== "capabilities" || HAS_CAPABILITIES);
}
const CONFIG_NAMES = installed(Object.keys(LOADERS) as ConfigName[]);
const PORT_VARIABLES: Readonly<Record<ConfigName, string>> = {
e2e: "TEST_E2E_PORT",
visual: "TEST_VISUAL_PORT",
capabilities: "TEST_CAPABILITIES_PORT",
storybook: "TEST_STORYBOOK_PORT",
dev: "TEST_DEV_PORT",
};
const RUN_VARIABLES = ["TEST_RUN_ID", "RUN_OUTPUT_ROOT", ...Object.values(PORT_VARIABLES)];
const held: Server[] = [];
afterEach(async () => {
vi.resetModules();
await Promise.all(
held.splice(0).map((server) => new Promise<void>((resolve) => server.close(() => resolve()))),
);
});
/** The config as one process sees it, and what it left in that environment. */
async function loadProcess(
name: ConfigName,
environment: Readonly<Record<string, string>> = {},
): Promise<{ config: PlaywrightTestConfig; after: Readonly<Record<string, string | undefined>> }> {
const saved = RUN_VARIABLES.map((variable) => [variable, process.env[variable]] as const);
for (const variable of RUN_VARIABLES) delete process.env[variable];
Object.assign(process.env, environment);
vi.resetModules();
try {
const config = (await LOADERS[name]()).default;
return {
config,
after: Object.fromEntries(RUN_VARIABLES.map((variable) => [variable, process.env[variable]])),
};
} finally {
for (const [variable, value] of saved) {
if (value === undefined) delete process.env[variable];
else process.env[variable] = value;
}
}
}
afterEach(releaseRuns);
async function load(
name: ConfigName,
environment: Readonly<Record<string, string>> = {},
): Promise<PlaywrightTestConfig> {
return (await loadProcess(name, environment)).config;
}
function portOf(config: PlaywrightTestConfig): number {
return Number(new URL(String(config.use?.baseURL)).port);
}
/** Listens on `port` the way the first run's server does. */
async function hold(port: number): Promise<void> {
const server = createServer();
held.push(server);
await new Promise<void>((resolve, reject) => {
server.once("error", reject);
server.listen(port, "127.0.0.1", () => resolve());
});
}
function reporterOption(config: PlaywrightTestConfig, reporter: string, option: string): string {
const reporters: readonly unknown[] = Array.isArray(config.reporter) ? config.reporter : [];
const entry = reporters.find(
(candidate) => Array.isArray(candidate) && candidate[0] === reporter,
) as readonly [string, Record<string, unknown>] | undefined;
return String(entry?.[1][option]);
}
function outputs(config: PlaywrightTestConfig) {
return {
results: path.resolve(String(config.outputDir)),
report: path.resolve(reporterOption(config, "html", "outputFolder")),
junit: path.resolve(reporterOption(config, "junit", "outputFile")),
};
}
function webServer(config: PlaywrightTestConfig) {
const server = config.webServer;
if (!server || Array.isArray(server)) throw new TypeError("expected one web server");
return server;
}
const RESULT_FOLDERS: Readonly<Record<Exclude<ConfigName, "dev">, string>> = {
e2e: "e2e",
visual: "visual",
capabilities: "browser-capabilities",
storybook: "storybook",
};
const INSTALLED_RESULT_FOLDERS = installed(
Object.keys(RESULT_FOLDERS) as Exclude<ConfigName, "dev">[],
).map((name) => [name, RESULT_FOLDERS[name]] as const);
describe.each(INSTALLED_RESULT_FOLDERS)("the %s config", (name, folder) => {
const expected = (root: string) => ({
results: path.resolve(root, `artifacts/tests/${folder}/results`),
report: path.resolve(root, `artifacts/tests/${folder}/report`),
junit: path.resolve(root, `artifacts/tests/${folder}/results.xml`),
});
it("writes where the gates read without a run ID", async () => {
expect(outputs(await load(name as ConfigName))).toEqual(expected("."));
});
it("gives each run ID its own results, report and JUnit file", async () => {
const a = outputs(await load(name as ConfigName, { TEST_RUN_ID: "a" }));
const b = outputs(await load(name as ConfigName, { TEST_RUN_ID: "b" }));
expect(a).toEqual(expected(".tmp/runs/a"));
expect(b).toEqual(expected(".tmp/runs/b"));
});
});
describeResultFolders(runs, [
["e2e", "e2e"],
["visual", "visual"],
["storybook", "storybook"],
]);
describe("the build a run serves", () => {
it.each(["e2e", "visual"] as const)(
"is the checkout's dist without a run ID, and the run's own with one (%s)",
async (name) => {
const checkout = webServer(await load(name));
const checkout = webServer(await runs.load(name));
expect(checkout.env?.["RUN_OUTPUT_ROOT"]).toBe(".");
expect(checkout.command).toMatch(/ --outDir dist(?: |$)/u);
const run = webServer(await load(name, { TEST_RUN_ID: "a" }));
const run = webServer(await runs.load(name, { TEST_RUN_ID: "a" }));
// The build writes under RUN_OUTPUT_ROOT and the preview serves it.
expect(run.env?.["RUN_OUTPUT_ROOT"]).toBe(".tmp/runs/a");
expect(run.command).toMatch(/^corepack pnpm build && corepack pnpm preview /u);
@@ -172,23 +64,15 @@ describe("the build a run serves", () => {
},
);
it.each(installed(["capabilities", "dev"] as const))(
"keeps the dev server's Vite cache in the run's folder (%s)",
async (name) => {
expect(webServer(await load(name)).env?.["RUN_OUTPUT_ROOT"]).toBe(".");
expect(webServer(await load(name, { TEST_RUN_ID: "a" })).env?.["RUN_OUTPUT_ROOT"]).toBe(
".tmp/runs/a",
);
},
);
itKeepsTheViteCacheInTheRun(runs, ["dev"]);
it("builds the workshop into the run's folder the way build:storybook does", async () => {
const checkout = webServer(await load("storybook")).command;
const checkout = webServer(await runs.load("storybook")).command;
expect(checkout).toMatch(
/^corepack pnpm build:storybook && node scripts\/serve-static\.ts artifacts\/storybook\/static /u,
);
const run = webServer(await load("storybook", { TEST_RUN_ID: "a" })).command;
const run = webServer(await runs.load("storybook", { TEST_RUN_ID: "a" })).command;
const script = (
JSON.parse(readFileSync("package.json", "utf8")) as { scripts: Record<string, string> }
).scripts["build:storybook"]!;
@@ -201,53 +85,8 @@ describe("the build a run serves", () => {
});
});
describe.each(CONFIG_NAMES)("the %s server port", (name) => {
it("is a free port the runner hands to its workers", async () => {
const runner = await loadProcess(name);
const port = portOf(runner.config);
const server = webServer(runner.config);
// Playwright evaluates the config again in each worker, which inherits
// the runner's environment: the port is there, so baseURL agrees.
expect(runner.after[PORT_VARIABLES[name]]).toBe(String(port));
expect(portOf(await load(name, { [PORT_VARIABLES[name]]: String(port) }))).toBe(port);
expect(server.url).toBe(`http://127.0.0.1:${port}`);
expect(server.command).toMatch(new RegExp(` (?:--port )?${port}(?: |$)`, "u"));
expect(server.reuseExistingServer).toBe(false);
});
it("moves for a second run while the first run's server holds its port", async () => {
const first = portOf(await load(name));
await hold(first);
expect(portOf(await load(name))).not.toBe(first);
});
it("is the one its variable pins", async () => {
const pinned = await load(name, { [PORT_VARIABLES[name]]: "40123" });
expect(portOf(pinned)).toBe(40123);
expect(webServer(pinned).url).toBe("http://127.0.0.1:40123");
});
});
describeServerPorts(runs, ["e2e", "visual", "storybook", "dev"]);
describe("vite servers", () => {
it.each(installed(["e2e", "visual", "capabilities", "dev"] as const))(
"exit instead of moving to the next port when theirs is taken (%s)",
async (name) => {
// Without --strictPort vite moved on, and Playwright, waiting on the
// configured URL, tested whatever already listened there.
expect(webServer(await load(name)).command).toMatch(/ --port \d+ --strictPort(?: |$)/u);
},
);
// Defined only where the capabilities config exists, not skipped:
// test:unit fails on a skipped test (0929/10-04).
if (HAS_CAPABILITIES) {
it("no longer share one port between the visual preview and the capability dev server", async () => {
const visual = portOf(await load("visual"));
await hold(visual);
expect(portOf(await load("capabilities"))).not.toBe(visual);
});
}
itExitsWhenItsPortIsTaken(runs, ["e2e", "visual", "dev"]);
});
+73 -2
View File
@@ -3,6 +3,7 @@ import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promis
import { tmpdir } from "node:os";
import path from "node:path";
import { parseAsync } from "@babel/core";
import { afterEach, describe, expect, it } from "vitest";
import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts";
@@ -137,6 +138,50 @@ it("rejects pruning that leaves a reduced gate without commands", async () => {
})).rejects.toThrow(/commandIds|too small|at least 1/i);
});
type BabelOptions = NonNullable<Parameters<typeof parseAsync>[1]>;
type BabelParserPlugin = NonNullable<NonNullable<BabelOptions["parserOpts"]>["plugins"]>[number];
type SyntaxNode = { type: string } & Record<string, unknown>;
/**
* 1106/12-01. The document paths the code of `source` spells out: string and
* template literal parts that are a document target (README.md, CHANGELOG.md,
* docs) or a path under one. Comments are not code.
*/
async function documentsNamedInCode(file: string, source: string): Promise<string[]> {
const plugins: BabelParserPlugin[] = [["typescript", { dts: false }]];
const tree = (await parseAsync(source, {
filename: file,
babelrc: false,
configFile: false,
sourceType: "module",
parserOpts: { plugins },
})) as unknown as SyntaxNode | null;
if (!tree) throw new Error(`cannot parse ${file}`);
const strings: string[] = [];
const visit = (node: SyntaxNode): void => {
const literal = node["value"];
if (node.type === "StringLiteral" && typeof literal === "string") strings.push(literal);
if (node.type === "TemplateElement") {
const cooked = (literal as { cooked?: unknown } | undefined)?.cooked;
if (typeof cooked === "string") strings.push(cooked);
}
for (const [key, value] of Object.entries(node)) {
if (key === "comments" || key.endsWith("Comments")) continue;
for (const child of Array.isArray(value) ? value : [value]) {
if (child && typeof child === "object" && typeof (child as SyntaxNode).type === "string") {
visit(child as SyntaxNode);
}
}
}
};
visit(tree);
return strings.filter((value) =>
REMOVAL_FIXTURE_DOCUMENT_TARGETS.some(
(target) => value === target || value.startsWith(`${target}/`),
),
);
}
// 1103/02-06. Three FE-GATE-020 drills copied the repository without its
// documents and still ran the tests that read them, so each failed its `test`
// check on ENOENT whatever it removed. Only the sample drill excluded them.
@@ -157,12 +202,38 @@ describe("document tests in a removal fixture", () => {
for (const test of REMOVAL_FIXTURE_DOCUMENT_TESTS) {
expect(existsSync(test), test).toBe(documentsPresent);
if (documentsPresent) {
// 1105/14-02. docs/ is one of the document targets too.
await expect(readFile(test, "utf8")).resolves.toMatch(/README\.md|CHANGELOG\.md|docs\//u);
// 1106/12-01. Named in its code, not in a comment. A comment naming
// the contract document let backend-contract-pin.test.ts on the list,
// and its fourteen checks of config and code left those drills with
// the one that read the document.
expect(await documentsNamedInCode(test, await readFile(test, "utf8")), test).not.toEqual([]);
}
}
});
it("counts a document named in code, not one named in a comment", async () => {
const commentOnly = [
"// Reads docs/architecture/a.md (README.md, CHANGELOG.md).",
"/** docs/manual/b.md */",
'const pin = JSON.parse(readFileSync("config/pin.json", "utf8"));',
"readFileSync(pin.document);",
].join("\n");
expect(await documentsNamedInCode("comment-only.test.ts", commentOnly)).toEqual([]);
const reads = [
'readFileSync("CHANGELOG.md", "utf8");',
"const name: string = 'a';",
"readFileSync(`docs/manual/${name}.md`, 'utf8');",
'z.string().startsWith("docs/");',
'const notADocument = "src/docs/x.ts";',
].join("\n");
expect((await documentsNamedInCode("reads.test.ts", reads)).sort()).toEqual([
"CHANGELOG.md",
"docs/",
"docs/manual/",
]);
});
it("is the only exclusion list: every drill prepares its fixture through it", async () => {
const drills: string[] = [];
for (const name of await readdir("scripts")) {
+19
View File
@@ -3,6 +3,7 @@ import { createServer, type Server } from "node:net";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
checkoutBuildReadFailure,
findFreePort,
moduleSpecifier,
reservePort,
@@ -91,6 +92,24 @@ describe("build output root (RUN_OUTPUT_ROOT)", () => {
expect(() => runOutputRoot({ RUN_OUTPUT_ROOT: root }), root).toThrow(/RUN_OUTPUT_ROOT/u);
}
});
// 1106/12-02. The steps after the build read the checkout's dist/ and
// artifacts/; under another root they judged an earlier build.
it("lets a step that reads the checkout's build run only when the build writes there", () => {
for (const environment of [{}, { RUN_OUTPUT_ROOT: "" }, { RUN_OUTPUT_ROOT: "." }, { RUN_OUTPUT_ROOT: "./" }]) {
expect(checkoutBuildReadFailure("check-bundle", environment), JSON.stringify(environment))
.toBeUndefined();
}
expect(checkoutBuildReadFailure("check-bundle", { RUN_OUTPUT_ROOT: "./.tmp/runs/a/" })).toBe(
"check-bundle reads the build at this checkout's paths (dist/, artifacts/), but " +
"RUN_OUTPUT_ROOT=.tmp/runs/a makes the build write under .tmp/runs/a/, so it would " +
"judge an earlier build. Unset RUN_OUTPUT_ROOT, build again and run check-bundle again.",
);
// A root the build itself refuses is no reason to read the checkout's.
expect(checkoutBuildReadFailure("check-bundle", { RUN_OUTPUT_ROOT: "dist" })).toMatch(
/^check-bundle: RUN_OUTPUT_ROOT must be/u,
);
});
});
describe("server ports", () => {
+21 -6
View File
@@ -3,6 +3,8 @@ import path from "node:path";
import { describe, expect, it } from "vitest";
import { REMOVABLE_TEMPLATE_FEATURES } from "../../scripts/lib/removable-template-features.ts";
/**
* 1105/15-03. Two copies of the list of files `vite build` reads from the
* root (the initial JavaScript measurement and the
@@ -12,14 +14,25 @@ import { describe, expect, it } from "vitest";
* now, and it has to cover what vite.config.ts imports.
*/
const LIST_MODULE = "scripts/lib/vite-build-inputs.ts";
// The measurement goes with the reference feature it copies
// (test:sample-removal), so a project without that feature checks the build
// test alone. In the template, tests/unit/feature-shape-growth.test.ts
// imports the measurement and fails if the file is gone.
const MEASUREMENT = "scripts/scale/measure-feature-shape-growth.ts";
// 1106/10-01. The measurement copies the reference sample and is one of its
// files (scripts/lib/removable-template-features.ts), so test:sample-removal
// deletes it with the sample. It is left out only where its owner is not
// installed: the owner's feature-module.ts is gone, the rule
// verify:documentation uses. The build test is a template file and is always
// read. Filtering both on "the file exists" let a renamed consumer drop out of
// the check unnoticed. The owner is found by its files, not written here: the
// sample drill fails on any test that still names the sample.
const MEASUREMENT_OWNER = REMOVABLE_TEMPLATE_FEATURES.find((feature) =>
feature.extraPaths.includes(MEASUREMENT),
);
const OWNER_INSTALLED =
MEASUREMENT_OWNER !== undefined &&
existsSync(`src/features/${MEASUREMENT_OWNER.featureId}/feature-module.ts`);
const CONSUMERS = [
"scripts/scale/measure-feature-shape-growth.ts",
"tests/unit/product-feature-selection-build.test.ts",
].filter((file) => existsSync(file));
...(OWNER_INSTALLED ? [MEASUREMENT] : []),
];
const LOCAL_IMPORT =
/\bfrom\s+["'](\.{1,2}\/[^"']+)["']|\bimport\s+["'](\.{1,2}\/[^"']+)["']/gu;
@@ -47,6 +60,8 @@ function localImportGraph(entry: string): string[] {
describe("vite build inputs (1105/15-03)", () => {
it("defines the list in one module that both builds import", () => {
// The measurement may be missing only because a removable feature owns it.
expect(MEASUREMENT_OWNER, `no removable template feature owns ${MEASUREMENT}`).toBeDefined();
for (const consumer of CONSUMERS) {
const source = readFileSync(consumer, "utf8");
expect(source, consumer).not.toMatch(/\bconst BUILD_INPUTS\s*=/u);