|
1 | | -import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 1 | +import { readFileSync } from "node:fs"; |
| 2 | +import { describe, expect, it } from "vitest"; |
2 | 3 |
|
3 | | -const loadBundledPluginPublicSurfaceModuleSync = vi.hoisted(() => vi.fn()); |
4 | | -const loadActivatedBundledPluginPublicSurfaceModuleSync = vi.hoisted(() => vi.fn()); |
5 | | -const createLazyFacadeObjectValue = vi.hoisted(() => { |
6 | | - return <T extends object>(load: () => T): T => |
7 | | - new Proxy( |
8 | | - {}, |
9 | | - { |
10 | | - get(_target, property, receiver) { |
11 | | - return Reflect.get(load(), property, receiver); |
12 | | - }, |
13 | | - }, |
14 | | - ) as T; |
15 | | -}); |
16 | | -const createLazyFacadeValue = vi.hoisted(() => { |
17 | | - return <T extends object, K extends keyof T>(load: () => T, key: K): T[K] => |
18 | | - ((...args: unknown[]) => { |
19 | | - const value = load()[key]; |
20 | | - if (typeof value !== "function") { |
21 | | - return value; |
22 | | - } |
23 | | - return (value as (...innerArgs: unknown[]) => unknown)(...args); |
24 | | - }) as T[K]; |
25 | | -}); |
26 | | - |
27 | | -vi.mock("../plugin-sdk/facade-runtime.js", () => ({ |
28 | | - createLazyFacadeObjectValue, |
29 | | - createLazyFacadeValue, |
30 | | - loadActivatedBundledPluginPublicSurfaceModuleSync, |
31 | | - loadBundledPluginPublicSurfaceModuleSync, |
32 | | -})); |
33 | | - |
34 | | -const tts = await import("./tts.js"); |
| 4 | +function readSource(relativePath: string): string { |
| 5 | + return readFileSync(new URL(relativePath, import.meta.url), "utf8"); |
| 6 | +} |
35 | 7 |
|
36 | 8 | describe("tts runtime facade", () => { |
37 | | - beforeEach(() => { |
38 | | - loadActivatedBundledPluginPublicSurfaceModuleSync.mockReset(); |
39 | | - loadBundledPluginPublicSurfaceModuleSync.mockReset(); |
40 | | - }); |
41 | | - |
42 | | - it("loads speech-core lazily after module import", () => { |
43 | | - const buildTtsSystemPromptHint = vi.fn().mockReturnValue("hint"); |
44 | | - loadActivatedBundledPluginPublicSurfaceModuleSync.mockReturnValue({ |
45 | | - buildTtsSystemPromptHint, |
46 | | - }); |
| 9 | + it("keeps speech-core behind the lazy runtime facade", () => { |
| 10 | + const publicFacadeSource = readSource("./tts.ts"); |
| 11 | + const runtimeFacadeSource = readSource("../plugin-sdk/tts-runtime.ts"); |
47 | 12 |
|
48 | | - expect(loadActivatedBundledPluginPublicSurfaceModuleSync).not.toHaveBeenCalled(); |
49 | | - expect(tts.buildTtsSystemPromptHint({} as never)).toBe("hint"); |
50 | | - expect(loadActivatedBundledPluginPublicSurfaceModuleSync).toHaveBeenCalledTimes(1); |
51 | | - expect(buildTtsSystemPromptHint).toHaveBeenCalledTimes(1); |
| 13 | + expect(publicFacadeSource).toContain('} from "../plugin-sdk/tts-runtime.js";'); |
| 14 | + expect(publicFacadeSource).not.toContain("speech-core"); |
| 15 | + expect(runtimeFacadeSource).toContain("function loadFacadeModule()"); |
| 16 | + expect(runtimeFacadeSource).toContain('dirName: "speech-core"'); |
| 17 | + expect(runtimeFacadeSource).toContain( |
| 18 | + 'createLazyFacadeRuntimeValue(loadFacadeModule, "buildTtsSystemPromptHint")', |
| 19 | + ); |
52 | 20 | }); |
53 | 21 | }); |
0 commit comments