Skip to content

Commit 82ce1a4

Browse files
refactor(config): trim the branch to the portable-keys and typed-profile-errors unit
Unit 1 of the split published on Zoo-Code-Org/Zoo-Code issue 1992. This commit removes units 2 through 5's content from the branch and moves nothing else: the nine changed files belonging to those units are reset to their content at the merge base e943530, which is where this branch's diff starts. Removed by this commit (9 files, 50 added and 2,703 deleted lines of unit content): src/core/webview/ClineProvider.ts src/core/webview/__tests__/ClineProvider.spec.ts src/core/webview/webviewMessageHandler.ts src/core/webview/__tests__/webviewMessageHandler.spec.ts src/extension/api.ts src/extension/__tests__/api-configuration.spec.ts src/extension/__tests__/api-start-new-task.spec.ts src/__tests__/extension.spec.ts src/services/language-models/copilotModelBroadcast.ts Kept (unit 1, 10 files, 188 added and 4 deleted lines): packages/types global-settings and vscode-extension-host with their two tests, src/core/config ContextProxy, ProviderSettingsManager and importExport with their three specs. The PR-wide 2,945 added-plus-deleted closes as 192 here plus 2,753 removed by this commit. Units 2 through 5 are not opened by this push; they branch from the tip in the declared merge order once this unit is green at its own head.
1 parent bc724b8 commit 82ce1a4

9 files changed

Lines changed: 50 additions & 2703 deletions

File tree

‎src/__tests__/extension.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ describe("extension.ts", () => {
374374
const getAll = vi.mocked(ClineProvider.getAllInstances)
375375
const post = vi.mocked(provider.postMessageToWebview)
376376
getAll.mockReturnValue([provider, provider])
377-
post.mockRejectedValueOnce(new Error("delivery failed")).mockResolvedValue(true)
377+
post.mockRejectedValueOnce(new Error("delivery failed")).mockResolvedValue(undefined)
378378
try {
379379
const { activate } = await import("../extension")
380380
await activate(mockContext)

‎src/core/webview/ClineProvider.ts‎

Lines changed: 27 additions & 936 deletions
Large diffs are not rendered by default.

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

Lines changed: 14 additions & 1635 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ const mockClineProvider = {
128128
},
129129
log: vi.fn(),
130130
postStateToWebview: vi.fn(),
131-
// The webviewDidLaunch handler flushes claims the provider queued before the renderer launched.
132-
deliverPendingViewStateClaims: vi.fn().mockResolvedValue(undefined),
133131
resolveWebviewThemeFixtureProbe: vi.fn(),
134132
getCurrentTask: vi.fn(),
135133
getTaskWithId: vi.fn(),
@@ -2806,24 +2804,6 @@ describe("webviewMessageHandler - telemetrySetting", () => {
28062804
expect(calls.at(-1)).toEqual([true])
28072805
})
28082806

2809-
// Review follow-up on the attach-time claim retry: a claim minted before the renderer launched is
2810-
// held by the provider, because a message posted before the webview attaches its listener can be
2811-
// lost while postMessage still resolves true. The flush therefore belongs to webviewDidLaunch, and
2812-
// it has to run only after isViewLaunched is set - flushing earlier would post back into the window
2813-
// the gate exists to close.
2814-
it("flushes the provider's pending view-state claims on webviewDidLaunch, after isViewLaunched is set", async () => {
2815-
vi.mocked(mockClineProvider.customModesManager.getCustomModes).mockResolvedValue([])
2816-
let launchedWhenFlushed: boolean | undefined
2817-
vi.mocked(mockClineProvider.deliverPendingViewStateClaims).mockImplementationOnce(async () => {
2818-
launchedWhenFlushed = mockClineProvider.isViewLaunched
2819-
})
2820-
2821-
await webviewMessageHandler(mockClineProvider, { type: "webviewDidLaunch" })
2822-
2823-
expect(mockClineProvider.deliverPendingViewStateClaims).toHaveBeenCalledTimes(1)
2824-
expect(launchedWhenFlushed).toBe(true)
2825-
})
2826-
28272807
// CodeRabbit follow-up on the finding #12 fix: webviewDidLaunch's telemetry init read state
28282808
// via an async provider.getStateToPostToWebview().then(...) continuation, outside
28292809
// telemetrySettingQueue -- so it could resolve after a concurrent "telemetrySetting" message
@@ -3075,35 +3055,8 @@ describe("webviewMessageHandler - renameTaskWithId", () => {
30753055
})
30763056
})
30773057

3078-
describe("webviewMessageHandler - non-portable settings keys", () => {
3079-
beforeEach(() => {
3080-
vi.clearAllMocks()
3081-
})
3082-
3083-
it("refuses viewStates while applying the portable keys of the same payload", async () => {
3084-
// The per-view selections and the claim token that binds them are minted by the host, and the
3085-
// settings-file path already refuses them. A posted updateSettings is the same untrusted input,
3086-
// so writing them straight into the shared store would let a webview choose which persisted view
3087-
// entry - and with which identity - it owns.
3088-
await webviewMessageHandler(mockClineProvider, {
3089-
type: "updateSettings",
3090-
updatedSettings: {
3091-
viewStates: { "some-view": { claimToken: "webview-minted", mode: "code", updatedAt: 1 } },
3092-
customInstructions: "carry on",
3093-
},
3094-
})
3095-
3096-
const writtenKeys = vi.mocked(mockClineProvider.contextProxy.setValue).mock.calls.map((call) => String(call[0]))
3097-
expect(writtenKeys).not.toContain("viewStates")
3098-
expect(writtenKeys).toContain("customInstructions")
3099-
expect(mockClineProvider.log).toHaveBeenCalledWith(
3100-
expect.stringContaining("Ignoring non-portable settings key viewStates"),
3101-
)
3102-
})
3103-
})
3104-
3105-
// The display settings are written like any other setting, but the webview is not trusted: a
3106-
// value its own controls cannot produce (a hand-written message) is ignored before storage.
3058+
// The display settings are written like any other setting, but the webview is not trusted: a value that its own
3059+
// controls cannot produce (a hand-written message) is ignored before anything is done for it.
31073060
describe("updateSettings with the display settings", () => {
31083061
const save = (updatedSettings: Record<string, unknown>) =>
31093062
webviewMessageHandler(mockClineProvider, { type: "updateSettings", updatedSettings })

‎src/core/webview/webviewMessageHandler.ts‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { isInvalidDisplayValue } from "../config/displaySettings"
4141
import { importRooTaskHistory } from "../task-persistence/importRooTaskHistory"
4242

4343
import { ClineProvider } from "./ClineProvider"
44-
import { isNonPortableSettingsKey } from "../config/ContextProxy"
4544
import { findOriginalContent } from "./stripOriginalContent"
4645
import { handleCheckpointRestoreOperation } from "./checkpointRestoreHandler"
4746
import { assertRecordedCheckpoint } from "../checkpoints/recordedCheckpoint"
@@ -702,17 +701,6 @@ export const webviewMessageHandler = async (
702701
)
703702

704703
provider.isViewLaunched = true
705-
// Claims minted before this launch were held by the provider, because posting one earlier
706-
// could be lost while postMessage still resolved true. The listener exists now, so this is
707-
// the point where the queued posts can actually be received. A failed flush must not fail
708-
// the launch, so it is contained here.
709-
try {
710-
await provider.deliverPendingViewStateClaims()
711-
} catch (error) {
712-
provider.log(
713-
`[viewStateClaim] Flushing pending claims on launch failed: ${error instanceof Error ? error.message : String(error)}`,
714-
)
715-
}
716704
break
717705
case "webviewHeartbeat":
718706
// Confirm renderer liveness and advance the watchdog recovery health window.
@@ -786,18 +774,6 @@ export const webviewMessageHandler = async (
786774
}
787775

788776
for (const [key, value] of Object.entries(message.updatedSettings)) {
789-
if (isNonPortableSettingsKey(key)) {
790-
// Per-view selections and the claim token that binds them are minted and held by the host,
791-
// and the settings-file path already refuses them. A posted updateSettings is the same
792-
// untrusted input, so writing them here would let a webview choose which persisted view
793-
// entry - and with which identity - it owns, bypassing the claim check in setViewStateId.
794-
provider.log(
795-
`[updateSettings] Ignoring non-portable settings key ${key} posted by the webview.`,
796-
)
797-
798-
continue
799-
}
800-
801777
// An invalid display value is ignored, before anything is done for it.
802778
if (isInvalidDisplayValue(key, value)) {
803779
provider.log(`[updateSettings] Ignored an invalid value for ${key}`)

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

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@ 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-
})
2815
it("persists every supplied mode API config mapping", async () => {
2916
const setValues = vi.fn().mockResolvedValue(undefined)
3017
const saveConfig = vi.fn().mockResolvedValue("default-id")
@@ -38,7 +25,7 @@ describe("API - configuration", () => {
3825
providerSettingsManager: { saveConfig, setModeConfig },
3926
postStateToWebview,
4027
} as unknown as ClineProvider
41-
const outputChannel = makeOutputChannel()
28+
const outputChannel = { appendLine: vi.fn() } as unknown as vscode.OutputChannel
4229
const api = new API(outputChannel, provider, makeClineProviderFactory())
4330

4431
await api.setConfiguration({
@@ -72,7 +59,7 @@ describe("API - configuration", () => {
7259
providerSettingsManager: { saveConfig, setModeConfig },
7360
postStateToWebview,
7461
} as unknown as ClineProvider
75-
const outputChannel = makeOutputChannel()
62+
const outputChannel = { appendLine: vi.fn() } as unknown as vscode.OutputChannel
7663
const api = new API(outputChannel, provider, makeClineProviderFactory())
7764

7865
await api.setConfiguration({ currentApiConfigName: "default" })
@@ -96,7 +83,7 @@ describe("API - configuration", () => {
9683
},
9784
postStateToWebview: vi.fn().mockResolvedValue(undefined),
9885
} as unknown as ClineProvider
99-
const outputChannel = makeOutputChannel()
86+
const outputChannel = { appendLine: vi.fn() } as unknown as vscode.OutputChannel
10087
return { api: new API(outputChannel, provider, makeClineProviderFactory()), setValues, log }
10188
}
10289

@@ -140,34 +127,4 @@ describe("API - configuration", () => {
140127
expect(log).toHaveBeenCalledWith(`[setConfiguration] Ignored an invalid value for ${key}`)
141128
})
142129
})
143-
144-
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.
147-
const provider = {
148-
context: {},
149-
on: vi.fn(),
150-
log: vi.fn(),
151-
getValues: () => ({
152-
currentApiConfigName: "default",
153-
// 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",
156-
viewStates: { "view-1": { claimToken: "claim-token-1", mode: "code" } },
157-
}),
158-
} as unknown as ClineProvider
159-
const outputChannel = makeOutputChannel()
160-
const api = new API(outputChannel, provider, makeClineProviderFactory())
161-
162-
const configuration = api.getConfiguration()
163-
164-
// Exact output: the portable setting survives and both host-owned keys are gone.
165-
expect(configuration).toEqual({ currentApiConfigName: "default" })
166-
expect(Object.keys(configuration)).not.toContain("viewStates")
167-
expect("viewStates" in configuration).toBe(false)
168-
// 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.
170-
expect(JSON.stringify(configuration)).not.toContain("claim-token-1")
171-
expect(JSON.stringify(configuration)).not.toContain("secret-api-key")
172-
})
173130
})

‎src/extension/__tests__/api-start-new-task.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function createProvider(taskId: string) {
1919
on: vi.fn<ClineProvider["on"]>(),
2020
evictCurrentTask: vi.fn<ClineProvider["evictCurrentTask"]>().mockResolvedValue(undefined),
2121
postStateToWebview: vi.fn<ClineProvider["postStateToWebview"]>().mockResolvedValue(undefined),
22-
postMessageToWebview: vi.fn<ClineProvider["postMessageToWebview"]>().mockResolvedValue(true),
22+
postMessageToWebview: vi.fn<ClineProvider["postMessageToWebview"]>().mockResolvedValue(undefined),
2323
createTask: vi.fn<ClineProvider["createTask"]>().mockResolvedValue(task),
2424
})
2525
}

‎src/extension/api.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { Package } from "../shared/package"
3232
import type { Mode } from "../shared/modes"
3333
import type { ClineProvider } from "../core/webview/ClineProvider"
3434
import type { ClineProviderFactory } from "../core/webview/ClineProviderFactory"
35-
import { isNonPortableSettingsKey } from "../core/config/ContextProxy"
3635
import { withoutInvalidDisplaySettings } from "../core/config/displaySettings"
3736
import { readTaskMessages } from "../core/task-persistence/taskMessages"
3837
import { Terminal } from "../integrations/terminal/Terminal"
@@ -624,17 +623,9 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
624623

625624
// Global Settings Management
626625

627-
/**
628-
* The settings an external caller may read. Secrets are the host's, and so are the per-view
629-
* selections plus the claim token that binds them: a caller that could read viewStates could
630-
* replay another view's identity, so both are dropped here rather than at whichever caller a
631-
* reviewer happened to point at. getValues() still serves the host's own consumers.
632-
*/
633626
public getConfiguration(): RooCodeSettings {
634627
return Object.fromEntries(
635-
Object.entries(this.sidebarProvider.getValues()).filter(
636-
([key]) => !isSecretStateKey(key) && !isNonPortableSettingsKey(key),
637-
),
628+
Object.entries(this.sidebarProvider.getValues()).filter(([key]) => !isSecretStateKey(key)),
638629
)
639630
}
640631

‎src/services/language-models/copilotModelBroadcast.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface CopilotModelBroadcastTarget {
1010
type: typeof VsCodeLmModelsMessageType.githubCopilotModels
1111
vsCodeLmModels: Awaited<ReturnType<typeof getGitHubCopilotModels>>
1212
githubCopilotAccount: string | null
13-
}): Promise<unknown>
13+
}): Promise<void>
1414
}
1515

1616
export interface CopilotModelBroadcastOptions {

0 commit comments

Comments
 (0)