Skip to content

Commit 2542e99

Browse files
test(core): measure the registry in the token-failure rows
Both rows named "leaves the registry empty" asserted only the result shape and carried the registry claim in a comment. Arm the failure the way the warm companions already arm it - only computeVersionToken asks for bigint stats, so arm on that call rather than on call parity (spec 1910-1914, 2010-2014) - and assert on the registry itself: ObservationRegistry exposes get, has, delete, clear and a size getter (observationRegistry.ts:51-91), so emptiness is reg.size === 0 alongside the path-level get the missing-file row already uses at 1862. Control: letting the bigint stat succeed so the read observes makes exactly the native row fail with "expected 1 to be 0", which is the assertion doing work. 96 passed with the production head untouched.
1 parent 12e591f commit 2542e99

1 file changed

Lines changed: 27 additions & 12 deletions

File tree

‎src/core/tools/__tests__/readFileTool.spec.ts‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,11 +1868,17 @@ describe("ReadFileTool", () => {
18681868
})
18691869
const callbacks = createMockCallbacks()
18701870

1871-
// The directory-check stat succeeds; the stat inside computeVersionToken
1872-
// rejects, so the token lookup fails after the file was read successfully.
1871+
// Only computeVersionToken asks for bigint stats, so arm the failure on that
1872+
// call rather than on call parity, which ties the test to how many stats a read
1873+
// happens to make: the directory check stays green and only the token lookup
1874+
// rejects.
18731875
const okStats = makeStats()
1874-
mockedFsStat.mockResolvedValueOnce(okStats)
1875-
mockedFsStat.mockRejectedValueOnce(new Error("EACCES"))
1876+
mockedFsStat.mockImplementation(async (_path: unknown, options?: { bigint?: boolean }) => {
1877+
if (options?.bigint === true) {
1878+
throw new Error("EACCES")
1879+
}
1880+
return okStats
1881+
})
18761882
mockedIsBinaryFile.mockResolvedValue(false)
18771883
mockedFsReadFile.mockResolvedValue(Buffer.from("content"))
18781884

@@ -1885,8 +1891,11 @@ describe("ReadFileTool", () => {
18851891
expect(callbacks.pushToolResult).toHaveBeenCalledWith(expect.stringContaining("existing.ts"))
18861892
expect(callbacks.pushToolResult).toHaveBeenCalledWith(expect.stringContaining("content"))
18871893

1888-
// The failed token lookup never observes: with a fresh registry the only path this read
1889-
// touches is the one it read, so target-absence is what "stays empty" means here.
1894+
// The failed token lookup observed nothing, and the name's claim is about the
1895+
// registry, not only about this path: it is still empty.
1896+
const reg = mockTask.observationRegistry!
1897+
expect(reg.size).toBe(0)
1898+
expect(reg.get(path.resolve("/test/workspace", "existing.ts"))).toBeUndefined()
18901899
})
18911900

18921901
it("drops the stale observation when the version-token lookup fails after an earlier successful read", async () => {
@@ -1945,11 +1954,15 @@ describe("ReadFileTool", () => {
19451954
})
19461955
const callbacks = createMockCallbacks()
19471956

1948-
// Same shape as the native case, on the legacy multi-file path:
1949-
// directory-check stat succeeds, the token stat rejects after the read.
1957+
// Same shape as the native case, on the legacy multi-file path: only the bigint
1958+
// stat that computeVersionToken asks for is made to reject.
19501959
const okStats = makeStats()
1951-
mockedFsStat.mockResolvedValueOnce(okStats)
1952-
mockedFsStat.mockRejectedValueOnce(new Error("EACCES"))
1960+
mockedFsStat.mockImplementation(async (_path: unknown, options?: { bigint?: boolean }) => {
1961+
if (options?.bigint === true) {
1962+
throw new Error("EACCES")
1963+
}
1964+
return okStats
1965+
})
19531966
mockedIsBinaryFile.mockResolvedValue(false)
19541967
mockedFsReadFile.mockResolvedValue("legacy content")
19551968
// The legacy path slices the raw content through readWithSlice, so the slice
@@ -1978,8 +1991,10 @@ describe("ReadFileTool", () => {
19781991
expect(callbacks.pushToolResult).toHaveBeenCalledWith(expect.stringContaining("legacy.ts"))
19791992
expect(callbacks.pushToolResult).toHaveBeenCalledWith(expect.stringContaining("legacy content"))
19801993

1981-
// The failed token lookup never observes: with a fresh registry the only path this read
1982-
// touches is the one it read, so target-absence is what "stays empty" means here.
1994+
// Same claim as the native case, measured on the registry itself.
1995+
const reg = mockTask.observationRegistry!
1996+
expect(reg.size).toBe(0)
1997+
expect(reg.get(path.resolve("/test/workspace", "legacy.ts"))).toBeUndefined()
19831998
})
19841999

19852000
it("drops the stale observation when a legacy read loses its version token after an earlier successful read", async () => {

0 commit comments

Comments
 (0)