import assert from "node:assert/strict";import { it } from "@effect/vitest";import { Effect, Schema } from "effect"; import { DEFAULT_PROVIDER_INTERACTION_MODE, DEFAULT_RUNTIME_MODE, OrchestrationGetTurnDiffInput, OrchestrationSession, ProjectCreateCommand, ThreadTurnStartCommand, ThreadCreatedPayload, ThreadTurnDiff, ThreadTurnStartRequestedPayload,} from "./orchestration"; const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput);const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff);const decodeProjectCreateCommand = Schema.decodeUnknownEffect(ProjectCreateCommand);const decodeThreadTurnStartCommand = Schema.decodeUnknownEffect(ThreadTurnStartCommand);const decodeThreadTurnStartRequestedPayload = Schema.decodeUnknownEffect( ThreadTurnStartRequestedPayload,);const decodeOrchestrationSession = Schema.decodeUnknownEffect(OrchestrationSession);const decodeThreadCreatedPayload = Schema.decodeUnknownEffect(ThreadCreatedPayload); it.effect("parses turn diff input when fromTurnCount <= toTurnCount", () => Effect.gen(function* () { const parsed = yield* decodeTurnDiffInput({ threadId: "thread-1", fromTurnCount: 1, toTurnCount: 2, }); assert.strictEqual(parsed.fromTurnCount, 1); assert.strictEqual(parsed.toTurnCount, 2); }),); it.effect("rejects turn diff input when fromTurnCount > toTurnCount", () => Effect.gen(function* () { const result = yield* Effect.exit( decodeTurnDiffInput({ threadId: "thread-1", fromTurnCount: 3, toTurnCount: 2, }), ); assert.strictEqual(result._tag, "Failure"); }),); it.effect("rejects thread turn diff when fromTurnCount > toTurnCount", () => Effect.gen(function* () { const result = yield* Effect.exit( decodeThreadTurnDiff({ threadId: "thread-1", fromTurnCount: 3, toTurnCount: 2, diff: "patch", }), ); assert.strictEqual(result._tag, "Failure"); }),); it.effect("trims branded ids and command string fields at decode boundaries", () => Effect.gen(function* () { const parsed = yield* decodeProjectCreateCommand({ type: "project.create", commandId: " cmd-1 ", projectId: " project-1 ", title: " Project Title ", workspaceRoot: " /tmp/workspace ", defaultModel: " gpt-5.2 ", createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.commandId, "cmd-1"); assert.strictEqual(parsed.projectId, "project-1"); assert.strictEqual(parsed.title, "Project Title"); assert.strictEqual(parsed.workspaceRoot, "/tmp/workspace"); assert.strictEqual(parsed.defaultModel, "gpt-5.2"); }),); it.effect("rejects command fields that become empty after trim", () => Effect.gen(function* () { const result = yield* Effect.exit( decodeProjectCreateCommand({ type: "project.create", commandId: "cmd-1", projectId: "project-1", title: " ", workspaceRoot: "/tmp/workspace", createdAt: "2026-01-01T00:00:00.000Z", }), ); assert.strictEqual(result._tag, "Failure"); }),); it.effect("decodes thread.turn.start defaults for provider and runtime mode", () => Effect.gen(function* () { const parsed = yield* decodeThreadTurnStartCommand({ type: "thread.turn.start", commandId: "cmd-turn-1", threadId: "thread-1", message: { messageId: "msg-1", role: "user", text: "hello", attachments: [], }, createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.provider, undefined); assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE); assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE); }),); it.effect("preserves explicit provider and runtime mode in thread.turn.start", () => Effect.gen(function* () { const parsed = yield* decodeThreadTurnStartCommand({ type: "thread.turn.start", commandId: "cmd-turn-2", threadId: "thread-1", message: { messageId: "msg-2", role: "user", text: "hello", attachments: [], }, provider: "codex", runtimeMode: "full-access", createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.provider, "codex"); assert.strictEqual(parsed.runtimeMode, "full-access"); assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE); }),); it.effect("decodes thread.created runtime mode for historical events", () => Effect.gen(function* () { const parsed = yield* decodeThreadCreatedPayload({ threadId: "thread-1", projectId: "project-1", title: "Thread title", model: "gpt-5.4", interactionMode: "default", branch: null, worktreePath: null, createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE); }),); it.effect("accepts provider-scoped model options in thread.turn.start", () => Effect.gen(function* () { const parsed = yield* decodeThreadTurnStartCommand({ type: "thread.turn.start", commandId: "cmd-turn-options", threadId: "thread-1", message: { messageId: "msg-options", role: "user", text: "hello", attachments: [], }, provider: "codex", model: "gpt-5.3-codex", modelOptions: { codex: { reasoningEffort: "high", fastMode: true, }, }, createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.provider, "codex"); assert.strictEqual(parsed.modelOptions?.codex?.reasoningEffort, "high"); assert.strictEqual(parsed.modelOptions?.codex?.fastMode, true); }),); it.effect( "decodes thread.turn-start-requested defaults for provider, runtime mode, and interaction mode", () => Effect.gen(function* () { const parsed = yield* decodeThreadTurnStartRequestedPayload({ threadId: "thread-1", messageId: "msg-1", createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.provider, undefined); assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE); assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE); }),); it.effect("decodes orchestration session runtime mode defaults", () => Effect.gen(function* () { const parsed = yield* decodeOrchestrationSession({ threadId: "thread-1", status: "idle", providerName: null, providerSessionId: null, providerThreadId: null, activeTurnId: null, lastError: null, updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE); }),);
import assert from "node:assert/strict";
import { it } from "@effect/vitest";
import { Effect, Schema } from "effect";
import {
DEFAULT_PROVIDER_INTERACTION_MODE,
DEFAULT_RUNTIME_MODE,
OrchestrationGetTurnDiffInput,
OrchestrationSession,
ProjectCreateCommand,
ThreadTurnStartCommand,
ThreadCreatedPayload,
ThreadTurnDiff,
ThreadTurnStartRequestedPayload,
} from "./orchestration";
const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput);
const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff);
const decodeProjectCreateCommand = Schema.decodeUnknownEffect(ProjectCreateCommand);
const decodeThreadTurnStartCommand = Schema.decodeUnknownEffect(ThreadTurnStartCommand);
const decodeThreadTurnStartRequestedPayload = Schema.decodeUnknownEffect(
ThreadTurnStartRequestedPayload,
);
const decodeOrchestrationSession = Schema.decodeUnknownEffect(OrchestrationSession);
const decodeThreadCreatedPayload = Schema.decodeUnknownEffect(ThreadCreatedPayload);
it.effect("parses turn diff input when fromTurnCount <= toTurnCount", () =>
Effect.gen(function* () {
const parsed = yield* decodeTurnDiffInput({
threadId: "thread-1",
fromTurnCount: 1,
toTurnCount: 2,
});
assert.strictEqual(parsed.fromTurnCount, 1);
assert.strictEqual(parsed.toTurnCount, 2);
}),
);
it.effect("rejects turn diff input when fromTurnCount > toTurnCount", () =>
Effect.gen(function* () {
const result = yield* Effect.exit(
decodeTurnDiffInput({
threadId: "thread-1",
fromTurnCount: 3,
toTurnCount: 2,
}),
);
assert.strictEqual(result._tag, "Failure");
}),
);
it.effect("rejects thread turn diff when fromTurnCount > toTurnCount", () =>
Effect.gen(function* () {
const result = yield* Effect.exit(
decodeThreadTurnDiff({
threadId: "thread-1",
fromTurnCount: 3,
toTurnCount: 2,
diff: "patch",
}),
);
assert.strictEqual(result._tag, "Failure");
}),
);
it.effect("trims branded ids and command string fields at decode boundaries", () =>
Effect.gen(function* () {
const parsed = yield* decodeProjectCreateCommand({
type: "project.create",
commandId: " cmd-1 ",
projectId: " project-1 ",
title: " Project Title ",
workspaceRoot: " /tmp/workspace ",
defaultModel: " gpt-5.2 ",
createdAt: "2026-01-01T00:00:00.000Z",
});
assert.strictEqual(parsed.commandId, "cmd-1");
assert.strictEqual(parsed.projectId, "project-1");
assert.strictEqual(parsed.title, "Project Title");
assert.strictEqual(parsed.workspaceRoot, "/tmp/workspace");
assert.strictEqual(parsed.defaultModel, "gpt-5.2");
}),
);
it.effect("rejects command fields that become empty after trim", () =>
Effect.gen(function* () {
const result = yield* Effect.exit(
decodeProjectCreateCommand({
type: "project.create",
commandId: "cmd-1",
projectId: "project-1",
title: " ",
workspaceRoot: "/tmp/workspace",
createdAt: "2026-01-01T00:00:00.000Z",
}),
);
assert.strictEqual(result._tag, "Failure");
}),
);
it.effect("decodes thread.turn.start defaults for provider and runtime mode", () =>
Effect.gen(function* () {
const parsed = yield* decodeThreadTurnStartCommand({
type: "thread.turn.start",
commandId: "cmd-turn-1",
threadId: "thread-1",
message: {
messageId: "msg-1",
role: "user",
text: "hello",
attachments: [],
},
createdAt: "2026-01-01T00:00:00.000Z",
});
assert.strictEqual(parsed.provider, undefined);
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
}),
);
it.effect("preserves explicit provider and runtime mode in thread.turn.start", () =>
Effect.gen(function* () {
const parsed = yield* decodeThreadTurnStartCommand({
type: "thread.turn.start",
commandId: "cmd-turn-2",
threadId: "thread-1",
message: {
messageId: "msg-2",
role: "user",
text: "hello",
attachments: [],
},
provider: "codex",
runtimeMode: "full-access",
createdAt: "2026-01-01T00:00:00.000Z",
});
assert.strictEqual(parsed.provider, "codex");
assert.strictEqual(parsed.runtimeMode, "full-access");
assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
}),
);
it.effect("decodes thread.created runtime mode for historical events", () =>
Effect.gen(function* () {
const parsed = yield* decodeThreadCreatedPayload({
threadId: "thread-1",
projectId: "project-1",
title: "Thread title",
model: "gpt-5.4",
interactionMode: "default",
branch: null,
worktreePath: null,
createdAt: "2026-01-01T00:00:00.000Z",
updatedAt: "2026-01-01T00:00:00.000Z",
});
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
}),
);
it.effect("accepts provider-scoped model options in thread.turn.start", () =>
Effect.gen(function* () {
const parsed = yield* decodeThreadTurnStartCommand({
type: "thread.turn.start",
commandId: "cmd-turn-options",
threadId: "thread-1",
message: {
messageId: "msg-options",
role: "user",
text: "hello",
attachments: [],
},
provider: "codex",
model: "gpt-5.3-codex",
modelOptions: {
codex: {
reasoningEffort: "high",
fastMode: true,
},
},
createdAt: "2026-01-01T00:00:00.000Z",
});
assert.strictEqual(parsed.provider, "codex");
assert.strictEqual(parsed.modelOptions?.codex?.reasoningEffort, "high");
assert.strictEqual(parsed.modelOptions?.codex?.fastMode, true);
}),
);
it.effect(
"decodes thread.turn-start-requested defaults for provider, runtime mode, and interaction mode",
() =>
Effect.gen(function* () {
const parsed = yield* decodeThreadTurnStartRequestedPayload({
threadId: "thread-1",
messageId: "msg-1",
createdAt: "2026-01-01T00:00:00.000Z",
});
assert.strictEqual(parsed.provider, undefined);
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
}),
);
it.effect("decodes orchestration session runtime mode defaults", () =>
Effect.gen(function* () {
const parsed = yield* decodeOrchestrationSession({
threadId: "thread-1",
status: "idle",
providerName: null,
providerSessionId: null,
providerThreadId: null,
activeTurnId: null,
lastError: null,
updatedAt: "2026-01-01T00:00:00.000Z",
});
assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
}),
);