sharedContextImportState.test.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { describe, expect, it } from "vitest";
  2. import { sharedContextImportStateSchema } from "../src/zcode-protocol-v4/snapshot.js";
  3. describe("shared context import state", () => {
  4. it("accepts the persisted handover lifecycle", () => {
  5. expect(
  6. sharedContextImportStateSchema.parse({
  7. contextId: "context-1",
  8. title: "分享标题",
  9. shareUrl: "https://zcode.z.ai/cn/share/code-1",
  10. status: "reserved",
  11. }),
  12. ).toEqual({
  13. contextId: "context-1",
  14. title: "分享标题",
  15. shareUrl: "https://zcode.z.ai/cn/share/code-1",
  16. status: "reserved",
  17. });
  18. });
  19. it.each(["pending", "attached", "discarded"] as const)("accepts %s status", (status) => {
  20. expect(
  21. sharedContextImportStateSchema.safeParse({
  22. contextId: "context-1",
  23. title: "分享标题",
  24. shareUrl: "https://zcode.z.ai/cn/share/code-1",
  25. status,
  26. }).success,
  27. ).toBe(true);
  28. });
  29. it("rejects non-canonical or unknown fields", () => {
  30. expect(
  31. sharedContextImportStateSchema.safeParse({
  32. contextId: "context-1",
  33. title: "分享标题",
  34. shareUrl: "https://share.example.com/share/code-1",
  35. status: "pending",
  36. }).success,
  37. ).toBe(false);
  38. expect(
  39. sharedContextImportStateSchema.safeParse({
  40. contextId: "context-1",
  41. title: "分享标题",
  42. shareUrl: "https://zcode.z.ai/cn/share/code-1",
  43. status: "pending",
  44. markdown: "must-not-cross-projection",
  45. }).success,
  46. ).toBe(false);
  47. });
  48. });