import { assert, it } from "@effect/vitest";import * as Effect from "effect/Effect";import * as Schema from "effect/Schema"; import { DEFAULT_PROVIDER_INTERACTION_MODE, DEFAULT_RUNTIME_MODE, ModelSelection, OrchestrationCommand, OrchestrationEvent, OrchestrationGetFullThreadDiffInput, OrchestrationGetTurnDiffInput, OrchestrationLatestTurn, ProjectCreatedPayload, ProjectMetaUpdatedPayload, OrchestrationProposedPlan, OrchestrationSession, ProjectCreateCommand, ThreadMetaUpdatedPayload, ThreadTurnStartCommand, ThreadCreatedPayload, ThreadTurnDiff, ThreadTurnStartRequestedPayload,} from "./orchestration.ts";import { ProviderInstanceId } from "./providerInstance.ts"; const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput);const decodeFullThreadDiffInput = Schema.decodeUnknownEffect(OrchestrationGetFullThreadDiffInput);const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff);const decodeProjectCreateCommand = Schema.decodeUnknownEffect(ProjectCreateCommand);const decodeProjectCreatedPayload = Schema.decodeUnknownEffect(ProjectCreatedPayload);const decodeProjectMetaUpdatedPayload = Schema.decodeUnknownEffect(ProjectMetaUpdatedPayload);const decodeThreadTurnStartCommand = Schema.decodeUnknownEffect(ThreadTurnStartCommand);const decodeThreadTurnStartRequestedPayload = Schema.decodeUnknownEffect( ThreadTurnStartRequestedPayload,);const decodeOrchestrationLatestTurn = Schema.decodeUnknownEffect(OrchestrationLatestTurn);const decodeOrchestrationProposedPlan = Schema.decodeUnknownEffect(OrchestrationProposedPlan);const decodeOrchestrationSession = Schema.decodeUnknownEffect(OrchestrationSession);const encodeThreadCreatedPayload = Schema.encodeEffect(ThreadCreatedPayload); function getOptionValue( options: ReadonlyArray<{ id: string; value: unknown }> | undefined, id: string,): unknown { return options?.find((option) => option.id === id)?.value;}const decodeThreadCreatedPayload = Schema.decodeUnknownEffect(ThreadCreatedPayload);const decodeOrchestrationCommand = Schema.decodeUnknownEffect(OrchestrationCommand);const decodeOrchestrationEvent = Schema.decodeUnknownEffect(OrchestrationEvent);const decodeThreadMetaUpdatedPayload = Schema.decodeUnknownEffect(ThreadMetaUpdatedPayload); 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("parses turn diff input with whitespace ignoring enabled", () => Effect.gen(function* () { const parsed = yield* decodeTurnDiffInput({ threadId: "thread-1", fromTurnCount: 1, toTurnCount: 2, ignoreWhitespace: true, }); assert.strictEqual(parsed.ignoreWhitespace, true); }),); it.effect("parses full thread diff input with whitespace ignoring enabled", () => Effect.gen(function* () { const parsed = yield* decodeFullThreadDiffInput({ threadId: "thread-1", toTurnCount: 2, ignoreWhitespace: true, }); assert.strictEqual(parsed.ignoreWhitespace, true); }),); 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 ", defaultModelSelection: { provider: "codex", model: " 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.createWorkspaceRootIfMissing, undefined); assert.deepStrictEqual(parsed.defaultModelSelection, { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.2", }); }),); it.effect("decodes project.create with createWorkspaceRootIfMissing enabled", () => Effect.gen(function* () { const parsed = yield* decodeProjectCreateCommand({ type: "project.create", commandId: "cmd-1", projectId: "project-1", title: "Project Title", workspaceRoot: "/tmp/workspace", createWorkspaceRootIfMissing: true, createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.createWorkspaceRootIfMissing, true); }),); it.effect("decodes historical project.created payloads with a default provider", () => Effect.gen(function* () { const parsed = yield* decodeProjectCreatedPayload({ projectId: "project-1", title: "Project Title", workspaceRoot: "/tmp/workspace", defaultModelSelection: { provider: "codex", model: "gpt-5.4", }, scripts: [], createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.defaultModelSelection?.instanceId, "codex"); }),); it.effect("decodes project.meta-updated payloads with explicit default provider", () => Effect.gen(function* () { const parsed = yield* decodeProjectMetaUpdatedPayload({ projectId: "project-1", defaultModelSelection: { provider: "claudeAgent", model: "claude-opus-4-6", }, updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.defaultModelSelection?.instanceId, "claudeAgent"); }),); 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.modelSelection, 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: [], }, modelSelection: { provider: "codex", model: "gpt-5.4", }, runtimeMode: "full-access", createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.modelSelection?.instanceId, "codex"); assert.strictEqual(parsed.runtimeMode, "full-access"); assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE); }),); it.effect("accepts bootstrap metadata in thread.turn.start", () => Effect.gen(function* () { const parsed = yield* decodeThreadTurnStartCommand({ type: "thread.turn.start", commandId: "cmd-turn-bootstrap", threadId: "thread-1", message: { messageId: "msg-bootstrap", role: "user", text: "hello", attachments: [], }, bootstrap: { createThread: { projectId: "project-1", title: "Bootstrap thread", modelSelection: { provider: "codex", model: "gpt-5.4", }, runtimeMode: "full-access", interactionMode: "default", branch: null, worktreePath: null, createdAt: "2026-01-01T00:00:00.000Z", }, prepareWorktree: { projectCwd: "/tmp/workspace", baseBranch: "main", branch: "t3code/example", startFromOrigin: true, }, runSetupScript: true, }, createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.bootstrap?.createThread?.projectId, "project-1"); assert.strictEqual(parsed.bootstrap?.prepareWorktree?.baseBranch, "main"); assert.strictEqual(parsed.bootstrap?.prepareWorktree?.startFromOrigin, true); assert.strictEqual(parsed.bootstrap?.runSetupScript, true); }),); 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", modelSelection: { provider: "codex", 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); assert.strictEqual(parsed.modelSelection.instanceId, "codex"); }),); it.effect("decodes thread.meta-updated payloads with explicit provider", () => Effect.gen(function* () { const parsed = yield* decodeThreadMetaUpdatedPayload({ threadId: "thread-1", modelSelection: { provider: "claudeAgent", model: "claude-opus-4-6", }, updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.modelSelection?.instanceId, "claudeAgent"); }),); it.effect("decodes thread archive and unarchive commands", () => Effect.gen(function* () { const archive = yield* decodeOrchestrationCommand({ type: "thread.archive", commandId: "cmd-archive-1", threadId: "thread-1", }); const unarchive = yield* decodeOrchestrationCommand({ type: "thread.unarchive", commandId: "cmd-unarchive-1", threadId: "thread-1", }); assert.strictEqual(archive.type, "thread.archive"); assert.strictEqual(unarchive.type, "thread.unarchive"); }),); it.effect("decodes thread archived and unarchived events", () => Effect.gen(function* () { const archived = yield* decodeOrchestrationEvent({ sequence: 1, eventId: "event-archive-1", aggregateKind: "thread", aggregateId: "thread-1", type: "thread.archived", occurredAt: "2026-01-01T00:00:00.000Z", commandId: "cmd-archive-1", causationEventId: null, correlationId: "cmd-archive-1", metadata: {}, payload: { threadId: "thread-1", archivedAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }, }); const unarchived = yield* decodeOrchestrationEvent({ sequence: 2, eventId: "event-unarchive-1", aggregateKind: "thread", aggregateId: "thread-1", type: "thread.unarchived", occurredAt: "2026-01-02T00:00:00.000Z", commandId: "cmd-unarchive-1", causationEventId: null, correlationId: "cmd-unarchive-1", metadata: {}, payload: { threadId: "thread-1", updatedAt: "2026-01-02T00:00:00.000Z", }, }); if (archived.type !== "thread.archived") { assert.fail(`Expected thread.archived event, received ${archived.type}.`); } assert.strictEqual(archived.payload.archivedAt, "2026-01-01T00:00:00.000Z"); assert.strictEqual(unarchived.type, "thread.unarchived"); }),); 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: [], }, modelSelection: { provider: "codex", model: "gpt-5.3-codex", options: [ { id: "reasoningEffort", value: "high" }, { id: "fastMode", value: true }, ], }, createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.modelSelection?.instanceId, "codex"); assert.strictEqual(getOptionValue(parsed.modelSelection?.options, "reasoningEffort"), "high"); assert.strictEqual(getOptionValue(parsed.modelSelection?.options, "fastMode"), true); }),); it.effect("normalizes legacy object-shaped modelSelection.options on decode", () => Effect.gen(function* () { const parsed = yield* decodeThreadCreatedPayload({ threadId: "thread-1", projectId: "project-1", title: "Legacy options thread", modelSelection: { provider: "claudeAgent", model: "claude-opus-4-6", options: { effort: "max", fastMode: true, // Falsy/garbage entries are dropped, matching migration 026. emptyStr: " ", nullish: null, nested: { foo: 1 }, }, }, branch: null, worktreePath: null, createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.modelSelection.instanceId, ProviderInstanceId.make("claudeAgent")); assert.deepStrictEqual(parsed.modelSelection.options, [ { id: "effort", value: "max" }, { id: "fastMode", value: true }, ]); }),); it.effect("normalizes legacy object-shaped defaultModelSelection.options on decode", () => Effect.gen(function* () { const parsed = yield* decodeProjectCreatedPayload({ projectId: "project-1", title: "Legacy default project", workspaceRoot: "/tmp/legacy", defaultModelSelection: { provider: "codex", model: "gpt-5.4", options: { reasoningEffort: "low" }, }, scripts: [], createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }); assert.deepStrictEqual(parsed.defaultModelSelection?.options, [ { id: "reasoningEffort", value: "low" }, ]); }),); it.effect( "normalizes legacy object-shaped options on decode and re-encodes as canonical array", () => Effect.gen(function* () { const decoded = yield* decodeThreadCreatedPayload({ threadId: "thread-1", projectId: "project-1", title: "Round trip thread", modelSelection: { provider: "codex", model: "gpt-5.4", options: { fastMode: true }, }, branch: null, worktreePath: null, createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }); const encoded = yield* encodeThreadCreatedPayload(decoded); assert.deepStrictEqual(encoded.modelSelection.options, [{ id: "fastMode", value: true }]); }),); it.effect("accepts a title seed in thread.turn.start", () => Effect.gen(function* () { const parsed = yield* decodeThreadTurnStartCommand({ type: "thread.turn.start",Lines 1–500 of 745. Load more
import { assert, it } from "@effect/vitest"; import * as Effect from "effect/Effect"; import * as Schema from "effect/Schema"; import { DEFAULT_PROVIDER_INTERACTION_MODE, DEFAULT_RUNTIME_MODE, ModelSelection, OrchestrationCommand, OrchestrationEvent, OrchestrationGetFullThreadDiffInput, OrchestrationGetTurnDiffInput, OrchestrationLatestTurn, ProjectCreatedPayload, ProjectMetaUpdatedPayload, OrchestrationProposedPlan, OrchestrationSession, ProjectCreateCommand, ThreadMetaUpdatedPayload, ThreadTurnStartCommand, ThreadCreatedPayload, ThreadTurnDiff, ThreadTurnStartRequestedPayload, } from "./orchestration.ts"; import { ProviderInstanceId } from "./providerInstance.ts"; const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput); const decodeFullThreadDiffInput = Schema.decodeUnknownEffect(OrchestrationGetFullThreadDiffInput); const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff); const decodeProjectCreateCommand = Schema.decodeUnknownEffect(ProjectCreateCommand); const decodeProjectCreatedPayload = Schema.decodeUnknownEffect(ProjectCreatedPayload); const decodeProjectMetaUpdatedPayload = Schema.decodeUnknownEffect(ProjectMetaUpdatedPayload); const decodeThreadTurnStartCommand = Schema.decodeUnknownEffect(ThreadTurnStartCommand); const decodeThreadTurnStartRequestedPayload = Schema.decodeUnknownEffect( ThreadTurnStartRequestedPayload, ); const decodeOrchestrationLatestTurn = Schema.decodeUnknownEffect(OrchestrationLatestTurn); const decodeOrchestrationProposedPlan = Schema.decodeUnknownEffect(OrchestrationProposedPlan); const decodeOrchestrationSession = Schema.decodeUnknownEffect(OrchestrationSession); const encodeThreadCreatedPayload = Schema.encodeEffect(ThreadCreatedPayload); function getOptionValue( options: ReadonlyArray<{ id: string; value: unknown }> | undefined, id: string, ): unknown { return options?.find((option) => option.id === id)?.value; } const decodeThreadCreatedPayload = Schema.decodeUnknownEffect(ThreadCreatedPayload); const decodeOrchestrationCommand = Schema.decodeUnknownEffect(OrchestrationCommand); const decodeOrchestrationEvent = Schema.decodeUnknownEffect(OrchestrationEvent); const decodeThreadMetaUpdatedPayload = Schema.decodeUnknownEffect(ThreadMetaUpdatedPayload); 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("parses turn diff input with whitespace ignoring enabled", () => Effect.gen(function* () { const parsed = yield* decodeTurnDiffInput({ threadId: "thread-1", fromTurnCount: 1, toTurnCount: 2, ignoreWhitespace: true, }); assert.strictEqual(parsed.ignoreWhitespace, true); }), ); it.effect("parses full thread diff input with whitespace ignoring enabled", () => Effect.gen(function* () { const parsed = yield* decodeFullThreadDiffInput({ threadId: "thread-1", toTurnCount: 2, ignoreWhitespace: true, }); assert.strictEqual(parsed.ignoreWhitespace, true); }), ); 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 ", defaultModelSelection: { provider: "codex", model: " 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.createWorkspaceRootIfMissing, undefined); assert.deepStrictEqual(parsed.defaultModelSelection, { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.2", }); }), ); it.effect("decodes project.create with createWorkspaceRootIfMissing enabled", () => Effect.gen(function* () { const parsed = yield* decodeProjectCreateCommand({ type: "project.create", commandId: "cmd-1", projectId: "project-1", title: "Project Title", workspaceRoot: "/tmp/workspace", createWorkspaceRootIfMissing: true, createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.createWorkspaceRootIfMissing, true); }), ); it.effect("decodes historical project.created payloads with a default provider", () => Effect.gen(function* () { const parsed = yield* decodeProjectCreatedPayload({ projectId: "project-1", title: "Project Title", workspaceRoot: "/tmp/workspace", defaultModelSelection: { provider: "codex", model: "gpt-5.4", }, scripts: [], createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.defaultModelSelection?.instanceId, "codex"); }), ); it.effect("decodes project.meta-updated payloads with explicit default provider", () => Effect.gen(function* () { const parsed = yield* decodeProjectMetaUpdatedPayload({ projectId: "project-1", defaultModelSelection: { provider: "claudeAgent", model: "claude-opus-4-6", }, updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.defaultModelSelection?.instanceId, "claudeAgent"); }), ); 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.modelSelection, 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: [], }, modelSelection: { provider: "codex", model: "gpt-5.4", }, runtimeMode: "full-access", createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.modelSelection?.instanceId, "codex"); assert.strictEqual(parsed.runtimeMode, "full-access"); assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE); }), ); it.effect("accepts bootstrap metadata in thread.turn.start", () => Effect.gen(function* () { const parsed = yield* decodeThreadTurnStartCommand({ type: "thread.turn.start", commandId: "cmd-turn-bootstrap", threadId: "thread-1", message: { messageId: "msg-bootstrap", role: "user", text: "hello", attachments: [], }, bootstrap: { createThread: { projectId: "project-1", title: "Bootstrap thread", modelSelection: { provider: "codex", model: "gpt-5.4", }, runtimeMode: "full-access", interactionMode: "default", branch: null, worktreePath: null, createdAt: "2026-01-01T00:00:00.000Z", }, prepareWorktree: { projectCwd: "/tmp/workspace", baseBranch: "main", branch: "t3code/example", startFromOrigin: true, }, runSetupScript: true, }, createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.bootstrap?.createThread?.projectId, "project-1"); assert.strictEqual(parsed.bootstrap?.prepareWorktree?.baseBranch, "main"); assert.strictEqual(parsed.bootstrap?.prepareWorktree?.startFromOrigin, true); assert.strictEqual(parsed.bootstrap?.runSetupScript, true); }), ); 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", modelSelection: { provider: "codex", 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); assert.strictEqual(parsed.modelSelection.instanceId, "codex"); }), ); it.effect("decodes thread.meta-updated payloads with explicit provider", () => Effect.gen(function* () { const parsed = yield* decodeThreadMetaUpdatedPayload({ threadId: "thread-1", modelSelection: { provider: "claudeAgent", model: "claude-opus-4-6", }, updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.modelSelection?.instanceId, "claudeAgent"); }), ); it.effect("decodes thread archive and unarchive commands", () => Effect.gen(function* () { const archive = yield* decodeOrchestrationCommand({ type: "thread.archive", commandId: "cmd-archive-1", threadId: "thread-1", }); const unarchive = yield* decodeOrchestrationCommand({ type: "thread.unarchive", commandId: "cmd-unarchive-1", threadId: "thread-1", }); assert.strictEqual(archive.type, "thread.archive"); assert.strictEqual(unarchive.type, "thread.unarchive"); }), ); it.effect("decodes thread archived and unarchived events", () => Effect.gen(function* () { const archived = yield* decodeOrchestrationEvent({ sequence: 1, eventId: "event-archive-1", aggregateKind: "thread", aggregateId: "thread-1", type: "thread.archived", occurredAt: "2026-01-01T00:00:00.000Z", commandId: "cmd-archive-1", causationEventId: null, correlationId: "cmd-archive-1", metadata: {}, payload: { threadId: "thread-1", archivedAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }, }); const unarchived = yield* decodeOrchestrationEvent({ sequence: 2, eventId: "event-unarchive-1", aggregateKind: "thread", aggregateId: "thread-1", type: "thread.unarchived", occurredAt: "2026-01-02T00:00:00.000Z", commandId: "cmd-unarchive-1", causationEventId: null, correlationId: "cmd-unarchive-1", metadata: {}, payload: { threadId: "thread-1", updatedAt: "2026-01-02T00:00:00.000Z", }, }); if (archived.type !== "thread.archived") { assert.fail(`Expected thread.archived event, received ${archived.type}.`); } assert.strictEqual(archived.payload.archivedAt, "2026-01-01T00:00:00.000Z"); assert.strictEqual(unarchived.type, "thread.unarchived"); }), ); 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: [], }, modelSelection: { provider: "codex", model: "gpt-5.3-codex", options: [ { id: "reasoningEffort", value: "high" }, { id: "fastMode", value: true }, ], }, createdAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.modelSelection?.instanceId, "codex"); assert.strictEqual(getOptionValue(parsed.modelSelection?.options, "reasoningEffort"), "high"); assert.strictEqual(getOptionValue(parsed.modelSelection?.options, "fastMode"), true); }), ); it.effect("normalizes legacy object-shaped modelSelection.options on decode", () => Effect.gen(function* () { const parsed = yield* decodeThreadCreatedPayload({ threadId: "thread-1", projectId: "project-1", title: "Legacy options thread", modelSelection: { provider: "claudeAgent", model: "claude-opus-4-6", options: { effort: "max", fastMode: true, // Falsy/garbage entries are dropped, matching migration 026. emptyStr: " ", nullish: null, nested: { foo: 1 }, }, }, branch: null, worktreePath: null, createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }); assert.strictEqual(parsed.modelSelection.instanceId, ProviderInstanceId.make("claudeAgent")); assert.deepStrictEqual(parsed.modelSelection.options, [ { id: "effort", value: "max" }, { id: "fastMode", value: true }, ]); }), ); it.effect("normalizes legacy object-shaped defaultModelSelection.options on decode", () => Effect.gen(function* () { const parsed = yield* decodeProjectCreatedPayload({ projectId: "project-1", title: "Legacy default project", workspaceRoot: "/tmp/legacy", defaultModelSelection: { provider: "codex", model: "gpt-5.4", options: { reasoningEffort: "low" }, }, scripts: [], createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }); assert.deepStrictEqual(parsed.defaultModelSelection?.options, [ { id: "reasoningEffort", value: "low" }, ]); }), ); it.effect( "normalizes legacy object-shaped options on decode and re-encodes as canonical array", () => Effect.gen(function* () { const decoded = yield* decodeThreadCreatedPayload({ threadId: "thread-1", projectId: "project-1", title: "Round trip thread", modelSelection: { provider: "codex", model: "gpt-5.4", options: { fastMode: true }, }, branch: null, worktreePath: null, createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", }); const encoded = yield* encodeThreadCreatedPayload(decoded); assert.deepStrictEqual(encoded.modelSelection.options, [{ id: "fastMode", value: true }]); }), ); it.effect("accepts a title seed in thread.turn.start", () => Effect.gen(function* () { const parsed = yield* decodeThreadTurnStartCommand({ type: "thread.turn.start",