Skip to content

Commit 5163cd3

Browse files
fix(webview): localize the profile-deletion warning and pin real ordering in two tests
The deletion-activation warning took its text from the error class, so it stayed English for every locale; it now goes through common:warnings.profile_deleted_activation_failed with the replacement profile name interpolated, and the key is present in all 18 locale bundles. The bundle wording differs from the class message on purpose: the class message stays in the log line, and an assertion that expected it verbatim would also pass for a handler that never asked i18n. locale-bundles.spec.ts now pins the added warning key next to the added error key. Two ordering assertions compared things that cannot differ. The rename rollback compared an index into deleteConfig.mock.calls with an index into saveConfig.mock.calls, which is 1 > 0 in every run whatever the real order is; it now compares the two mocks' shared invocation clock, which reddens when the restore is moved before the delete. The overlapping-write cases parked both rejections at once, so both handlers ran in creation order and the B-settles-first case never exercised B-before-A; the memento double now parks each update until the test rejects it, so the case picks the handler order, and the older write leaving the cache alone is what keeps both cases on the persisted value. Gates: tsc --noEmit exit 0; eslint --max-warnings=0 --no-warn-ignored exit 0 on every touched file; prettier --check exit 0 (locales included); ContextProxy.globalStateRestore.spec.ts 5 passed, webviewMessageHandler.spec.ts 187 passed, locale-bundles.spec.ts 18 passed; src/eslint-suppressions.json untouched. Controls measured before landing: the invocation-clock assertion goes 1 failed with the restore moved ahead of the delete, the class-message handler goes 1 failed against the key-based expectation, and the generation-map restore goes 1 failed (A rejects first) while B rejects first stays green. No .changeset, no CHANGELOG edit.
1 parent 5cbdcf1 commit 5163cd3

22 files changed

Lines changed: 94 additions & 33 deletions

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

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ vi.mock("vscode", () => ({
2222
describe("ContextProxy globalState cache restore", () => {
2323
const KEY = "currentApiConfigName"
2424

25-
const setup = (persisted: string, failOnValues: readonly string[] = []) => {
25+
const setup = (persisted: string, failOnValues: readonly string[] = [], deferredUpdates = false) => {
2626
const store = new Map<string, unknown>([[KEY, persisted]])
2727
let storageWorks = true
2828

29+
// Deferred mode for the two overlapping-write cases below: each update parks in this list instead
30+
// of rejecting at once, so the test - not the fixture - decides whose rejection handler runs first.
31+
const pending: { value: unknown; resolve: () => void; reject: (error: Error) => void }[] = []
32+
2933
// Plain functions rather than vi.fn for the memento doubles: vitest's Mock wrapper
3034
// instantiates a generic signature at its call-site type, which drops the genericity
3135
// Memento.get and Secrets.get are declared with, and nothing here asserts on spies.
@@ -40,6 +44,11 @@ describe("ContextProxy globalState cache restore", () => {
4044
},
4145
setKeysForSync(_keys: readonly string[]): void {},
4246
async update(key: string, value: unknown): Promise<void> {
47+
if (deferredUpdates) {
48+
return new Promise<void>((resolve, reject) => {
49+
pending.push({ value, resolve, reject })
50+
})
51+
}
4352
if (failOnValues.includes(value as string)) {
4453
throw new Error("storage unavailable")
4554
}
@@ -74,7 +83,12 @@ describe("ContextProxy globalState cache restore", () => {
7483
logUri: makeUri("/test/logs"),
7584
extension: { packageJSON: { version: "1.0.0" } },
7685
} as unknown as vscode.ExtensionContext
77-
return { proxy: new ContextProxy(context), store, setStorageWorks: (works: boolean) => (storageWorks = works) }
86+
return {
87+
proxy: new ContextProxy(context),
88+
store,
89+
setStorageWorks: (works: boolean) => (storageWorks = works),
90+
pending,
91+
}
7892
}
7993
it("only restores for keys the cache actually owns", () => {
8094
// Guards the tests below: if this key were passed straight through to storage, the cache
@@ -83,31 +97,41 @@ describe("ContextProxy globalState cache restore", () => {
8397
expect(isPassThroughStateKey(KEY)).toBe(false)
8498
})
8599

86-
it.each(["A settles first", "B settles first"])(
100+
it.each(["A rejects first", "B rejects first"])(
87101
"keeps the cache on the persisted value when two overlapping writes both reject (%s)",
88102
async (_order: string) => {
89-
const { proxy, store, setStorageWorks } = setup("X")
103+
const { proxy, store, pending } = setup("X", [], true)
90104
await proxy.initialize()
91-
setStorageWorks(false)
92105

93106
const writeA = Promise.resolve(proxy.updateGlobalState(KEY, "a"))
94107
const writeB = Promise.resolve(proxy.updateGlobalState(KEY, "b"))
95108

96-
const settle = async (first: Promise<unknown>, second: Promise<unknown>) => {
97-
await expect(first).rejects.toThrow("storage unavailable")
98-
await expect(second).rejects.toThrow("storage unavailable")
99-
}
100-
101-
if (_order === "A settles first") {
102-
await settle(writeA, writeB)
109+
// Both writes park in the memento, so nothing has rejected yet and the case really does
110+
// choose whose rejection handler runs first. Rejecting at once, as this fixture used to,
111+
// made the handlers run in creation order whatever the case awaited first, so the two
112+
// cases were the same scenario and a B-before-A break could not show up.
113+
expect(pending.map((p) => p.value)).toEqual(["a", "b"])
114+
const [a, b] = pending
115+
116+
if (_order === "A rejects first") {
117+
a.reject(new Error("storage unavailable"))
118+
await expect(writeA).rejects.toThrow("storage unavailable")
119+
b.reject(new Error("storage unavailable"))
120+
await expect(writeB).rejects.toThrow("storage unavailable")
103121
} else {
104-
await settle(writeB, writeA)
122+
b.reject(new Error("storage unavailable"))
123+
await expect(writeB).rejects.toThrow("storage unavailable")
124+
a.reject(new Error("storage unavailable"))
125+
await expect(writeA).rejects.toThrow("storage unavailable")
105126
}
106127

107-
// Write B owns the current generation, so B is the only write allowed to restore. If
108-
// it restored the cache content it found - write A's value - the cache would advertise
109-
// 'a' while storage still holds 'X', which is the stale-cache state this guard exists
110-
// to prevent.
128+
// Write B owns the key: it started last, so B is the only write allowed to correct the
129+
// cache, and it reads the value back from the store. Under A rejects first the older write
130+
// A has already failed and its handler has already run, so it must leave the cache alone
131+
// even though it ran before the owner. Restoring each write's own pre-write cache value
132+
// instead - the generation-map design this guard replaced - splits the two cases: measured on
133+
// that design, A rejects first is the case that ends with the cache advertising 'a', a value
134+
// the store never accepted, while B rejects first happens to land back on 'X'.
111135
expect(proxy.getGlobalState(KEY)).toBe("X")
112136
expect(store.get(KEY)).toBe("X")
113137
},

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,9 +2346,13 @@ describe("webviewMessageHandler - profile deletion routes through the provider m
23462346

23472347
await webviewMessageHandler(mockClineProvider, { type: "deleteApiConfiguration", text: "doomed-profile" })
23482348

2349-
// The deletion landed: the user must not be told the delete failed.
2349+
// The deletion landed: the user must not be told the delete failed. The text comes from
2350+
// the locale bundle, as every other notification in this handler does, so it is not pinned to
2351+
// English. The bundle wording deliberately differs from the error class message, which stays
2352+
// in the log line: an assertion that expected the class message verbatim would also pass for
2353+
// a handler that never asked i18n.
23502354
expect(vscode.window.showWarningMessage).toHaveBeenCalledWith(
2351-
"The profile was deleted, but activating replacement profile 'keeper-profile' failed.",
2355+
t("common:warnings.profile_deleted_activation_failed", { name: "keeper-profile" }),
23522356
)
23532357
expect(vscode.window.showErrorMessage).not.toHaveBeenCalledWith("common:errors.delete_api_config")
23542358
})
@@ -3176,16 +3180,20 @@ describe("webviewMessageHandler - renameApiConfiguration", () => {
31763180
expect.objectContaining({ id: "profile-id" }),
31773181
)
31783182
expect(mockClineProvider.providerSettingsManager.deleteConfig).toHaveBeenCalledWith("new-profile")
3179-
// The rename legitimately deletes old-profile before the activation runs, so the ordering is
3180-
// the assertion that matters: restoring the record before that delete would let the delete
3181-
// undo the restore and leave the selection naming a missing profile again.
3182-
const deleteOldCall = vi
3183-
.mocked(mockClineProvider.providerSettingsManager.deleteConfig)
3184-
.mock.calls.findIndex(([name]) => name === "old-profile")
3185-
const restoreOldCall = vi
3186-
.mocked(mockClineProvider.providerSettingsManager.saveConfig)
3187-
.mock.calls.findIndex(([name]) => name === "old-profile")
3188-
expect(restoreOldCall).toBeGreaterThan(deleteOldCall)
3183+
// The two indices are positions in two different arrays, so comparing them says nothing:
3184+
// deleteConfig is called with old-profile first and saveConfig with old-profile second in
3185+
// every run of this flow, whatever the real order is. The two mocks share one invocation
3186+
// clock, and that is the only thing on this double that can show the restore landing after
3187+
// the delete rather than before it.
3188+
const deleteCalls = vi.mocked(mockClineProvider.providerSettingsManager.deleteConfig).mock
3189+
const saveCalls = vi.mocked(mockClineProvider.providerSettingsManager.saveConfig).mock
3190+
const deleteOldIndex = deleteCalls.calls.findIndex(([name]) => name === "old-profile")
3191+
const restoreOldIndex = saveCalls.calls.findIndex(([name]) => name === "old-profile")
3192+
expect(deleteOldIndex).toBeGreaterThanOrEqual(0)
3193+
expect(restoreOldIndex).toBeGreaterThanOrEqual(0)
3194+
expect(saveCalls.invocationCallOrder[restoreOldIndex]).toBeGreaterThan(
3195+
deleteCalls.invocationCallOrder[deleteOldIndex],
3196+
)
31893197
// The fallback must not move the shared selection on its own, and it must not resurrect a
31903198
// delete of the name it just restored.
31913199
expect(mockClineProvider.setValue).not.toHaveBeenCalledWith("currentApiConfigName", expect.anything())

‎src/core/webview/webviewMessageHandler.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,11 @@ export const webviewMessageHandler = async (
28492849
: String(error.activationError)
28502850
}`,
28512851
)
2852-
vscode.window.showWarningMessage(error.message)
2852+
vscode.window.showWarningMessage(
2853+
t("common:warnings.profile_deleted_activation_failed", {
2854+
name: error.replacementProfileName,
2855+
}),
2856+
)
28532857
break
28542858
}
28552859

‎src/i18n/__tests__/locale-bundles.spec.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import vi from "../locales/vi/common.json"
2626
import zhCn from "../locales/zh-CN/common.json"
2727
import zhTw from "../locales/zh-TW/common.json"
2828

29-
const bundles: Record<string, { errors: Record<string, unknown> }> = {
29+
const bundles: Record<string, { errors: Record<string, unknown>; warnings: Record<string, unknown> }> = {
3030
ca,
3131
de,
3232
en,
@@ -49,12 +49,19 @@ const bundles: Record<string, { errors: Record<string, unknown> }> = {
4949

5050
// Keys this unit adds to the common namespace (the openFile workspace
5151
// containment error posted by webviewMessageHandler).
52-
const addedKeys = ["path_outside_workspace"]
52+
// Keys this unit adds to the common namespace: the openFile workspace containment
53+
// error, and the warning shown when a profile deletion landed but the replacement
54+
// activation failed (webviewMessageHandler). Both lists are asserted below.
55+
const addedErrorKeys = ["path_outside_workspace"]
56+
const addedWarningKeys = ["profile_deleted_activation_failed"]
5357

5458
describe("common locale bundles", () => {
5559
it.each(Object.keys(bundles))("%s defines every key this unit adds", (locale) => {
56-
for (const key of addedKeys) {
60+
for (const key of addedErrorKeys) {
5761
expect(bundles[locale].errors[key]).toEqual(expect.any(String))
5862
}
63+
for (const key of addedWarningKeys) {
64+
expect(bundles[locale].warnings[key]).toEqual(expect.any(String))
65+
}
5966
})
6067
})

‎src/i18n/locales/ca/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/de/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/en/common.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"warnings": {
124124
"no_terminal_content": "No terminal content selected",
125125
"auto_import_failed": "Failed to auto-import ZooCode settings: {{error}}",
126+
"profile_deleted_activation_failed": "Profile deleted, but activating the replacement profile '{{name}}' failed.",
126127
"rooHistoryImport": {
127128
"nothingFound": "No Roo Code task history was found to import from {{domain}}.",
128129
"alreadyImported_one": "All {{count}} Roo Code task history has already been imported into Zoo Code.",

‎src/i18n/locales/es/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/fr/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/hi/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)