zcodeDraftSkillInvalidation.test.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { beforeEach, describe, expect, it } from "vitest";
  2. import { invalidateDeferredDraftSessionForSkillChange } from "@/lib/zcodeDraftSkillInvalidation.js";
  3. import { useZCodeSessionStore } from "@/store/zcodeSessionStore.js";
  4. beforeEach(() => {
  5. useZCodeSessionStore.setState({ workspaces: {} });
  6. });
  7. describe("draft capability invalidation", () => {
  8. it("invalidates only the requested identity without changing its active task", async () => {
  9. const workspacePath = "/workspace/app";
  10. const workspaceIdentity = "remote:server:dev:/workspace/app";
  11. const store = useZCodeSessionStore.getState();
  12. store.setActiveTaskId(workspacePath, "active", workspaceIdentity);
  13. await invalidateDeferredDraftSessionForSkillChange({
  14. reason: "test",
  15. workspacePath,
  16. workspaceIdentity: ` ${workspaceIdentity} `,
  17. });
  18. expect(
  19. useZCodeSessionStore.getState().getWorkspaceState(workspacePath, workspaceIdentity),
  20. ).toMatchObject({
  21. activeTaskId: "active",
  22. draftRuntimeInvalidationVersion: 1,
  23. });
  24. expect(
  25. useZCodeSessionStore.getState().getWorkspaceState(workspacePath)
  26. .draftRuntimeInvalidationVersion,
  27. ).toBe(0);
  28. });
  29. it("invalidates a prewarm on each capability change without a copied session id", async () => {
  30. for (const reason of ["skill-enabled", "plugin-updated"]) {
  31. await invalidateDeferredDraftSessionForSkillChange({
  32. reason,
  33. workspacePath: "/workspace/app",
  34. });
  35. }
  36. expect(
  37. useZCodeSessionStore.getState().getWorkspaceState("/workspace/app")
  38. .draftRuntimeInvalidationVersion,
  39. ).toBe(2);
  40. });
  41. it("does not create a workspace for a settings view without an execution target", async () => {
  42. await invalidateDeferredDraftSessionForSkillChange({ reason: "test" });
  43. expect(useZCodeSessionStore.getState().workspaces).toEqual({});
  44. });
  45. });