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 / fixtures / policy-until-stopped.ts
23 lines · 728 BRaw
1import type { On, Settings } from 'claude-code'
2
3/**
4 * Answers every settings read beneath the plugins with the policy given
5 * until the answer is called; every read after it is refused.
6 *
7 * So a test's plugins load under a policy that reads, and meet one that
8 * does not.
9 *
10 * @param on the test's `on`
11 * @param policy the managed settings in force while reads are answered
12 * @param reason what a read is denied with once stopped
13 * @returns `() => void`: from then on a read is denied
14 */
15export function policyUntilStopped(on: On, policy: Settings, reason: string) {
16 let isStopped = false
17
18 on('settings.read', () => (isStopped ? { deny: reason } : { value: policy }))
19
20 return () => {
21 isStopped = true
22 }
23}