first-message-attribution.test.ts 1.4 KB

12345678910111213141516171819202122232425
  1. import { describe, expect, it } from "vitest";
  2. import type { SessionId, SessionStorePort } from "@zcode/contracts";
  3. import { readFirstMessageAttribution } from "../src/runtime/methods/input-intent-persistence.js";
  4. describe("持久接纳首条身份", () => {
  5. const store = {
  6. getSessionInputById: async (id: string) =>
  7. [
  8. { id: "later", sessionID: "s", admittedSequence: 4, status: "admitted" },
  9. { id: "first", sessionID: "s", admittedSequence: 0, status: "cancelled" },
  10. ].find((input) => input.id === id) ?? null,
  11. } as unknown as SessionStorePort;
  12. it("按持久接纳顺序而非执行顺序,取消首条不提升后续输入", async () => {
  13. expect(await readFirstMessageAttribution(store, "s" as SessionId, "first", 0)).toBe(true);
  14. expect(await readFirstMessageAttribution(store, "s" as SessionId, "later", 0)).toBe(false);
  15. });
  16. it("重开后读同一账本;旧历史缺少接纳记录不猜首条", async () => {
  17. expect(await readFirstMessageAttribution(store, "s" as SessionId, "later", 12)).toBe(false);
  18. expect(await readFirstMessageAttribution(store, "s" as SessionId, "first", 12)).toBeUndefined();
  19. expect(await readFirstMessageAttribution(store, "s" as SessionId, "legacy", 0)).toBeUndefined();
  20. expect(
  21. await readFirstMessageAttribution(undefined, "s" as SessionId, "first", 0),
  22. ).toBeUndefined();
  23. });
  24. });