Repository navigation
Commit 696aa22
committed
test(webview): pin the unset viewStates write the Anything matcher cannot see
The review row on src/core/webview/__tests__/webviewMessageHandler.spec.ts:2134 was right about the
assertion, and the reason is worth keeping where the next person will read it. expect.anything() excludes
undefined and null, so not.toHaveBeenCalledWith("viewStates", expect.anything()) still passes when the
updateSettings loop writes the key with an undefined value - which is the shape that erases the registered
map, since ContextProxy reads an undefined value as a delete (ContextProxy.ts:464-466 for secrets, and
globalState.update(key, undefined) deletes, which this repo relies on at :173, :280-282, :305 and :346).
The shipped guard is not wrong: webviewMessageHandler.ts:790 drops the key regardless of value, so the
defect here was test strength rather than behaviour. It is worth strengthening anyway because the same file
already pins that undefined shape for another key at :2109-2116, so the weaker form is one copy-paste away.
The asymmetry between the two doubles is the general rule for this family, and it is why the new case asserts
the call rather than a value-shaped matcher: the provider-side test is erase-safe for free because it asserts
on the stored state (ClineProvider.spec.ts:9038-9040, where an unset write makes the equality fail), while
the handler double is a bare contextProxy.setValue mock that has to pin the call and its value. Copy the
stronger form, not the neighbour.
Case: updateSettings with { viewStates: undefined, alwaysDenyUnapprovedCommands: true } must never write
viewStates - neither as undefined nor through the Anything matcher - must still write the other key, and must
log the ignore. Control: with the guard block removed from webviewMessageHandler.ts the file reports 2 failed
| 174 passed, the new case failing with expected "vi.fn()" to not be called with arguments: [ 'viewStates',
undefined ]; with the guard in place it is 176 passed and exit 0.
Gates on the committed text: webviewMessageHandler.spec 176 passing, src tsc --noEmit exit 0, eslint clean
with the file's single suppression entry unchanged at 35 and src/eslint-suppressions.json byte-identical to
its blob at 3298. The compile-job command list was run in job order with the same results as the previous
heads: lint, check-types, code-qa-ci, solheim-smoke check-types, agent-evals unit and check-types, lifecycle
model-check, webview-recovery check-types and model-check and the MCP OAuth check green; format:check red
locally on 2004 files, none of them the file touched here, which passes prettier --check after LF
normalisation, and the two solheim record.sh suites need ffprobe and POSIX path separators that this box
lacks. Test-only change: no behaviour touched, no changeset, no CHANGELOG, no suppression increase.1 parent 138b147 commit 696aa22
1 file changed
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2138 | 2138 | | |
2139 | 2139 | | |
2140 | 2140 | | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
| 2155 | + | |
| 2156 | + | |
| 2157 | + | |
| 2158 | + | |
| 2159 | + | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
2141 | 2164 | | |
2142 | 2165 | | |
2143 | 2166 | | |
| |||
0 commit comments