Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import { Effect, Schema } from "effect";
3
4import {
5 OrchestrationGetTurnDiffInput,
6 ProjectCreateCommand,
7 ThreadTurnDiff,
8} from "./orchestration";
9
10const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput);
11const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff);
12const decodeProjectCreateCommand = Schema.decodeUnknownEffect(ProjectCreateCommand);
13
14it.effect("parses turn diff input when fromTurnCount <= toTurnCount", () =>
15 Effect.gen(function* () {
16 const parsed = yield* decodeTurnDiffInput({
17 threadId: "thread-1",
18 fromTurnCount: 1,
19 toTurnCount: 2,
20 });
21 assert.strictEqual(parsed.fromTurnCount, 1);
22 assert.strictEqual(parsed.toTurnCount, 2);
23 }),
24);
25
26it.effect("rejects turn diff input when fromTurnCount > toTurnCount", () =>
27 Effect.gen(function* () {
28 const result = yield* Effect.exit(
29 decodeTurnDiffInput({
30 threadId: "thread-1",
31 fromTurnCount: 3,
32 toTurnCount: 2,
33 }),
34 );
35 assert.strictEqual(result._tag, "Failure");
36 }),
37);
38
39it.effect("rejects thread turn diff when fromTurnCount > toTurnCount", () =>
40 Effect.gen(function* () {
41 const result = yield* Effect.exit(
42 decodeThreadTurnDiff({
43 threadId: "thread-1",
44 fromTurnCount: 3,
45 toTurnCount: 2,
46 diff: "patch",
47 }),
48 );
49 assert.strictEqual(result._tag, "Failure");
50 }),
51);
52
53it.effect("trims branded ids and command string fields at decode boundaries", () =>
54 Effect.gen(function* () {
55 const parsed = yield* decodeProjectCreateCommand({
56 type: "project.create",
57 commandId: " cmd-1 ",
58 projectId: " project-1 ",
59 title: " Project Title ",
60 workspaceRoot: " /tmp/workspace ",
61 defaultModel: " gpt-5.2 ",
62 createdAt: "2026-01-01T00:00:00.000Z",
63 });
64 assert.strictEqual(parsed.commandId, "cmd-1");
65 assert.strictEqual(parsed.projectId, "project-1");
66 assert.strictEqual(parsed.title, "Project Title");
67 assert.strictEqual(parsed.workspaceRoot, "/tmp/workspace");
68 assert.strictEqual(parsed.defaultModel, "gpt-5.2");
69 }),
70);
71
72it.effect("rejects command fields that become empty after trim", () =>
73 Effect.gen(function* () {
74 const result = yield* Effect.exit(
75 decodeProjectCreateCommand({
76 type: "project.create",
77 commandId: "cmd-1",
78 projectId: "project-1",
79 title: " ",
80 workspaceRoot: "/tmp/workspace",
81 createdAt: "2026-01-01T00:00:00.000Z",
82 }),
83 );
84 assert.strictEqual(result._tag, "Failure");
85 }),
86);