| | @@ -8,7 +8,19 @@ |
| 8 | 8 | tier('builtin') |
| 9 | 9 | |
| 10 | 10 | describe('register', () => { |
| 11 | | - test('/diff at boot joins the boot probe, then asks again', async ($, on) => { |
| 11 | + test('the start asks nothing of git and registers /diff', async ($, on) => { |
| 12 | + const world = Fixtures.inRepository(on) |
| 13 | + |
| 14 | + await $.session.start(Fixtures.SESSION) |
| 15 | + |
| 16 | + expect(world.runs, "no git, as the built-in's start runs none").toEqual([]) |
| 17 | + |
| 18 | + expect(await $.command.run(Fixtures.DIFF), '/diff was registered').toEqual({ |
| 19 | + text: 'Diff panel shown', |
| 20 | + }) |
| 21 | + }) |
| 22 | + |
| 23 | + test('/diff whose probe never answers probes once more', async ($, on) => { |
| 12 | 24 | const probes: (readonly string[])[] = [] |
| 13 | 25 | const clock = Fixtures.startsSession(on) |
| 14 | 26 | |
| | @@ -24,26 +36,42 @@ |
| 24 | 36 | return { value: Fixtures.NOT_A_REPOSITORY } |
| 25 | 37 | }) |
| 26 | 38 | |
| 27 | | - const booting = $.session.start(Fixtures.SESSION) |
| 39 | + await $.session.start(Fixtures.SESSION) |
| 28 | 40 | |
| 29 | | - await clock.settle() |
| 30 | | - |
| 31 | 41 | const ran = $.command.run(Fixtures.DIFF) |
| 32 | 42 | |
| 33 | 43 | await clock.settle() |
| 34 | 44 | |
| 35 | | - expect(probes, 'the boot probe, which /diff joined').toHaveLength(1) |
| 45 | + expect(probes, "this /diff's probe, unanswered yet").toHaveLength(1) |
| 36 | 46 | |
| 37 | 47 | await clock.advance(Limits.GIT_TIMEOUT_MS) |
| 38 | | - await booting |
| 39 | 48 | |
| 40 | 49 | expect(await ran).toEqual({ |
| 41 | 50 | text: expect.stringContaining("isn't in a git repository"), |
| 42 | 51 | }) |
| 43 | 52 | |
| 44 | | - expect(probes, 'then one more of its own').toHaveLength(2) |
| 53 | + expect(probes, 'then one more, which answered').toHaveLength(2) |
| 45 | 54 | }) |
| 46 | 55 | |
| 56 | + test('two /diff typed together probe the repository once', async ($, on) => { |
| 57 | + const world = Fixtures.inRepository(on) |
| 58 | + |
| 59 | + await $.session.start(Fixtures.SESSION) |
| 60 | + |
| 61 | + const [first, second] = await Promise.all([ |
| 62 | + $.command.run(Fixtures.DIFF), |
| 63 | + $.command.run(Fixtures.DIFF), |
| 64 | + ]) |
| 65 | + |
| 66 | + const probes = world.runs.filter(run => |
| 67 | + run.argv.includes('--show-toplevel'), |
| 68 | + ) |
| 69 | + |
| 70 | + expect(first.text).toMatch(/^Diff panel (shown|hidden)$/) |
| 71 | + expect(second.text).toMatch(/^Diff panel (shown|hidden)$/) |
| 72 | + expect(probes, 'the second joined the probe in flight').toHaveLength(1) |
| 73 | + }) |
| 74 | + |
| 47 | 75 | test('outside a repository /diff says so, opens nothing', async ($, on) => { |
| 48 | 76 | const opened: string[] = [] |
| 49 | 77 | |
| | @@ -77,12 +105,20 @@ |
| 77 | 105 | |
| 78 | 106 | test('when the built-in holds /diff, the mod stands down', async ($, on) => { |
| 79 | 107 | const logged: string[] = [] |
| 108 | + const runs: Args<'process.run'>[] = [] |
| 80 | 109 | |
| 81 | 110 | mock.clock(on) |
| 82 | 111 | on('session.start', ($, e) => ({ cwd: e.cwd })) |
| 83 | 112 | on('command.register', () => ({ deny: Fixtures.BUILTIN_HOLDS })) |
| 84 | 113 | on('command.run', () => ({ text: 'the built-in /diff ran' })) |
| 114 | + on('tool.call', () => ({ result: 'edited' })) |
| 85 | 115 | |
| 116 | + on('process.run', ($, e) => { |
| 117 | + runs.push(e) |
| 118 | + |
| 119 | + return { value: Fixtures.gitIn(e.argv) } |
| 120 | + }) |
| 121 | + |
| 86 | 122 | on('ui.log', ($, e) => { |
| 87 | 123 | logged.push(e.text) |
| 88 | 124 | |
| | @@ -95,7 +131,15 @@ |
| 95 | 131 | text: 'the built-in /diff ran', |
| 96 | 132 | }) |
| 97 | 133 | |
| 134 | + await $.tool.call({ |
| 135 | + tool: 'Edit', |
| 136 | + file_path: '/work/app.ts', |
| 137 | + old_string: '1', |
| 138 | + new_string: '2', |
| 139 | + }) |
| 140 | + |
| 98 | 141 | expect(logged).toEqual([]) |
| 142 | + expect(runs, 'idle: no git for /diff or the edit').toEqual([]) |
| 99 | 143 | }) |
| 100 | 144 | |
| 101 | 145 | test('a refusal the built-in did not cause is said aloud', async ($, on) => { |
| | @@ -127,10 +171,16 @@ |
| 127 | 171 | |
| 128 | 172 | await $.session.start(Fixtures.SESSION) |
| 129 | 173 | |
| 174 | + expect(world.runs, 'the start ran nothing').toEqual([]) |
| 175 | + |
| 130 | 176 | expect(await $.command.run(Fixtures.DIFF)).toEqual({ |
| 131 | 177 | text: 'Diff panel shown', |
| 132 | 178 | }) |
| 133 | 179 | |
| 180 | + expect(world.runs[0]?.argv, '/diff found the repository first').toContain( |
| 181 | + '--show-toplevel', |
| 182 | + ) |
| 183 | + |
| 134 | 184 | expect(world.opened).toEqual([ |
| 135 | 185 | { id: 'diff', title: 'Diff', holdToasts: true }, |
| 136 | 186 | ]) |
| | @@ -322,9 +372,13 @@ |
| 322 | 372 | expect(before.text).toContain("isn't in a git repository") |
| 323 | 373 | expect(after.text).toBe('Diff panel shown') |
| 324 | 374 | expect(world.opened[0]?.id).toBe('diff') |
| 325 | | - expect(probes).toHaveLength(3) |
| 326 | 375 | |
| 327 | 376 | expect( |
| 377 | + probes, |
| 378 | + 'the first two /diff probed; the third was pinned', |
| 379 | + ).toHaveLength(2) |
| 380 | + |
| 381 | + expect( |
| 328 | 382 | world.runs.some(run => run.argv.includes('--git-dir=/else/.git')), |
| 329 | 383 | ).toBe(false) |
| 330 | 384 | |
| | @@ -380,7 +434,7 @@ |
| 380 | 434 | const probes = runs.filter(run => run.argv.includes('--show-toplevel')) |
| 381 | 435 | |
| 382 | 436 | expect(text).toContain("isn't in a git repository") |
| 383 | | - expect(probes, "the boot's, then this /diff's; no retry").toHaveLength(2) |
| 437 | + expect(probes, "this /diff's alone; no retry").toHaveLength(1) |
| 384 | 438 | }) |
| 385 | 439 | |
| 386 | 440 | test('/diff on a narrow terminal: the resize line', async ($, on) => { |