Skip to content

Commit abe5683

Browse files
test(extension): cover secret filtering and export retention, type the doubles
Three review comments on the settings surface measured true against f3fa813: - ContextProxy.spec.ts "omits host-owned viewStates from a settings export" passed on an empty export: the only positive check was toBeDefined(). It now sets customInstructions, a portable global setting that globalSettingsExportSchema keeps, and asserts the exported value, so a regression that drops settings fails. The viewStates rejection checks and the claim-token escape check stay. - api-configuration.spec.ts "omits host-owned viewStates from the settings the API returns" had no secret in its fixture, so nothing covered the isSecretStateKey half of getConfiguration(). The fixture now carries apiKey and the test asserts the full output with toEqual plus a check that neither host-owned value escapes as a string. - The same test's ClineProvider double carries a comment naming the members it provides, and all four OutputChannel doubles come from makeOutputChannel(): vscode.OutputChannel with every member per test-utils/provider.ts:9-13 instead of a double assertion. Controls, both run against this tree and reverted before the commit: dropping !isSecretStateKey(key) from getConfiguration() fails the api-configuration test (1 failed / 10 passed); making ContextProxy.export() parse an empty object fails the export test (1 failed / 64 passed); after `git checkout HEAD --` both files are green again (10/10 and 64/64). Restore point f3fa813. Test titles unchanged in both specs (6 and 75, same order): no case was reworded, skipped or deleted. prettier --check, tsc --noEmit -p . and eslint --max-warnings=0 are clean, and the scope measure still reports 494 extension / 8 types executable lines because specs do not count.
1 parent f3fa813 commit abe5683

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎src/core/config/__tests__/ContextProxy.spec.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,10 +842,13 @@ describe("ContextProxy", () => {
842842
await proxy.setValue("viewStates", {
843843
"export-view": { claimToken: "export-claim-token", mode: "architect" },
844844
})
845+
// A portable global setting the export schema keeps: without it the test would pass on an
846+
// empty export, because every remaining check only asserts absence.
847+
await proxy.setValue("customInstructions", "retain these instructions")
845848
// The cache carries the key; only the export must not.
846849
expect(Object.keys(proxy.getValues())).toContain("viewStates")
847850
const exported = await proxy.export()
848-
expect(exported).toBeDefined()
851+
expect(exported?.customInstructions).toBe("retain these instructions")
849852
expect(exported && Object.keys(exported)).not.toContain("viewStates")
850853
expect(exported && "viewStates" in exported).toBe(false)
851854
// The value must not escape under another name either: the claim token is host state.

‎src/extension/__tests__/api-configuration.spec.ts‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ vi.mock("@roo-code/ipc", () => ({
1212
}))
1313

1414
describe("API - configuration", () => {
15+
// API needs an OutputChannel it can log to. The shared helper in test-utils/provider.ts types one the
16+
// same way, so this double carries every vscode.OutputChannel member and stays type-checked instead
17+
// of cast (AGENTS.md: new code avoids any-style assertions).
18+
const makeOutputChannel = (): vscode.OutputChannel => ({
19+
name: "test-output",
20+
append: vi.fn(),
21+
appendLine: vi.fn(),
22+
replace: vi.fn(),
23+
clear: vi.fn(),
24+
show: vi.fn(),
25+
hide: vi.fn(),
26+
dispose: vi.fn(),
27+
})
1528
it("persists every supplied mode API config mapping", async () => {
1629
const setValues = vi.fn().mockResolvedValue(undefined)
1730
const saveConfig = vi.fn().mockResolvedValue("default-id")
@@ -25,7 +38,7 @@ describe("API - configuration", () => {
2538
providerSettingsManager: { saveConfig, setModeConfig },
2639
postStateToWebview,
2740
} as unknown as ClineProvider
28-
const outputChannel = { appendLine: vi.fn() } as unknown as vscode.OutputChannel
41+
const outputChannel = makeOutputChannel()
2942
const api = new API(outputChannel, provider, makeClineProviderFactory())
3043

3144
await api.setConfiguration({
@@ -59,7 +72,7 @@ describe("API - configuration", () => {
5972
providerSettingsManager: { saveConfig, setModeConfig },
6073
postStateToWebview,
6174
} as unknown as ClineProvider
62-
const outputChannel = { appendLine: vi.fn() } as unknown as vscode.OutputChannel
75+
const outputChannel = makeOutputChannel()
6376
const api = new API(outputChannel, provider, makeClineProviderFactory())
6477

6578
await api.setConfiguration({ currentApiConfigName: "default" })
@@ -83,7 +96,7 @@ describe("API - configuration", () => {
8396
},
8497
postStateToWebview: vi.fn().mockResolvedValue(undefined),
8598
} as unknown as ClineProvider
86-
const outputChannel = { appendLine: vi.fn() } as unknown as vscode.OutputChannel
99+
const outputChannel = makeOutputChannel()
87100
return { api: new API(outputChannel, provider, makeClineProviderFactory()), setValues, log }
88101
}
89102

@@ -129,25 +142,32 @@ describe("API - configuration", () => {
129142
})
130143

131144
it("omits host-owned viewStates from the settings the API returns", () => {
145+
// API reads only getValues() in this test; the double provides that plus the members the
146+
// constructor touches (context, on, log) and leaves the rest of ClineProvider unbuilt.
132147
const provider = {
133148
context: {},
134149
on: vi.fn(),
135150
log: vi.fn(),
136151
getValues: () => ({
137152
currentApiConfigName: "default",
138153
// Minted by the host: per-view selections plus the claim token that binds them.
154+
// A secret, so the filter has to drop it for the same reason it drops viewStates.
155+
apiKey: "secret-api-key",
139156
viewStates: { "view-1": { claimToken: "claim-token-1", mode: "code" } },
140157
}),
141158
} as unknown as ClineProvider
142-
const outputChannel = { appendLine: vi.fn() } as unknown as vscode.OutputChannel
159+
const outputChannel = makeOutputChannel()
143160
const api = new API(outputChannel, provider, makeClineProviderFactory())
144161

145162
const configuration = api.getConfiguration()
146163

147-
expect(configuration.currentApiConfigName).toBe("default")
164+
// Exact output: the portable setting survives and both host-owned keys are gone.
165+
expect(configuration).toEqual({ currentApiConfigName: "default" })
148166
expect(Object.keys(configuration)).not.toContain("viewStates")
149167
expect("viewStates" in configuration).toBe(false)
150168
// The value must not escape either: the claim token is host-owned state.
169+
// Neither value may escape either: the claim token and the API key are host-owned state.
151170
expect(JSON.stringify(configuration)).not.toContain("claim-token-1")
171+
expect(JSON.stringify(configuration)).not.toContain("secret-api-key")
152172
})
153173
})

0 commit comments

Comments
 (0)