subagent-browser-boundary.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { resolve } from "node:path";
  2. import { describe, expect, it } from "vitest";
  3. import type { NodeReplRequestMeta, NodeReplSession } from "@zcode/core";
  4. import { setupBrowserRuntime } from "../src/browser-client.js";
  5. import { createBrowserBridgeGlobals, type ActiveNodeReplCall } from "@zcode/node-repl-host/browser-bridge";
  6. import { readNodeReplBrowserRuntimeBridge } from "@zcode/node-repl-host/runtime-bridge";
  7. describe("subagent browser boundary", () => {
  8. it("keeps browser bridge access and initialization available in subagent scope", async () => {
  9. let requestMeta: NodeReplRequestMeta = {
  10. runtime_scope: "main",
  11. session_id: "main-session",
  12. };
  13. const activeCall = (): ActiveNodeReplCall => ({
  14. generation: 1,
  15. requestMeta,
  16. signal: new AbortController().signal,
  17. });
  18. const globals = createBrowserBridgeGlobals({
  19. documentationRoot: resolve(process.cwd(), "docs"),
  20. generation: 1,
  21. getActiveCall: activeCall,
  22. // 本用例只走本地 documentation guard,不会执行需要 response meta 的 transport。
  23. session: () => undefined as unknown as NodeReplSession,
  24. });
  25. await setupBrowserRuntime({ globals });
  26. const documentation = (
  27. globals.agent as { documentation: { get(name: string): Promise<string> } }
  28. ).documentation;
  29. await expect(documentation.get("overview")).resolves.toContain("Browser");
  30. const bridge = readNodeReplBrowserRuntimeBridge(globals);
  31. requestMeta = { runtime_scope: "subagent", session_id: "subagent-session" };
  32. expect(() => bridge.assertAvailable()).not.toThrow();
  33. await expect(setupBrowserRuntime({ globals })).resolves.toBeUndefined();
  34. await expect(documentation.get("overview")).resolves.toContain("Browser");
  35. });
  36. });