Skip to content

Commit 94b624c

Browse files
test(vps2-f2a): cover the launched view and share the settings key lists
- registerCommands.spec: plusButtonClicked gains the isViewLaunched true case. It counts SidebarProvider.focus executions around the handler rather than asserting on global history, asserts whenViewResolved was not called, and asserts both actions are still posted. Control: neutralising the guard at registerCommands.ts:194 turns the case red. 70 tests to 71. - webviewMessageHandler: build the two key sets from the exported GLOBAL_SETTINGS_KEYS and PROVIDER_SETTINGS_KEYS and rename the local global set to GLOBAL_SETTINGS_KEY_SET, so it no longer shares a name with the shared array. Measured first with a throwaway probe spec: the exported lists and the schema shape keys have an empty symmetric difference, and the derived provider-profile set is identical either way, so this is naming and single source rather than behaviour - the handler suite is 187 tests before and after. Control: emptying the provider-profile set fails the host-owned-keys case, so the guard the refactor keeps is load-bearing. Gates on this head: src tsc 0, eslint --max-warnings=0 clean on both files, prettier clean, registerCommands 71 and webviewMessageHandler 187 green.
1 parent 8559e8b commit 94b624c

2 files changed

Lines changed: 46 additions & 5 deletions

File tree

‎src/activate/__tests__/registerCommands.spec.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,47 @@ describe("registerCommands handlers", () => {
900900
action: "focusInput",
901901
})
902902
})
903+
904+
// The shared double above never sets isViewLaunched, so every case that goes through it
905+
// takes the not-launched branch. This is the other side of the guard at
906+
// registerCommands.ts:194: a view that is already resolved must neither focus the pane nor
907+
// wait on the resolution gate, while still posting both actions.
908+
it("plusButtonClicked skips the focus command and the wait when the sidebar view is already launched", async () => {
909+
const sidebarProvider = Object.assign({} as ClineProvider, {
910+
isViewLaunched: true,
911+
evictCurrentTask: vi.fn().mockResolvedValue(undefined),
912+
refreshWorkspace: vi.fn().mockResolvedValue(undefined),
913+
postMessageToWebview: vi.fn().mockResolvedValue(undefined),
914+
whenViewResolved: vi.fn().mockResolvedValue(undefined),
915+
})
916+
const commandHandlers: Record<string, (...args: unknown[]) => unknown> = {}
917+
;(vscode.commands.registerCommand as Mock).mockImplementation(
918+
(id: string, cb: (...args: unknown[]) => unknown) => {
919+
commandHandlers[id] = cb
920+
return { dispose: vi.fn() }
921+
},
922+
)
923+
registerCommands({ context: mockContext, outputChannel: mockOutputChannel, provider: sidebarProvider })
924+
925+
// Counted rather than absolute: earlier cases in this file also invoke commands, so the
926+
// claim under test is that this handler adds no focus call of its own.
927+
const executeCommandMock = vscode.commands.executeCommand as Mock
928+
const isFocus = (command: unknown) => typeof command === "string" && command.includes("SidebarProvider.focus")
929+
const focusCallsBefore = executeCommandMock.mock.calls.filter(isFocus).length
930+
931+
await commandHandlers["zoo-code.plusButtonClicked"]()
932+
933+
expect(executeCommandMock.mock.calls.filter(isFocus).length).toBe(focusCallsBefore)
934+
expect(sidebarProvider.whenViewResolved).not.toHaveBeenCalled()
935+
expect(sidebarProvider.postMessageToWebview).toHaveBeenNthCalledWith(1, {
936+
type: "action",
937+
action: "chatButtonClicked",
938+
})
939+
expect(sidebarProvider.postMessageToWebview).toHaveBeenNthCalledWith(2, {
940+
type: "action",
941+
action: "focusInput",
942+
})
943+
})
903944
it("plusButtonClicked calls evictCurrentTask on the registered sidebar provider", async () => {
904945
await handlers["zoo-code.plusButtonClicked"]()
905946

‎src/core/webview/webviewMessageHandler.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import {
2424
checkoutRestorePayloadSchema,
2525
getCompletionCheckpoint,
2626
providerIdentifiers,
27-
providerSettingsSchema,
28-
globalSettingsSchema,
27+
GLOBAL_SETTINGS_KEYS,
28+
PROVIDER_SETTINGS_KEYS,
2929
retiredProviderIdentifiers,
3030
LmStudioModelsMessageType,
3131
OllamaModelsMessageType,
@@ -126,9 +126,9 @@ const HOST_OWNED_SETTINGS = new Set(["apiConfiguration", "listApiConfigMeta", "v
126126
// task unvalidated. Every settings payload the webview actually sends was checked (packages/types
127127
// vs webview-ui) and carries global keys only, so a profile-only key here is never a real setting.
128128
// Keys that are genuinely global too (rateLimitSeconds) stay on the ordinary route.
129-
const GLOBAL_SETTINGS_KEYS = new Set(Object.keys(globalSettingsSchema.shape))
130-
const PROVIDER_PROFILE_SETTINGS = new Set(
131-
Object.keys(providerSettingsSchema.shape).filter((key) => !GLOBAL_SETTINGS_KEYS.has(key)),
129+
const GLOBAL_SETTINGS_KEY_SET = new Set<string>(GLOBAL_SETTINGS_KEYS)
130+
const PROVIDER_PROFILE_SETTINGS = new Set<string>(
131+
PROVIDER_SETTINGS_KEYS.filter((key) => !GLOBAL_SETTINGS_KEY_SET.has(key)),
132132
)
133133

134134
// Serializes handling of "telemetrySetting" messages. Each invocation reads the previous

0 commit comments

Comments
 (0)