appTaskQueryCacheSubscription.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  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. function expectNoTaskQueryCacheHookSubscription(source: string) {
  7. // 性能回归保护:task meta 高频刷新只应在命令触发时通过 getState 读取快照,
  8. // 不应让 App 或导航 hook 订阅整个 task query cache 后带动 shell 重渲染。
  9. expect(source).not.toMatch(/\buseTaskQueryCacheStore\s*\(/);
  10. }
  11. describe("task query cache render subscription boundary", () => {
  12. it("keeps App from subscribing to the whole task query cache", () => {
  13. expectNoTaskQueryCacheHookSubscription(readUiSource("App.tsx"));
  14. });
  15. it("keeps task navigation handlers from subscribing to the whole task query cache", () => {
  16. const source = readUiSource("app-shell/useWorkspaceTaskNavigation.ts");
  17. expectNoTaskQueryCacheHookSubscription(source);
  18. expect(source).toContain("setTaskQueryCacheUnreadOverlay");
  19. expect(source).toContain("reconcileTaskQueryCacheUnread");
  20. expect(source).not.toContain("setTaskUnreadIndicator");
  21. expect(source).not.toContain("targetWorkspaceState.taskListCache");
  22. });
  23. it("选择已有 task 时保留 workspace slash command 目录", () => {
  24. const source = readUiSource("app-shell/useWorkspaceTaskNavigation.ts");
  25. // Bug 原因:目录属于 workspace identity;task 导航若主动清空,session projection
  26. // 不会替 composer 回填,已知 session 的自定义 slash command 会永久消失。
  27. expect(source).not.toMatch(/\.setSlashCommands\s*\(/);
  28. expect(source).not.toMatch(/const\s+setSlashCommands\s*=\s*useZCodeSessionStore/);
  29. });
  30. });