Skip to content
Source
Sign inSign up
Open History to see the last commit

output.ts

55 lines2.0 KB

1import { assert } from "@effect/vitest";
2import type { ProviderReplayTranscript } from "@t3tools/contracts";
3​
4import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts";
5import {
6 assertAssistantTextIncludes,
7 assertBaseProjection,
8 assertSemanticProjectionIntegrity,
9 assertUserMessagesInclude,
10 assertVisibleTurnItemsMirrorLocalTurnItems,
11 OPENCODE2_COMPACTION_FIRST_PROMPT,
12 OPENCODE2_COMPACTION_RECALL_PROMPT,
13 projectionFor,
14} from "../shared.ts";
15​
16/** session.compact queues a compaction execution that ends /compact; the next turn uses its summary. */
17export function assertOpenCode2CompactionOutput(
18 result: OrchestratorV2ScenarioResult,
19 transcript: ProviderReplayTranscript,
20) {
21 assertBaseProjection({
22 result,
23 transcript,
24 runCount: 3,
25 runStatuses: ["completed", "completed", "completed"],
26 });
27 const projection = projectionFor(result, transcript.scenario);
28 assertSemanticProjectionIntegrity(projection);
29 assertVisibleTurnItemsMirrorLocalTurnItems(projection);
30 assertUserMessagesInclude(projection, [
31 OPENCODE2_COMPACTION_FIRST_PROMPT,
32 "/compact",
33 OPENCODE2_COMPACTION_RECALL_PROMPT,
34 ]);
35​
36 const compactRun = projection.runs[1];
37 const compactions = projection.turnItems.filter((item) => item.type === "compaction");
38 assert.lengthOf(compactions, 1);
39 const [compaction] = compactions;
40 assert.equal(compaction?.runId, compactRun?.id);
41 assert.equal(compaction?.status, "completed");
42 assert.equal(compaction?.title, "Context compacted");
43 assert.include(compaction?.type === "compaction" ? compaction.summary : "", "PAPAYA");
44 assert.include(compaction?.type === "compaction" ? compaction.summary : "", "## Objective");
45 assert.isUndefined(
46 projection.turnItems.find(
47 (item) => item.type === "assistant_message" && item.runId === compactRun?.id,
48 ),
49 );
50 assertAssistantTextIncludes(projection, "PAPAYA");
51 assert.deepEqual(
52 projection.providerTurns.map((turn) => turn.status),
53 ["completed", "completed", "completed"],
54 );