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 / sec-default / tests / register.test.ts
82 lines · 2.1 KBRaw
1import { describe, expect, test, tier } from 'claude-code/testing'
2
3import Fixtures from './fixtures'
4
5tier('prepend')
6
7describe('register', () => {
8 test(
9 'under an MCP allowlist a plugin the person installed may not add a tool',
10 {
11 plugins: [
12 Fixtures.registering('mine'),
13 Fixtures.registering('bundled', 'builtin'),
14 ],
15 },
16 async ($, on) => {
17 on('settings.read', () => ({ value: Fixtures.ALLOWLIST }))
18
19 const registered = Fixtures.toolsRegistered(on)
20
21 await $.session.start(Fixtures.SESSION)
22
23 expect(registered).toEqual(['bundled'])
24 },
25 )
26
27 test(
28 'with no allowlist, a plugin the person installed adds its tool',
29 { plugins: [Fixtures.registering('mine')] },
30 async ($, on) => {
31 on('settings.read', () => ({ value: Fixtures.NO_ALLOWLIST }))
32
33 const registered = Fixtures.toolsRegistered(on)
34
35 await $.session.start(Fixtures.SESSION)
36
37 expect(registered).toEqual(['mine'])
38 },
39 )
40
41 test(
42 'a policy that cannot be read counts as one in force',
43 { plugins: [Fixtures.registering('mine')] },
44 async ($, on) => {
45 on('settings.read', () => ({ deny: 'managed settings unreadable' }))
46
47 const registered = Fixtures.toolsRegistered(on)
48
49 await $.session.start(Fixtures.SESSION)
50
51 expect(registered).toEqual([])
52 },
53 )
54
55 test(
56 'the organization tools are listed as its tiers listed them',
57 { plugins: [Fixtures.relabeling, Fixtures.listing] },
58 async ($, on) => {
59 on('settings.read', () => ({ value: Fixtures.ALLOWLIST }))
60 on('tool.list', () => ({ value: [...Fixtures.TOOLS] }))
61
62 const { text } = await $.command.run(Fixtures.TOOLS_COMMAND)
63
64 expect(text?.split('\n')).toEqual([
65 'mcp__corp__search: Searches the corp wiki.',
66 'Bash: relabeled',
67 ])
68 },
69 )
70
71 test(
72 'a prompt section passes over the plugins the person installed',
73 { plugins: [Fixtures.dropping, Fixtures.signing] },
74 async ($, on) => {
75 on('prompt.section', ($, e) => ({ text: e.text }))
76
77 expect(await $.prompt.section(Fixtures.MEMORY)).toEqual({
78 text: 'the org says hi (signed)',
79 })
80 },
81 )
82})