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:
@@ -0,0 +1,59 @@
|
||||
import path from "node:path";
|
||||
|
||||
import { expect, test } from "../support/browser/strict-browser-test.ts";
|
||||
import {
|
||||
editOnce,
|
||||
prepareFixtureBuilds,
|
||||
removeFixtureBuilds,
|
||||
type FixtureBuilds,
|
||||
} from "./support/fixture-builds.ts";
|
||||
import { startBuildServer } from "./support/service-worker-builds.ts";
|
||||
|
||||
/**
|
||||
* 09-03 (F-2). A production build whose application graph throws while its
|
||||
* modules evaluate: the installed features are composed twice, so
|
||||
* `installed-feature-messages.ts` meets every message key a second time and
|
||||
* throws at module top level. The static "loading" shell used to stay up
|
||||
* forever; the boot error shell has to replace it.
|
||||
*/
|
||||
|
||||
let builds: FixtureBuilds<"broken"> | undefined;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
test.setTimeout(300_000);
|
||||
builds = await prepareFixtureBuilds("boot-module-failure", [
|
||||
{
|
||||
name: "broken",
|
||||
edit: (root) =>
|
||||
editOnce(
|
||||
path.join(root, "src/features/installed-feature-messages.ts"),
|
||||
"composeInstalledMessageCatalogs(\n INSTALLED_PRODUCT_FEATURE_MODULES,\n)",
|
||||
"composeInstalledMessageCatalogs([\n ...INSTALLED_PRODUCT_FEATURE_MODULES,\n ...INSTALLED_PRODUCT_FEATURE_MODULES,\n])",
|
||||
),
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await removeFixtureBuilds(builds);
|
||||
});
|
||||
|
||||
test("shows the boot error shell when a module throws while it evaluates", async ({
|
||||
page,
|
||||
}) => {
|
||||
if (!builds) throw new Error("Fixture build was not prepared.");
|
||||
const broken = builds.dist.broken;
|
||||
const server = await startBuildServer({ a: broken, b: broken });
|
||||
try {
|
||||
await page.goto(`${server.origin}/`);
|
||||
|
||||
const shell = page.getByRole("alert");
|
||||
await expect(shell).toContainText("애플리케이션을 시작할 수 없습니다.");
|
||||
await expect(shell).toContainText("BOOT_UNEXPECTED_FAILURE");
|
||||
await expect(shell).toContainText("TypeError");
|
||||
await expect(shell).toContainText("boot-module-failure-broken");
|
||||
await expect(page.locator("[data-boot-shell]")).toHaveCount(0);
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,125 @@
|
||||
import { appendFile, readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts";
|
||||
import { expect, test } from "../support/browser/strict-browser-test.ts";
|
||||
import {
|
||||
prepareFixtureBuilds,
|
||||
removeFixtureBuilds,
|
||||
type FixtureBuilds,
|
||||
} from "./support/fixture-builds.ts";
|
||||
import { startBuildServer } from "./support/service-worker-builds.ts";
|
||||
|
||||
/**
|
||||
* 11-05. A tab opened on build A, in the default configuration (no Service
|
||||
* Worker), after build B is deployed. B changes two lazy route pages, so their
|
||||
* A chunks no longer exist on the server. The first missing chunk reloads the
|
||||
* tab once, into B. A second missing chunk (the server alternates back to A,
|
||||
* as mismatched replicas do) must not reload again: the tab shows the
|
||||
* recovery failure instead.
|
||||
*/
|
||||
|
||||
const PLATFORM = ROUTE_REGISTRY.EXAMPLES_PLATFORM;
|
||||
const UI = ROUTE_REGISTRY.EXAMPLES_UI;
|
||||
const PAGES = [
|
||||
"src/presentation/examples/platform-overview-page.tsx",
|
||||
"src/presentation/examples/ui-gallery-page.tsx",
|
||||
] as const;
|
||||
|
||||
let builds: FixtureBuilds<"a" | "b"> | undefined;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
test.setTimeout(300_000);
|
||||
builds = await prepareFixtureBuilds("chunk-recovery", [
|
||||
{ name: "a" },
|
||||
{
|
||||
name: "b",
|
||||
edit: async (root) => {
|
||||
for (const page of PAGES) {
|
||||
await appendFile(
|
||||
path.join(root, page),
|
||||
'\n(globalThis as Record<string, unknown>).__caFixtureBuild = "b";\n',
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await removeFixtureBuilds(builds);
|
||||
});
|
||||
|
||||
async function routeChunk(dist: string, chunkId: string): Promise<string> {
|
||||
const manifest = JSON.parse(
|
||||
await readFile(path.join(dist, "release-manifest.json"), "utf8"),
|
||||
) as { routeChunks: Record<string, string> };
|
||||
return `/${manifest.routeChunks[chunkId]}`;
|
||||
}
|
||||
|
||||
// Each missing page chunk fails its request and the dynamic import. Chromium
|
||||
// may also log the 404 itself (without its URL), and Firefox logs the error
|
||||
// object React caught. Nothing else is allowed.
|
||||
const MISSING_PAGE = String.raw`/assets/(?:platform-overview|ui-gallery)-page-[\w-]+\.js`;
|
||||
test.use({
|
||||
allowedBrowserFailure: new RegExp(
|
||||
[
|
||||
String.raw`^requestfailed:GET:${MISSING_PAGE}:`,
|
||||
String.raw`^console:error:TypeError: Failed to fetch dynamically imported module: http://127\.0\.0\.1:\d+${MISSING_PAGE}$`,
|
||||
String.raw`^console:error:\[JavaScript Error: "Loading module from “http://127\.0\.0\.1:\d+${MISSING_PAGE}” was blocked`,
|
||||
String.raw`^console:error:Failed to load resource: the server responded with a status of 404 \(Not Found\)$`,
|
||||
String.raw`^console:error:JSHandle@object$`,
|
||||
].join("|"),
|
||||
"u",
|
||||
),
|
||||
});
|
||||
|
||||
test("an old tab reloads once into the new build, then stops reloading", async ({
|
||||
page,
|
||||
}) => {
|
||||
if (!builds) throw new Error("Fixture builds were not prepared.");
|
||||
const aPlatform = await routeChunk(builds.dist.a, PLATFORM.chunkId);
|
||||
const bPlatform = await routeChunk(builds.dist.b, PLATFORM.chunkId);
|
||||
const bUi = await routeChunk(builds.dist.b, UI.chunkId);
|
||||
expect(bPlatform).not.toBe(aPlatform);
|
||||
expect(bUi).not.toBe(await routeChunk(builds.dist.a, UI.chunkId));
|
||||
|
||||
const server = await startBuildServer(builds.dist);
|
||||
try {
|
||||
await page.goto(`${server.origin}/`);
|
||||
await expect(
|
||||
page.getByRole("link", { name: PLATFORM.navigationLabel!, exact: true }),
|
||||
).toBeVisible();
|
||||
let loads = 0;
|
||||
page.on("load", () => {
|
||||
loads += 1;
|
||||
});
|
||||
|
||||
// Build B is deployed while the A tab stays open.
|
||||
server.serve("b");
|
||||
await page
|
||||
.getByRole("link", { name: PLATFORM.navigationLabel!, exact: true })
|
||||
.click();
|
||||
|
||||
await expect(page.getByRole("heading", { name: PLATFORM.title })).toBeVisible();
|
||||
expect(loads).toBe(1);
|
||||
const served = server.served.map((entry) => entry.path);
|
||||
expect(served).not.toContain(aPlatform);
|
||||
expect(served).toContain(bPlatform);
|
||||
await expect
|
||||
.poll(() => page.evaluate(() => (globalThis as Record<string, unknown>).__caFixtureBuild))
|
||||
.toBe("b");
|
||||
|
||||
// The replicas alternate: the B tab now meets A, which lacks B's chunk.
|
||||
server.serve("a");
|
||||
await page.getByRole("link", { name: UI.navigationLabel!, exact: true }).click();
|
||||
|
||||
await expect(page.getByRole("alert")).toContainText(
|
||||
"화면 자산을 복구하지 못했습니다.",
|
||||
);
|
||||
expect(loads).toBe(1);
|
||||
expect(page.url()).toBe(`${server.origin}${UI.path}`);
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
});
|
||||
@@ -29,4 +29,6 @@ test("opens the protected integration route through the local demo seam", async
|
||||
page.getByRole("heading", { name: protectedRoute.title }),
|
||||
).toBeVisible();
|
||||
await expect(page.getByText("인증됨")).toBeVisible();
|
||||
// The mocked row went through the production codec, mapper and query cache.
|
||||
await expect(page.getByText("Browser reference")).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import type { Page, Route } from "@playwright/test";
|
||||
import { expect, test } from "../support/browser/strict-browser-test.ts";
|
||||
|
||||
const CREATE_URL = "http://localhost:8080/api/reference-resources";
|
||||
|
||||
type CreateCall = Readonly<{ name: unknown; idempotencyKey: string | null }>;
|
||||
|
||||
async function openForm(page: Page) {
|
||||
await page.route(`${CREATE_URL}?*`, (route) => route.fulfill({ json: [] }));
|
||||
await page.goto("/examples/reference-resources/new");
|
||||
await page.getByRole("button", { name: "로그인 시작" }).click();
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "Reference resource 만들기" }),
|
||||
).toBeVisible();
|
||||
}
|
||||
|
||||
/** Answers each POST with the next responder and records what was sent. */
|
||||
async function routeCreate(
|
||||
page: Page,
|
||||
responders: readonly ((route: Route) => Promise<void>)[],
|
||||
): Promise<CreateCall[]> {
|
||||
const calls: CreateCall[] = [];
|
||||
await page.route(CREATE_URL, async (route) => {
|
||||
const request = route.request();
|
||||
if (request.method() !== "POST") return route.fallback();
|
||||
calls.push({
|
||||
name: (request.postDataJSON() as { name?: unknown }).name,
|
||||
idempotencyKey: await request.headerValue("idempotency-key"),
|
||||
});
|
||||
const respond = responders[calls.length - 1];
|
||||
if (!respond) throw new Error(`unexpected create call ${calls.length}`);
|
||||
await respond(route);
|
||||
});
|
||||
return calls;
|
||||
}
|
||||
|
||||
const created = (route: Route) =>
|
||||
route.fulfill({
|
||||
status: 201,
|
||||
json: {
|
||||
id: "browser-created",
|
||||
name: "Saved in the browser",
|
||||
createdAt: "2026-07-26T00:00:00.000Z",
|
||||
},
|
||||
});
|
||||
|
||||
test("saves a new reference resource through the production command path", async ({
|
||||
page,
|
||||
}) => {
|
||||
await openForm(page);
|
||||
const calls = await routeCreate(page, [created]);
|
||||
|
||||
await page
|
||||
.getByRole("textbox", { name: /새 항목 이름/ })
|
||||
.fill("Saved in the browser");
|
||||
await page.getByRole("button", { name: "저장" }).click();
|
||||
|
||||
await expect(page.getByRole("status")).toHaveText("저장했습니다.");
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(calls[0]?.name).toBe("Saved in the browser");
|
||||
expect(calls[0]?.idempotencyKey).toBeTruthy();
|
||||
});
|
||||
|
||||
test.describe("after a rate-limited save", () => {
|
||||
// Chromium and WebKit log a 4xx fetch response to the console, and the
|
||||
// client cancels the 429 body unread, which Chromium reports as aborted.
|
||||
test.use({
|
||||
allowedBrowserFailure:
|
||||
/^console:error:.*status of 429|^requestfailed:POST:\/api\/reference-resources:net::ERR_ABORTED$/u,
|
||||
});
|
||||
|
||||
test("keeps the input and saves on retry", async ({ page }) => {
|
||||
await openForm(page);
|
||||
const calls = await routeCreate(page, [
|
||||
(route) =>
|
||||
route.fulfill({
|
||||
status: 429,
|
||||
headers: { "retry-after": "1" },
|
||||
json: { title: "Too many requests" },
|
||||
}),
|
||||
created,
|
||||
]);
|
||||
|
||||
const name = page.getByRole("textbox", { name: /새 항목 이름/ });
|
||||
await name.fill("Saved in the browser");
|
||||
await page.getByRole("button", { name: "저장" }).click();
|
||||
|
||||
await expect(
|
||||
page.getByText("요청이 많습니다. 잠시 후 다시 시도해 주세요."),
|
||||
).toBeVisible();
|
||||
await expect(name).toHaveValue("Saved in the browser");
|
||||
await page.getByRole("button", { name: "다시 시도" }).click();
|
||||
|
||||
await expect(page.getByRole("status")).toHaveText("저장했습니다.");
|
||||
expect(calls.map((call) => call.name)).toEqual([
|
||||
"Saved in the browser",
|
||||
"Saved in the browser",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { cp, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { linkFixtureNodeModules } from "../../../scripts/lib/fixture-node-modules.ts";
|
||||
|
||||
/**
|
||||
* Real production builds of an edited temp copy of the repository, in the
|
||||
* template's default configuration (`serviceWorker: null`). `edit` changes the
|
||||
* copy right before that build runs, and edits persist into later builds. The
|
||||
* working tree and its `dist` (served by the e2e preview server) are never
|
||||
* touched. Serve the result with `startBuildServer` from
|
||||
* `service-worker-builds.ts`.
|
||||
*/
|
||||
|
||||
const repoRoot = path.resolve(import.meta.dirname, "../../..");
|
||||
const skipped = new Set([
|
||||
"node_modules",
|
||||
".git",
|
||||
".claude",
|
||||
".generated",
|
||||
".tmp",
|
||||
"dist",
|
||||
"artifacts",
|
||||
"graphify-out",
|
||||
]);
|
||||
|
||||
export type FixtureBuild<Name extends string> = Readonly<{
|
||||
name: Name;
|
||||
edit?: (root: string) => Promise<void>;
|
||||
}>;
|
||||
|
||||
export type FixtureBuilds<Name extends string> = Readonly<{
|
||||
root: string;
|
||||
dist: Readonly<Record<Name, string>>;
|
||||
}>;
|
||||
|
||||
/** Replaces the one occurrence of `search` in `file` of the copy. */
|
||||
export async function editOnce(
|
||||
file: string,
|
||||
search: string,
|
||||
replacement: string,
|
||||
): Promise<void> {
|
||||
const source = await readFile(file, "utf8");
|
||||
if (source.split(search).length !== 2) {
|
||||
throw new Error(`Expected exactly one "${search}" in ${file}.`);
|
||||
}
|
||||
await writeFile(file, source.replace(search, replacement));
|
||||
}
|
||||
|
||||
function run(cwd: string, script: string, buildId: string): void {
|
||||
const result = spawnSync("node", [script], {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, VITE_BUILD_ID: buildId, RELEASE_ID: buildId },
|
||||
});
|
||||
if (result.status !== 0) {
|
||||
throw new Error(
|
||||
`${script} failed for ${buildId}:\n${result.stdout}\n${result.stderr}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function prepareFixtureBuilds<Name extends string>(
|
||||
prefix: string,
|
||||
builds: readonly FixtureBuild<Name>[],
|
||||
): Promise<FixtureBuilds<Name>> {
|
||||
const root = await mkdtemp(path.join(tmpdir(), `${prefix}-`));
|
||||
try {
|
||||
await cp(repoRoot, root, {
|
||||
recursive: true,
|
||||
filter: (source) =>
|
||||
!skipped.has(path.relative(repoRoot, source).split(path.sep)[0]!),
|
||||
});
|
||||
await linkFixtureNodeModules(root, repoRoot);
|
||||
const dist = {} as Record<Name, string>;
|
||||
for (const build of builds) {
|
||||
await build.edit?.(root);
|
||||
const buildId = `${prefix}-${build.name}`;
|
||||
run(root, "scripts/generate-product-feature-index.ts", buildId);
|
||||
run(root, "scripts/build-frontend.ts", buildId);
|
||||
dist[build.name] = path.join(root, `dist-${build.name}`);
|
||||
await rename(path.join(root, "dist"), dist[build.name]);
|
||||
}
|
||||
return { root, dist };
|
||||
} catch (error) {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function removeFixtureBuilds(
|
||||
builds: Readonly<{ root: string }> | undefined,
|
||||
): Promise<void> {
|
||||
if (builds) await rm(builds.root, { recursive: true, force: true });
|
||||
}
|
||||
@@ -4,9 +4,15 @@ import {
|
||||
QueryClient,
|
||||
QueryClientProvider,
|
||||
} from "@tanstack/react-query";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import {
|
||||
configure,
|
||||
getConfig,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
} from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createDemoSessionAdapter } from "../../../src/adapters/auth/external-session-adapter.ts";
|
||||
import type { AuthSessionPort } from "../../../src/application/ports/auth-session-port.ts";
|
||||
@@ -122,6 +128,16 @@ function inputWith(
|
||||
}
|
||||
|
||||
describe("reference feature page states", () => {
|
||||
// Entering an installed route resolves the context route table and then a
|
||||
// lazy page, and React holds each Suspense reveal for up to 300ms. That
|
||||
// floor alone uses half of Testing Library's 1s findBy default, so a busy
|
||||
// host misses it and reports a missing heading instead of a slow route.
|
||||
// Keep the wider wait scoped to this file; the test timeout still catches
|
||||
// a real hang.
|
||||
const defaultAsyncUtilTimeout = getConfig().asyncUtilTimeout;
|
||||
beforeAll(() => configure({ asyncUtilTimeout: 5_000 }));
|
||||
afterAll(() => configure({ asyncUtilTimeout: defaultAsyncUtilTimeout }));
|
||||
|
||||
it("mounts list and detail keys under the installed governed namespace", async () => {
|
||||
expect(REFERENCE_RESOURCE_QUERY_NAMESPACE).toEqual({
|
||||
namespaceId: "reference-resource",
|
||||
|
||||
+8
-8
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"total": {
|
||||
"lines": { "pct": 0 },
|
||||
"statements": { "pct": 0 },
|
||||
"functions": { "pct": 0 },
|
||||
"branches": { "pct": 0 }
|
||||
"lines": { "total": 10, "covered": 0, "skipped": 0, "pct": 0 },
|
||||
"statements": { "total": 10, "covered": 0, "skipped": 0, "pct": 0 },
|
||||
"functions": { "total": 2, "covered": 0, "skipped": 0, "pct": 0 },
|
||||
"branches": { "total": 4, "covered": 0, "skipped": 0, "pct": 0 }
|
||||
},
|
||||
"src/adapters/http/http-execution-v3.ts": {
|
||||
"lines": { "pct": 0 },
|
||||
"statements": { "pct": 0 },
|
||||
"functions": { "pct": 0 },
|
||||
"branches": { "pct": 0 }
|
||||
"lines": { "total": 10, "covered": 0, "skipped": 0, "pct": 0 },
|
||||
"statements": { "total": 10, "covered": 0, "skipped": 0, "pct": 0 },
|
||||
"functions": { "total": 2, "covered": 0, "skipped": 0, "pct": 0 },
|
||||
"branches": { "total": 4, "covered": 0, "skipped": 0, "pct": 0 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
// quarantine(owner=frontend-platform, defect=expired-fixture, expires=2020-01-01)
|
||||
test.skip("quarantine whose expiry date has passed", async () => {});
|
||||
@@ -0,0 +1 @@
|
||||
test.only("focused test that would pass alone", async () => {});
|
||||
@@ -15,7 +15,10 @@ import {
|
||||
RELEASE_CANDIDATE_MANIFEST_PATH,
|
||||
releaseCandidateManifestSchema,
|
||||
} from "../../scripts/lib/release-candidate.ts";
|
||||
import { linkFixtureNodeModules } from "../../scripts/lib/fixture-node-modules.ts";
|
||||
import {
|
||||
FIXTURE_PNPM_ENVIRONMENT,
|
||||
linkFixtureNodeModules,
|
||||
} from "../../scripts/lib/fixture-node-modules.ts";
|
||||
|
||||
it(
|
||||
"builds a real candidate assessment and passes the default archived verifier from the captured archive",
|
||||
@@ -61,6 +64,7 @@ it(
|
||||
maxBuffer: 32 * 1024 * 1024,
|
||||
env: {
|
||||
...process.env,
|
||||
...FIXTURE_PNPM_ENVIRONMENT,
|
||||
CI: "true",
|
||||
VITE_BUILD_ID: "security-followup-integration",
|
||||
VITE_COMMIT_SHA: revision,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
function listTestFiles(...filters: string[]): string[] {
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
["node_modules/vitest/vitest.mjs", "list", "--filesOnly", ...filters],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
expect(result.status, result.stderr).toBe(0);
|
||||
return result.stdout.split("\n").filter((line) => line.length > 0);
|
||||
}
|
||||
|
||||
describe("Vitest file collection", () => {
|
||||
it("leaves Playwright specs and host system tests out of a bare run", () => {
|
||||
const files = listTestFiles();
|
||||
|
||||
expect(files).toContain("tests/integration/vitest-collection.test.ts");
|
||||
expect(files.filter((file) => file.endsWith(".spec.ts"))).toEqual([]);
|
||||
expect(files.filter((file) => file.startsWith("tests/system/"))).toEqual(
|
||||
[],
|
||||
);
|
||||
}, 30_000);
|
||||
|
||||
it("still collects system tests when test:system names them", () => {
|
||||
expect(listTestFiles("tests/system")).toContain(
|
||||
"tests/system/ci-runner/ci-evidence-freshness.test.ts",
|
||||
);
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -2,7 +2,15 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { CACHE_POLICY, createReleaseFixture } from "./release-fixture.ts";
|
||||
|
||||
describe("old hashed-asset reachability", () => {
|
||||
/**
|
||||
* 11-05. A contract of the in-memory hosting model in `release-fixture.ts`
|
||||
* against `config/hosting/cache-policy.json`: no product code, deploy script or
|
||||
* browser runs here. Keeping old assets reachable is the hosting provider's
|
||||
* job (`docs/operations/release-cache-rollback.md`). What an old tab does when
|
||||
* an asset is gone anyway is checked in a real browser by
|
||||
* `tests/e2e/old-tab-chunk-recovery.spec.ts`.
|
||||
*/
|
||||
describe("old hashed-asset reachability (hosting fixture contract)", () => {
|
||||
it("keeps R10 hashed assets reachable after R11 becomes active", async () => {
|
||||
const deployment = createReleaseFixture(["R10", "R11"]);
|
||||
deployment.activate("R11");
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { rm } from "node:fs/promises";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
generateAppIndexes,
|
||||
@@ -80,11 +82,20 @@ describe("feature index generator", () => {
|
||||
});
|
||||
|
||||
describe("app-scoped selection from ownership declarations", () => {
|
||||
// 00-03. The fake repositories used to stay in /tmp.
|
||||
const temporaryRoots: string[] = [];
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporaryRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
async function repo(files: Record<string, string>) {
|
||||
const { mkdtemp, mkdir, writeFile } = await import("node:fs/promises");
|
||||
const { tmpdir } = await import("node:os");
|
||||
const path = await import("node:path");
|
||||
const root = await mkdtemp(path.join(tmpdir(), "generator-"));
|
||||
temporaryRoots.push(root);
|
||||
for (const [file, content] of Object.entries(files)) {
|
||||
await mkdir(path.dirname(path.join(root, file)), { recursive: true });
|
||||
await writeFile(path.join(root, file), content);
|
||||
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { cleanup } from "@testing-library/react";
|
||||
import { afterEach } from "vitest";
|
||||
import { afterEach, vi } from "vitest";
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
// A test that fails before its own vi.useRealTimers() must not leave fake
|
||||
// timers to the next test in the file.
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
@@ -12,8 +12,18 @@ function ignoredConsole(message: ConsoleMessage) {
|
||||
);
|
||||
}
|
||||
|
||||
export const test = base.extend({
|
||||
page: async ({ page }, use) => {
|
||||
export const test = base.extend<{
|
||||
/**
|
||||
* Browser failures a test provokes on purpose, matched against the recorded
|
||||
* `console:…`, `pageerror:…` or `requestfailed:…` line (for example the
|
||||
* browser's log line for a mocked 4xx). Everything else still fails. One
|
||||
* pattern, not an array: `test.use` reads an array as a `[value, options]`
|
||||
* fixture tuple.
|
||||
*/
|
||||
allowedBrowserFailure: RegExp | undefined;
|
||||
}>({
|
||||
allowedBrowserFailure: [undefined, { option: true }],
|
||||
page: async ({ page, allowedBrowserFailure }, use) => {
|
||||
const failures: string[] = [];
|
||||
const onConsole = (message: ConsoleMessage) => {
|
||||
if (
|
||||
@@ -38,7 +48,12 @@ export const test = base.extend({
|
||||
page.off("console", onConsole);
|
||||
page.off("pageerror", onPageError);
|
||||
page.off("requestfailed", onRequestFailed);
|
||||
expect(failures, "unexpected browser console/page errors").toEqual([]);
|
||||
expect(
|
||||
failures.filter(
|
||||
(failure) => !allowedBrowserFailure?.test(failure),
|
||||
),
|
||||
"unexpected browser console/page errors",
|
||||
).toEqual([]);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
import { vi } from "vitest";
|
||||
|
||||
export function createDeterministicClock(start = 0) {
|
||||
let current = start;
|
||||
return Object.freeze({
|
||||
now: () => current,
|
||||
sleep: async (milliseconds: number, signal?: AbortSignal) => {
|
||||
if (signal?.aborted) throw new DOMException("aborted", "AbortError");
|
||||
current += Math.max(0, milliseconds);
|
||||
},
|
||||
advance(milliseconds: number) {
|
||||
current += Math.max(0, milliseconds);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function createSeededRandom(seed = 1) {
|
||||
let state = seed >>> 0;
|
||||
return () => {
|
||||
state = (state * 1_664_525 + 1_013_904_223) >>> 0;
|
||||
return state / 0x1_0000_0000;
|
||||
};
|
||||
}
|
||||
|
||||
export function createControlledScheduler() {
|
||||
const callbacks: Array<() => void> = [];
|
||||
return Object.freeze({
|
||||
callbacks,
|
||||
setTimeout: vi.fn((callback: () => void) => {
|
||||
callbacks.push(callback);
|
||||
return callbacks.length - 1;
|
||||
}),
|
||||
clearTimeout: vi.fn(),
|
||||
runNext() {
|
||||
callbacks.shift()?.();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function createRecordingStorage() {
|
||||
const values = new Map<string, string>();
|
||||
const operations: Array<
|
||||
Readonly<{ operation: "get" | "set" | "remove"; key: string }>
|
||||
> = [];
|
||||
const storage: Storage = {
|
||||
getItem(key) {
|
||||
operations.push({ operation: "get", key });
|
||||
return values.get(key) ?? null;
|
||||
},
|
||||
setItem(key, value) {
|
||||
operations.push({ operation: "set", key });
|
||||
values.set(key, value);
|
||||
},
|
||||
removeItem(key) {
|
||||
operations.push({ operation: "remove", key });
|
||||
values.delete(key);
|
||||
},
|
||||
clear() {
|
||||
values.clear();
|
||||
},
|
||||
key(index) {
|
||||
return [...values.keys()][index] ?? null;
|
||||
},
|
||||
get length() {
|
||||
return values.size;
|
||||
},
|
||||
};
|
||||
return Object.freeze({ storage, operations, values });
|
||||
}
|
||||
@@ -19,7 +19,10 @@ import {
|
||||
validateCiArtifact,
|
||||
} from "../../../scripts/lib/ci-artifact-validator.ts";
|
||||
import { writeCiGateLogAtomic } from "../../../scripts/lib/ci-gate-log.ts";
|
||||
import { linkFixtureNodeModules } from "../../../scripts/lib/fixture-node-modules.ts";
|
||||
import {
|
||||
FIXTURE_PNPM_ENVIRONMENT,
|
||||
linkFixtureNodeModules,
|
||||
} from "../../../scripts/lib/fixture-node-modules.ts";
|
||||
import { copyReleaseEvidenceTree } from "../../../scripts/lib/removal-fixture.ts";
|
||||
import { captureCiCandidateArchive, verifyCiCandidateArchive } from "../../../scripts/lib/ci-candidate-archive.ts";
|
||||
import {
|
||||
@@ -2289,6 +2292,7 @@ async function ensureProviderBaseFixture(): Promise<string> {
|
||||
maxBuffer: 32 * 1024 * 1024,
|
||||
env: {
|
||||
...process.env,
|
||||
...FIXTURE_PNPM_ENVIRONMENT,
|
||||
CI: "true",
|
||||
VITE_BUILD_ID: "provider-v2-fixture",
|
||||
VITE_COMMIT_SHA: revision,
|
||||
|
||||
@@ -6,6 +6,12 @@ import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { loadCiGateContract } from "../../../scripts/contracts/ci-gates.ts";
|
||||
import { FIXTURE_PNPM_ENVIRONMENT } from "../../../scripts/lib/fixture-node-modules.ts";
|
||||
|
||||
// F-12. The temp roots have a package.json but no node_modules or lockfile.
|
||||
// Run directly (not under pnpm), pnpm's pre-script install check started an
|
||||
// install there and failed with ERR_PNPM_IGNORED_BUILDS; the gate runner has
|
||||
// to run the scripts as they are.
|
||||
|
||||
const temporaryRoots: string[] = [];
|
||||
|
||||
@@ -58,7 +64,7 @@ describe("CI-runner command-generated evidence freshness", () => {
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
[path.resolve("scripts/run-ci-gate.ts"), "FE-GATE-004"],
|
||||
{ cwd: root, encoding: "utf8", env: { ...process.env, CI: "false" } },
|
||||
{ cwd: root, encoding: "utf8", env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT, CI: "false" } },
|
||||
);
|
||||
|
||||
expect(result.status).toBe(1);
|
||||
@@ -112,7 +118,7 @@ describe("CI-runner command-generated evidence freshness", () => {
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
[path.resolve("scripts/run-ci-gate.ts"), "FE-GATE-004"],
|
||||
{ cwd: root, encoding: "utf8", env: { ...process.env, CI: "false" } },
|
||||
{ cwd: root, encoding: "utf8", env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT, CI: "false" } },
|
||||
);
|
||||
|
||||
expect(result.status).toBe(0);
|
||||
@@ -165,7 +171,7 @@ describe("CI-runner gate output budget", () => {
|
||||
{
|
||||
cwd: root,
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, CI: "false" },
|
||||
env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT, CI: "false" },
|
||||
timeout: 15_000,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
FEATURE_SHAPE_BASELINE_PATH,
|
||||
renameReferenceFeature,
|
||||
} from "../../scripts/scale/measure-feature-shape-growth.ts";
|
||||
|
||||
/**
|
||||
* 11-04 (D-18). The scale evidence used to come from stub features that only
|
||||
* differ by name, so the cost of one app growing towards its declared ceiling
|
||||
* (20 contexts x 200 features) was never measured. The committed baseline is a
|
||||
* measurement with copies of the real reference feature.
|
||||
*/
|
||||
const context = { id: "shape-context-0", routeRoot: "shape-0" } as const;
|
||||
|
||||
type Run = Readonly<{
|
||||
addedFeatures: number;
|
||||
routes: number;
|
||||
tsc: Readonly<{ passed: boolean; instantiations: number; wallMs: number }>;
|
||||
build: Readonly<{
|
||||
wallMs: number;
|
||||
initialJavascriptGzipBytes: number;
|
||||
lazyJavascriptFiles: number;
|
||||
}>;
|
||||
loadBefore: readonly number[];
|
||||
}>;
|
||||
|
||||
describe("feature-shape growth measurement (11-04)", () => {
|
||||
it("renames every feature-owned identifier of a reference copy", () => {
|
||||
const source = [
|
||||
'featureId: "reference-feature"',
|
||||
'path: "/examples/reference-resources/:id"',
|
||||
"REFERENCE_RESOURCE_LIST",
|
||||
"ReferenceResourcePage",
|
||||
'contextId: "reference-context"',
|
||||
'topic: "qinv.01k10f7m3w9p6r2c8v5n4x"',
|
||||
"NoRequest",
|
||||
].join("\n");
|
||||
|
||||
const renamed = renameReferenceFeature(source, "s007", context);
|
||||
|
||||
expect(renamed).not.toMatch(/reference/iu);
|
||||
expect(renamed).toContain('featureId: "s007-feature"');
|
||||
expect(renamed).toContain('path: "/shape-0/s007-resources/:id"');
|
||||
expect(renamed).toContain("S007_RESOURCE_LIST");
|
||||
expect(renamed).toContain("S007ResourcePage");
|
||||
expect(renamed).toContain('contextId: "shape-context-0"');
|
||||
expect(renamed).toContain('topic: "qinv.shape.s007"');
|
||||
expect(renamed).toContain("S007NoRequest");
|
||||
});
|
||||
|
||||
it("keeps platform-owned names that only contain the word", () => {
|
||||
const source =
|
||||
"REFERENCE_EXTERNAL_BEARER REFERENCE_FEATURE_V1 supportReference";
|
||||
|
||||
expect(renameReferenceFeature(source, "s001", context)).toBe(source);
|
||||
});
|
||||
|
||||
it("commits a baseline measured at 25 and 100 real-shape features, twice each", async () => {
|
||||
const baseline = JSON.parse(
|
||||
await readFile(FEATURE_SHAPE_BASELINE_PATH, "utf8"),
|
||||
) as Readonly<{
|
||||
environment: Readonly<Record<string, unknown>>;
|
||||
runs: readonly Run[];
|
||||
}>;
|
||||
expect(baseline.environment).toMatchObject({
|
||||
cpuModel: expect.any(String),
|
||||
logicalCpus: expect.any(Number),
|
||||
});
|
||||
|
||||
const bySize = (size: number) =>
|
||||
baseline.runs.filter((run) => run.addedFeatures === size);
|
||||
const [origin] = bySize(0);
|
||||
expect(origin?.tsc.passed).toBe(true);
|
||||
for (const size of [25, 100]) {
|
||||
const runs = bySize(size);
|
||||
// A failed typecheck is the result and is not repeated.
|
||||
expect(runs.length).toBeGreaterThanOrEqual(runs[0]?.tsc.passed ? 2 : 1);
|
||||
for (const run of runs) {
|
||||
// Every copy contributes the reference feature's own routes.
|
||||
expect((run.routes - origin!.routes) % size).toBe(0);
|
||||
expect(run.routes).toBeGreaterThan(origin!.routes);
|
||||
expect(run.build.lazyJavascriptFiles).toBeGreaterThan(
|
||||
origin!.build.lazyJavascriptFiles,
|
||||
);
|
||||
expect(run.loadBefore).toHaveLength(3);
|
||||
}
|
||||
// Compiler counts are deterministic; only times vary with the host.
|
||||
expect(new Set(runs.map((run) => run.tsc.instantiations)).size).toBe(1);
|
||||
}
|
||||
});
|
||||
|
||||
it("states in the acceptance matrix what the ceilings rest on", async () => {
|
||||
const acceptance = await readFile(
|
||||
"docs/reviews/2026-09-23-extreme-scale-acceptance.md",
|
||||
"utf8",
|
||||
);
|
||||
expect(acceptance).toContain(FEATURE_SHAPE_BASELINE_PATH);
|
||||
expect(acceptance).toMatch(/\| Growth axis \| Verified \| Condition \| Not verified \|/u);
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,24 @@
|
||||
import { lstat, mkdtemp, mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import {
|
||||
copyFile,
|
||||
lstat,
|
||||
mkdtemp,
|
||||
mkdir,
|
||||
readdir,
|
||||
readFile,
|
||||
rm,
|
||||
stat,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { linkFixtureNodeModules } from "../../scripts/lib/fixture-node-modules.ts";
|
||||
import {
|
||||
FIXTURE_PNPM_ENVIRONMENT,
|
||||
linkFixtureNodeModules,
|
||||
} from "../../scripts/lib/fixture-node-modules.ts";
|
||||
|
||||
/**
|
||||
* A removal or provider fixture runs `pnpm` inside a throwaway copy of the
|
||||
@@ -146,3 +160,128 @@ describe("fixture node_modules linking", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* F-4. pnpm 11 verifies the install before it runs a script and, finding the
|
||||
* fixture's copied state unfamiliar, installs. `.pnpm` and `.bin` are
|
||||
* directory links into the repository's own node_modules, so that install
|
||||
* rewrote the shared `.pnpm/lock.yaml` and bin shims. A fixture launched
|
||||
* through `pnpm <script>` inherited `pnpm_config_verify_deps_before_run=false`
|
||||
* from pnpm and was safe; the same fixture started directly
|
||||
* (`node scripts/run-vitest.ts run <file>`) was not.
|
||||
*/
|
||||
describe("pnpm inside a linked fixture (F-4)", () => {
|
||||
const scratch: string[] = [];
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
scratch.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
/** A tiny installed workspace standing in for the repository, offline. */
|
||||
async function installedSource() {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "fixture-pnpm-"));
|
||||
scratch.push(root);
|
||||
const tool = path.join(root, "tool");
|
||||
const source = path.join(root, "source");
|
||||
await mkdir(tool, { recursive: true });
|
||||
await mkdir(source, { recursive: true });
|
||||
await writeFile(
|
||||
path.join(tool, "package.json"),
|
||||
JSON.stringify({ name: "tool", version: "1.0.0", bin: { tool: "cli.js" } }),
|
||||
);
|
||||
await writeFile(path.join(tool, "cli.js"), "#!/usr/bin/env node\n");
|
||||
await writeFile(
|
||||
path.join(source, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "fixture-source",
|
||||
version: "1.0.0",
|
||||
private: true,
|
||||
packageManager: "pnpm@11.17.0",
|
||||
scripts: { hello: "echo hello-from-fixture" },
|
||||
dependencies: { tool: "file:../tool" },
|
||||
}),
|
||||
);
|
||||
await writeFile(path.join(source, "pnpm-workspace.yaml"), "allowBuilds: {}\n");
|
||||
const environment: NodeJS.ProcessEnv = {
|
||||
...pnpmFreeEnvironment(),
|
||||
pnpm_config_store_dir: path.join(root, "store"),
|
||||
};
|
||||
// Installed on a developer machine (no CI); the fixtures then run pnpm
|
||||
// with CI=true, which pnpm reads as different settings and reinstalls.
|
||||
const { CI: _ci, ...developer } = environment;
|
||||
const install = spawnSync("corepack", ["pnpm", "install", "--offline"], {
|
||||
cwd: source,
|
||||
encoding: "utf8",
|
||||
env: developer,
|
||||
});
|
||||
expect(install.status, install.stdout + install.stderr).toBe(0);
|
||||
return { root, source, environment };
|
||||
}
|
||||
|
||||
// The test runner itself may run under pnpm, which exports the setting.
|
||||
function pnpmFreeEnvironment(): NodeJS.ProcessEnv {
|
||||
const environment: NodeJS.ProcessEnv = { ...process.env, CI: "true" };
|
||||
delete environment.pnpm_config_verify_deps_before_run;
|
||||
return environment;
|
||||
}
|
||||
|
||||
async function sharedState(source: string) {
|
||||
const lock = await stat(path.join(source, "node_modules/.pnpm/lock.yaml"));
|
||||
const bin = await stat(path.join(source, "node_modules/.bin/tool"));
|
||||
return [lock.mtimeMs, lock.ino, bin.mtimeMs, bin.ino];
|
||||
}
|
||||
|
||||
async function runInFixture(
|
||||
root: string,
|
||||
source: string,
|
||||
environment: NodeJS.ProcessEnv,
|
||||
) {
|
||||
const fixture = path.join(root, `fixture-${scratch.length}-${Date.now()}`);
|
||||
await mkdir(fixture);
|
||||
for (const file of ["package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml"]) {
|
||||
await copyFile(path.join(source, file), path.join(fixture, file));
|
||||
}
|
||||
await linkFixtureNodeModules(fixture, source);
|
||||
const before = await sharedState(source);
|
||||
const result = spawnSync("corepack", ["pnpm", "hello"], {
|
||||
cwd: fixture,
|
||||
encoding: "utf8",
|
||||
env: environment,
|
||||
});
|
||||
return { result, changed: (await sharedState(source)).join() !== before.join() };
|
||||
}
|
||||
|
||||
it("installs through the linked directories unless told not to", async () => {
|
||||
const { root, source, environment } = await installedSource();
|
||||
|
||||
// The hazard: the default re-verification installs into the shared tree.
|
||||
expect((await runInFixture(root, source, environment)).changed).toBe(true);
|
||||
|
||||
const guarded = await runInFixture(root, source, {
|
||||
...environment,
|
||||
...FIXTURE_PNPM_ENVIRONMENT,
|
||||
});
|
||||
expect(guarded.result.status, guarded.result.stderr).toBe(0);
|
||||
expect(guarded.result.stdout).toContain("hello-from-fixture");
|
||||
expect(guarded.changed).toBe(false);
|
||||
}, 60_000);
|
||||
|
||||
it("is used by every fixture that links node_modules and runs pnpm", async () => {
|
||||
const listed = spawnSync(
|
||||
"git",
|
||||
["grep", "-l", "linkFixtureNodeModules(", "--", "scripts", "tests"],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
expect(listed.status, listed.stderr).toBe(0);
|
||||
const offenders: string[] = [];
|
||||
for (const file of listed.stdout.trim().split("\n")) {
|
||||
if (file === "scripts/lib/fixture-node-modules.ts") continue;
|
||||
if (file === "tests/unit/fixture-node-modules.test.ts") continue;
|
||||
const source = await readFile(file, "utf8");
|
||||
const runsPnpm = /\["pnpm"|\[pnpmCli\b/u.test(source);
|
||||
if (runsPnpm && !source.includes("FIXTURE_PNPM_ENVIRONMENT")) offenders.push(file);
|
||||
}
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { createServer, type Server } from "node:http";
|
||||
import type { AddressInfo } from "node:net";
|
||||
import path from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
assertPortUnused,
|
||||
assertServedRelease,
|
||||
previewArguments,
|
||||
summarizeSamples,
|
||||
} from "../../scripts/lib/lab-performance.ts";
|
||||
|
||||
/**
|
||||
* 11-07. The lab performance gate measured once, and measured whatever server
|
||||
* held its port: `vite preview` without `--strictPort` moved elsewhere and the
|
||||
* script never checked which build answered.
|
||||
*/
|
||||
const servers: Server[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
servers.splice(0).map(
|
||||
(server) => new Promise<void>((resolve) => server.close(() => resolve())),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
async function foreignServer(manifest: unknown): Promise<string> {
|
||||
const server = createServer((_request, response) => {
|
||||
response
|
||||
.writeHead(200, { "content-type": "application/json" })
|
||||
.end(JSON.stringify(manifest));
|
||||
});
|
||||
servers.push(server);
|
||||
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", () => resolve()));
|
||||
return `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
|
||||
}
|
||||
|
||||
describe("lab performance gate (11-07)", () => {
|
||||
it("starts the preview server on exactly the requested port", () => {
|
||||
expect(previewArguments(4173)).toEqual([
|
||||
"pnpm",
|
||||
"preview",
|
||||
"--host",
|
||||
"127.0.0.1",
|
||||
"--port",
|
||||
"4173",
|
||||
"--strictPort",
|
||||
]);
|
||||
});
|
||||
|
||||
it("summarizes repeated runs by their median and keeps every sample", () => {
|
||||
expect(summarizeSamples([326, 1103, 410, 390, 505])).toEqual({
|
||||
median: 410,
|
||||
min: 326,
|
||||
max: 1103,
|
||||
samples: [326, 1103, 410, 390, 505],
|
||||
});
|
||||
expect(summarizeSamples([1, 4, 2, 3]).median).toBe(2.5);
|
||||
expect(() => summarizeSamples([])).toThrow(RangeError);
|
||||
});
|
||||
|
||||
it("refuses a port that another server already answers on", async () => {
|
||||
const baseUrl = await foreignServer({});
|
||||
await expect(assertPortUnused(baseUrl)).rejects.toThrow(/another server/u);
|
||||
await expect(assertPortUnused("http://127.0.0.1:9")).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("refuses a server that serves a different build", async () => {
|
||||
const baseUrl = await foreignServer({ buildId: "other", releaseId: "r1" });
|
||||
await expect(
|
||||
assertServedRelease(baseUrl, { buildId: "measured", releaseId: "r1" }),
|
||||
).rejects.toThrow(/serves build other\/r1, not the measured measured\/r1/u);
|
||||
await expect(
|
||||
assertServedRelease(baseUrl, { buildId: "other", releaseId: "r1" }),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("fails the gate before measuring when its port is taken", async () => {
|
||||
const baseUrl = await foreignServer({ buildId: "other", releaseId: "r1" });
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[path.resolve("scripts/test-performance.ts")],
|
||||
{
|
||||
env: { ...process.env, LAB_PERFORMANCE_PORT: new URL(baseUrl).port },
|
||||
stdio: ["ignore", "ignore", "pipe"],
|
||||
},
|
||||
);
|
||||
let stderr = "";
|
||||
child.stderr.on("data", (chunk: Buffer) => {
|
||||
stderr += chunk.toString("utf8");
|
||||
});
|
||||
const code = await new Promise<number | null>((resolve) => {
|
||||
const timer = setTimeout(() => child.kill("SIGKILL"), 20_000);
|
||||
child.on("exit", (exitCode) => {
|
||||
clearTimeout(timer);
|
||||
resolve(exitCode);
|
||||
});
|
||||
});
|
||||
|
||||
expect(code).not.toBe(0);
|
||||
expect(stderr).toMatch(/another server holds the port/u);
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
import { mkdtemp, mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { mkdtemp, mkdir, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
buildRepositoryFileInventory,
|
||||
@@ -23,8 +23,19 @@ function gitResult(
|
||||
};
|
||||
}
|
||||
|
||||
// 00-03. Every temp root is removed after its test; they used to pile up in
|
||||
// /tmp by the thousand.
|
||||
const temporaryRoots: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporaryRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
async function repositoryFixture() {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "repository-inventory-"));
|
||||
temporaryRoots.push(root);
|
||||
await mkdir(path.join(root, "src"));
|
||||
await mkdir(path.join(root, "docs"));
|
||||
await writeFile(path.join(root, "src", "tracked.ts"), "tracked\n");
|
||||
@@ -203,6 +214,7 @@ describe("repository file inventory", () => {
|
||||
it("rejects a tracked symlink whose real path escapes the repository", async () => {
|
||||
const repositoryRoot = await repositoryFixture();
|
||||
const outside = await mkdtemp(path.join(tmpdir(), "inventory-outside-"));
|
||||
temporaryRoots.push(outside);
|
||||
await writeFile(path.join(outside, "secret.ts"), "secret\n");
|
||||
await symlink(
|
||||
path.join(outside, "secret.ts"),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
@@ -80,10 +80,19 @@ describe("SW-RR-03 one authoritative cacheable asset table", () => {
|
||||
* had just produced, failing the release build at install time.
|
||||
*/
|
||||
describe("SW-02 the generator and the decoder share one path grammar", () => {
|
||||
// 00-03. The dist fixtures used to stay in /tmp.
|
||||
const temporaryRoots: string[] = [];
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporaryRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
async function distWith(
|
||||
files: Readonly<Record<string, string>>,
|
||||
): Promise<string> {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "sw-assets-"));
|
||||
temporaryRoots.push(root);
|
||||
for (const [relative, content] of Object.entries(files)) {
|
||||
const absolute = path.join(root, relative);
|
||||
await mkdir(path.dirname(absolute), { recursive: true });
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { afterAll, describe, expect, it } from "vitest";
|
||||
|
||||
const FORBIDDEN = "tests/fixtures/test-evidence/forbidden";
|
||||
const roots: string[] = [];
|
||||
|
||||
afterAll(async () => {
|
||||
await Promise.all(roots.map((root) => rm(root, { recursive: true, force: true })));
|
||||
});
|
||||
|
||||
function checkSource(sourceRoot: string) {
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
"scripts/check-test-evidence.ts",
|
||||
"--source-only",
|
||||
"--source-root",
|
||||
sourceRoot,
|
||||
"--artifact",
|
||||
"artifacts/quality/test-evidence-source-rules.json",
|
||||
],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
return { status: result.status, stderr: result.stderr };
|
||||
}
|
||||
|
||||
// 11-08. Each forbidden fixture is checked alone, so a rule that stops firing
|
||||
// is not hidden by another fixture in the same directory still failing.
|
||||
describe("test evidence source rules", () => {
|
||||
it("rejects a focused test", () => {
|
||||
const result = checkSource(`${FORBIDDEN}/focused-test.fixture`);
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stderr).toContain("focused test");
|
||||
}, 30_000);
|
||||
|
||||
it("rejects a quarantine whose expiry date has passed", () => {
|
||||
const result = checkSource(`${FORBIDDEN}/expired-quarantine.fixture`);
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stderr).toContain("quarantine expired on 2020-01-01");
|
||||
}, 30_000);
|
||||
|
||||
it("rejects a skip without a quarantine", () => {
|
||||
const result = checkSource(`${FORBIDDEN}/unowned-skip.fixture`);
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stderr).toContain("lacks owned expiring quarantine");
|
||||
}, 30_000);
|
||||
|
||||
it("accepts a skip under an unexpired quarantine", async () => {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "test-evidence-quarantine-"));
|
||||
roots.push(root);
|
||||
const file = path.join(root, "quarantined.fixture");
|
||||
// Built from parts so this file is not itself a skip the checker scans.
|
||||
const skip = ["test", "skip"].join(".");
|
||||
await writeFile(
|
||||
file,
|
||||
[
|
||||
`// ${"quarantine"}(owner=frontend-platform, defect=open-fixture, expires=2999-12-31)`,
|
||||
`${skip}("quarantined", async () => {});`,
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
const result = checkSource(file);
|
||||
expect(result.stderr).toBe("");
|
||||
expect(result.status).toBe(0);
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
// tests/setup.ts restores real timers after every test, so a test that fails
|
||||
// before its own vi.useRealTimers() does not hand fake timers to the next one.
|
||||
describe("global test setup", () => {
|
||||
it("may end with fake timers still installed", () => {
|
||||
vi.useFakeTimers();
|
||||
expect(vi.isFakeTimers()).toBe(true);
|
||||
});
|
||||
|
||||
it("starts the next test on real timers", () => {
|
||||
expect(vi.isFakeTimers()).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user