-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshells-command.test.ts
More file actions
83 lines (70 loc) · 2.85 KB
/
Copy pathshells-command.test.ts
File metadata and controls
83 lines (70 loc) · 2.85 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
// Tests for /shells, which drives the session-scoped ShellRegistry the REPL
// owns (ctx.shells). Uses a real registry — a persistent shell is a real
// process and the interesting assertions are about real ones being listed and
// really closed.
import { afterEach, describe, expect, it } from 'vitest';
import { tmpdir } from 'node:os';
import { SessionManager, ShellRegistry } from '@deepcode/core';
import { CommandRegistry, type SessionContext } from './commands.js';
const reg = new CommandRegistry();
const opened: ShellRegistry[] = [];
function registry(): ShellRegistry {
const r = new ShellRegistry();
opened.push(r);
return r;
}
afterEach(async () => {
await Promise.all(opened.splice(0).map((r) => r.closeAll()));
});
function ctx(overrides: Partial<SessionContext> = {}): SessionContext {
return {
cwd: tmpdir(),
model: 'deepseek-chat',
mode: 'default',
effort: 'medium',
settings: {},
creds: { apiKey: 'sk-test' },
sessionId: 's1',
sessions: new SessionManager({ root: tmpdir() }),
usage: { inputTokens: 0, outputTokens: 0, reasoningTokens: 0, cacheReadTokens: 0 },
...overrides,
};
}
const run = async (args: string[], c: SessionContext): Promise<string> =>
(await reg.match('/shells')!.cmd.run(args, c)).join('\n');
describe('/shells', () => {
it('says what opens a shell when none are open', async () => {
const out = await run([], ctx({ shells: registry() }));
expect(out).toContain('No persistent shells open');
expect(out).toContain('ShellOpen');
});
it('lists an open shell with where it started', async () => {
const shells = registry();
const id = await shells.open({ cwd: tmpdir() });
const out = await run([], ctx({ shells }));
expect(out).toContain(id);
expect(out).toContain(tmpdir());
expect(out).toContain('close when this session ends');
});
it('closes a shell for real, not just from the listing', async () => {
const shells = registry();
const id = await shells.open({ cwd: tmpdir() });
expect(await run(['close', id], ctx({ shells }))).toContain(`Closed ${id}`);
expect(shells.get(id)).toBeUndefined();
expect(shells.list()).toEqual([]);
});
it('reports an unknown id instead of claiming it closed something', async () => {
const out = await run(['close', 'shell-999'], ctx({ shells: registry() }));
expect(out).toContain('No open shell');
});
it('asks for an id when close is given none', async () => {
expect(await run(['close'], ctx({ shells: registry() }))).toContain('Usage:');
});
it('rejects an unrecognised argument rather than silently listing', async () => {
const out = await run(['kill', 'shell-1'], ctx({ shells: registry() }));
expect(out).toContain('Unknown argument');
});
it('says so when the host owns no registry', async () => {
expect(await run([], ctx())).toContain('unavailable');
});
});