7582a88d6b
- types.ts: START/END, RoleMeta, ThreadContext, Role, Moderator, WorkflowDefinition - engine.ts: executeThread with JSONL persistence + AbortSignal - worker.ts: per-bundle process, TCP IPC, kill individual threads - CLI: run/ps/kill/threads/thread/thread rm commands - 32 tests pass, biome clean 小橘 <xiaoju@shazhou.work>
30 lines
948 B
TypeScript
30 lines
948 B
TypeScript
import { describe, expect, test } from "bun:test";
|
|
|
|
import { decodeCrockfordBase32Bits } from "../src/base32.js";
|
|
import { generateUlid } from "../src/ulid.js";
|
|
|
|
describe("generateUlid", () => {
|
|
test("length and decodable Crockford payload", () => {
|
|
const id = generateUlid(1_714_963_200_000);
|
|
expect(id.length).toBe(26);
|
|
const decoded = decodeCrockfordBase32Bits(id, 128);
|
|
expect(decoded.ok).toBe(true);
|
|
});
|
|
|
|
test("embeds 48-bit timestamp at the MSB of the 128-bit payload", () => {
|
|
const ts = 9_999_888_777_666;
|
|
const id = generateUlid(ts);
|
|
const decoded = decodeCrockfordBase32Bits(id, 128);
|
|
expect(decoded.ok).toBe(true);
|
|
if (decoded.ok) {
|
|
const recoveredMs = decoded.value >> 80n;
|
|
expect(Number(recoveredMs)).toBe(ts);
|
|
}
|
|
});
|
|
|
|
test("rejects out-of-range timestamps", () => {
|
|
expect(() => generateUlid(-1)).toThrow();
|
|
expect(() => generateUlid(2 ** 48)).toThrow();
|
|
});
|
|
});
|