rootWebRemoteTaskSyncBoundary.test.ts 1.6 KB

1234567891011121314151617181920212223242526272829
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. function readUiSource(relativePath: string): string {
  4. return readFileSync(new URL(`../src/${relativePath}`, import.meta.url), "utf8");
  5. }
  6. describe("Root Web remote task sync subscription boundary", () => {
  7. it("全局数据库门禁移出 Root,正常启动壳仍保留远控同步边界", () => {
  8. const rootSource = readUiSource("Root.tsx");
  9. expect(rootSource).not.toContain("useStorageStartup");
  10. const startupBranch = rootSource.slice(rootSource.indexOf("if (isStartupRenderBlocked)"));
  11. expect(startupBranch).toContain("{webRemoteControlTaskSyncNode}");
  12. });
  13. it("keeps the Root shell from subscribing to all workspaces when Web remote task sync is disabled", () => {
  14. const rootSource = readUiSource("Root.tsx");
  15. const rootInnerSource = rootSource.slice(rootSource.indexOf("function RootInner"));
  16. const webRemoteTaskSyncSource = rootSource.slice(
  17. rootSource.indexOf("function WebRemoteControlTaskSync"),
  18. rootSource.indexOf("/**\n * Root"),
  19. );
  20. // 性能回归保护:桌面 continuous 主链路没有开启 Web remote 时,
  21. // Root 不能为了远控 task 索引订阅整张 workspace 表,否则流式更新会唤醒整棵 shell。
  22. expect(rootInnerSource).not.toContain("useZCodeSessionStore((state) => state.workspaces)");
  23. expect(webRemoteTaskSyncSource).toContain("useZCodeSessionStore((state) => state.workspaces)");
  24. expect(rootSource).toMatch(/hasCompletedFullRestore\s*&&\s*webRemoteControlTaskSyncEnabled/);
  25. });
  26. });