返回 DeepSeek-Reasonix
refResolver.test.ts
根目录 / desktop / electron / src / main / browser / refResolver.test.ts
1 import assert from "node:assert/strict";
2 import { test } from "node:test";
3 import { FakeFrame, FakePage } from "./fakeGuestViews.js";
4 import { locateRef, resolveRef } from "./refResolver.js";
5 import { browserFailure } from "./errors.js";
6 import type { DocumentBinding } from "./documents.js";
7
8 test("reference lookups preserve typed runtime failures for main and child frames", async () => {
9 for (const child of [false, true]) for (const kind of ["page_not_ready", "script_runtime_error", "cancelled"] as const) {
10 for (const operation of [locateRef, (page: FakePage, binding: DocumentBinding, ref: string) => resolveRef(page, binding, ref, false)]) {
11 const failure = browserFailure(kind, "protocol preparation failed");
12 const page = new FakePage(1, () => { throw failure; });
13 const frame = child ? new FakeFrame(2, "https://child.test", () => { throw failure; }) : page.mainFrame;
14 if (child) { frame.parent = page.mainFrame; page.mainFrame.children.push(frame); }
15 page.debugger.attached = true;
16 page.debugger.respond = () => { throw failure; };
17 const prefix = child ? "f1" : "";
18 const binding: DocumentBinding = { tabId: "tab", epoch: 1, snapshotId: "snapshot", frames: [{ prefix, frameTreeNodeId: frame.frameTreeNodeId, docId: "document" }] };
19 await assert.rejects(operation(page, binding, `${prefix}e1`), error => error === failure,
20 `${child ? "child" : "main"} ${kind} must not be relabeled as an expired ref`);
21 }
22 }
23 });
24
25 test("an expired page registry still produces the stale-reference contract", async () => {
26 const page = new FakePage(1, () => ({ ok: false, reason: "stale" }));
27 const binding: DocumentBinding = { tabId: "tab", epoch: 1, snapshotId: "old", frames: [{ prefix: "", frameTreeNodeId: page.mainFrame.frameTreeNodeId, docId: "old" }] };
28 await assert.rejects(locateRef(page, binding, "e1"), { code: -32010, data: { kind: "stale_document" } });
29 await assert.rejects(resolveRef(page, binding, "e1", false), { code: -32010, data: { kind: "stale_document" } });
30 });
31
31 lines TYPESCRIPT