Open History to see the last commit
1import {
2 CommandId,
3 ProjectId,
4 ProviderInstanceId,
5 ThreadId,
6 type OrchestrationReadModel,
7} from "@t3tools/contracts";
8import * as NodeServices from "@effect/platform-node/NodeServices";
9import { expect, it } from "@effect/vitest";
10import * as Effect from "effect/Effect";
11
12import { decideOrchestrationCommand } from "./decider.ts";
13
14const UPDATED_AT = "2026-01-01T00:00:00.000Z";
15
16const readModel: OrchestrationReadModel = {
17 snapshotSequence: 0,
18 projects: [],
19 threads: [
20 {
21 id: ThreadId.make("thread-1"),
22 projectId: ProjectId.make("project-1"),
23 title: "Manual title",
24 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
25 runtimeMode: "full-access",
26 interactionMode: "default",
27 branch: null,
28 worktreePath: null,
29 latestTurn: null,
30 createdAt: UPDATED_AT,
31 updatedAt: UPDATED_AT,
32 archivedAt: null,
33 settledOverride: null,
34 settledAt: null,
35 snoozedUntil: null,
36 snoozedAt: null,
37 deletedAt: null,
38 messages: [],
39 proposedPlans: [],
40 activities: [],
41 checkpoints: [],
42 session: null,
43 },
44 ],
45 updatedAt: UPDATED_AT,
46};
47
48it.layer(NodeServices.layer)("title regeneration decider", (it) => {
49 it.effect("preserves updatedAt for a stale completion", () =>
50 Effect.gen(function* () {
51 const result = yield* decideOrchestrationCommand({
52 command: {
53 type: "thread.title.regeneration.complete",
54 commandId: CommandId.make("cmd-regeneration-complete"),
55 threadId: ThreadId.make("thread-1"),
56 requestId: CommandId.make("cmd-old-regeneration-request"),
57 title: "Generated title",
58 },
59 readModel,
60 });
61 const event = Array.isArray(result) ? result[0] : result;
62
63 expect(event.type).toBe("thread.meta-updated");
64 if (event.type === "thread.meta-updated") {
65 expect(event.payload).toEqual({
66 threadId: ThreadId.make("thread-1"),
67 updatedAt: UPDATED_AT,
68 });
69 }
70 }),
71 );
72});