-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathsession-routing.test.ts
More file actions
113 lines (102 loc) · 2.94 KB
/
session-routing.test.ts
File metadata and controls
113 lines (102 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { test, type TestContext } from 'vitest';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { SessionStore } from '../session-store.ts';
import { resolveEffectiveSessionName } from '../session-routing.ts';
import type { SessionState } from '../types.ts';
function makeSession(name: string): SessionState {
return {
name,
device: {
platform: 'android',
id: 'emulator-5554',
name: 'Pixel',
kind: 'emulator',
booted: true,
},
createdAt: Date.now(),
actions: [],
};
}
function makeStore(t: TestContext): SessionStore {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-session-routing-'));
t.onTestFinished(() => {
fs.rmSync(root, { recursive: true, force: true });
});
return new SessionStore(path.join(root, 'sessions'));
}
test('does not reuse lone active session for implicit default session from another scope', (t) => {
const store = makeStore(t);
store.set('android', makeSession('android'));
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-cwd-scope-'));
t.onTestFinished(() => {
fs.rmSync(cwd, { recursive: true, force: true });
});
const resolved = resolveEffectiveSessionName(
{
token: 't',
session: 'default',
command: 'open',
positionals: ['com.google.android.apps.maps'],
flags: {},
meta: { cwd },
},
store,
);
assert.match(resolved, /^cwd:[a-f0-9]{16}:default$/);
assert.notEqual(resolved, 'android');
});
test('uses git worktree root for implicit default session scope', (t) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-cwd-scope-'));
const nested = path.join(root, 'packages', 'app');
fs.mkdirSync(path.join(root, '.git'));
fs.mkdirSync(nested, { recursive: true });
t.onTestFinished(() => {
fs.rmSync(root, { recursive: true, force: true });
});
const store = makeStore(t);
const fromRoot = resolveEffectiveSessionName(
{
token: 't',
session: 'default',
command: 'snapshot',
positionals: [],
flags: {},
meta: { cwd: root },
},
store,
);
const fromNested = resolveEffectiveSessionName(
{
token: 't',
session: 'default',
command: 'snapshot',
positionals: [],
flags: {},
meta: { cwd: nested },
},
store,
);
assert.equal(fromNested, fromRoot);
});
test('keeps explicitly configured default session global', (t) => {
const store = makeStore(t);
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-cwd-scope-'));
t.onTestFinished(() => {
fs.rmSync(cwd, { recursive: true, force: true });
});
const resolved = resolveEffectiveSessionName(
{
token: 't',
session: 'default',
command: 'snapshot',
positionals: [],
flags: {},
meta: { cwd, sessionExplicit: true },
},
store,
);
assert.equal(resolved, 'default');
});