Skip to content

Commit d19bb3f

Browse files
test(extension): cover the explicit unset at the API viewStates door
The row on src/extension/__tests__/api-configuration.spec.ts:101 was right that the API boundary pinned only the populated map, and an explicit unset is the same hazard: ContextProxy reads an undefined value as a delete - the repo relies on update(key, undefined) at ContextProxy.ts:173, :280-282, :305 and :346 - and withoutInvalidDisplaySettings cannot catch the key either, because it filters through Object.entries, so a key holding undefined survives it and reaches both writes. One thing worth recording about the shape of the test, because it decides whether the case has teeth: toHaveBeenCalledWith compares the way toEqual does and ignores undefined-valued keys. Measured with a throwaway probe against this vitest: a mock called with { soundEnabled: true, viewStates: undefined } satisfies toHaveBeenCalledWith({ soundEnabled: true }), while toStrictEqual on the same shape fails with + "viewStates": undefined. So an assertion written only in the loose form would have passed on this head with the drop removed, and the strict assertions on the captured arguments are the ones carrying the teeth here. The loose assertions stay next to them for continuity with the case above. Case at api-configuration.spec.ts:109-137: setConfiguration({ viewStates: undefined, soundEnabled: true }) must call contextProxy.setValues and providerSettingsManager.saveConfig with an object that strictly equals { soundEnabled: true }, against the profile name default, and must log the ignore. Control: with the guard block at src/extension/api.ts:645-656 spliced out the file reports 2 failed | 9 passed, the new case red on expected { viewStates: undefined, ... } to strictly equal { soundEnabled: true }; with the guard in place it is 11 passed, exit 0. Gates on the committed text: api-configuration 11, displaySettings 22, ClineProvider 475, webviewMessageHandler 176, all passing; src tsc --noEmit exit 0; eslint clean, and neither touched file carries a suppression entry, so src/eslint-suppressions.json came back byte-identical to its blob at 3298; the compile-job command list reproduced the previous heads exactly in job order - 1,0,0,0,1,1,0,0,0,0,0,0,0 - with the same two box-local attributions (format:check against 2004 locally-CRLF files, none of them the file touched here, and the two solheim record.sh suites needing ffprobe and POSIX separators). Test-only: no behaviour touched, no changeset, no CHANGELOG, no suppression change.
1 parent 696aa22 commit d19bb3f

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

‎src/extension/__tests__/api-configuration.spec.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,42 @@ describe("API - configuration", () => {
100100
)
101101
})
102102

103+
// An explicit unset is the same hazard as a crafted map, because ContextProxy reads an undefined value as a
104+
// delete (the repo relies on update(key, undefined) at ContextProxy.ts:173, :280-282, :305 and :346), and
105+
// withoutInvalidDisplaySettings cannot catch it either - it filters by Object.entries, so a key holding
106+
// undefined survives it. toHaveBeenCalledWith compares the way toEqual does and ignores undefined-valued
107+
// keys, so the loose assertions alone could not tell a dropped key from a forwarded undefined; the strict
108+
// assertions on the captured arguments are what carry the teeth here.
109+
it("drops an explicitly unset viewStates value before either write", async () => {
110+
const setValues = vi.fn().mockResolvedValue(undefined)
111+
const saveConfig = vi.fn().mockResolvedValue("default-id")
112+
const postStateToWebview = vi.fn().mockResolvedValue(undefined)
113+
const log = vi.fn()
114+
const provider = {
115+
context: {},
116+
on: vi.fn(),
117+
log,
118+
contextProxy: { setValues },
119+
providerSettingsManager: { saveConfig, setModeConfig: vi.fn().mockResolvedValue(undefined) },
120+
postStateToWebview,
121+
} as unknown as ClineProvider
122+
const outputChannel = { appendLine: vi.fn() } as unknown as vscode.OutputChannel
123+
const api = new API(outputChannel, provider, makeClineProviderFactory())
124+
125+
await api.setConfiguration({ viewStates: undefined, soundEnabled: true } as unknown as RooCodeSettings)
126+
127+
const [valuesArgument] = setValues.mock.calls[0] as [RooCodeSettings]
128+
const [savedName, savedArgument] = saveConfig.mock.calls[0] as [string, RooCodeSettings]
129+
expect(savedName).toBe("default")
130+
expect(valuesArgument).toStrictEqual({ soundEnabled: true })
131+
expect(savedArgument).toStrictEqual({ soundEnabled: true })
132+
expect(setValues).toHaveBeenCalledWith({ soundEnabled: true })
133+
expect(saveConfig).toHaveBeenCalledWith("default", { soundEnabled: true })
134+
expect(log).toHaveBeenCalledWith(
135+
"[setConfiguration] Ignored a caller-supplied viewStates map; the registered map is written by the extension host.",
136+
)
137+
})
138+
103139
describe("the display settings", () => {
104140
const setup = () => {
105141
const setValues = vi.fn().mockResolvedValue(undefined)

0 commit comments

Comments
 (0)