|
1 | | -/** The re-read denial circuit breaker and the Write blind-drop guard compose: a whole-file denial loop the breaker ends hands over one real read the Write guard counts as seen, while a line-range retry is locked rather than let through, so a refused retry is never counted as seen. Provenance: HAND-DERIVED from a 200-line file; the whole-file rows read it unranged, the range rows serve its first 60 lines; the first version of the range sequence was driven through the built hook entry (PreToolUse/PostToolUse payloads with Read and Write tool inputs) and printed the deny, the breaker's advisory note, and the blind-drop refusal quoted in the merge report. The range rows pin main's 44e95a016, where a refused range read locks later slices instead of going through the breaker (the fileRereadDenyKey comment in src/hooks_read.ts). */ |
| 1 | +/** The re-read denial circuit breaker and the Write blind-drop guard compose: a whole-file denial loop the breaker ends hands over one real read the Write guard counts as seen, while a line-range retry is redirected once and then let through for that same range, so a refused retry is never counted as seen. Provenance: HAND-DERIVED from a 200-line file; the whole-file rows read it unranged, the range rows serve its first 60 lines; the first version of the range sequence was driven through the built hook entry (PreToolUse/PostToolUse payloads with Read and Write tool inputs) and printed the deny, the breaker's advisory note, and the blind-drop refusal quoted in the merge report. The range rows pin main's 44e95a016, where a refused range read locks later slices instead of going through the breaker (the fileRereadDenyKey comment in src/hooks_read.ts). */ |
2 | 2 | import * as fs from 'node:fs' |
3 | 3 | import * as os from 'node:os' |
4 | 4 | import * as path from 'node:path' |
@@ -87,16 +87,19 @@ describe('the re-read circuit breaker and the Write blind-drop guard', () => { |
87 | 87 | expect((await preWriteRewriteHandler(writeEvent(target, FIRST_60_ONLY))).hookType).toBe('pass') |
88 | 88 | }) |
89 | 89 |
|
90 | | - it('locks the second identical line-range retry instead of letting it through the breaker', () => { |
| 90 | + // bf14d04ad (CHANGELOG: "redirect to the cached output once, then fail open for that same range") replaced the old second-retry lock: the redirect is spent on the first retry, the identical retry is let through, and a shifted window stays denied. |
| 91 | + it('lets the second identical line-range retry through after one redirect, and keeps a shifted window denied', () => { |
91 | 92 | const target = seed('ts') |
92 | 93 | serveFirstWindow(target) |
93 | 94 | expect(preReadHandler(rangeReadEvent('pre_tool_use', target)).hookType, 'the first retry is denied').toBe('deny') |
94 | 95 | const second = preReadHandler(rangeReadEvent('pre_tool_use', target)) |
95 | | - expect(second.hookType, 'the second identical range retry stays denied').toBe('deny') |
96 | | - if (second.hookType === 'deny') expect(second.message).toContain('Line-range reads of this file are locked') |
| 96 | + expect(second.hookType, 'the second identical range retry is let through').toBe('context') |
| 97 | + if (second.hookType === 'context') expect(second.context).toContain('Read allowed after the prior redirect') |
| 98 | + const shifted = preReadHandler(makeHookEvent({ eventName: 'pre_tool_use', toolName: 'Read', toolInput: { file_path: target, offset: 2, limit: 58 }, sessionId: 'breaker-write' })) |
| 99 | + expect(shifted.hookType, 'a shifted window inside the served lines stays denied').toBe('deny') |
97 | 100 | }) |
98 | 101 |
|
99 | | - it('still refuses a Write that drops lines nobody saw after a locked line-range retry', async () => { |
| 102 | + it('still refuses a Write that drops lines nobody saw after line-range retries', async () => { |
100 | 103 | const target = seed('ts') |
101 | 104 | serveFirstWindow(target) |
102 | 105 | preReadHandler(rangeReadEvent('pre_tool_use', target)) |
|
0 commit comments