The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { assert } from "@effect/vitest"; |
| 2 | import type { ProviderReplayTranscript } from "@t3tools/contracts"; |
| 3 | |
| 4 | import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts"; |
| 5 | import { |
| 6 | assertBaseProjection, |
| 7 | assertSemanticProjectionIntegrity, |
| 8 | field, |
| 9 | projectionFor, |
| 10 | } from "../shared.ts"; |
| 11 | import { KIRO_COMPACTION_MARKER } from "./input.ts"; |
| 12 | |
| 13 | function promptText(frame: unknown): string { |
| 14 | const prompt = field(field(frame, "params"), "prompt"); |
| 15 | return Array.isArray(prompt) ? prompt.map((block) => String(field(block, "text"))).join("") : ""; |
| 16 | } |
| 17 | |
| 18 | export function assertKiroCompactionOutput( |
| 19 | result: OrchestratorV2ScenarioResult, |
| 20 | transcript: ProviderReplayTranscript, |
| 21 | ) { |
| 22 | const outbound = transcript.entries.flatMap((entry) => |
| 23 | entry.type === "expect_outbound" ? [entry.frame] : [], |
| 24 | ); |
| 25 | const prompts = outbound.filter((frame) => field(frame, "method") === "session/prompt"); |
| 26 | assert.lengthOf(prompts, 2, "/compact must not be sent as a prompt"); |
| 27 | assert.lengthOf( |
| 28 | outbound.filter((frame) => field(frame, "method") === "_kiro/session/compact"), |
| 29 | 1, |
| 30 | ); |
| 31 | // Compaction drops T3's instructions from Kiro's context, so the next prompt carries them again. |
| 32 | assert.deepEqual( |
| 33 | prompts.map((frame) => promptText(frame).startsWith("<t3_code_instructions>")), |
| 34 | [true, true], |
| 35 | ); |
| 36 | |
| 37 | assertBaseProjection({ |
| 38 | result, |
| 39 | transcript, |
| 40 | runCount: 3, |
| 41 | runStatuses: ["completed", "completed", "completed"], |
| 42 | }); |
| 43 | const projection = projectionFor(result, transcript.scenario); |
| 44 | assertSemanticProjectionIntegrity(projection); |
| 45 | assert.deepEqual( |
| 46 | projection.turnItems |
| 47 | .filter((item) => item.type === "compaction") |
| 48 | .map((item) => [item.runId, item.status, item.title]), |
| 49 | [[projection.runs[1]?.id ?? null, "completed", "Context compacted"]], |
| 50 | ); |
| 51 | const recall = projection.turnItems |
| 52 | .filter((item) => item.type === "assistant_message" && item.runId === projection.runs[2]?.id) |
| 53 | .map((item) => (item.type === "assistant_message" ? item.text : "")) |
| 54 | .join(""); |
| 55 | assert.include(recall, KIRO_COMPACTION_MARKER); |
| 56 | } |