|
1 | | -import type { |
2 | | - CommandRunInput, |
3 | | - ProcessRunResult, |
4 | | - SessionStartInput, |
5 | | -} from 'claude-code' |
6 | | -import { expect, test, tier } from 'claude-code/testing' |
| 1 | +import { describe, expect, test, tier } from 'claude-code/testing' |
7 | 2 |
|
8 | | -tier('builtin') |
| 3 | +import Fixtures from './fixtures' |
9 | 4 |
|
10 | | -const SESSION: SessionStartInput = { |
11 | | - surface: 'terminal', |
12 | | - isInteractive: true, |
13 | | - cwd: '/work', |
14 | | -} |
15 | | -const DIFF: CommandRunInput = { |
16 | | - command: 'diff', |
17 | | - args: '', |
18 | | - origin: { kind: 'composer' }, |
19 | | -} |
20 | | -const NOT_A_REPOSITORY: ProcessRunResult = { |
21 | | - exitCode: 128, |
22 | | - stdout: '', |
23 | | - stderr: 'fatal: not a git repository', |
24 | | -} |
25 | 5 | const BUILTIN_HOLDS = '"/diff" refused: it is the built-in /diff' |
26 | 6 |
|
27 | | -test('outside a git repository /diff says so and opens nothing', async ($, on) => { |
28 | | - const opened: string[] = [] |
29 | | - on('session.start', ($, e) => ({ cwd: e.cwd })) |
30 | | - on('command.register', ($, e) => ({ value: { command: e.name } })) |
31 | | - on('process.run', () => ({ value: NOT_A_REPOSITORY })) |
32 | | - on('ui.open', ($, e, next) => { |
33 | | - opened.push(e.id) |
34 | | - return next(e) |
35 | | - }) |
| 7 | +tier('builtin') |
36 | 8 |
|
37 | | - await $.session.start(SESSION) |
38 | | - const { text } = await $.command.run(DIFF) |
| 9 | +describe('command', () => { |
| 10 | + test('outside a repository /diff says so, opens nothing', async ($, on) => { |
| 11 | + const opened: string[] = [] |
| 12 | + Fixtures.startsSession(on) |
| 13 | + on('process.run', () => ({ value: Fixtures.NOT_A_REPOSITORY })) |
| 14 | + on('ui.open', ($, e, next) => { |
| 15 | + opened.push(e.id) |
39 | 16 |
|
40 | | - expect(text).toContain("isn't in a git repository") |
41 | | - expect(opened).toEqual([]) |
42 | | -}) |
| 17 | + return next(e) |
| 18 | + }) |
43 | 19 |
|
44 | | -test('a git that never answers is not "no repository"', async ($, on) => { |
45 | | - on('session.start', ($, e) => ({ cwd: e.cwd })) |
46 | | - on('command.register', ($, e) => ({ value: { command: e.name } })) |
47 | | - on('process.run', () => ({ |
48 | | - deny: 'git aborted: still running after 5000ms', |
49 | | - })) |
| 20 | + await $.session.start(Fixtures.SESSION) |
| 21 | + const { text } = await $.command.run(Fixtures.DIFF) |
50 | 22 |
|
51 | | - await $.session.start(SESSION) |
52 | | - const { text } = await $.command.run(DIFF) |
| 23 | + expect(text).toContain("isn't in a git repository") |
| 24 | + expect(opened).toEqual([]) |
| 25 | + }) |
53 | 26 |
|
54 | | - expect(text).toContain("git didn't answer") |
55 | | -}) |
| 27 | + test('a git that never answers is not "no repository"', async ($, on) => { |
| 28 | + Fixtures.startsSession(on) |
| 29 | + on('process.run', () => ({ |
| 30 | + deny: 'git aborted: still running after 5000ms', |
| 31 | + })) |
56 | 32 |
|
57 | | -test('with the built-in holding /diff, the plugin stands down', async ($, on) => { |
58 | | - const logged: string[] = [] |
59 | | - on('session.start', ($, e) => ({ cwd: e.cwd })) |
60 | | - on('command.register', () => ({ deny: BUILTIN_HOLDS })) |
61 | | - on('command.run', () => ({ text: 'the built-in /diff ran' })) |
62 | | - on('ui.log', ($, e) => { |
63 | | - logged.push(e.text) |
64 | | - return { value: undefined } |
| 33 | + await $.session.start(Fixtures.SESSION) |
| 34 | + const { text } = await $.command.run(Fixtures.DIFF) |
| 35 | + |
| 36 | + expect(text).toContain("git didn't answer") |
65 | 37 | }) |
66 | 38 |
|
67 | | - await $.session.start(SESSION) |
| 39 | + test('when the built-in holds /diff, the mod stands down', async ($, on) => { |
| 40 | + const logged: string[] = [] |
| 41 | + on('session.start', ($, e) => ({ cwd: e.cwd })) |
| 42 | + on('command.register', () => ({ deny: BUILTIN_HOLDS })) |
| 43 | + on('command.run', () => ({ text: 'the built-in /diff ran' })) |
| 44 | + on('ui.log', ($, e) => { |
| 45 | + logged.push(e.text) |
68 | 46 |
|
69 | | - expect(await $.command.run(DIFF)).toEqual({ text: 'the built-in /diff ran' }) |
70 | | - expect(logged).toEqual([]) |
71 | | -}) |
| 47 | + return { value: undefined } |
| 48 | + }) |
| 49 | + |
| 50 | + await $.session.start(Fixtures.SESSION) |
72 | 51 |
|
73 | | -test('a refusal the built-in did not cause is said aloud', async ($, on) => { |
74 | | - const logged: string[] = [] |
75 | | - on('session.start', ($, e) => ({ cwd: e.cwd })) |
76 | | - on('command.register', () => ({ deny: '32 commands are registered already' })) |
77 | | - on('ui.log', ($, e) => { |
78 | | - logged.push(e.text) |
79 | | - return { value: undefined } |
| 52 | + expect(await $.command.run(Fixtures.DIFF)).toEqual({ |
| 53 | + text: 'the built-in /diff ran', |
| 54 | + }) |
| 55 | + expect(logged).toEqual([]) |
80 | 56 | }) |
81 | 57 |
|
82 | | - await $.session.start(SESSION) |
| 58 | + test('a refusal the built-in did not cause is said aloud', async ($, on) => { |
| 59 | + const logged: string[] = [] |
| 60 | + on('session.start', ($, e) => ({ cwd: e.cwd })) |
| 61 | + on('command.register', () => ({ |
| 62 | + deny: '32 commands are registered already', |
| 63 | + })) |
| 64 | + on('ui.log', ($, e) => { |
| 65 | + logged.push(e.text) |
83 | 66 |
|
84 | | - expect(logged).toEqual([ |
85 | | - 'could not register /diff: diff: $.command.register: 32 commands are ' + |
86 | | - 'registered already; the diff panel is unavailable this session', |
87 | | - ]) |
| 67 | + return { value: undefined } |
| 68 | + }) |
| 69 | + |
| 70 | + await $.session.start(Fixtures.SESSION) |
| 71 | + |
| 72 | + expect(logged).toEqual([ |
| 73 | + 'could not register /diff: diff: $.command.register: 32 commands are ' + |
| 74 | + 'registered already; the diff panel is unavailable this session', |
| 75 | + ]) |
| 76 | + }) |
88 | 77 | }) |
0 commit comments