Skip to content

Commit 4fc14c4

Browse files
committed
fix(fws): address CodeRabbit round-4 findings (unknown guard + pre-hydration defaults test)
McpHub.spec: narrow the caught value with an unknown-safe type guard instead of an object cast when reading error.code (the 'in' check narrows to object & Record<'code', unknown>). ExtensionStateContext: export createInitialExtensionState and add a focused pre-hydration test asserting perWriteCheckpoints: true, changeCardDetail: 'summary', and writeDelayMs: DEFAULT_WRITE_DELAY_MS from the initializer itself, so a regression that drops the series defaults can no longer hide behind merge fixtures that supply the keys manually.
1 parent d2239ce commit 4fc14c4

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎src/services/mcp/__tests__/McpHub.spec.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ vi.mock("../../../utils/safeWriteJson", () => ({
5656
// Mirror the production safeWriteJson merge contract: only ENOENT
5757
// and SyntaxError are recoverable; an EACCES or I/O failure must
5858
// reject before the merge callback runs.
59-
const code = (error as { code?: string })?.code
59+
// unknown-safe narrowing: no cast on the caught value (the "in"
60+
// check narrows to object & Record<"code", unknown>).
61+
const code =
62+
error && typeof error === "object" && "code" in error && typeof error.code === "string"
63+
? error.code
64+
: undefined
6065
if (!(error instanceof SyntaxError) && code !== "ENOENT") {
6166
throw error
6267
}

‎webview-ui/src/context/ExtensionStateContext.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export const mergeExtensionState = (prevState: ExtensionState, newState: Partial
197197
}
198198
}
199199

200-
const createInitialExtensionState = (): ExtensionState => ({
200+
export const createInitialExtensionState = (): ExtensionState => ({
201201
apiConfiguration: {},
202202
version: "",
203203
clineMessages: [],

‎webview-ui/src/context/__tests__/ExtensionStateContext.spec.tsx‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ import {
1111
type RouterModels,
1212
DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
1313
DEFAULT_DIFF_FUZZY_THRESHOLD,
14+
DEFAULT_WRITE_DELAY_MS,
1415
} from "@roo-code/types"
1516

16-
import { ExtensionStateContextProvider, useExtensionState, mergeExtensionState } from "../ExtensionStateContext"
17+
import {
18+
ExtensionStateContextProvider,
19+
useExtensionState,
20+
mergeExtensionState,
21+
createInitialExtensionState,
22+
} from "../ExtensionStateContext"
1723

1824
const TestComponent = () => {
1925
const { allowedCommands, setAllowedCommands, soundEnabled, showRooIgnoredFiles, setShowRooIgnoredFiles } =
@@ -212,6 +218,18 @@ describe("ExtensionStateContext", () => {
212218
expect(JSON.parse(screen.getByTestId("show-rooignored-files").textContent!)).toBe(true)
213219
})
214220

221+
it("initializes the checkpoint keys and write delay to the pre-hydration defaults", () => {
222+
// The initializer itself (not a merge fixture) must carry the series
223+
// defaults: a regression that dropped them from createInitialExtensionState
224+
// would otherwise stay hidden because the merge tests supply the keys
225+
// manually.
226+
const state = createInitialExtensionState()
227+
228+
expect(state.perWriteCheckpoints).toBe(true)
229+
expect(state.changeCardDetail).toBe("summary")
230+
expect(state.writeDelayMs).toBe(DEFAULT_WRITE_DELAY_MS)
231+
})
232+
215233
it("initializes shadowed context fields from initialState", () => {
216234
const routerModels = {} as RouterModels
217235
const marketplaceItems: MarketplaceItem[] = [

0 commit comments

Comments
 (0)