Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

Normalizer.test.ts

73 lines2.3 KB

1import { describe, expect, it } from "vite-plus/test";
2import {
3 CommandId,
4 type ClientOrchestrationCommand,
5 MessageId,
6 ProjectId,
7 ProviderInstanceId,
8 ThreadId,
9} from "@t3tools/contracts";
10​
11import { canonicalizeClientCommandTimestamps } from "./Normalizer.ts";
12​
13const clientCreatedAt = "2031-01-01T00:00:00.000Z";
14const serverReceivedAt = "2026-07-18T00:00:00.000Z";
15​
16describe("canonicalizeClientCommandTimestamps", () => {
17 it("replaces a client command timestamp with the server receipt timestamp", () => {
18 const command: ClientOrchestrationCommand = {
19 type: "project.create",
20 commandId: CommandId.make("command-1"),
21 projectId: ProjectId.make("project-1"),
22 title: "Clock-safe project",
23 workspaceRoot: "/tmp/clock-safe-project",
24 createdAt: clientCreatedAt,
25 };
26​
27 expect(canonicalizeClientCommandTimestamps(command, serverReceivedAt)).toEqual({
28 ...command,
29 createdAt: serverReceivedAt,
30 });
31 });
32​
33 it("replaces both timestamps when the first turn bootstraps a thread", () => {
34 const command: ClientOrchestrationCommand = {
35 type: "thread.turn.start",
36 commandId: CommandId.make("command-2"),
37 threadId: ThreadId.make("thread-1"),
38 message: {
39 messageId: MessageId.make("message-1"),
40 role: "user",
41 text: "Start a thread",
42 attachments: [],
43 },
44 runtimeMode: "full-access",
45 interactionMode: "default",
46 bootstrap: {
47 createThread: {
48 projectId: ProjectId.make("project-1"),
49 title: "Clock-safe thread",
50 modelSelection: {
51 instanceId: ProviderInstanceId.make("codex"),
52 model: "gpt-5.4",
53 },
54 runtimeMode: "full-access",
55 interactionMode: "default",
56 branch: null,
57 worktreePath: null,
58 createdAt: clientCreatedAt,
59 },
60 },
61 createdAt: clientCreatedAt,
62 };
63​
64 const result = canonicalizeClientCommandTimestamps(command, serverReceivedAt);
65​
66 expect(result.type).toBe("thread.turn.start");
67 if (result.type !== "thread.turn.start") {
68 throw new Error("Expected a thread.turn.start command");
69 }
70 expect(result.createdAt).toBe(serverReceivedAt);
71 expect(result.bootstrap?.createThread?.createdAt).toBe(serverReceivedAt);
72 });
73});