























@@ -1,53 +1,21 @@
1-import { beforeEach, describe, expect, it, vi } from "vitest";
1+import { readFileSync } from "node:fs";
2+import { describe, expect, it } from "vitest";
233-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+}
357368describe("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");
471248-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+);
5220});
5321});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。