File size: 2,132 Bytes
776286d | 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 | import { describe, expect, test, tier } from 'claude-code/testing'
import Backend from '../../hooks/backend'
import Fixtures from '../fixtures'
tier('builtin')
describe('backend-of', () => {
test('as published: no probes, so git or nothing', async () => {
const inGit = Fixtures.gitHostOf()
const outside = Fixtures.recordingBackendHostOf({})
expect((await Backend.backendOf(inGit.host, []))?.words.lister).toBe('git')
expect(await Backend.backendOf(outside.host, [])).toBeNull()
expect(
[inGit.programs, outside.programs],
'pinning spawns the one rev-parse and walks nothing',
).toEqual([['git'], ['git']])
})
test('a declining probe leaves a git working tree to git', async () => {
const declining = Fixtures.recordingProbeOf(null)
const inGit = Fixtures.gitHostOf()
const backend = await Backend.backendOf(inGit.host, [declining.probe])
expect(backend?.words.lister).toBe('git')
expect(backend?.baseModes).toEqual(['session', 'uncommitted', 'branch'])
expect(declining.asked).toEqual([inGit.host])
expect(inGit.programs).toEqual(['git'])
})
test('a probe that answers pins before git is asked', async () => {
const inGit = Fixtures.gitHostOf()
const backend = await Backend.backendOf(inGit.host, [
Fixtures.recordingProbeOf('/home/me/src').probe,
])
expect(backend?.repository).toEqual({ toplevel: '/home/me/src' })
expect(inGit.programs).toEqual([])
})
test('the probes are asked in order and the first answer pins', async () => {
const declining = Fixtures.recordingProbeOf(null)
const first = Fixtures.recordingProbeOf('/first')
const second = Fixtures.recordingProbeOf('/second')
const { host } = Fixtures.recordingBackendHostOf({})
const backend = await Backend.backendOf(host, [
declining.probe,
first.probe,
second.probe,
])
expect(backend?.repository).toEqual({ toplevel: '/first' })
expect([
declining.asked.length,
first.asked.length,
second.asked.length,
]).toEqual([1, 1, 0])
expect(declining.asked[0]).toBe(host)
})
})
|