Skip to content

Commit 902436f

Browse files
navidshadclaude
andcommitted
fix(analytics): import authentication from client lib so unit suites load
The analytics commit imported `authentication` from plugins/modular-rest, which runs GlobalOptions.set() plus chrome listeners and profile-store wiring at module load. Three unit suites (translate.service, nibble-surface, selection-popup) mock @modular-rest/client with only `functionProvider`, so pulling in the plugin threw "No GlobalOptions export is defined on the mock" and the files failed to load — yarn test dropped from 138 to 124. Import `authentication` straight from @modular-rest/client (the same singleton the plugin re-exports, and how functionProvider is already imported in this file) and stub it in the three mocks. No plugin side-effects in the service. yarn test back to 138/138; typecheck clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6e3236e commit 902436f

4 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/common/services/translate.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import {
66
import { Dictionary } from "../types/general.type";
77

88
import proxy from "./proxy.service";
9-
import { functionProvider } from "@modular-rest/client";
10-
import { authentication } from "../../plugins/modular-rest";
9+
import { functionProvider, authentication } from "@modular-rest/client";
1110
import {
1211
Chunk,
1312
LanguageLearningData,

tests/nibble-surface.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ vi.mock("../src/nibble/composables/useTextSelection", async () => {
3030
// the child stub doesn't trigger a real fetch chain just by importing.
3131
vi.mock("@modular-rest/client", () => ({
3232
functionProvider: { run: vi.fn() },
33+
authentication: { user: { id: "test-user-id" } },
3334
}));
3435

3536
import NibbleSurface from "../src/nibble/components/NibbleSurface.vue";

tests/selection-popup.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createTestingPinia } from "@pinia/testing";
66
// network layer so a stray click in another test can't fire a real request.
77
vi.mock("@modular-rest/client", () => ({
88
functionProvider: { run: vi.fn() },
9+
authentication: { user: { id: "test-user-id" } },
910
}));
1011

1112
import SelectionPopup from "../src/nibble/components/SelectionPopup.vue";

tests/translate.service.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ vi.mock("@modular-rest/client", () => ({
55
functionProvider: {
66
run: vi.fn(),
77
},
8+
// translate.service reads authentication.user?.id to attach a userId for the
9+
// server-side translation_requested event.
10+
authentication: { user: { id: "test-user-id" } },
811
}));
912

1013
import { TranslateService } from "../src/common/services/translate.service";

0 commit comments

Comments
 (0)