spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / tests / backend / backend-of.test.ts
66 lines · 2.0 KBRaw
1import { describe, expect, test, tier } from 'claude-code/testing'
2
3import Backend from '../../hooks/backend'
4import Fixtures from '../fixtures'
5
6tier('builtin')
7
8describe('backend-of', () => {
9 test('as published: no probes, so git or nothing', async () => {
10 const inGit = Fixtures.gitHostOf()
11 const outside = Fixtures.recordingBackendHostOf({})
12
13 expect((await Backend.backendOf(inGit.host, []))?.words.lister).toBe('git')
14 expect(await Backend.backendOf(outside.host, [])).toBeNull()
15
16 expect([inGit.programs, outside.programs]).toEqual([
17 ['git', 'git'],
18 ['git'],
19 ])
20 })
21
22 test('a declining probe leaves a git working tree to git', async () => {
23 const declining = Fixtures.recordingProbeOf(null)
24 const inGit = Fixtures.gitHostOf()
25 const backend = await Backend.backendOf(inGit.host, [declining.probe])
26
27 expect(backend?.words.lister).toBe('git')
28 expect(backend?.baseModes).toEqual(['session', 'uncommitted', 'branch'])
29 expect(declining.asked).toEqual([inGit.host])
30 expect(inGit.programs).toEqual(['git', 'git'])
31 })
32
33 test('a probe that answers pins before git is asked', async () => {
34 const inGit = Fixtures.gitHostOf()
35
36 const backend = await Backend.backendOf(inGit.host, [
37 Fixtures.recordingProbeOf('/home/me/src').probe,
38 ])
39
40 expect(backend?.repository).toEqual({ toplevel: '/home/me/src' })
41 expect(inGit.programs).toEqual([])
42 })
43
44 test('the probes are asked in order and the first answer pins', async () => {
45 const declining = Fixtures.recordingProbeOf(null)
46 const first = Fixtures.recordingProbeOf('/first')
47 const second = Fixtures.recordingProbeOf('/second')
48 const { host } = Fixtures.recordingBackendHostOf({})
49
50 const backend = await Backend.backendOf(host, [
51 declining.probe,
52 first.probe,
53 second.probe,
54 ])
55
56 expect(backend?.repository).toEqual({ toplevel: '/first' })
57
58 expect([
59 declining.asked.length,
60 first.asked.length,
61 second.asked.length,
62 ]).toEqual([1, 1, 0])
63
64 expect(declining.asked[0]).toBe(host)
65 })
66})