Skip to content

Commit 4f6735a

Browse files
committed
test: trim duplicate session recovery coverage
1 parent 794ba07 commit 4f6735a

5 files changed

Lines changed: 1 addition & 221 deletions

File tree

src/daemon/__tests__/request-finalization.test.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,3 @@ test('finalizeDaemonResponse preserves handler error hints from details', () =>
2929
expect(finalized.error.hint).toBe('Run agent-device session list and reuse --session default.');
3030
}
3131
});
32-
33-
test('finalizeDaemonResponse prefers top-level error hint over details hint', () => {
34-
const req: DaemonRequest = {
35-
token: 'token',
36-
session: 'default',
37-
command: 'open',
38-
positionals: [],
39-
flags: {},
40-
};
41-
const response: DaemonResponse = {
42-
ok: false,
43-
error: {
44-
code: 'DEVICE_IN_USE',
45-
message: 'Device is already in use by session "default".',
46-
hint: 'Use the top-level hint.',
47-
details: {
48-
hint: 'Use the details hint.',
49-
},
50-
},
51-
};
52-
53-
const finalized = finalizeDaemonResponse(req, response, () => 'artifact-id');
54-
55-
expect(finalized.ok).toBe(false);
56-
if (!finalized.ok) {
57-
expect(finalized.error.hint).toBe('Use the top-level hint.');
58-
}
59-
});

src/daemon/__tests__/request-lock-policy.test.ts

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { test } from 'vitest';
22
import assert from 'node:assert/strict';
33
import { applyRequestLockPolicy } from '../request-lock-policy.ts';
44
import type { SessionState } from '../types.ts';
5-
import { AppError } from '../../utils/errors.ts';
65

76
const IOS_SESSION: SessionState = {
87
name: 'qa-ios',
@@ -33,21 +32,6 @@ const ANDROID_SESSION: SessionState = {
3332
},
3433
};
3534

36-
const RECORDING_SESSION: SessionState = {
37-
...ANDROID_SESSION,
38-
name: 'default',
39-
recordOnlySession: true,
40-
recording: {
41-
platform: 'android',
42-
outPath: '/tmp/recording.mp4',
43-
remotePath: '/sdcard/recording.mp4',
44-
remotePid: '1234',
45-
startedAt: Date.now(),
46-
showTouches: false,
47-
gestureEvents: [],
48-
},
49-
};
50-
5135
test('rejects fresh-session selector conflicts under request lock policy', () => {
5236
assert.throws(
5337
() =>
@@ -68,37 +52,6 @@ test('rejects fresh-session selector conflicts under request lock policy', () =>
6852
);
6953
});
7054

71-
test('reject lock policy explains fresh-session recovery commands', () => {
72-
assert.throws(
73-
() =>
74-
applyRequestLockPolicy({
75-
token: 'token',
76-
session: 'qa-ios',
77-
command: 'snapshot',
78-
positionals: [],
79-
flags: {
80-
device: 'Pixel 9',
81-
},
82-
meta: {
83-
lockPolicy: 'reject',
84-
lockPlatform: 'ios',
85-
},
86-
}),
87-
(error) => {
88-
assert.ok(error instanceof AppError);
89-
assert.match(error.message, /snapshot is using a bound-session lock for ios/i);
90-
assert.match(error.message, /--device=Pixel 9/i);
91-
assert.match(error.details?.hint ?? '', /Remove conflicting device selectors/i);
92-
assert.match(
93-
error.details?.hint ?? '',
94-
/agent-device open <app> --session qa-ios --platform ios/i,
95-
);
96-
assert.match(error.details?.hint ?? '', /agent-device session list/i);
97-
return true;
98-
},
99-
);
100-
});
101-
10255
test('allows open to choose a fresh-session target under request lock policy', () => {
10356
const req = applyRequestLockPolicy({
10457
token: 'token',
@@ -165,66 +118,6 @@ test('rejects existing-session selector conflicts under request lock policy', ()
165118
);
166119
});
167120

168-
test('reject lock policy explains existing-session recovery commands', () => {
169-
assert.throws(
170-
() =>
171-
applyRequestLockPolicy(
172-
{
173-
token: 'token',
174-
session: 'qa-ios',
175-
command: 'snapshot',
176-
positionals: [],
177-
flags: {
178-
serial: 'emulator-5554',
179-
},
180-
meta: {
181-
lockPolicy: 'reject',
182-
},
183-
},
184-
IOS_SESSION,
185-
),
186-
(error) => {
187-
assert.ok(error instanceof AppError);
188-
assert.match(error.message, /already bound to session "qa-ios"/i);
189-
assert.match(error.message, /ios device "iPhone 16" \(SIM-001\)/i);
190-
assert.match(error.message, /--serial=emulator-5554/i);
191-
assert.match(error.details?.hint ?? '', /agent-device session list/i);
192-
assert.match(error.details?.hint ?? '', /--session qa-ios/i);
193-
assert.match(error.details?.hint ?? '', /agent-device close --session qa-ios/i);
194-
return true;
195-
},
196-
);
197-
});
198-
199-
test('reject lock policy explains recording-session recovery commands', () => {
200-
assert.throws(
201-
() =>
202-
applyRequestLockPolicy(
203-
{
204-
token: 'token',
205-
session: 'default',
206-
command: 'snapshot',
207-
positionals: [],
208-
flags: {
209-
device: 'Pixel 8',
210-
},
211-
meta: {
212-
lockPolicy: 'reject',
213-
},
214-
},
215-
RECORDING_SESSION,
216-
),
217-
(error) => {
218-
assert.ok(error instanceof AppError);
219-
assert.match(error.message, /already bound to session "default"/i);
220-
assert.match(error.details?.hint ?? '', /recording session "default"/i);
221-
assert.match(error.details?.hint ?? '', /agent-device record stop --session default/i);
222-
assert.match(error.details?.hint ?? '', /agent-device close --session default/i);
223-
return true;
224-
},
225-
);
226-
});
227-
228121
test('allows inventory commands to use explicit Apple selectors under another lock platform', () => {
229122
const req = applyRequestLockPolicy({
230123
token: 'token',

src/daemon/__tests__/session-routing.test.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import fs from 'node:fs';
44
import os from 'node:os';
55
import path from 'node:path';
66
import { SessionStore } from '../session-store.ts';
7-
import {
8-
resolveEffectiveSessionName,
9-
resolveImplicitSessionScope,
10-
sessionMatchesScope,
11-
} from '../session-routing.ts';
7+
import { resolveEffectiveSessionName } from '../session-routing.ts';
128
import type { SessionState } from '../types.ts';
139

1410
function makeSession(name: string): SessionState {
@@ -115,32 +111,3 @@ test('keeps explicitly configured default session global', (t) => {
115111

116112
assert.equal(resolved, 'default');
117113
});
118-
119-
test('matches sessions only within the same implicit scope', (t) => {
120-
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-cwd-scope-'));
121-
t.onTestFinished(() => {
122-
fs.rmSync(cwd, { recursive: true, force: true });
123-
});
124-
const req = {
125-
token: 't',
126-
session: 'default',
127-
command: 'session_list',
128-
positionals: [],
129-
flags: {},
130-
meta: { cwd },
131-
};
132-
const scope = resolveImplicitSessionScope(req);
133-
assert.ok(scope);
134-
135-
assert.equal(
136-
sessionMatchesScope({ ...makeSession('default'), sessionScope: scope }, scope),
137-
true,
138-
);
139-
assert.equal(
140-
sessionMatchesScope(
141-
{ ...makeSession('default'), sessionScope: { kind: 'cwd', id: 'other' } },
142-
scope,
143-
),
144-
false,
145-
);
146-
});

src/daemon/__tests__/session-selector.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,6 @@ test('selector mismatch explains session recovery commands', () => {
6060
);
6161
});
6262

63-
test('selector mismatch quotes unsafe session names in recovery commands', () => {
64-
const session = makeSession({ name: "default session; echo 'oops'" });
65-
assert.throws(
66-
() => assertSessionSelectorMatches(session, { platform: 'ios' }),
67-
(err: unknown) => {
68-
assert.ok(err instanceof AppError);
69-
assert.match(err.details?.hint ?? '', /--session 'default session; echo '\\''oops'\\'''/);
70-
assert.match(
71-
err.details?.hint ?? '',
72-
/agent-device close --session 'default session; echo '\\''oops'\\'''/,
73-
);
74-
return true;
75-
},
76-
);
77-
});
78-
7963
test('accepts --platform apple alias for ios sessions', () => {
8064
const session = makeSession({
8165
device: {

src/daemon/handlers/__tests__/record-trace.test.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -280,42 +280,6 @@ test('record stop releases session created only for recording', async () => {
280280
expect(sessionStore.get(sessionName)).toBeUndefined();
281281
});
282282

283-
test('record stop releases record-only session even when recording state is stale', async () => {
284-
const sessionStore = makeSessionStore();
285-
const sessionName = 'stale-record-only-session';
286-
const session = makeIosSimulatorSession(sessionName);
287-
session.recordOnlySession = true;
288-
sessionStore.set(sessionName, session);
289-
290-
const response = await runRecordCommand({
291-
sessionStore,
292-
sessionName,
293-
positionals: ['stop'],
294-
});
295-
296-
expect(response?.ok).toBe(false);
297-
expect(sessionStore.get(sessionName)).toBeUndefined();
298-
});
299-
300-
test('record stop keeps normal app session open after recording', async () => {
301-
const sessionStore = makeSessionStore();
302-
const sessionName = 'app-session';
303-
const session = makeIosSimulatorRecordingSession(sessionName, {
304-
appBundleId: 'com.apple.Preferences',
305-
});
306-
sessionStore.set(sessionName, session);
307-
308-
const response = await runRecordCommand({
309-
sessionStore,
310-
sessionName,
311-
positionals: ['stop'],
312-
});
313-
314-
expect(response?.ok).toBe(true);
315-
expect(sessionStore.get(sessionName)).toBe(session);
316-
expect(sessionStore.get(sessionName)?.recording).toBeUndefined();
317-
});
318-
319283
test('record stop keeps normal app session open when stop validation fails', async () => {
320284
vi.useFakeTimers();
321285
vi.setSystemTime(20_000);

0 commit comments

Comments
 (0)