1import { assert } from "@effect/vitest";
2import type { ProviderReplayTranscript } from "@t3tools/contracts";
3
4import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts";
5import {
6 assertAssistantTextIncludes,
7 assertBaseProjection,
8 assertConversationMessageRoles,
9 assertRunOrdinals,
10 assertSemanticProjectionIntegrity,
11 assertTurnItemTypes,
12 assertUserMessageInputIntents,
13 assertUserMessagesInclude,
14 assertVisibleTurnItemsMirrorLocalTurnItems,
15 MULTI_TURN_FIRST_PROMPT,
16 MULTI_TURN_SECOND_PROMPT,
17 projectionFor,
18} from "../shared.ts";
19
20export function assertQueuedTurnOutput(
21 result: OrchestratorV2ScenarioResult,
22 transcript: ProviderReplayTranscript,
23) {
24 assertBaseProjection({
25 result,
26 transcript,
27 runCount: 2,
28 runStatuses: ["completed", "completed"],
29 });
30
31 const projection = projectionFor(result, transcript.scenario);
32 assertSemanticProjectionIntegrity(projection);
33 assertVisibleTurnItemsMirrorLocalTurnItems(projection);
34 assertRunOrdinals(projection, [1, 2]);
35 assertConversationMessageRoles(projection, ["user", "assistant", "user", "assistant"]);
36 assertTurnItemTypes(projection, ["user_message", "assistant_message"]);
37 assertUserMessagesInclude(projection, [MULTI_TURN_FIRST_PROMPT, MULTI_TURN_SECOND_PROMPT]);
38 assertUserMessageInputIntents(projection, ["turn_start", "queued_turn"]);
39 assert.equal(projection.turnItems.filter((item) => item.type === "user_message").length, 2);
40 assertAssistantTextIncludes(projection, "first fixture turn complete");
41 assertAssistantTextIncludes(projection, "second fixture turn complete");
42
43 const run2Events = result.domainEvents
44 .filter((event) => event.type === "run.created" || event.type === "run.updated")
45 .filter((event) => event.runId === projection.runs[1]?.id);
46 assert.equal(run2Events[0]?.type, "run.created");
47 assert.equal(run2Events[0]?.payload.status, "queued");
48 assert.isTrue(run2Events.some((event) => event.payload.status === "running"));
49}