mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
* refactor(errors): compose multi-part provider cleanup failures through one owner CdpBrowserProvider, CdpElectronProvider, FridaInstrumentationManager and PlaywrightBrowserScenarioProvider each built the same composite by hand: a ProviderCleanupError listing the parts' resources, an AggregateError cause, and bindCleanupDependencies over the parts. providerCleanupErrorFromFailures in src/domain/analysisErrorCleanup.ts now owns that composition. `causes` keeps non-AnalysisError failures in the aggregate cause without making them own completion, as the CDP providers did; `message` keeps the aggregate messages Frida and Playwright used. Tests: helper unit tests, new close-composition tests for both CDP providers, and a Playwright test with two failed cleanup retries. They pass on the base revision and on this change, and fail when the helper drops the dependency binding, the extra causes or the message. Lowers the cleanup-dependency-binding baseline to 43 files / 73 sites. Refs #11859 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style(test): format the Playwright cleanup test with oxfmt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(errors): assert cleanup composition facts instead of reason prose Follows docs/development/testing.md: the close-composition tests now check provider, operation, resources, aggregate causes and completion, not the explanatory reason or aggregate message. A harmless wording change passes; a lost binding, lost cause or wrong operation still fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Anant Mandanka <anant.mandanka@renaissancejewel.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
116 lines
3.8 KiB
TypeScript
116 lines
3.8 KiB
TypeScript
import { expect, it, onTestFinished, vi } from "vitest";
|
|
|
|
import { CdpBrowserProvider } from "../../../src/browser/CdpBrowserProvider.js";
|
|
import { CdpElectronProvider } from "../../../src/browser/CdpElectronProvider.js";
|
|
import { CdpTargetSessionOwner } from "../../../src/browser/CdpTargetSessionOwner.js";
|
|
import { ElectronFileScope } from "../../../src/browser/ElectronFileScope.js";
|
|
import { IsolatedWebBundleAnalyzer } from "../../../src/browser/IsolatedWebBundleAnalyzer.js";
|
|
import { ProviderCleanupError } from "../../../src/domain/providerCleanupError.js";
|
|
import { releaseOwnedCleanup } from "../../support/cleanupRelease.js";
|
|
|
|
const cleanupFailure = (resource: string) =>
|
|
new ProviderCleanupError(
|
|
"fixture",
|
|
[resource],
|
|
{ reason: `${resource} remains owned` },
|
|
{ operation: "fixture_close" },
|
|
);
|
|
|
|
const closeFailure = async (close: () => Promise<void>): Promise<unknown> => {
|
|
try {
|
|
await close();
|
|
} catch (cause: unknown) {
|
|
return cause;
|
|
}
|
|
throw new Error("Expected close to fail");
|
|
};
|
|
|
|
const providers = [
|
|
{
|
|
name: "CdpBrowserProvider",
|
|
providerId: "rea-cdp-browser",
|
|
operation: "analyze_web_bundle",
|
|
create: () => new CdpBrowserProvider(),
|
|
failSecondClose: (cause: unknown) =>
|
|
vi
|
|
.spyOn(IsolatedWebBundleAnalyzer.prototype, "close")
|
|
.mockRejectedValueOnce(cause),
|
|
},
|
|
{
|
|
name: "CdpElectronProvider",
|
|
providerId: "rea-cdp-electron",
|
|
operation: "inspect_electron_page",
|
|
create: () => new CdpElectronProvider(),
|
|
failSecondClose: (cause: unknown) =>
|
|
vi
|
|
.spyOn(ElectronFileScope.prototype, "retryCleanup")
|
|
.mockRejectedValueOnce(cause),
|
|
},
|
|
] as const;
|
|
|
|
it.each(providers)(
|
|
"$name keeps both close failures and completes only after both release",
|
|
async ({ providerId, operation, create, failSecondClose }) => {
|
|
onTestFinished(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
const transport = cleanupFailure("transport-handle");
|
|
const second = cleanupFailure("second-handle");
|
|
vi.spyOn(CdpTargetSessionOwner.prototype, "close").mockRejectedValueOnce(
|
|
transport,
|
|
);
|
|
failSecondClose(second);
|
|
const provider = create();
|
|
|
|
const composite = await closeFailure(() => provider.close());
|
|
|
|
if (!(composite instanceof ProviderCleanupError))
|
|
throw new Error("Expected a provider cleanup failure");
|
|
expect(composite).toMatchObject({
|
|
providerId,
|
|
operation,
|
|
cleanupIncomplete: true,
|
|
cleanupResources: ["transport-handle", "second-handle"],
|
|
});
|
|
expect(composite.cause).toBeInstanceOf(AggregateError);
|
|
expect((composite.cause as AggregateError).errors).toEqual([
|
|
transport,
|
|
second,
|
|
]);
|
|
|
|
releaseOwnedCleanup(transport);
|
|
expect(composite.cleanupIncomplete).toBe(true);
|
|
releaseOwnedCleanup(second);
|
|
expect(composite.cleanupIncomplete).toBe(false);
|
|
},
|
|
);
|
|
|
|
it.each(providers)(
|
|
"$name keeps an untyped close failure in the cause without owning its completion",
|
|
async ({ create, failSecondClose }) => {
|
|
onTestFinished(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
const transport = cleanupFailure("transport-handle");
|
|
const untyped = new Error("untyped close failure");
|
|
vi.spyOn(CdpTargetSessionOwner.prototype, "close").mockRejectedValueOnce(
|
|
transport,
|
|
);
|
|
failSecondClose(untyped);
|
|
const provider = create();
|
|
|
|
const composite = await closeFailure(() => provider.close());
|
|
|
|
if (!(composite instanceof ProviderCleanupError))
|
|
throw new Error("Expected a provider cleanup failure");
|
|
expect(composite.cleanupResources).toEqual(["transport-handle"]);
|
|
expect((composite.cause as AggregateError).errors).toEqual([
|
|
transport,
|
|
untyped,
|
|
]);
|
|
expect(composite.cleanupIncomplete).toBe(true);
|
|
releaseOwnedCleanup(transport);
|
|
expect(composite.cleanupIncomplete).toBe(false);
|
|
},
|
|
);
|