Skip to content

Commit 0a77cf8

Browse files
test(webview): cover both halves of the sibling task-handler rebuild selector
The rebuild that applies a saved profile's settings to a running task is keyed on the task's own profile name rather than on the view's pin (ClineProvider.ts:2897-2902), and the case at this file's :6365 that the review row pointed at covers the overlay refresh, not that selector. Two cases now cover it: a sibling whose task follows the saved profile, whose handler rebuild is asserted with the settings and with forceRebuild: true and exactly once, and a sibling whose task follows another profile, whose rebuild is asserted not to happen at all. The rebuild itself is stubbed so the case asserts the call and its options rather than the internals of a handler build; the one assertion-free cast is there because updateTaskApiHandlerIfNeeded is private and vi.spyOn needs the object and the key together, which the private-field alternative cannot give it. The profile-store doubles are spies on the public methods (saveConfig, listConfig, setModeConfig) rather than manager replacements, so this commit adds no suppression directive. Controls, run rather than described. Change forceRebuild: true to false at the call site and the matching case is the only failure in core/webview: Test Files 1 failed | 33 passed (34), Tests 1 failed | 955 passed (956), so the option is asserted rather than assumed. Comment the call line out and the same case is the only failure again, so the rebuild call is what makes it pass rather than the surrounding loop. The non-matching case stays green under both, which is its job. With production restored: Test Files 34 passed (34), Tests 956 passed (956); tsc -p . --noEmit exit 0, eslint --max-warnings=0 --no-warn-ignored on the file exit 0, prettier --check exit 0, and src/eslint-suppressions.json untouched. Test-only, and __tests__ is one of the mutation gate's excluded path segments (scripts/stryker-diff.mjs:85), so this adds nothing to the changed executable-line bucket. Review row: ClineProvider.spec.ts:6365 on this PR.
1 parent 515cc02 commit 0a77cf8

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

‎src/core/webview/__tests__/ClineProvider.spec.ts‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6366,6 +6366,115 @@ describe("ClineProvider", () => {
63666366
await saver.dispose()
63676367
await pinned.dispose()
63686368
})
6369+
6370+
// The task-handler rebuild is keyed on the task's own profile name rather than on the view's
6371+
// pin: a task restored from history can follow profile A while its view pins profile B, and only
6372+
// the matching side gets its handler rebuilt with forceRebuild (ClineProvider.ts:2897-2902).
6373+
// These two cases are the matching and non-matching halves of that branch, which is the coverage
6374+
// the review row on this file asked for.
6375+
it("rebuilds a sibling task's API handler with a forced rebuild when that task follows the saved profile", async () => {
6376+
const saver = new ClineProvider(
6377+
mockContext,
6378+
mockOutputChannel,
6379+
"sidebar",
6380+
new ContextProxy(mockContext),
6381+
new WebviewFocusTracker(),
6382+
)
6383+
const runner = new ClineProvider(
6384+
mockContext,
6385+
mockOutputChannel,
6386+
"editor",
6387+
new ContextProxy(mockContext),
6388+
new WebviewFocusTracker(),
6389+
)
6390+
// The rebuild itself is stubbed so the case asserts the call and its options rather than the
6391+
// internals of a handler build. The assertion-free cast is needed because
6392+
// updateTaskApiHandlerIfNeeded is private on ClineProvider and vi.spyOn needs the object and
6393+
// the key together; the private-field alternative of instance["name"] cannot be spied.
6394+
const task = new Task(defaultTaskOptions)
6395+
Object.defineProperty(task, "taskApiConfigName", { value: "shared-profile" })
6396+
vi.spyOn(runner, "getCurrentTask").mockReturnValue(task)
6397+
vi.spyOn(saver, "getCurrentTask").mockReturnValue(undefined)
6398+
const rebuildTarget = runner as unknown as {
6399+
updateTaskApiHandlerIfNeeded: (
6400+
settings: Record<string, unknown>,
6401+
options?: { forceRebuild?: boolean },
6402+
) => void
6403+
}
6404+
const rebuild = vi.spyOn(rebuildTarget, "updateTaskApiHandlerIfNeeded").mockImplementation(() => {})
6405+
vi.spyOn(saver.providerSettingsManager, "saveConfig").mockResolvedValue("shared-id")
6406+
vi.spyOn(saver.providerSettingsManager, "listConfig").mockResolvedValue([
6407+
{ name: "shared-profile", id: "shared-id" },
6408+
])
6409+
vi.spyOn(saver.providerSettingsManager, "setModeConfig").mockResolvedValue(undefined)
6410+
6411+
await saver.upsertProviderProfile(
6412+
"shared-profile",
6413+
{ apiProvider: providerIdentifiers.anthropic, apiKey: "fresh-key" },
6414+
false,
6415+
)
6416+
6417+
// Forced, because the saved settings can change with the provider and model both the same,
6418+
// and a rebuild that skipped on equality would leave the running task on the old client.
6419+
expect(rebuild).toHaveBeenCalledWith(
6420+
expect.objectContaining({ apiProvider: providerIdentifiers.anthropic, apiKey: "fresh-key" }),
6421+
{ forceRebuild: true },
6422+
)
6423+
expect(rebuild).toHaveBeenCalledTimes(1)
6424+
6425+
await saver.dispose()
6426+
await runner.dispose()
6427+
vi.restoreAllMocks()
6428+
})
6429+
6430+
it("leaves a sibling task alone when that task follows a different profile than the one saved", async () => {
6431+
const saver = new ClineProvider(
6432+
mockContext,
6433+
mockOutputChannel,
6434+
"sidebar",
6435+
new ContextProxy(mockContext),
6436+
new WebviewFocusTracker(),
6437+
)
6438+
const runner = new ClineProvider(
6439+
mockContext,
6440+
mockOutputChannel,
6441+
"editor",
6442+
new ContextProxy(mockContext),
6443+
new WebviewFocusTracker(),
6444+
)
6445+
// Same shape as the case above with one value changed: the sibling's task follows another
6446+
// profile, so its handler must keep the settings it was built with rather than inherit this
6447+
// save's settings. Its overlay refresh is a separate question and is covered by the two cases
6448+
// above this one; this case is only about the rebuild's own selector.
6449+
const task = new Task(defaultTaskOptions)
6450+
Object.defineProperty(task, "taskApiConfigName", { value: "other-profile" })
6451+
vi.spyOn(runner, "getCurrentTask").mockReturnValue(task)
6452+
vi.spyOn(saver, "getCurrentTask").mockReturnValue(undefined)
6453+
const rebuildTarget = runner as unknown as {
6454+
updateTaskApiHandlerIfNeeded: (
6455+
settings: Record<string, unknown>,
6456+
options?: { forceRebuild?: boolean },
6457+
) => void
6458+
}
6459+
const rebuild = vi.spyOn(rebuildTarget, "updateTaskApiHandlerIfNeeded").mockImplementation(() => {})
6460+
vi.spyOn(saver.providerSettingsManager, "saveConfig").mockResolvedValue("shared-id")
6461+
vi.spyOn(saver.providerSettingsManager, "listConfig").mockResolvedValue([
6462+
{ name: "shared-profile", id: "shared-id" },
6463+
])
6464+
vi.spyOn(saver.providerSettingsManager, "setModeConfig").mockResolvedValue(undefined)
6465+
6466+
await saver.upsertProviderProfile(
6467+
"shared-profile",
6468+
{ apiProvider: providerIdentifiers.anthropic, apiKey: "fresh-key" },
6469+
false,
6470+
)
6471+
6472+
expect(rebuild).not.toHaveBeenCalled()
6473+
6474+
await saver.dispose()
6475+
await runner.dispose()
6476+
vi.restoreAllMocks()
6477+
})
63696478
})
63706479

63716480
describe("saveViewState", () => {

0 commit comments

Comments
 (0)