Repository navigation
fix(snapshot): print the value of labeled non-editable nodes #5422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thymikee
merged 2 commits into
callstack:main
from
pcbeingused33:fix/snapshot-labeled-value
Dec 6, 2026
+126
−7
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
packages/capture-kit/src/snapshot/__tests__/snapshot-lines-value.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { test } from 'vitest'; | ||
| import type { SnapshotNode } from '@agent-device/kernel/snapshot'; | ||
| import { formatRole } from '@agent-device/kernel/snapshot'; | ||
| import { buildSnapshotDiff } from '../snapshot-diff.ts'; | ||
| import { formatSnapshotLine } from '../snapshot-lines.ts'; | ||
|
|
||
| function slider(value?: string, label = 'Brightness', type = 'Other'): SnapshotNode { | ||
| return { | ||
| ref: 'e3', | ||
| index: 0, | ||
| depth: 0, | ||
| type, | ||
| kind: formatRole(type), | ||
| label, | ||
| ...(value === undefined ? {} : { value }), | ||
| enabled: true, | ||
| hittable: true, | ||
| }; | ||
| } | ||
|
|
||
| test.each([[false], [true]])( | ||
| 'a labeled non-editable node prints its differing value (summarize=%s)', | ||
| (summarizeTextSurfaces) => { | ||
| const line = formatSnapshotLine(slider('60%'), 0, false, undefined, { summarizeTextSurfaces }); | ||
| assert.equal(line, '@e3 [other] "Brightness" [value:"60%"]'); | ||
| }, | ||
| ); | ||
|
|
||
| test.each([ | ||
| ['no value', slider()], | ||
| ['value equal to the label', slider('Brightness')], | ||
| ['unlabeled node, value already shown as the label', slider('60%', '')], | ||
| ['editable node, value already shown as the label', slider('hello', 'Name', 'TextField')], | ||
| [ | ||
| 'checkable node, value already shown as its state', | ||
| { ...slider('1', 'Wi-Fi', 'Switch'), checked: true }, | ||
| ], | ||
| ])('no value marker for %s', (_name, node) => { | ||
| const line = formatSnapshotLine(node, 0, false, undefined, { summarizeTextSurfaces: true }); | ||
| assert.doesNotMatch(line, /\[value:/); | ||
| }); | ||
|
|
||
| test('a long value with quotes and backslashes is escaped and truncated', () => { | ||
| const value = `say "hi" C:\\dir ${'x'.repeat(60)}`; | ||
| const line = formatSnapshotLine(slider(value), 0, false, undefined, {}); | ||
| assert.equal( | ||
| line, | ||
| `@e3 [other] "Brightness" [value:"say \\"hi\\" C:\\\\dir ${'x'.repeat(29)}..."]`, | ||
| ); | ||
| }); | ||
|
|
||
| test.each([ | ||
| [ | ||
| 'a labeled SecureTextField', | ||
| { ...slider('••••••••', 'Password', 'SecureTextField'), password: true }, | ||
| ], | ||
| ['a password node under a non-field role', { ...slider('hunter2', 'PIN'), password: true }], | ||
| ])('%s never prints its value', (_name, node) => { | ||
| for (const summarizeTextSurfaces of [false, true]) { | ||
| const line = formatSnapshotLine(node, 0, false, undefined, { summarizeTextSurfaces }); | ||
| assert.doesNotMatch(line, /\[value:|••|hunter2/); | ||
| } | ||
| const diff = buildSnapshotDiff([node], [{ ...node, value: `${node.value}x` }]); | ||
| assert.equal(diff.summary.unchanged, 1); | ||
| }); | ||
|
|
||
| test('a value-only change diffs as changed lines that read differently', () => { | ||
| const diff = buildSnapshotDiff([slider('60%')], [slider('96%')]); | ||
| const changed = diff.lines.filter((line) => line.kind !== 'unchanged'); | ||
|
|
||
| assert.equal(diff.summary.unchanged, 0); | ||
| assert.equal(diff.summary.additions, 1); | ||
| assert.equal(diff.summary.removals, 1); | ||
| assert.match(changed[0]!.text, /\[value:"60%"\]/); | ||
| assert.match(changed.at(-1)!.text, /\[value:"96%"\]/); | ||
| }); | ||
|
|
||
| test('a still value diffs as unchanged', () => { | ||
| const diff = buildSnapshotDiff([slider('60%')], [slider('60%')]); | ||
| assert.equal( | ||
| diff.lines.every((line) => line.kind === 'unchanged'), | ||
| true, | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |||||
| formatRole, | ||||||
| formatSnapshotLine, | ||||||
| stateMarkers, | ||||||
| valueMarker, | ||||||
| } from './snapshot-lines.ts'; | ||||||
|
|
||||||
| export type SnapshotDiffResult = { | ||||||
|
|
@@ -31,14 +32,15 @@ function snapshotNodeToComparableLine(node: SnapshotNode, depthOverride?: number | |||||
| // The states the rendered line prints are the states the key compares, from one function, so a | ||||||
| // fact the diff weighs is always visible in the line it prints. | ||||||
| const statePart = stateMarkers(node).join(','); | ||||||
| const valuePart = valueMarker(node, role) ?? ''; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents
Suggested change
|
||||||
| const hittablePart = node.hittable === true ? 'hittable' : 'not-hittable'; | ||||||
| const depthPart = String(depthOverride ?? node.depth ?? 0); | ||||||
| // The rendered line carries the actions list, so the comparable key has to as | ||||||
| // well: otherwise an action-only change diffs as 'unchanged' while its text | ||||||
| // silently differs from the baseline's. JSON-encoded because the names are | ||||||
| // app-authored and may contain the field separator. | ||||||
| const actionsPart = node.actions ? JSON.stringify(node.actions) : ''; | ||||||
| return [depthPart, role, textPart, statePart, hittablePart, actionsPart].join('|'); | ||||||
| return [depthPart, role, textPart, statePart, valuePart, hittablePart, actionsPart].join('|'); | ||||||
| } | ||||||
|
|
||||||
| export function buildSnapshotDiff( | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.