mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
* refactor(errors): give caller aborts a typed reason at the adapters Squashes 908813551f, 87858de4dc (fix(mcp): preserve cancellation reasons in handlers) and fa151dc3f6 (test(server): race handler-entry gates against the triggering tool call) onto main without #10566's pre-squash commits. * refactor(errors): give owner-initiated aborts a typed reason outside the browser adapters (#10692) * refactor(errors): give owner-initiated aborts a typed reason outside the browser adapters * refactor(verify): keep the abort-reason scan receiver-independent Playwright's route.abort takes a network error code; the one call site now names its default code instead of the guard exempting a variable name. * refactor(browser): give owner-initiated CDP aborts typed reasons (#10706) * refactor(browser): give owner-initiated CDP aborts typed reasons * fix(browser): give the page-side request fetch page-native abort reasons The request callback runs in the page through page.evaluate and cannot reach REA's modules. Define its deadline and cleanup reasons as DOMExceptions inside the callback, and make the test fake evaluate the callback from its source so module imports are unavailable, as in a page. * test(process): expect the reader close's typed owner reason Closing the Darwin run-token reader aborts its compilation with OwnerCancellation.ownerClosed since the owner-abort change in this PR; the boundary test still expected the default DOMException. * fix(server): report HTTP session replacement and shutdown to pending tools as an owner close
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { EventEmitter } from "node:events";
|
|
import { expect, it } from "vitest";
|
|
import {
|
|
withCommandCancellation,
|
|
type CommandCancellationHost,
|
|
} from "../../../src/cli/commandCancellation.js";
|
|
import { CallerAbort } from "../../../src/domain/analysisErrorCore.js";
|
|
|
|
it.each([
|
|
["SIGINT", 130, "interrupt"],
|
|
["SIGTERM", 143, "terminate"],
|
|
] as const)(
|
|
"awaits cleanup after %s and removes its listeners",
|
|
async (event, expectedExit, expectedKind) => {
|
|
const events = new EventEmitter();
|
|
const host: CommandCancellationHost = {
|
|
on: events.on.bind(events),
|
|
off: events.off.bind(events),
|
|
};
|
|
let cleaned = false;
|
|
let reason: unknown;
|
|
const operation = withCommandCancellation(async (signal) => {
|
|
await new Promise<void>((resolve) =>
|
|
signal.addEventListener("abort", () => resolve(), { once: true }),
|
|
);
|
|
reason = signal.reason;
|
|
cleaned = true;
|
|
return "cancelled after cleanup";
|
|
}, host);
|
|
expect(host.exitCode).toBeUndefined();
|
|
events.emit(event);
|
|
expect(await operation).toBe("cancelled after cleanup");
|
|
expect(cleaned).toBe(true);
|
|
// The adapter names its caller; a platform AbortError shape is kept.
|
|
expect(reason).toBeInstanceOf(CallerAbort);
|
|
expect(reason).toMatchObject({ kind: expectedKind, name: "AbortError" });
|
|
expect(host.exitCode).toBe(expectedExit);
|
|
expect(events.listenerCount("SIGINT")).toBe(0);
|
|
expect(events.listenerCount("SIGTERM")).toBe(0);
|
|
},
|
|
);
|
|
|
|
it("leaves the exit code alone on success and removes listeners when execution throws", async () => {
|
|
const events = new EventEmitter();
|
|
const host: CommandCancellationHost = {
|
|
on: events.on.bind(events),
|
|
off: events.off.bind(events),
|
|
exitCode: 0,
|
|
};
|
|
expect(await withCommandCancellation(async () => "success", host)).toBe(
|
|
"success",
|
|
);
|
|
expect(host.exitCode).toBe(0);
|
|
await expect(
|
|
withCommandCancellation(async () => {
|
|
throw new Error("fixture failure");
|
|
}, host),
|
|
).rejects.toThrow("fixture failure");
|
|
expect(events.listenerCount("SIGINT")).toBe(0);
|
|
expect(events.listenerCount("SIGTERM")).toBe(0);
|
|
});
|