Skip to content

Commit a1d1eb8

Browse files
committed
test(web): pin the two spellings the backend prints for one string
agent-browser prints a control's own string two ways on one line-set, both captured live against a page whose value contains a quote: the trailing `: value` form carries it raw, a quoted payload carries it escaped. The projection already reads both as the same string, which is what makes the control's own text line dedup against it, and the raw form must stay raw: a value that legitimately contains a backslash would otherwise be published as a different string than the page holds. These two cases were reported as a defect in the escaping fix; they are the behaviour the backend has, so they get tests rather than a change.
1 parent 0ab9b9d commit a1d1eb8

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎packages/platform-web/src/__tests__/agent-browser-snapshot-refless.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,34 @@ describe('normalizeAgentBrowserSnapshot ref-less content', () => {
253253
expect(refLessNodes(result)).toEqual([]);
254254
});
255255

256+
test('matches a value across the two spellings the backend prints for one string', async () => {
257+
// agent-browser prints a control's value two ways (both captured live): the trailing `: value`
258+
// form carries it RAW and a quoted payload carries it ESCAPED. Those are the same string, and
259+
// the projection must read them that way — unescaping the trailing form as well would turn a
260+
// value that legitimately contains a backslash into a different string.
261+
const result = await normalizeAgentBrowserSnapshot({
262+
snapshot: [
263+
'- textbox "Name" [ref=e2]: He said "hi"',
264+
String.raw` - StaticText "He said \"hi\""`,
265+
].join('\n'),
266+
refs: { e2: { name: 'Name', role: 'textbox' } },
267+
});
268+
269+
expect(result.nodes.find((node) => node.ref === 'e2')?.value).toBe('He said "hi"');
270+
expect(refLessNodes(result)).toEqual([]);
271+
});
272+
273+
test('preserves a backslash in a value the backend printed raw', async () => {
274+
const result = await normalizeAgentBrowserSnapshot({
275+
snapshot: [String.raw`- textbox "Name" [ref=e2]: a\"b`].join('\n'),
276+
refs: { e2: { name: 'Name', role: 'textbox' } },
277+
});
278+
279+
// The page really holds `a\"b` (verified through the backend against a live input), and the
280+
// trailing form is not an escaped payload, so the two characters stay.
281+
expect(result.nodes.find((node) => node.ref === 'e2')?.value).toBe(String.raw`a\"b`);
282+
});
283+
256284
test('attaches geometry only to the nodes the backend can measure', async () => {
257285
const result = await normalizeAgentBrowserSnapshot(FORM_AFTER_SUBMIT, async (ref) =>
258286
ref === 'e2' ? { x: 1, y: 2, width: 10, height: 20 } : undefined,

0 commit comments

Comments
 (0)