Skip to content

Commit bafdf4d

Browse files
Answer the three review rows at 932c9a4 with the cases they name
Run the partial-observation cleanup tests against a real ObservationRegistry, so the entry the failure exit decides about is the object the registry actually stored: a stand-in that builds a fresh object on every lookup cannot show ownership at all, and the two rows that name a concurrent read could only assert on doubles. A concurrent complete read that records this very version keeps its entry, the entry this call created is still forgotten while it is the recorded one, and a partial concurrent read behind the same version is forgotten too - that is where matching fields and ownership part company, recorded as production behaves it, with no production line moved. Add the ARN the settings row says is missing: the Bedrock spec now rerenders the same tree with a matching ARN after the mismatch, asserts the region warning is gone, that the format error is still absent, and that the input carries the new ARN. Add the accept path the provider-validation row pins at the line it names: a model that is in the fetched routerModels list earns no error from getModelValidationError, beside the rejection case that was already there. Legs run before this commit, each transcript under .tmp-cr-audit/_scratch/u181: the src core vitest leg on applyDiffTool.failureReporting printed 37 tests passed in 1 file before the change and 38 in 1 file after; the Bedrock ARN spec printed 2 before and 3 after; validate.provider-validation printed 18 before and 19 after. Each new assertion was inverted once: flipping the keep case's forget expectation failed that test with 'expected forget to be called at least once'; asking for the regionMismatch text after the matching rerender failed it with TestingLibraryElementError, unable to find /regionMismatch/; asking the accept path to be defined failed with 'expected undefined to be defined'. Every file was written back to the digest its passing run used. The first push attempt was stopped by the pre-push hook: its check-types leg reported TS2540 on assigning the installed registry to the read-only Task property. The case now holds a mutable view of the double for that one assignment, src tsc --noEmit is silent, and the root check-types leg finished 12 successful, 12 total; the src vitest leg was run again on the fixed file and printed 38 passed in 1 file, and the inverted keep-case expectation failed it again before the file was written back. prettier 3.9.10 --check passes on all three files. eslint under --max-warnings=0 printed nothing on each, and an injected unused variable made the same command fail on the same file, so those legs read the files instead of ignoring them. src/eslint-suppressions.json stayed 30910 B, byte identical to its head blob: no count moved, no suppression was added, and the --prune-suppressions line-ending rewrite it made was written back from that blob.
1 parent 932c9a4 commit bafdf4d

3 files changed

Lines changed: 116 additions & 13 deletions

File tree

‎src/core/tools/__tests__/applyDiffTool.failureReporting.spec.ts‎

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import fs from "fs/promises"
22
import path from "path"
33

44
import type { DiffResult, ToolResponse } from "../../../shared/tools"
5+
import type { FileObservation } from "../../task/observationRegistry"
56
import type { Task } from "../../task/Task"
7+
import { ObservationRegistry } from "../../task/observationRegistry"
68
import { fileExistsAtPath } from "../../../utils/fs"
79
import { MultiSearchReplaceDiffStrategy } from "../../diff/strategies/multi-search-replace"
810
import type { ToolCallbacks } from "../BaseTool"
@@ -538,33 +540,93 @@ describe("ApplyDiffTool failure reporting", () => {
538540
// the hunks were computed against, and a failure exit revokes exactly that observation.
539541
// A matching token is not the same entry - a concurrent complete read can carry the same
540542
// token and deserve to stay.
541-
function _handEntryToAnotherRead(complete: boolean) {
542-
let lookups = 0
543-
vi.mocked(mockTask.observationRegistry.get).mockImplementation(() => {
544-
const created = vi.mocked(mockTask.observationRegistry.observe).mock.calls.at(0)
545-
if (lookups++ === 0 || created === undefined) {
546-
// Nothing observed yet, so this call is the one that creates the partial entry.
547-
return undefined
543+
// Every case installs a real registry, so the entry the tool creates is the object the registry
544+
// actually stores. A stand-in that builds a fresh object on each lookup never hands the failure
545+
// exit the entry it is deciding about, and an identity-based cleanup would then fail whatever
546+
// the implementation did. The concurrent read replaces that stored object through observe and
547+
// carries the very version the tool recorded.
548+
function installRealRegistry(concurrentComplete?: boolean) {
549+
const observeForReal = ObservationRegistry.prototype.observe
550+
const forgetForReal = ObservationRegistry.prototype.forget
551+
const registry = new ObservationRegistry()
552+
let observedPath: string | undefined
553+
let created: FileObservation | undefined
554+
let concurrent: FileObservation | undefined
555+
let entryAtForget: FileObservation | undefined
556+
const observeSpy = vi.spyOn(registry, "observe").mockImplementation((absolutePath, version, complete) => {
557+
observeForReal.call(registry, absolutePath, version, complete)
558+
observedPath = absolutePath
559+
if (created !== undefined) {
560+
return
548561
}
549-
// The second lookup is the failure exit deciding whether it may forget.
550-
return { version: created[1], observedAt: 0, complete }
562+
created = registry.get(absolutePath)
563+
if (concurrentComplete !== undefined) {
564+
observeForReal.call(registry, absolutePath, version, concurrentComplete)
565+
concurrent = registry.get(absolutePath)
566+
}
567+
})
568+
const forgetSpy = vi.spyOn(registry, "forget").mockImplementation((absolutePath) => {
569+
entryAtForget = registry.get(absolutePath)
570+
return forgetForReal.call(registry, absolutePath)
551571
})
572+
// Task declares the registry read-only, so installing one per case needs a mutable view.
573+
const taskWithRegistry = mockTask as { observationRegistry: ObservationRegistry }
574+
taskWithRegistry.observationRegistry = registry
575+
const observedPathOfTool = (): string => {
576+
if (observedPath === undefined) {
577+
throw new Error("the tool never recorded an observation")
578+
}
579+
return observedPath
580+
}
581+
return {
582+
registry,
583+
observeSpy,
584+
forgetSpy,
585+
observedPathOfTool,
586+
created: () => created,
587+
concurrent: () => concurrent,
588+
entryAtForget: () => entryAtForget,
589+
}
552590
}
553591

554592
it("keeps the entry a concurrent complete read recorded on the same version", async () => {
555-
_handEntryToAnotherRead(true)
593+
const recorded = installRealRegistry(true)
556594
const output = await runApplyDiff({ success: false, failParts: makeFailureSet(1) }, 1)
557595

558596
expect(output).toContain("FAILURE-MARKER-1")
559-
expect(mockTask.observationRegistry.forget).not.toHaveBeenCalled()
597+
expect(recorded.observeSpy.mock.calls[0]?.[2]).toBe(false)
598+
expect(recorded.created()?.complete).toBe(false)
599+
expect(recorded.concurrent()?.complete).toBe(true)
600+
expect(recorded.concurrent()?.version).toBe(recorded.created()?.version)
601+
expect(recorded.forgetSpy).not.toHaveBeenCalled()
602+
expect(recorded.registry.get(recorded.observedPathOfTool())).toBe(recorded.concurrent())
560603
})
561604

562605
it("forgets the entry this call created while it is still the recorded one", async () => {
563-
_handEntryToAnotherRead(false)
606+
const recorded = installRealRegistry()
607+
const output = await runApplyDiff({ success: false, failParts: makeFailureSet(1) }, 1)
608+
609+
expect(output).toContain("FAILURE-MARKER-1")
610+
expect(recorded.concurrent()).toBeUndefined()
611+
expect(recorded.entryAtForget()).toBe(recorded.created())
612+
expect(recorded.forgetSpy).toHaveBeenCalledWith(recorded.observedPathOfTool())
613+
expect(recorded.registry.get(recorded.observedPathOfTool())).toBeUndefined()
614+
})
615+
616+
// This is where ownership and matching fields part company: the entry the failure exit
617+
// compares is not the one this call created, yet its version and completeness match, so
618+
// production forgets it. Recorded as it behaves, with no production change.
619+
it("forgets the entry a partial concurrent read left behind the same version", async () => {
620+
const recorded = installRealRegistry(false)
564621
const output = await runApplyDiff({ success: false, failParts: makeFailureSet(1) }, 1)
565622

566623
expect(output).toContain("FAILURE-MARKER-1")
567-
expect(mockTask.observationRegistry.forget).toHaveBeenCalledWith(expect.stringContaining("file.txt"))
624+
expect(recorded.concurrent()?.version).toBe(recorded.created()?.version)
625+
expect(recorded.concurrent()?.complete).toBe(false)
626+
expect(recorded.entryAtForget()).toBeDefined()
627+
expect(recorded.entryAtForget()).not.toBe(recorded.created())
628+
expect(recorded.forgetSpy).toHaveBeenCalledWith(recorded.observedPathOfTool())
629+
expect(recorded.registry.get(recorded.observedPathOfTool())).toBeUndefined()
568630
})
569631
})
570632
})

‎webview-ui/src/components/settings/providers/__tests__/BedrockCustomArn.arn-validation.spec.tsx‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,36 @@ describe("BedrockCustomArn - the memoised ARN validation", () => {
103103
screen.getByText("settings:validation.arn.regionMismatch arnRegion=eu-west-1 region=us-east-1"),
104104
).toBeDefined()
105105
})
106+
it("drops the region warning once a matching ARN arrives and keeps that ARN in the input", () => {
107+
const base: ProviderSettings = { apiProvider: providerIdentifiers.bedrock, awsRegion: "us-east-1" }
108+
const setApiConfigurationField = vi.fn()
109+
const mismatchedArn =
110+
"arn:aws:bedrock:eu-west-1:123456789012:inference-profile/eu.anthropic.claude-3-7-sonnet-20250219-v1:0"
111+
const matchedArn =
112+
"arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0"
113+
114+
const { rerender } = render(
115+
<BedrockCustomArn apiConfiguration={base} setApiConfigurationField={setApiConfigurationField} />,
116+
)
117+
rerender(
118+
<BedrockCustomArn
119+
apiConfiguration={{ ...base, awsCustomArn: mismatchedArn }}
120+
setApiConfigurationField={setApiConfigurationField}
121+
/>,
122+
)
123+
expect(
124+
screen.getByText("settings:validation.arn.regionMismatch arnRegion=eu-west-1 region=us-east-1"),
125+
).toBeDefined()
126+
127+
rerender(
128+
<BedrockCustomArn
129+
apiConfiguration={{ ...base, awsCustomArn: matchedArn }}
130+
setApiConfigurationField={setApiConfigurationField}
131+
/>,
132+
)
133+
134+
expect(screen.queryByText(/regionMismatch/)).toBeNull()
135+
expect(screen.queryByText("settings:providers.invalidArnFormat")).toBeNull()
136+
expect((screen.getByTestId("custom-arn-input") as HTMLInputElement).value).toBe(matchedArn)
137+
})
106138
})

‎webview-ui/src/utils/__tests__/validate.provider-validation.spec.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,13 @@ describe("getModelValidationError - the model a dynamic provider rejected", () =
179179
"settings:validation.modelAvailability modelId=not-in-the-list",
180180
)
181181
})
182+
it("accepts the model that is in the fetched list", () => {
183+
const config: ProviderSettings = {
184+
apiProvider: providerIdentifiers.openrouter,
185+
openRouterApiKey: "mock-key",
186+
openRouterModelId: "valid-model",
187+
}
188+
189+
expect(getModelValidationError(config, t, routerModels)).toBeUndefined()
190+
})
182191
})

0 commit comments

Comments
 (0)