Skip to content

Commit 104f34c

Browse files
committed
fix(replay): keep recorded ref labels verbatim in written scripts
The ref label parses back into `result.refLabel`, which replay compares literally and never interpolates. Escaping it wrote `Pay \${amount}` and broke ref matching. The writer now leaves it as is; the scoped snapshot flag built from the same label stays escaped because replay does interpolate flags. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016qAu53rMak1bXMuR5U2gF4
1 parent 711d26f commit 104f34c

2 files changed

Lines changed: 18 additions & 27 deletions

File tree

‎packages/daemon/src/core/__tests__/session-script-writer.test.ts‎

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ test('write() escapes recorded literal ${...} text so replay resolves it back un
116116
expect(resolved[4]?.positionals).toEqual(['label="Other"', '${PASSWORD}']);
117117
});
118118

119-
test('write() keeps a target annotation verbatim because replay never interpolates it', () => {
120-
const root = mkdtempForTestSync('agent-device-script-writer-annotation-literal-');
119+
test('write() keeps ref labels and target annotations verbatim because replay matches them literally', () => {
120+
const root = mkdtempForTestSync('agent-device-script-writer-literal-identity-');
121121
const writer = new SessionScriptWriter(path.join(root, 'sessions'), hostCwd);
122-
const session = makeAuthoringSession('default');
123122
const targetEvidence = {
124123
role: 'button',
125124
label: 'Pay ${amount}',
@@ -128,26 +127,22 @@ test('write() keeps a target annotation verbatim because replay never interpolat
128127
viewportOrder: 0,
129128
verification: 'verified' as const,
130129
};
131-
recordActionEntry(
132-
session,
133-
{
134-
command: 'click',
135-
positionals: ['label="Pay ${amount}"'],
136-
flags: {},
137-
result: {},
138-
targetEvidence,
139-
},
140-
hostCwd,
141-
);
130+
const session = makeAuthoringSession('default', {
131+
actions: [
132+
action({ command: 'click', positionals: ['@e3'], result: { refLabel: 'Pay ${amount}' } }),
133+
action({ command: 'click', positionals: ['label="Pay ${amount}"'], targetEvidence }),
134+
],
135+
});
142136

143-
const { parsed } = writeAndParse(writer, session);
144-
const resolved = resolveReplayAction(
145-
parsed.actions[0]!,
146-
{ values: { amount: 'WRONG', step: 'WRONG' } },
147-
{ file: 'test.ad', line: 3 },
137+
const scope = { values: { amount: 'WRONG', step: 'WRONG' } };
138+
const [snapshot, refClick, selectorClick] = writeAndParse(writer, session).parsed.actions.map(
139+
(entry, index) => resolveReplayAction(entry, scope, { file: 'test.ad', line: index + 2 }),
148140
);
149-
expect(resolved.positionals).toEqual(['label="Pay ${amount}"']);
150-
expect(resolved.targetEvidence).toMatchObject({
141+
// The label also scopes the recorded snapshot, a flag replay does interpolate.
142+
expect(snapshot?.flags.snapshotScope).toBe('Pay ${amount}');
143+
expect(refClick?.result?.refLabel).toBe('Pay ${amount}');
144+
expect(selectorClick?.positionals).toEqual(['label="Pay ${amount}"']);
145+
expect(selectorClick?.targetEvidence).toMatchObject({
151146
label: 'Pay ${amount}',
152147
ancestry: [{ role: 'form', label: 'Checkout ${step}' }],
153148
});

‎packages/daemon/src/core/session-script-writer.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,26 +480,22 @@ function formatScript(
480480

481481
/**
482482
* Replay interpolates every written positional, flag, and runtime string, so recorded literal
483-
* text gets the `\${` escape. Only a parameterized fill's own placeholder text stays live.
483+
* text gets the `\${` escape. Only a parameterized fill's own placeholder text stays live. The
484+
* ref label parses back into `result.refLabel`, which replay compares literally, so it stays as is.
484485
*/
485486
function escapeRecordedLiterals(action: SessionAction): SessionAction {
486487
const placeholder =
487488
action.command === 'fill' && action.recordedInputVariable !== undefined
488489
? recordedInputPlaceholder(action.recordedInputVariable)
489490
: undefined;
490491
const lastIndex = action.positionals.length - 1;
491-
const refLabel = action.result?.refLabel;
492492
return {
493493
...action,
494494
positionals: action.positionals.map((value, index) =>
495495
index === lastIndex && value === placeholder ? value : escapeReplayLiteral(value),
496496
),
497497
flags: escapeReplayStringValues(action.flags),
498498
runtime: escapeReplayStringValues(action.runtime),
499-
result:
500-
typeof refLabel === 'string'
501-
? { ...action.result, refLabel: escapeReplayLiteral(refLabel) }
502-
: action.result,
503499
};
504500
}
505501

0 commit comments

Comments
 (0)