mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
Builder E2E still takes too long. The goal is all 145 cases under 3 minutes end to end, with exactly ten shards and the same UI, MCP, and generated Preview checks. This PR has not met that goal. ### Measured results - Initial green CI run: 9m43s from build start to the last shard; slowest test step 439s. - Best green run after replacing repeated UI project setup: about 5m35s; slowest test step 250s. - Best green run (393e51c): about 4m59s; slowest test step 201s. The two-file rebalance reduced the prior green run by about 50s. The 3-minute goal remains unmet. - Latest green run (de2f4ed): about 5m56s; slowest test step 257s. All ten shards and required workflows passed. The preceding green run took about 6m09s, showing substantial run-to-run variation. - The 119 content-mode project setup calls fell from 599s to 23.5s of aggregate worker time by using the app's dev login and project creation API. The sum of shard test steps fell from 2,178s to 1,721s in the first run with this change. Per-shard wall time still varies substantially between runs. - The shared build takes about 85s, including roughly 30s of setup and 51s of Builder compilation. During tests, the four-CPU shard runners showed 27–52% CPU scheduling pressure and 0% memory pressure; peak memory was unavailable. ### Changes - Cache the test schema and share one Builder build artifact across ten shards. Shard setup overlaps the build; each shard still starts an isolated database. - Keep real MCP and browser sessions alive for repeated Preview submissions, and reuse generated Previews where checks can share one. - Give independent cases separate projects and run them within the existing shard workers. Keep exactly ten shards. - Create content-mode fixture projects through the app's normal login and project API, using its CSRF token. Dedicated UI project creation remains in the Builder project fixture. - Capture managed Form responses before fast redirects discard their bodies. Fix drag targeting and unique drag fixture IDs. - Report CPU and memory pressure for every shard. Allow the MCP browser startup enough time under CI load. An earlier shard rebalance worsened the run and was reverted; a measured two-file rebalance improved the slowest shard without changing test logic. ### Verification and remaining work Focused local runs passed for a single project, three projects sharing one session, a paid-plan MCP project, and the MCP Preview form case. Builder and Vision typechecks, lint, formatting, the ten-shard matrix check, and Vision regression tests passed. All required workflows passed onde2f4ed. The latest review fix also passed all 63 Vision tests, Vision typecheck, lint, and formatting locally. - [x] Profile the full suite and measure complete ten-shard CI runs. - [x] Remove repeated UI project setup from the shared fixture. - [x] Measure CPU and memory pressure in CI. - [ ] Reduce Builder interactions, generated Preview work, and build time enough to finish under 3 minutes. - [x] Resolve five review threads and verify the affected paths. - [x] Check authoritative Builder documentation; these test harness and capture fixes do not change user-facing behavior or documentation. CI still checks out and installs dependencies, builds Builder, uploads and downloads its artifact, starts a database for each shard, and runs real browsers and generated production Previews. Warm caches remove downloads and schema generation, but do not remove setup, compilation, browser work, or cache transfers. No product behavior or authoritative documentation changed.
168 lines
4.9 KiB
TypeScript
168 lines
4.9 KiB
TypeScript
import { EventEmitter } from "node:events";
|
|
import type { ChildProcess } from "node:child_process";
|
|
import { expect, test, vi } from "vitest";
|
|
import { closeChildProcessInput, stopChildProcess } from "./process";
|
|
|
|
const createChild = () => {
|
|
const child = new EventEmitter() as ChildProcess;
|
|
Object.defineProperties(child, {
|
|
exitCode: { value: null, writable: true },
|
|
signalCode: { value: null, writable: true },
|
|
});
|
|
child.kill = vi.fn(() => true);
|
|
return child;
|
|
};
|
|
|
|
test("stops a child gracefully without escalating", async () => {
|
|
const child = createChild();
|
|
vi.mocked(child.kill).mockImplementation((signal) => {
|
|
Object.defineProperty(child, "signalCode", {
|
|
value: signal,
|
|
writable: true,
|
|
});
|
|
child.emit("exit", null, signal);
|
|
return true;
|
|
});
|
|
|
|
await stopChildProcess(child, { timeoutMs: 1 });
|
|
|
|
expect(child.kill).toHaveBeenCalledTimes(1);
|
|
expect(child.kill).toHaveBeenCalledWith("SIGTERM");
|
|
});
|
|
|
|
test("closes child input and waits for cleanup", async () => {
|
|
const child = createChild();
|
|
const end = vi.fn(() => {
|
|
queueMicrotask(() => {
|
|
Object.defineProperty(child, "exitCode", { value: 0, writable: true });
|
|
child.emit("close", 0, null);
|
|
});
|
|
});
|
|
Object.defineProperty(child, "stdin", { value: { end } });
|
|
|
|
await closeChildProcessInput(child, 10);
|
|
|
|
expect(end).toHaveBeenCalledOnce();
|
|
expect(child.kill).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("forces a child to stop if closing input stalls", async () => {
|
|
const child = createChild();
|
|
const end = vi.fn();
|
|
Object.defineProperty(child, "stdin", { value: { end } });
|
|
vi.mocked(child.kill).mockImplementation((signal) => {
|
|
Object.defineProperty(child, "signalCode", {
|
|
value: signal,
|
|
writable: true,
|
|
});
|
|
child.emit("close", null, signal);
|
|
return true;
|
|
});
|
|
|
|
await closeChildProcessInput(child, 1);
|
|
|
|
expect(end).toHaveBeenCalledOnce();
|
|
expect(child.kill).toHaveBeenCalledWith("SIGTERM");
|
|
});
|
|
|
|
test("escalates a child that ignores SIGTERM", async () => {
|
|
const child = createChild();
|
|
vi.mocked(child.kill).mockImplementation((signal) => {
|
|
if (signal === "SIGKILL") {
|
|
Object.defineProperty(child, "signalCode", {
|
|
value: signal,
|
|
writable: true,
|
|
});
|
|
child.emit("exit", null, signal);
|
|
}
|
|
return true;
|
|
});
|
|
|
|
await stopChildProcess(child, { timeoutMs: 1 });
|
|
|
|
expect(child.kill).toHaveBeenNthCalledWith(1, "SIGTERM");
|
|
expect(child.kill).toHaveBeenNthCalledWith(2, "SIGKILL");
|
|
});
|
|
|
|
test("rejects when a child remains alive after SIGKILL", async () => {
|
|
const child = createChild();
|
|
Object.defineProperty(child, "pid", { value: 42 });
|
|
|
|
await expect(stopChildProcess(child, { timeoutMs: 1 })).rejects.toThrow(
|
|
"Child process 42 did not exit after SIGKILL"
|
|
);
|
|
|
|
expect(child.kill).toHaveBeenNthCalledWith(1, "SIGTERM");
|
|
expect(child.kill).toHaveBeenNthCalledWith(2, "SIGKILL");
|
|
});
|
|
|
|
test.runIf(process.platform !== "win32")(
|
|
"signals the detached process group used by generated previews",
|
|
async () => {
|
|
const child = createChild();
|
|
Object.defineProperty(child, "pid", { value: 42 });
|
|
let groupRunning = true;
|
|
const kill = vi
|
|
.spyOn(process, "kill")
|
|
.mockImplementation((_pid, signal) => {
|
|
if (signal === 0) {
|
|
if (groupRunning) {
|
|
return true;
|
|
}
|
|
throw Object.assign(new Error("Process group not found"), {
|
|
code: "ESRCH",
|
|
});
|
|
}
|
|
if (signal === "SIGKILL") {
|
|
groupRunning = false;
|
|
Object.defineProperty(child, "signalCode", {
|
|
value: signal,
|
|
writable: true,
|
|
});
|
|
child.emit("exit", null, signal);
|
|
}
|
|
return true;
|
|
});
|
|
|
|
await stopChildProcess(child, { killGroup: true, timeoutMs: 1 });
|
|
|
|
expect(kill).toHaveBeenCalledWith(-42, "SIGTERM");
|
|
expect(kill).toHaveBeenCalledWith(-42, "SIGKILL");
|
|
expect(child.kill).not.toHaveBeenCalled();
|
|
kill.mockRestore();
|
|
}
|
|
);
|
|
|
|
test.runIf(process.platform !== "win32")(
|
|
"uses the child state when a stopped process group cannot be probed",
|
|
async () => {
|
|
const child = createChild();
|
|
Object.defineProperty(child, "pid", { value: 42 });
|
|
let signalSent = false;
|
|
const kill = vi
|
|
.spyOn(process, "kill")
|
|
.mockImplementation((_pid, signal) => {
|
|
if (signal === 0 && signalSent) {
|
|
throw Object.assign(new Error("Process group cannot be probed"), {
|
|
code: "EPERM",
|
|
});
|
|
}
|
|
if (signal === "SIGTERM") {
|
|
signalSent = true;
|
|
Object.defineProperty(child, "signalCode", {
|
|
value: signal,
|
|
writable: true,
|
|
});
|
|
child.emit("exit", null, signal);
|
|
}
|
|
return true;
|
|
});
|
|
|
|
await stopChildProcess(child, { killGroup: true, timeoutMs: 1 });
|
|
|
|
expect(kill).toHaveBeenCalledWith(-42, "SIGTERM");
|
|
expect(child.kill).not.toHaveBeenCalled();
|
|
kill.mockRestore();
|
|
}
|
|
);
|