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 { isOutsideWorkingTree } from '../hooks/is-outside-working-tree' |
| 4 | |
| 5 | tier('builtin') |
| 6 | |
| 7 | describe('is-outside-working-tree', () => { |
| 8 | const WORK = { cwd: '/work/src', toplevel: '/work' } |
| 9 | |
| 10 | test('the top and what is spelled under it are inside', () => { |
| 11 | for (const path of [ |
| 12 | '/work', |
| 13 | '/work/', |
| 14 | '/work/app.ts', |
| 15 | '/work//src/./deep/../a.ts', |
| 16 | 'a.ts', |
| 17 | './deep/a.ts', |
| 18 | '../app.ts', |
| 19 | ]) { |
| 20 | expect(isOutsideWorkingTree(path, WORK), path).toBe(false) |
| 21 | } |
| 22 | }) |
| 23 | |
| 24 | test('elsewhere, climbed out, or a sibling sharing its spelling: outside', () => { |
| 25 | for (const path of [ |
| 26 | '/', |
| 27 | '/tmp/notes.md', |
| 28 | '/workshop/a.ts', |
| 29 | '/work-old/a.ts', |
| 30 | '/work/../etc/hosts', |
| 31 | '../../elsewhere/a.ts', |
| 32 | ]) { |
| 33 | expect(isOutsideWorkingTree(path, WORK), path).toBe(true) |
| 34 | } |
| 35 | }) |
| 36 | |
| 37 | test('a drive-letter tree: either separator, any case', () => { |
| 38 | const tree = { cwd: 'C:\\Users\\me\\work', toplevel: 'C:/Users/me/work' } |
| 39 | |
| 40 | expect(isOutsideWorkingTree('c:\\users\\me\\work\\a.ts', tree)).toBe(false) |
| 41 | expect(isOutsideWorkingTree('src\\a.ts', tree)).toBe(false) |
| 42 | expect(isOutsideWorkingTree('C:\\Users\\me\\workshop\\a.ts', tree)).toBe( |
| 43 | true, |
| 44 | ) |
| 45 | expect(isOutsideWorkingTree('D:\\Users\\me\\work\\a.ts', tree)).toBe(true) |
| 46 | }) |
| 47 | |
| 48 | test('a tree at the root holds every path', () => { |
| 49 | expect(isOutsideWorkingTree('/tmp/a.ts', { cwd: '/', toplevel: '/' })).toBe( |
| 50 | false, |
| 51 | ) |
| 52 | }) |
| 53 | |
| 54 | test("a session's directory spelled outside its own top proves nothing", () => { |
| 55 | const linked = { cwd: '/tmp/work', toplevel: '/private/tmp/work' } |
| 56 | |
| 57 | expect(isOutsideWorkingTree('/tmp/work/a.ts', linked)).toBe(false) |
| 58 | expect(isOutsideWorkingTree('/elsewhere/a.ts', linked)).toBe(false) |
| 59 | }) |
| 60 | }) |