Skip to content

Commit 723c363

Browse files
test(webview): pin zoo-gateway seeding to every-profile semantics
The review thread on the seeding suite measured true against 45795c8: every seeding case put a single zoo-gateway profile in the store, where a first-only check, a last-only check, an every-profile check and the shipped any-profile guard all take the same branch, and the case titled "...stale or missing token" never left zooSessionToken unset. Added three cases, with the production guard untouched. Two run through it.each over a store of ["Zoo Gateway", "Other", "Zoo Gateway 2"] where "Other" is an anthropic profile: one with the stale profile last, one with it first; each asserts handleZooCodeCallback ran with the fresh token and that getProfile was never asked about "Other", which is what exercises the apiProvider filter. The third gives a zoo-gateway profile with a current base URL and no token at all, and asserts seeding still runs. Controls, each applied to src/core/webview/ClineProvider.ts, measured, then reverted (the file's blob is ee8203a before and after, and git checkout HEAD -- confirmed it): zooGatewayProfiles.slice(0, 1) fails the stale-last case; .slice(-1) fails the stale-first case; replacing the apiProvider filter with () => true fails the "Other" assertion in the stale-last row; requiring a non-null token before comparing fails the no-token case. Every mutation kills exactly one test and nothing else. vitest core/webview + core/config: 44 files / 1299 tests green (1296 before this commit, plus the three new cases). prettier --check, tsc --noEmit -p . and eslint --max-warnings=0 are clean; scope unchanged at 810 extension-package executable lines (no production change).
1 parent 45795c8 commit 723c363

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9785,6 +9785,73 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
97859785

97869786
expect(handleSpy).toHaveBeenCalledWith("current-token")
97879787
})
9788+
// The up-to-date guard reads every zoo-gateway profile rather than one end of the list, and it
9789+
// skips profiles that belong to another provider. With a single profile in the store a
9790+
// first-only, a last-only and an every-profile check all behave the same, so the order of the
9791+
// two rows below is what pins the guard down.
9792+
it.each([
9793+
{
9794+
title: "re-seeds when a later zoo-gateway profile is stale and the first is current",
9795+
profiles: ["Zoo Gateway", "Other", "Zoo Gateway 2"],
9796+
staleProfile: "Zoo Gateway 2",
9797+
},
9798+
{
9799+
title: "re-seeds when the first zoo-gateway profile is stale and the last is current",
9800+
profiles: ["Zoo Gateway", "Other", "Zoo Gateway 2"],
9801+
staleProfile: "Zoo Gateway",
9802+
},
9803+
])("$title", async ({ profiles, staleProfile }) => {
9804+
const { getCachedZooCodeToken } = await import("../../../services/zoo-code-auth")
9805+
vi.mocked(getCachedZooCodeToken).mockReturnValue("fresh-token")
9806+
const handleSpy = vi.spyOn(provider, "handleZooCodeCallback").mockResolvedValue(undefined)
9807+
const getProfile = vi.fn().mockImplementation(({ name }: { name: string }) =>
9808+
// Name-keyed so the non-gateway profile reads as up to date: the only way this test
9809+
// fails on that profile is if the provider filter stops ignoring it.
9810+
name === staleProfile
9811+
? {
9812+
zooSessionToken: "stale-token",
9813+
zooGatewayBaseUrl: "https://www.zoocode.dev/api/gateway/v1",
9814+
}
9815+
: {
9816+
zooSessionToken: "fresh-token",
9817+
zooGatewayBaseUrl: "https://www.zoocode.dev/api/gateway/v1",
9818+
},
9819+
)
9820+
;(provider as MemberSwapTarget).providerSettingsManager = {
9821+
listConfig: vi.fn().mockResolvedValue(
9822+
profiles.map((name) => ({
9823+
name,
9824+
apiProvider:
9825+
name === "Other" ? providerIdentifiers.anthropic : providerIdentifiers.zooGateway,
9826+
})),
9827+
),
9828+
getProfile,
9829+
}
9830+
9831+
await provider["ensureZooGatewayProfileSeeded"]()
9832+
9833+
expect(handleSpy).toHaveBeenCalledWith("fresh-token")
9834+
expect(getProfile.mock.calls.map(([arg]) => arg.name)).not.toContain("Other")
9835+
})
9836+
9837+
it("re-seeds when a zoo-gateway profile carries no token at all", async () => {
9838+
const { getCachedZooCodeToken } = await import("../../../services/zoo-code-auth")
9839+
vi.mocked(getCachedZooCodeToken).mockReturnValue("fresh-token")
9840+
const handleSpy = vi.spyOn(provider, "handleZooCodeCallback").mockResolvedValue(undefined)
9841+
;(provider as MemberSwapTarget).providerSettingsManager = {
9842+
listConfig: vi
9843+
.fn()
9844+
.mockResolvedValue([{ name: "Zoo Gateway", apiProvider: providerIdentifiers.zooGateway }]),
9845+
// An imported or half-written profile: the base URL is right, the token is absent.
9846+
getProfile: vi
9847+
.fn()
9848+
.mockResolvedValue({ zooGatewayBaseUrl: "https://www.zoocode.dev/api/gateway/v1" }),
9849+
}
9850+
9851+
await provider["ensureZooGatewayProfileSeeded"]()
9852+
9853+
expect(handleSpy).toHaveBeenCalledWith("fresh-token")
9854+
})
97889855
})
97899856
})
97909857
})

0 commit comments

Comments
 (0)