NodeRegistry: pin that reset never reuses an id

`reset` clears the lookup maps and deliberately leaves `node_id` where it
is, so a stale id fails closed with a miss instead of resolving to
whatever registers next. Nothing asserted that, and it is the invariant
every id-addressed tool call leans on across a navigation.
This commit is contained in:
Adrià Arrufat committed 2026-09-22 15:53:21 +02:00
1 parent b012c44fa0
commit 182ad25157
1 file changed
+18
+18
View File
@@ -190,3 +190,21 @@ test "NodeRegistry: resetFrame" {
try testing.expectEqual(rb, registry.lookup_by_id.get(rb.id).?);
try testing.expectEqual(b_node, registry.lookup_by_node.get(b_node).?.dom);
}
test "NodeRegistry: reset never reuses an id" {
var registry = NodeRegistry.init(testing.allocator);
defer registry.deinit();
var page = try testing.pageTest("cdp/registry1.html", .{});
defer page.close();
const frame = page.frame().?;
const dom_node = (try frame.window._document.querySelector(.wrap("#a1"), frame)).?.asNode();
// The pool recycles the `Node` itself, so keep the id, not the pointer.
const first_id = (try registry.register(dom_node)).id;
registry.reset();
try testing.expectEqual(null, registry.lookup_by_id.get(first_id));
// A stale id stays a miss rather than resolving to whatever registers next.
try testing.expect((try registry.register(dom_node)).id != first_id);
}