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 Limits from '../../hooks/limits' |
| 4 | import Turns from '../../hooks/turns' |
| 5 | import Fixtures from '../fixtures' |
| 6 | |
| 7 | tier('builtin') |
| 8 | |
| 9 | describe('turn-diffs-of', () => { |
| 10 | test('turns with edits, newest first, numbered by prompt', () => { |
| 11 | const turns = Turns.turnDiffsOf([ |
| 12 | Fixtures.promptOf('first'), |
| 13 | Fixtures.editsOf(Fixtures.editPatchOf(['-a', '+b'])), |
| 14 | Fixtures.toolResults(), |
| 15 | Fixtures.promptOf('second, nothing edited'), |
| 16 | Fixtures.promptOf('third turn with a long prompt that gets cut'), |
| 17 | Fixtures.editsOf(Fixtures.editPatchOf(['+c']), { |
| 18 | filePath: '/r/new.ts', |
| 19 | type: 'create', |
| 20 | content: 'x\ny', |
| 21 | }), |
| 22 | Fixtures.toolResults(), |
| 23 | ]) |
| 24 | |
| 25 | expect(turns.map(turn => turn.index)).toEqual([3, 1]) |
| 26 | expect(turns[0]?.preview).toBe('third turn with a long prompt…') |
| 27 | |
| 28 | expect( |
| 29 | turns[0]?.files.map(file => [ |
| 30 | file.path, |
| 31 | file.added, |
| 32 | file.removed, |
| 33 | file.isNewFile, |
| 34 | ]), |
| 35 | ).toEqual([ |
| 36 | ['/r/a.ts', 1, 0, false], |
| 37 | ['/r/new.ts', 2, 0, true], |
| 38 | ]) |
| 39 | |
| 40 | expect(turns[0]?.files[1]?.hunks).toEqual([ |
| 41 | { oldStart: 0, newStart: 1, lines: ['+x', '+y'] }, |
| 42 | ]) |
| 43 | |
| 44 | expect(turns[1]?.files.map(file => [file.added, file.removed])).toEqual([ |
| 45 | [1, 1], |
| 46 | ]) |
| 47 | }) |
| 48 | |
| 49 | test('a file edited twice in a turn: both hunks, summed', () => { |
| 50 | const [turn] = Turns.turnDiffsOf([ |
| 51 | Fixtures.promptOf('go'), |
| 52 | Fixtures.editsOf( |
| 53 | Fixtures.editPatchOf(['+a']), |
| 54 | Fixtures.editPatchOf(['-b', '+c']), |
| 55 | ), |
| 56 | ]) |
| 57 | |
| 58 | expect(turn?.files).toHaveLength(1) |
| 59 | expect(turn?.files[0]?.hunks).toHaveLength(2) |
| 60 | expect([turn?.files[0]?.added, turn?.files[0]?.removed]).toEqual([2, 1]) |
| 61 | }) |
| 62 | |
| 63 | test('results that are not file edits are ignored', () => { |
| 64 | expect( |
| 65 | Turns.turnDiffsOf([ |
| 66 | Fixtures.promptOf('go'), |
| 67 | Fixtures.editsOf({ stdout: 'x' }, 'text', null), |
| 68 | ]), |
| 69 | ).toEqual([]) |
| 70 | }) |
| 71 | |
| 72 | test('a big created file is cut at the line cap and says so', () => { |
| 73 | const [turn] = Turns.turnDiffsOf([ |
| 74 | Fixtures.promptOf('write it'), |
| 75 | Fixtures.editsOf({ |
| 76 | filePath: '/r/big.ts', |
| 77 | type: 'create', |
| 78 | content: Array.from( |
| 79 | { length: Fixtures.BIG_LINES }, |
| 80 | (_, at) => `l${at}`, |
| 81 | ).join('\n'), |
| 82 | }), |
| 83 | ]) |
| 84 | |
| 85 | const file = turn?.files[0] |
| 86 | |
| 87 | expect(file?.hunks.flatMap(hunk => hunk.lines)).toHaveLength( |
| 88 | Limits.MAX_LINES_PER_FILE, |
| 89 | ) |
| 90 | |
| 91 | expect(file?.isTruncated).toBe(true) |
| 92 | expect(file?.added).toBe(Fixtures.BIG_LINES) |
| 93 | }) |
| 94 | }) |