Skip to content

Commit 4f414b6

Browse files
committed
fix(webview): guard telemetry queue and fix visual test CI failures
1 parent 2375591 commit 4f414b6

5 files changed

Lines changed: 49 additions & 35 deletions

File tree

src/core/webview/webviewMessageHandler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@ export const webviewMessageHandler = async (
659659
telemetrySettingQueue = telemetrySettingQueue
660660
.catch(() => undefined)
661661
.then(async () => {
662+
if (!TelemetryService.hasInstance()) {
663+
return
664+
}
665+
662666
const telemetrySetting = getGlobalState("telemetrySetting") || "unset"
663667
TelemetryService.instance.updateTelemetryState(
664668
isTelemetryOptedIn(telemetrySetting) && vscode.env.isTelemetryEnabled,

webview-ui/src/components/chat/__tests__/ChatView.scroll-debug-repro.spec.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ vi.mock("./WorktreeSelector", () => ({ WorktreeSelector: () => null }))
9292

9393
vi.mock("@vscode/webview-ui-toolkit/react", () => ({
9494
VSCodeLink: ({ children }: { children: React.ReactNode }) => <>{children}</>,
95+
VSCodeButton: ({ children, onClick }: { children: React.ReactNode; onClick?: () => void }) => (
96+
<button onClick={onClick}>{children}</button>
97+
),
9598
}))
9699

97100
vi.mock("@/components/ui", async (importOriginal) => {

webview-ui/src/components/common/__tests__/TelemetryBanner.visual.fixture.tsx

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,15 @@
11
import React from "react"
2-
import i18next from "i18next"
3-
import { I18nextProvider, initReactI18next } from "react-i18next"
2+
import { I18nextProvider } from "react-i18next"
43

54
import { TranslationContext } from "@src/i18n/TranslationContext"
65
import TelemetryBanner from "../TelemetryBanner"
7-
8-
const translations: Record<string, string> = {
9-
"welcome:telemetry.helpImprove": "Help Improve Zoo Code",
10-
"welcome:telemetry.helpImproveMessage":
11-
"Zoo Code collects error and usage data, linked to a per-install identifier, to help us fix bugs and improve the extension. This telemetry does not collect your code or prompts. You can turn this off in <settingsLink>settings</settingsLink>.",
12-
"welcome:telemetry.accept": "Accept",
13-
"welcome:telemetry.decline": "Decline",
14-
}
15-
16-
// Trans reads from its own react-i18next instance rather than the useAppTranslation
17-
// context, so it needs a real (if minimal) i18next init to resolve helpImproveMessage
18-
// and the settingsLink interpolation instead of rendering nothing.
19-
const visualTestI18n = i18next.createInstance()
20-
void visualTestI18n.use(initReactI18next).init({
21-
lng: "en",
22-
fallbackLng: "en",
23-
ns: ["welcome"],
24-
defaultNS: "welcome",
25-
resources: {
26-
en: {
27-
welcome: {
28-
telemetry: {
29-
helpImprove: translations["welcome:telemetry.helpImprove"],
30-
helpImproveMessage: translations["welcome:telemetry.helpImproveMessage"],
31-
accept: translations["welcome:telemetry.accept"],
32-
decline: translations["welcome:telemetry.decline"],
33-
},
34-
},
35-
},
36-
},
37-
interpolation: { escapeValue: false },
38-
})
6+
import { visualTestI18n, visualTestTranslations } from "./TelemetryBanner.visual.i18n"
397

408
export const TelemetryBannerFixture = () => (
419
<I18nextProvider i18n={visualTestI18n}>
4210
<TranslationContext.Provider
4311
value={{
44-
t: (key) => translations[key] ?? key,
12+
t: (key) => visualTestTranslations[key] ?? key,
4513
i18n: null as unknown as typeof import("../../../i18n/setup").default,
4614
}}>
4715
<TelemetryBanner />
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import i18next from "i18next"
2+
import { initReactI18next } from "react-i18next"
3+
4+
export const visualTestTranslations: Record<string, string> = {
5+
"welcome:telemetry.helpImprove": "Help Improve Zoo Code",
6+
"welcome:telemetry.helpImproveMessage":
7+
"Zoo Code collects error and usage data, linked to a per-install identifier, to help us fix bugs and improve the extension. This telemetry does not collect your code or prompts. You can turn this off in <settingsLink>settings</settingsLink>.",
8+
"welcome:telemetry.accept": "Accept",
9+
"welcome:telemetry.decline": "Decline",
10+
}
11+
12+
// Trans reads from its own react-i18next instance rather than the useAppTranslation
13+
// context, so it needs a real (if minimal) i18next init to resolve helpImproveMessage
14+
// and the settingsLink interpolation instead of rendering nothing. init() returns a
15+
// promise even for inline resources, so callers must await it before mounting.
16+
export const visualTestI18n = i18next.createInstance()
17+
18+
export const visualTestI18nReady = visualTestI18n.use(initReactI18next).init({
19+
lng: "en",
20+
fallbackLng: "en",
21+
ns: ["welcome"],
22+
defaultNS: "welcome",
23+
resources: {
24+
en: {
25+
welcome: {
26+
telemetry: {
27+
helpImprove: visualTestTranslations["welcome:telemetry.helpImprove"],
28+
helpImproveMessage: visualTestTranslations["welcome:telemetry.helpImproveMessage"],
29+
accept: visualTestTranslations["welcome:telemetry.accept"],
30+
decline: visualTestTranslations["welcome:telemetry.decline"],
31+
},
32+
},
33+
},
34+
},
35+
interpolation: { escapeValue: false },
36+
})

webview-ui/src/components/common/__tests__/TelemetryBanner.visual.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import React from "react"
22

33
import { expect, test } from "../../../../playwright/coverage-fixture"
44
import { TelemetryBannerFixture } from "./TelemetryBanner.visual.fixture"
5+
import { visualTestI18nReady } from "./TelemetryBanner.visual.i18n"
56

67
test("renders the telemetry consent banner in the VS Code dark theme", async ({ mount }) => {
8+
await visualTestI18nReady
9+
710
const component = await mount(<TelemetryBannerFixture />)
811

912
await component.evaluate(async () => {

0 commit comments

Comments
 (0)