test(lifecycle): align cleanup fixtures with owned resource contracts
This commit is contained in:
1 parent
e389d6ea4e
commit
54a663ddd5
4 files changed
+48
-19
No files matched your search
@@ -420,7 +420,9 @@ it("retains exact caller cancellation after a real ZIP member opens and leaves a
|
||||
expect(translateArtifactFailure("extract_artifact", failure).cause).toBe(
|
||||
reason,
|
||||
);
|
||||
await expect(reader.open(entry, controller.signal)).rejects.toMatchObject({
|
||||
await expect(
|
||||
Promise.resolve().then(() => reader.open(entry, controller.signal)),
|
||||
).rejects.toMatchObject({
|
||||
reason: "cancelled",
|
||||
cancellation: { reason },
|
||||
});
|
||||
|
||||
@@ -144,7 +144,7 @@ it("retains Inspector scripts and contexts when final ASAR authorization cannot
|
||||
if (!control.ok) throw control.error;
|
||||
expect(control.value.normalized_result).toMatchObject({
|
||||
scripts: { observed_total: 1 },
|
||||
execution_contexts: [{ name: "main" }],
|
||||
execution_contexts: [{ name: "node[fixture]" }],
|
||||
});
|
||||
await prependAsarJsonWhitespace(archive, " ");
|
||||
handleState.failCloseCount = 1;
|
||||
@@ -153,11 +153,15 @@ it("retains Inspector scripts and contexts when final ASAR authorization cannot
|
||||
if (result.ok) throw new Error("Expected descriptor close failure");
|
||||
expect(result.error.cleanupIncomplete).toBe(true);
|
||||
expect(result.error.partialObservation).toMatchObject({
|
||||
scripts: {
|
||||
observed_total: 1,
|
||||
items: [{ location: { kind: "unresolved", reported_url: scriptUrl } }],
|
||||
normalized_result: {
|
||||
scripts: {
|
||||
observed_total: 1,
|
||||
items: [
|
||||
{ location: { kind: "unresolved", reported_url: scriptUrl } },
|
||||
],
|
||||
},
|
||||
execution_contexts: [{ name: "node[fixture]" }],
|
||||
},
|
||||
execution_contexts: [{ name: "main" }],
|
||||
});
|
||||
await provider.close();
|
||||
expect(result.error.cleanupIncomplete).toBe(false);
|
||||
@@ -408,7 +412,7 @@ it.each(["completed", "read-failed", "cancelled"] as const)(
|
||||
const origin = result.error.cleanupPrimary ?? result.error;
|
||||
expect(origin.diagnostics).toMatchObject({
|
||||
completed_prefix: {
|
||||
examined_targets: 2,
|
||||
examined_targets: 1,
|
||||
allowed_targets: [{ target_id: "page-0", file_path: page }],
|
||||
coverage: expect.stringContaining("remaining targets are unknown"),
|
||||
},
|
||||
|
||||
@@ -13,6 +13,7 @@ const mocks = vi.hoisted(() => ({
|
||||
| {
|
||||
initialize: ReturnType<typeof vi.fn>;
|
||||
settle: ReturnType<typeof vi.fn>;
|
||||
limitations: ReturnType<typeof vi.fn>;
|
||||
close: ReturnType<typeof vi.fn>;
|
||||
limitations: ReturnType<typeof vi.fn>;
|
||||
}
|
||||
@@ -27,9 +28,16 @@ const mocks = vi.hoisted(() => ({
|
||||
}));
|
||||
|
||||
vi.mock("./CdpTargetSession.js", () => ({
|
||||
openCdpEndpoint: async () => ({
|
||||
discovery: { targets: [{ id: "target" }] },
|
||||
connection: {
|
||||
openCdpEndpoint: async (
|
||||
_endpoint: unknown,
|
||||
operation: Parameters<
|
||||
import("./CdpTargetSessionOwner.js").CdpTargetSessionOwner["register"]
|
||||
>[1],
|
||||
_signal: unknown,
|
||||
_limits: unknown,
|
||||
owner: import("./CdpTargetSessionOwner.js").CdpTargetSessionOwner,
|
||||
) => {
|
||||
const connection = {
|
||||
send: mocks.policySend,
|
||||
onEvent: (listener: typeof mocks.policyEvent) => {
|
||||
mocks.policyEvent = listener;
|
||||
@@ -37,8 +45,13 @@ vi.mock("./CdpTargetSession.js", () => ({
|
||||
},
|
||||
close: mocks.policyTransportClose,
|
||||
beginCleanupGrace: mocks.policyBeginCleanupGrace,
|
||||
},
|
||||
}),
|
||||
} as unknown as import("./CdpConnection.js").CdpConnection;
|
||||
owner.register(connection, operation, "target");
|
||||
return {
|
||||
discovery: { targets: [{ id: "target" }] },
|
||||
connection,
|
||||
};
|
||||
},
|
||||
attachCdpTargetSession: async (connection: unknown) => ({
|
||||
connection,
|
||||
sessionId: "policy-session",
|
||||
@@ -206,6 +219,7 @@ const fixture = () => {
|
||||
mocks.storage = {
|
||||
initialize: vi.fn(async () => undefined),
|
||||
settle: vi.fn(async () => undefined),
|
||||
limitations: vi.fn(() => []),
|
||||
close: vi.fn(async (stopLoading = false) => ({
|
||||
loadingStopped: stopLoading,
|
||||
})),
|
||||
@@ -1040,7 +1054,7 @@ it("retries transport close without detaching an already released policy session
|
||||
const failure = new Error("transport close rejected");
|
||||
mocks.policyTransportClose.mockRejectedValueOnce(failure);
|
||||
await expect(session.close()).rejects.toMatchObject({
|
||||
cause: failure,
|
||||
cause: { cause: failure },
|
||||
cleanupIncomplete: true,
|
||||
});
|
||||
await expect(session.close()).resolves.toBe("disconnected-external");
|
||||
|
||||
@@ -957,9 +957,12 @@ describe("serveEnvironment with a state", () => {
|
||||
await expect(
|
||||
add({ kind: "data", data: renamedDocument() }),
|
||||
).resolves.toMatchObject({ result: {} });
|
||||
await expect(environment.close()).rejects.toBeInstanceOf(
|
||||
ArtifactResourceRetryFailure,
|
||||
);
|
||||
await expect(environment.close()).rejects.toMatchObject({
|
||||
_tag: "AnalysisOutputError",
|
||||
diagnostics: { cleanup_stages: ["state-files"] },
|
||||
cause: expect.any(ArtifactResourceRetryFailure),
|
||||
cleanupIncomplete: true,
|
||||
});
|
||||
expect(owners[0]?.handle.fd).toBeGreaterThanOrEqual(0);
|
||||
failing = false;
|
||||
await expect(environment.close()).resolves.toBeUndefined();
|
||||
@@ -991,10 +994,16 @@ describe("serveEnvironment cleanup retries", () => {
|
||||
const listenerFailure = new Error("injected listener cleanup failure");
|
||||
closeFailureControl.failure = listenerFailure;
|
||||
await expect(environment.close()).rejects.toSatisfy((cause: unknown) => {
|
||||
if (!(cause instanceof AggregateError)) return false;
|
||||
if (!(cause instanceof Error) || !(cause.cause instanceof AggregateError))
|
||||
return false;
|
||||
expect(cause).toMatchObject({
|
||||
_tag: "AnalysisOutputError",
|
||||
diagnostics: { cleanup_stages: ["http-server", "state-files"] },
|
||||
cleanupIncomplete: true,
|
||||
});
|
||||
return (
|
||||
cause.errors[0] === listenerFailure &&
|
||||
cause.errors[1] instanceof ArtifactResourceRetryFailure
|
||||
cause.cause.errors[0] === listenerFailure &&
|
||||
cause.cause.errors[1] instanceof ArtifactResourceRetryFailure
|
||||
);
|
||||
});
|
||||
expect(owners[0]?.handle.fd).toBeGreaterThanOrEqual(0);
|
||||
|
||||
Reference in new issue
Block a user