mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 19:51:20 -05:00
fix(lifecycle): supervise assetutil, keep cleanup-time interruptions, and cover browser-transport handshakes (#11502)
* test(lifecycle): cover browser-transport handshakes and cleanup retry Close six provider lifecycle gaps: Electron CDP handshake, cleanup and retry; V8 inspector handshake; web-module-trace handshake and retry. * test(lifecycle): assert retained cleanup finishes before the next acquisition Hold the retried browser and Electron transport close and check that no replacement launch or connect starts until it completes. Track gated upgrade sockets in the fake CDP browser so close() destroys them. * test(lifecycle): release held retry gates and join gated work on failure Teardown for the resolver and Electron retry tests releases the held close and awaits the gated request even when an assertion fails while it is held. * test(lifecycle): cover worker and tool launch, worker handshake, and decoder completion (#11512) * test(lifecycle): cover worker and tool launch, worker handshake, and decoder completion Close six provider lifecycle gaps: SQLite and JavaScript worker launch, JavaScript worker handshake, assetutil launch, and qlog and mitmproxy decoding through the owned decoder child. * test(lifecycle): run the worker relaunch in a built project and check exits before close The relaunch starts the built worker entry, so it moves to tests/boundary/javascript. The handshake tests now check that the stand-in child has exited when analyze() returns, before close() runs. * test(lifecycle): cover in-process cancellation and PE certificate completion (#11524) * test(lifecycle): cover in-process cancellation and PE certificate completion Close six provider lifecycle gaps: caller cancellation for the managed, Harmony, JavaScript workflow, runtime reconciliation and V8 code cache providers, and PE certificate completion (an existing CLI/MCP regression). Two Apple application gaps remain (#11509). * test(lifecycle): compare the whole retained V8 code cache observation * test(javascript): hold the startup deadline clock until the stand-in worker is running * test(javascript): restore real timers in a void teardown * test(lifecycle): join the held Electron request on failure, refuse unmodeled Inspector commands, drop a wording assertion * fix(apple): run assetutil under owned process supervision and retain unproven cleanup (#11586) * fix(process): report a cancellation or deadline during refused final cleanup as that interruption * fix(apple): prepare ownership before the assetutil deadline, keep per-stream allowances, join interrupted-cleanup tests * fix(artifacts): classify assetutil launch failures through the shared launch owner After #11615, owned-command launch failures are one launch-failed outcome classified by the shared owner. The assetutil dialect keeps only its unavailable report (launchUnavailable) and names its provider; host capacity and E2BIG become resource constraints. * fix(artifacts): keep a completed assetutil run's output on its cleanup-only report When assetutil exits 0 but its process cleanup is unproven, the cleanup error is the primary report. retainOwnedCommandCleanup now accepts the completed run's captured output for such a caller, so CLI and MCP keep the retained output beside the cleanup owner.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, describe, expect, it, onTestFinished, vi } from "vitest";
|
||||
import {
|
||||
NativeModuleResolver,
|
||||
type ModuleResolverLauncher,
|
||||
@@ -7,52 +7,60 @@ import { webModuleResolutionObservationSchema } from "../../domain/webModuleTrac
|
||||
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
|
||||
|
||||
import { completedModuleResolverLauncher } from "../../../tests/fixtures/webModuleTrace.js";
|
||||
import {
|
||||
controlledCleanup,
|
||||
phaseGate,
|
||||
} from "../../../tests/support/lifecycleHarness.js";
|
||||
|
||||
const input = {
|
||||
importerUrl: "https://app.test/main.js",
|
||||
importMap: null,
|
||||
specifiers: ["./dep.js"],
|
||||
};
|
||||
describe("native module resolver cleanup ownership", () => {
|
||||
it.each([false, true])(
|
||||
"awaits owned cleanup when acquisition is cancelled (cleanup fails: %s)",
|
||||
async (cleanupFails) => {
|
||||
const controller = new AbortController();
|
||||
let closed = false;
|
||||
const provider = new NativeModuleResolver(
|
||||
{ REA_BROWSER_EXECUTABLE: "/browser" },
|
||||
() => {
|
||||
controller.abort();
|
||||
return Promise.resolve({
|
||||
version: () => "fixture",
|
||||
newContext: () => {
|
||||
throw new Error("must not acquire context");
|
||||
},
|
||||
close: () => {
|
||||
closed = true;
|
||||
if (cleanupFails)
|
||||
return Promise.reject(new Error("fixture cleanup refusal"));
|
||||
return Promise.resolve();
|
||||
},
|
||||
});
|
||||
/** The browser connection completes after the caller cancelled acquisition. */
|
||||
const resolveWithLateBrowserConnection = async (
|
||||
cleanupFails: boolean,
|
||||
): Promise<void> => {
|
||||
const controller = new AbortController();
|
||||
let closed = false;
|
||||
const provider = new NativeModuleResolver(
|
||||
{ REA_BROWSER_EXECUTABLE: "/browser" },
|
||||
() => {
|
||||
controller.abort();
|
||||
return Promise.resolve({
|
||||
version: () => "fixture",
|
||||
newContext: () => {
|
||||
throw new Error("must not acquire context");
|
||||
},
|
||||
close: () => {
|
||||
closed = true;
|
||||
if (cleanupFails)
|
||||
return Promise.reject(new Error("fixture cleanup refusal"));
|
||||
return Promise.resolve();
|
||||
},
|
||||
);
|
||||
const result = await provider.resolve(input, {
|
||||
signal: controller.signal,
|
||||
});
|
||||
expect(closed).toBe(true);
|
||||
if (result.ok) throw new Error("expected cancelled result");
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected.code).toBe(
|
||||
cleanupFails ? "cleanup_incomplete" : "cancelled",
|
||||
);
|
||||
if (cleanupFails) {
|
||||
expect(projected.details).toMatchObject({
|
||||
diagnostics: { primary_error: { code: "cancelled" } },
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
const result = await provider.resolve(input, {
|
||||
signal: controller.signal,
|
||||
});
|
||||
expect(closed).toBe(true);
|
||||
if (result.ok) throw new Error("expected cancelled result");
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected.code).toBe(
|
||||
cleanupFails ? "cleanup_incomplete" : "cancelled",
|
||||
);
|
||||
if (cleanupFails) {
|
||||
expect(projected.details).toMatchObject({
|
||||
diagnostics: { primary_error: { code: "cancelled" } },
|
||||
});
|
||||
}
|
||||
};
|
||||
describe("native module resolver cleanup ownership", () => {
|
||||
it("closes a browser whose connection completes after cancellation", () =>
|
||||
resolveWithLateBrowserConnection(false));
|
||||
it("reports failed cleanup of a browser whose connection completes after cancellation", () =>
|
||||
resolveWithLateBrowserConnection(true));
|
||||
it("returns cleanup_incomplete when owned cleanup fails after an engine error", async () => {
|
||||
let launches = 0;
|
||||
let closes = 0;
|
||||
@@ -107,6 +115,58 @@ describe("native module resolver cleanup ownership", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("native module resolver cleanup retry", () => {
|
||||
it("retries retained browser cleanup before launching the next resolution", async () => {
|
||||
let launches = 0;
|
||||
const cleanup = controlledCleanup({
|
||||
refused: true,
|
||||
failure: new Error("fixture owned cleanup refusal"),
|
||||
});
|
||||
const retriedClose = phaseGate<number>();
|
||||
const completed = completedModuleResolverLauncher(input, async () => {});
|
||||
const provider = new NativeModuleResolver(
|
||||
{ REA_BROWSER_EXECUTABLE: "/browser" },
|
||||
async (...args) => {
|
||||
launches += 1;
|
||||
if (launches > 1) return completed(...args);
|
||||
return {
|
||||
version: () => "fixture",
|
||||
newContext: () =>
|
||||
Promise.reject(new Error("fixture context failure")),
|
||||
close: () => cleanup.close(() => retriedClose.hold(launches)),
|
||||
};
|
||||
},
|
||||
);
|
||||
let retrying: ReturnType<NativeModuleResolver["resolve"]> | undefined;
|
||||
// Release the held close and join the gated request even when an
|
||||
// assertion fails while it is held.
|
||||
onTestFinished(async () => {
|
||||
cleanup.allow();
|
||||
retriedClose.release();
|
||||
await retrying?.catch(() => undefined);
|
||||
await provider.close();
|
||||
});
|
||||
const first = await provider.resolve(input);
|
||||
if (first.ok) throw new Error("expected retained browser cleanup");
|
||||
expect(first.error.cleanupIncomplete).toBe(true);
|
||||
cleanup.allow();
|
||||
retrying = provider.resolve(input);
|
||||
// The retained close is still running: no replacement browser yet.
|
||||
expect(
|
||||
await retriedClose.reached(retrying, "retained browser close retry"),
|
||||
).toBe(1);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
expect(launches).toBe(1);
|
||||
retriedClose.release();
|
||||
const retried = await retrying;
|
||||
if (!retried.ok) throw retried.error;
|
||||
expect(cleanup.attempts).toBe(2);
|
||||
expect(launches).toBe(2);
|
||||
expect(first.error.cleanupIncomplete).toBe(false);
|
||||
expect(first.error.cleanupResources).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("native module resolver shutdown admission", () => {
|
||||
it("awaits acquisition and cleanup while refusing queued work during shutdown", async () => {
|
||||
let acquired: () => void = () => {
|
||||
|
||||
Reference in New Issue
Block a user