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 / agents-md / tests / register.test.ts
139 lines · 3.7 KBRaw
1import { describe, expect, test, tier } from 'claude-code/testing'
2
3import Hooks from '../hooks'
4import Fixtures from './fixtures'
5
6tier('builtin')
7
8/**
9 * The blocks the engine hands `prompt.context`.
10 */
11const BLOCKS = [
12 { name: 'claudeMd', text: 'x' },
13 { name: 'currentDate', text: 'today' },
14]
15
16describe('register', () => {
17 test('by default a project with AGENTS.md alone gets it', async ($, on) => {
18 const started = Fixtures.projectOf(
19 on,
20 [Fixtures.ancestorOf('/repo', 'AGENTS.md', '# top\n')],
21 [],
22 )
23
24 on('prompt.context', ($, e) => ({
25 blocks: e.blocks,
26 instructionFiles: e.instructionFiles,
27 }))
28
29 const context = await $.prompt.context({
30 blocks: BLOCKS,
31 instructionFiles: [],
32 })
33
34 expect(context.instructionFiles).toEqual([
35 { path: '/repo/AGENTS.md', kind: 'project', content: '# top\n' },
36 ])
37 expect(context.blocks?.[0]?.text).toContain(
38 'Contents of /repo/AGENTS.md (project instructions, checked into the ' +
39 'codebase):\n\n# top',
40 )
41
42 await started.clock.settle()
43
44 expect(started.lines, 'nothing new in the transcript').toEqual([])
45 expect(started.debugLines).toEqual([
46 'no CLAUDE.md found; AGENTS.md loaded: /repo/AGENTS.md',
47 ])
48 })
49
50 test('by default a project with a CLAUDE.md is left to the engine', async ($, on) => {
51 const started = Fixtures.projectOf(
52 on,
53 [Fixtures.ancestorOf('/repo', 'AGENTS.md', '# top\n')],
54 [Fixtures.ancestorOf('/repo/a/b', 'CLAUDE.md', '# mine\n')],
55 )
56 const handed = [
57 { path: '/repo/a/b/CLAUDE.md', kind: 'project' as const, content: '#' },
58 ]
59
60 on('prompt.context', ($, e) => ({
61 blocks: e.blocks,
62 instructionFiles: e.instructionFiles,
63 }))
64
65 expect(
66 await $.prompt.context({ blocks: BLOCKS, instructionFiles: handed }),
67 ).toEqual({ blocks: BLOCKS, instructionFiles: handed })
68
69 await started.clock.settle()
70
71 expect(started.walks).toEqual([])
72 expect(started.lines).toEqual([])
73 expect(started.debugLines).toEqual([])
74 })
75
76 test('a failed walk leaves the context as handed', async ($, on) => {
77 Fixtures.unreadableProjectOf(on)
78
79 on('prompt.context', ($, e) => ({
80 blocks: e.blocks,
81 instructionFiles: e.instructionFiles,
82 }))
83
84 expect(
85 await $.prompt.context({ blocks: BLOCKS, instructionFiles: [] }),
86 ).toEqual({ blocks: BLOCKS, instructionFiles: [] })
87 })
88
89 test(
90 'the start sends the mode row alone: no walk, no toast',
91 { plugins: [Fixtures.RECORDING] },
92 async ($, on) => {
93 const started = Fixtures.projectOf(
94 on,
95 [Fixtures.ancestorOf('/repo', 'AGENTS.md', '# top\n')],
96 [],
97 )
98
99 expect(await $.session.start(Fixtures.SESSION)).toEqual({
100 cwd: '/repo/a/b',
101 })
102
103 await started.clock.settle()
104
105 expect(Fixtures.rowsOf(started)).toEqual([
106 [
107 'log',
108 {
109 event: Hooks.MODE_EVENT,
110 props: {
111 mode: { value: 'claude-md-or-agents-md', of: [...Hooks.MODES] },
112 is_interactive: true,
113 },
114 },
115 ],
116 ])
117 expect(Hooks.MODE_EVENT).toBe('agents_md_mode')
118 expect(started.walks).toEqual([])
119 expect(started.toasts).toEqual([])
120 },
121 )
122
123 test('with no telemetry noun the start goes on untouched', async ($, on) => {
124 const started = Fixtures.projectOf(
125 on,
126 [Fixtures.ancestorOf('/repo', 'AGENTS.md', '# top\n')],
127 [],
128 )
129
130 expect(
131 await $.session.start({ ...Fixtures.SESSION, isInteractive: false }),
132 ).toEqual({ cwd: '/repo/a/b' })
133
134 await started.clock.settle()
135
136 expect(Fixtures.rowsOf(started)).toEqual([])
137 expect(started.toasts).toEqual([])
138 })
139})