Skip to content

Commit 2b9664a

Browse files
committed
fix(browser): keep snapshot delta helper private
1 parent b10205b commit 2b9664a

3 files changed

Lines changed: 16 additions & 22 deletions

File tree

extensions/browser/src/browser/pw-role-snapshot.test.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Browser tests cover pw role snapshot plugin behavior.
22
import { describe, expect, it } from "vitest";
33
import {
4-
annotateRoleSnapshotDelta,
54
buildRoleSnapshotFromAiSnapshot,
65
buildRoleSnapshotFromAriaSnapshot,
76
finalizeRoleSnapshot,
@@ -137,7 +136,7 @@ describe("pw-role-snapshot", () => {
137136
const snapshot = '- button "Save" [ref=e1]';
138137
const refs = { e1: { role: "button", name: "Save" } };
139138

140-
const result = annotateRoleSnapshotDelta({ snapshot, refs, mode: "role" });
139+
const result = finalizeRoleSnapshot({ snapshot, refs, delta: { mode: "role" } });
141140

142141
expect(result.snapshot).toBe(snapshot);
143142
expect(result.newElements).toBeUndefined();
@@ -152,39 +151,36 @@ describe("pw-role-snapshot", () => {
152151
e7: { role: "button", name: "Save" },
153152
e8: { role: "dialog", name: "Confirmation" },
154153
};
155-
const annotated = annotateRoleSnapshotDelta({
154+
const finalized = finalizeRoleSnapshot({
156155
snapshot: ['- button "Save" [ref=e7]', '- dialog "Confirmation" [ref=e8]'].join("\n"),
157156
refs,
158-
mode: "role",
159-
previousKeys,
157+
delta: { mode: "role", previousKeys },
160158
});
161-
const finalized = finalizeRoleSnapshot({ snapshot: annotated.snapshot, refs });
162159

163-
expect(annotated.snapshot).toBe(
160+
expect(finalized.snapshot).toBe(
164161
[
165162
'- button "Save" [ref=e7]',
166163
'- dialog "Confirmation" [ref=e8] [new]',
167164
"1 new element(s) since last snapshot",
168165
].join("\n"),
169166
);
170-
expect(annotated.newElements).toBe(1);
167+
expect(finalized.newElements).toBe(1);
171168
expect(finalized.refs).toEqual(refs);
172169
});
173170

174171
it("uses preserved aria refs as AI snapshot identities", () => {
175-
const annotated = annotateRoleSnapshotDelta({
172+
const finalized = finalizeRoleSnapshot({
176173
snapshot: ['- button "Save" [ref=7]', '- dialog "Confirmation" [ref=8]'].join("\n"),
177174
refs: {
178175
"7": { role: "button", name: "Save" },
179176
"8": { role: "dialog", name: "Confirmation" },
180177
},
181-
mode: "aria",
182-
previousKeys: new Set(["7"]),
178+
delta: { mode: "aria", previousKeys: new Set(["7"]) },
183179
});
184180

185-
expect(annotated.snapshot).toContain('- button "Save" [ref=7]\n');
186-
expect(annotated.snapshot).toContain('- dialog "Confirmation" [ref=8] [new]');
187-
expect(annotated.newElements).toBe(1);
181+
expect(finalized.snapshot).toContain('- button "Save" [ref=7]\n');
182+
expect(finalized.snapshot).toContain('- dialog "Confirmation" [ref=8] [new]');
183+
expect(finalized.newElements).toBe(1);
188184
});
189185

190186
it("annotates before truncation and keeps only complete annotated refs", () => {

extensions/browser/src/browser/pw-role-snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function getRoleSnapshotIdentityKeys<T extends RoleRef>(
7575
}
7676

7777
/** Mark ref-bearing lines that were absent from the previous compatible snapshot. */
78-
export function annotateRoleSnapshotDelta<T extends RoleRef>(params: {
78+
function annotateRoleSnapshotDelta<T extends RoleRef>(params: {
7979
snapshot: string;
8080
refs: Record<string, T>;
8181
mode: RoleSnapshotIdentityMode;

extensions/browser/src/browser/snapshot-delta-cache.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from "vitest";
2-
import { annotateRoleSnapshotDelta } from "./pw-role-snapshot.js";
2+
import { finalizeRoleSnapshot } from "./pw-role-snapshot.js";
33
import type { BrowserRouteContext } from "./server-context.types.js";
44
import {
55
getPreviousSnapshotKeys,
@@ -26,11 +26,10 @@ describe("snapshot delta cache", () => {
2626
});
2727

2828
const previousKeys = getPreviousSnapshotKeys(ctx, cacheScope("pw:document-2"));
29-
const snapshot = annotateRoleSnapshotDelta({
29+
const snapshot = finalizeRoleSnapshot({
3030
snapshot: '- button "Continue" [ref=e1]',
3131
refs: { e1: { role: "button", name: "Continue" } },
32-
mode: "role",
33-
previousKeys,
32+
delta: { mode: "role", previousKeys },
3433
});
3534

3635
expect(previousKeys).toBeUndefined();
@@ -46,14 +45,13 @@ describe("snapshot delta cache", () => {
4645
refs: { e1: { role: "button", name: "Save" } },
4746
});
4847

49-
const snapshot = annotateRoleSnapshotDelta({
48+
const snapshot = finalizeRoleSnapshot({
5049
snapshot: ['- button "Save" [ref=e7]', '- alert "Required" [ref=e8]'].join("\n"),
5150
refs: {
5251
e7: { role: "button", name: "Save" },
5352
e8: { role: "alert", name: "Required" },
5453
},
55-
mode: "role",
56-
previousKeys: getPreviousSnapshotKeys(ctx, scope),
54+
delta: { mode: "role", previousKeys: getPreviousSnapshotKeys(ctx, scope) },
5755
});
5856

5957
expect(snapshot.snapshot).toContain('- alert "Required" [ref=e8] [new]');

0 commit comments

Comments
 (0)