Skip to content

Commit 950ce4c

Browse files
committed
test(replay): carry the dispatch envelope's merge tests into the unit
#2672 grew `session-replay-command.test.ts` coverage for the private-half merge while this branch moved that merge into the replay unit, so the two tests move with it and now sit beside `replay-dispatch-envelope.ts`. Assertions are unchanged. Reads `ReplayDispatchOptions` from its contracts declaration, which is where #2672 now declares it.
1 parent c08b4c6 commit 950ce4c

3 files changed

Lines changed: 66 additions & 67 deletions

File tree

‎src/daemon/handlers/__tests__/session-replay-command.test.ts‎

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {
88
import { createScreenRecordingAdmissionLedger } from '@agent-device/capture-kit/screen-recording-admission-ledger';
99
import { platformResourceCleanup } from '../../../platform-runtime-resource-cleanup.ts';
1010
import type { SessionCommandParams } from '../session-command-input.ts';
11-
import { handleReplayTestCommand, replayInvoke } from '../session-replay-command.ts';
12-
import type { DaemonRequest } from '../../daemon-request.ts';
11+
import { handleReplayTestCommand } from '../session-replay-command.ts';
1312
import { makeSessionStore } from './session-test-harness.ts';
1413
import { mkdtempForTestSync } from '../../../__tests__/test-utils/tmp-dir.ts';
1514

@@ -52,63 +51,3 @@ test('replay test handler threads the complete video owner into the application
5251
expect(response.error.code).toBe('INVALID_ARGS');
5352
expect(response.error.message).not.toContain('Screen-recording runtime is not configured');
5453
});
55-
56-
test('replayInvoke re-attaches the originating private half, then folds the dispatch bag over it', async () => {
57-
const base: DaemonRequest = {
58-
token: 'token',
59-
session: 'default',
60-
command: 'replay',
61-
positionals: [],
62-
internal: {
63-
publicNetworkOnly: true,
64-
replayTargetGuard: {
65-
identity: { role: 'button', label: 'Old' },
66-
structural: { documentOrder: 0, sibling: 0 },
67-
},
68-
},
69-
};
70-
const invoked: DaemonRequest[] = [];
71-
const invoke = replayInvoke(async (request) => {
72-
invoked.push(request);
73-
return { ok: true, data: {} };
74-
}, base);
75-
76-
await invoke({
77-
token: 'token',
78-
session: 'default',
79-
command: 'tap',
80-
positionals: ['@e1'],
81-
dispatch: {
82-
replayPlanStep: true,
83-
replayTargetGuard: {
84-
identity: { role: 'button', label: 'New' },
85-
structural: { documentOrder: 1, sibling: 0 },
86-
},
87-
},
88-
});
89-
await invoke({ token: 'token', session: 'default', command: 'snapshot', positionals: [] });
90-
91-
expect(invoked[0]?.internal).toEqual({
92-
publicNetworkOnly: true,
93-
replayPlanStep: true,
94-
replayTargetGuard: {
95-
identity: { role: 'button', label: 'New' },
96-
structural: { documentOrder: 1, sibling: 0 },
97-
},
98-
});
99-
expect(invoked[0]).not.toHaveProperty('dispatch');
100-
expect(invoked[1]?.internal).toEqual(base.internal);
101-
});
102-
103-
test('replayInvoke sends no private half when neither side carries one', async () => {
104-
const invoked: DaemonRequest[] = [];
105-
const invoke = replayInvoke(
106-
async (request) => {
107-
invoked.push(request);
108-
return { ok: true, data: {} };
109-
},
110-
{ token: 'token', session: 'default', command: 'replay', positionals: [] },
111-
);
112-
await invoke({ token: 'token', session: 'default', command: 'snapshot', positionals: [] });
113-
expect(invoked[0]).not.toHaveProperty('internal');
114-
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { expect, test } from 'vitest';
2+
import type { DaemonRequest } from '../../../daemon-request.ts';
3+
import { replayInvokeOverDispatch } from '../replay-dispatch-envelope.ts';
4+
5+
test('replayInvokeOverDispatch re-attaches the originating private half, then folds the dispatch bag over it', async () => {
6+
const base: DaemonRequest = {
7+
token: 'token',
8+
session: 'default',
9+
command: 'replay',
10+
positionals: [],
11+
internal: {
12+
publicNetworkOnly: true,
13+
replayTargetGuard: {
14+
identity: { role: 'button', label: 'Old' },
15+
structural: { documentOrder: 0, sibling: 0 },
16+
},
17+
},
18+
};
19+
const invoked: DaemonRequest[] = [];
20+
const invoke = replayInvokeOverDispatch(async (request) => {
21+
invoked.push(request);
22+
return { ok: true, data: {} };
23+
}, base);
24+
25+
await invoke({
26+
token: 'token',
27+
session: 'default',
28+
command: 'tap',
29+
positionals: ['@e1'],
30+
dispatch: {
31+
replayPlanStep: true,
32+
replayTargetGuard: {
33+
identity: { role: 'button', label: 'New' },
34+
structural: { documentOrder: 1, sibling: 0 },
35+
},
36+
},
37+
});
38+
await invoke({ token: 'token', session: 'default', command: 'snapshot', positionals: [] });
39+
40+
expect(invoked[0]?.internal).toEqual({
41+
publicNetworkOnly: true,
42+
replayPlanStep: true,
43+
replayTargetGuard: {
44+
identity: { role: 'button', label: 'New' },
45+
structural: { documentOrder: 1, sibling: 0 },
46+
},
47+
});
48+
expect(invoked[0]).not.toHaveProperty('dispatch');
49+
expect(invoked[1]?.internal).toEqual(base.internal);
50+
});
51+
52+
test('replayInvokeOverDispatch sends no private half when neither side carries one', async () => {
53+
const invoked: DaemonRequest[] = [];
54+
const invoke = replayInvokeOverDispatch(
55+
async (request) => {
56+
invoked.push(request);
57+
return { ok: true, data: {} };
58+
},
59+
{ token: 'token', session: 'default', command: 'replay', positionals: [] },
60+
);
61+
await invoke({ token: 'token', session: 'default', command: 'snapshot', positionals: [] });
62+
expect(invoked[0]).not.toHaveProperty('internal');
63+
});

‎src/daemon/replay/internal/replay-dispatch-envelope.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import type { SessionScope } from '@agent-device/contracts/session';
22
import type { DaemonWireRequest } from '@agent-device/contracts/command';
3+
import type { ReplayDispatchOptions } from '@agent-device/contracts/replay';
34
import { stripUndefined } from '@agent-device/kernel/record';
45
import type { DaemonResponse } from '@agent-device/kernel/contracts';
5-
import type {
6-
ReplayDispatchOptions,
7-
ReplayDispatchRequest,
8-
ReplayInvoke,
9-
} from './command-types.ts';
6+
import type { ReplayDispatchRequest, ReplayInvoke } from './command-types.ts';
107

118
/** The request-private facts replay's own decisions read, as the daemon resolves them. */
129
export type ReplayPrivateAdmission = Readonly<{

0 commit comments

Comments
 (0)