v4CommandFactoryIdentity.test.ts 742 B

1234567891011121314151617
  1. import { describe, expect, it } from "vitest";
  2. import { uuidv7 } from "@zcode/shared";
  3. import { uuidv7 as commandUuidv7 } from "../src/v4/commandFactory.js";
  4. describe("shared main-turn UUID v7", () => {
  5. it("uses the same generator for renderer commands and runtime wake inputs", () => {
  6. expect(commandUuidv7).toBe(uuidv7);
  7. const now = 1_788_749_627_422;
  8. const ids = Array.from({ length: 100 }, () => uuidv7(now));
  9. expect(new Set(ids).size).toBe(ids.length);
  10. for (const id of ids) {
  11. expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
  12. expect(parseInt(id.replaceAll("-", "").slice(0, 12), 16)).toBe(now);
  13. expect(id < uuidv7(now + 1)).toBe(true);
  14. }
  15. });
  16. });