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
| 1 | import { describe, expect, test, tier } from 'claude-code/testing' |
| 2 | |
| 3 | import Hooks from '../hooks' |
| 4 | import Fixtures from './fixtures' |
| 5 | |
| 6 | tier('prepend') |
| 7 | |
| 8 | describe('held-verdict', () => { |
| 9 | test('a deny that names its rule is a rule deny; any other is not', () => { |
| 10 | expect( |
| 11 | [Fixtures.RULE_DENY, Fixtures.PLAIN_DENY, Fixtures.ASKED].map( |
| 12 | Hooks.isRuleDeny, |
| 13 | ), |
| 14 | ).toEqual([true, false, false]) |
| 15 | }) |
| 16 | |
| 17 | test('a link of theirs is named when it answered looser than handed', () => { |
| 18 | expect( |
| 19 | Hooks.loosenedByUsers([ |
| 20 | Fixtures.linkOf('listening', 'user', Fixtures.ALLOWED), |
| 21 | Fixtures.linkOf('easy', 'user', Fixtures.ALLOWED), |
| 22 | Fixtures.linkOf('engine', 'core', Fixtures.ASKED), |
| 23 | ]), |
| 24 | ).toEqual(['easy']) |
| 25 | }) |
| 26 | |
| 27 | test('one that never called next is measured against a deny', () => { |
| 28 | expect( |
| 29 | Hooks.loosenedByUsers([ |
| 30 | Fixtures.linkOf('listening', 'user', Fixtures.ALLOWED), |
| 31 | Fixtures.linkOf('blind', 'user', Fixtures.ALLOWED), |
| 32 | ]), |
| 33 | ).toEqual(['blind']) |
| 34 | }) |
| 35 | |
| 36 | test('a tightening, a skipped link and links beneath theirs are not', () => { |
| 37 | expect( |
| 38 | Hooks.loosenedByUsers([ |
| 39 | Fixtures.linkOf('strict', 'user', Fixtures.PLAIN_DENY), |
| 40 | Fixtures.linkOf('passed-over', 'user'), |
| 41 | Fixtures.linkOf('suite', 'append', Fixtures.ALLOWED), |
| 42 | Fixtures.linkOf('bundled', 'builtin', Fixtures.ALLOWED), |
| 43 | Fixtures.linkOf('engine', 'core', Fixtures.RULE_DENY), |
| 44 | ]), |
| 45 | ).toEqual([]) |
| 46 | }) |
| 47 | |
| 48 | test('a batch listed under prepend may hold a plugin of theirs', () => { |
| 49 | expect( |
| 50 | Hooks.loosenedByUsers([ |
| 51 | Fixtures.linkOf('audit+easy', 'prepend', Fixtures.ALLOWED), |
| 52 | Fixtures.linkOf('engine', 'core', Fixtures.RULE_DENY), |
| 53 | ]), |
| 54 | ).toEqual(['audit+easy']) |
| 55 | }) |
| 56 | |
| 57 | test('the handler keeps a deny, and a verdict none of theirs made', () => { |
| 58 | const pastUsers = [ |
| 59 | Fixtures.linkOf('easy', 'user'), |
| 60 | Fixtures.linkOf('engine', 'core', Fixtures.ASKED), |
| 61 | ] |
| 62 | |
| 63 | expect([ |
| 64 | Hooks.caughtAnswer(Fixtures.RULE_DENY, [ |
| 65 | Fixtures.linkOf('easy', 'user', Fixtures.ALLOWED), |
| 66 | ]), |
| 67 | Hooks.caughtAnswer(Fixtures.ASKED, pastUsers), |
| 68 | ]).toEqual([Fixtures.RULE_DENY, Fixtures.ASKED]) |
| 69 | }) |
| 70 | |
| 71 | test('the handler refuses a verdict they loosened, and no verdict', () => { |
| 72 | expect([ |
| 73 | Hooks.caughtAnswer(Fixtures.ALLOWED, [ |
| 74 | Fixtures.linkOf('easy', 'user', Fixtures.ALLOWED), |
| 75 | Fixtures.linkOf('engine', 'core', Fixtures.ASKED), |
| 76 | ]), |
| 77 | Hooks.caughtAnswer(undefined, []), |
| 78 | ]).toEqual([Hooks.UNCHECKED_DENY, Hooks.UNCHECKED_DENY]) |
| 79 | }) |
| 80 | }) |