|
1 | 1 | import { expect, test } from 'vitest'; |
2 | 2 | import type { SnapshotState } from '@agent-device/contracts/snapshot-model'; |
3 | | -import { surfaceScopedNodes } from './snapshot-baseline.ts'; |
| 3 | +import type { SurfaceScopedNodes } from '@agent-device/contracts/interaction'; |
| 4 | +import { postActionBaseline, surfaceScopedNodes } from './snapshot-baseline.ts'; |
4 | 5 |
|
5 | 6 | const nodes = [{ index: 0, type: 'Application', ref: 'e1' }]; |
6 | 7 |
|
@@ -33,6 +34,54 @@ test('a session with no stored snapshot still mints an empty baseline', () => { |
33 | 34 | expect(surfaceScopedNodes(undefined)).toEqual({ nodes: [] }); |
34 | 35 | }); |
35 | 36 |
|
| 37 | +test('the mint carries the presentation the capture read', () => { |
| 38 | + expect(surfaceScopedNodes(snapshot({ presentation: { interactiveOnly: true } }))).toEqual({ |
| 39 | + nodes, |
| 40 | + presentation: { interactiveOnly: true }, |
| 41 | + }); |
| 42 | +}); |
| 43 | + |
| 44 | +const INTERACTIVE = { interactiveOnly: true }; |
| 45 | +const FULL = {}; |
| 46 | +const frame = (presentation: SurfaceScopedNodes['presentation']) => tree('frame', presentation); |
| 47 | + |
| 48 | +// #4486: a settle diff compares one view, and the agent's view is its ref frame's presentation. |
| 49 | +test.each([ |
| 50 | + ['interactive frame, interactive candidate', INTERACTIVE, INTERACTIVE, 'candidate'], |
| 51 | + ['interactive frame, full candidate', INTERACTIVE, FULL, 'frame'], |
| 52 | + ['full frame, interactive candidate', FULL, INTERACTIVE, 'frame'], |
| 53 | + ['full frame, full candidate', FULL, FULL, 'candidate'], |
| 54 | + [ |
| 55 | + 'interactive frame, scoped interactive candidate', |
| 56 | + INTERACTIVE, |
| 57 | + { interactiveOnly: true, scope: 'Composer' }, |
| 58 | + 'frame', |
| 59 | + ], |
| 60 | + ['interactive frame, candidate with no recorded view', INTERACTIVE, undefined, 'candidate'], |
| 61 | +] as const)('%s: the %s answers', (_case, framePresentation, candidatePresentation, expected) => { |
| 62 | + const baseline = postActionBaseline({ |
| 63 | + frame: frame(framePresentation), |
| 64 | + candidates: [tree('candidate', candidatePresentation)], |
| 65 | + }); |
| 66 | + expect(baseline.nodes[0]?.label).toBe(expected); |
| 67 | +}); |
| 68 | + |
| 69 | +test('without a frame the first non-empty candidate answers, in its own view', () => { |
| 70 | + const baseline = postActionBaseline({ |
| 71 | + frame: undefined, |
| 72 | + candidates: [undefined, { nodes: [] }, tree('candidate', FULL)], |
| 73 | + }); |
| 74 | + expect(baseline).toEqual(tree('candidate', FULL)); |
| 75 | + expect(postActionBaseline({ frame: undefined, candidates: [] })).toEqual({ nodes: [] }); |
| 76 | +}); |
| 77 | + |
| 78 | +function tree(label: string, presentation: SurfaceScopedNodes['presentation']): SurfaceScopedNodes { |
| 79 | + return { |
| 80 | + nodes: [{ index: 0, type: 'Button', label, ref: 'e1' }], |
| 81 | + ...(presentation ? { presentation } : {}), |
| 82 | + }; |
| 83 | +} |
| 84 | + |
36 | 85 | function snapshot(fields: Partial<SnapshotState>): SnapshotState { |
37 | 86 | return { nodes, createdAt: 0, presentationKey: '', ...fields } as SnapshotState; |
38 | 87 | } |
0 commit comments