|
| 1 | +import { |
| 2 | + CommandId, |
| 3 | + DEFAULT_PROVIDER_INTERACTION_MODE, |
| 4 | + EventId, |
| 5 | + MessageId, |
| 6 | + ProjectId, |
| 7 | + ProviderInstanceId, |
| 8 | + ThreadId, |
| 9 | +} from "@t3tools/contracts"; |
| 10 | +import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 11 | +import { expect, it } from "@effect/vitest"; |
| 12 | +import * as Effect from "effect/Effect"; |
| 13 | + |
| 14 | +import { decideOrchestrationCommand } from "./decider.ts"; |
| 15 | +import { createEmptyReadModel, projectEvent } from "./projector.ts"; |
| 16 | + |
| 17 | +it.layer(NodeServices.layer)("decider imported messages", (it) => { |
| 18 | + it.effect("replaces an existing history slot even when the imported text is empty", () => |
| 19 | + Effect.gen(function* () { |
| 20 | + const createdAt = "2026-01-01T00:00:00.000Z"; |
| 21 | + const projectId = ProjectId.make("project-import"); |
| 22 | + const threadId = ThreadId.make("thread-import"); |
| 23 | + const initial = createEmptyReadModel(createdAt); |
| 24 | + const withProject = yield* projectEvent(initial, { |
| 25 | + sequence: 1, |
| 26 | + eventId: EventId.make("event-project-import"), |
| 27 | + aggregateKind: "project", |
| 28 | + aggregateId: projectId, |
| 29 | + type: "project.created", |
| 30 | + occurredAt: createdAt, |
| 31 | + commandId: CommandId.make("command-project-import"), |
| 32 | + causationEventId: null, |
| 33 | + correlationId: CommandId.make("command-project-import"), |
| 34 | + metadata: {}, |
| 35 | + payload: { |
| 36 | + projectId, |
| 37 | + title: "Imports", |
| 38 | + workspaceRoot: "/tmp/imports", |
| 39 | + defaultModelSelection: null, |
| 40 | + scripts: [], |
| 41 | + createdAt, |
| 42 | + updatedAt: createdAt, |
| 43 | + }, |
| 44 | + }); |
| 45 | + const readModel = yield* projectEvent(withProject, { |
| 46 | + sequence: 2, |
| 47 | + eventId: EventId.make("event-thread-import"), |
| 48 | + aggregateKind: "thread", |
| 49 | + aggregateId: threadId, |
| 50 | + type: "thread.created", |
| 51 | + occurredAt: createdAt, |
| 52 | + commandId: CommandId.make("command-thread-import"), |
| 53 | + causationEventId: null, |
| 54 | + correlationId: CommandId.make("command-thread-import"), |
| 55 | + metadata: {}, |
| 56 | + payload: { |
| 57 | + threadId, |
| 58 | + projectId, |
| 59 | + title: "Imported thread", |
| 60 | + modelSelection: { |
| 61 | + instanceId: ProviderInstanceId.make("hermes"), |
| 62 | + model: "openai-codex::gpt-5.6-sol", |
| 63 | + }, |
| 64 | + runtimeMode: "full-access", |
| 65 | + interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE, |
| 66 | + branch: null, |
| 67 | + worktreePath: null, |
| 68 | + createdAt, |
| 69 | + updatedAt: createdAt, |
| 70 | + }, |
| 71 | + }); |
| 72 | + |
| 73 | + const event = yield* decideOrchestrationCommand({ |
| 74 | + command: { |
| 75 | + type: "thread.message.import", |
| 76 | + commandId: CommandId.make("command-message-import"), |
| 77 | + threadId, |
| 78 | + messageId: MessageId.make("message-import"), |
| 79 | + role: "assistant", |
| 80 | + text: "", |
| 81 | + createdAt: "2026-01-01T00:01:00.000Z", |
| 82 | + }, |
| 83 | + readModel, |
| 84 | + }); |
| 85 | + |
| 86 | + const importedEvent = Array.isArray(event) ? event[0] : event; |
| 87 | + expect(importedEvent?.type).toBe("thread.message-sent"); |
| 88 | + if (importedEvent?.type !== "thread.message-sent") { |
| 89 | + return; |
| 90 | + } |
| 91 | + expect(importedEvent.payload.imported).toBe(true); |
| 92 | + expect(importedEvent.payload.replaceText).toBe(true); |
| 93 | + expect(importedEvent.payload.text).toBe(""); |
| 94 | + }), |
| 95 | + ); |
| 96 | +}); |
0 commit comments