From c86ed345a450d56311c4a7e4889a0acf3c83ba10 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 3 Jul 2026 03:01:26 -0700 Subject: [PATCH] Add claude_text_segments regression fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Locks in per-uuid assistant text segmentation (audit plan #11): the 6d618dc4 MCP session on build fc23be8184 merged 5 interleaved assistant text segments into one separator-less end-of-turn item ordered after all tool calls. The current emitAssistantTextArtifacts path already projects one item per SDK message uuid; this fixture asserts text → command → text ordering survives replay. Co-Authored-By: Claude Fable 5 --- .../claude_transcript.ndjson | 10 +++++ .../fixtures/claude_text_segments/input.ts | 17 ++++++++ .../fixtures/claude_text_segments/output.ts | 40 +++++++++++++++++++ .../testkit/fixtures/index.ts | 10 +++++ 4 files changed, 77 insertions(+) create mode 100644 apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/claude_transcript.ndjson create mode 100644 apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/input.ts create mode 100644 apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/output.ts diff --git a/apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/claude_transcript.ndjson b/apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/claude_transcript.ndjson new file mode 100644 index 0000000000..bd02994f55 --- /dev/null +++ b/apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/claude_transcript.ndjson @@ -0,0 +1,10 @@ +{"type":"transcript_start","provider":"claudeAgent","protocol":"claude-agent-sdk.query","version":"0.2.111","scenario":"claude_text_segments","metadata":{"prompts":["List the workspace files, narrating before and after."],"model":"claude-sonnet-4-6","nativeSessionId":"5e97e975-1041-4e40-8e40-000000000002","queryMode":"streaming","tools":"claude_code","permissionMode":"bypassPermissions","generatedBy":"manual-replay-from-thread-mcp-6d618dc4 (5 interleaved assistant text segments were merged into one end-of-turn item, 2026-06-29T22:13:07Z)"}} +{"type":"expect_outbound","label":"query.open","frame":{"type":"query.open","options":{"model":"claude-sonnet-4-6","tools":{"type":"preset","preset":"claude_code"},"permissionMode":"bypassPermissions","allowDangerouslySkipPermissions":true,"sessionId":"5e97e975-1041-4e40-8e40-000000000002"}}} +{"type":"expect_outbound","label":"prompt.offer:1","frame":{"type":"prompt.offer","message":{"type":"user","message":{"role":"user","content":"List the workspace files, narrating before and after."},"parent_tool_use_id":null}}} +{"type":"emit_inbound","label":"system:init:1","frame":{"type":"system","subtype":"init","agents":[],"apiKeySource":"none","claude_code_version":"2.1.183","cwd":"/tmp/claude-replay-claude_text_segments","tools":[],"mcp_servers":[],"model":"claude-sonnet-4-6","permissionMode":"bypassPermissions","slash_commands":[],"output_style":"default","skills":[],"plugins":[],"fast_mode_state":"off","uuid":"5e975e97-0000-4000-8000-000000000001","session_id":"5e97e975-1041-4e40-8e40-000000000002"}} +{"type":"emit_inbound","label":"assistant:segment_one","frame":{"type":"assistant","message":{"model":"claude-sonnet-4-6","id":"msg_01segmentfixture1","type":"message","role":"assistant","content":[{"type":"text","text":"Listing the workspace now."}],"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":1,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"},"context_management":null},"parent_tool_use_id":null,"session_id":"5e97e975-1041-4e40-8e40-000000000002","uuid":"5e975e97-0000-4000-8000-000000000002"}} +{"type":"emit_inbound","label":"assistant:ls_bash","frame":{"type":"assistant","message":{"model":"claude-sonnet-4-6","id":"msg_01segmentfixture2","type":"message","role":"assistant","content":[{"type":"tool_use","id":"toolu_01segmentfixturels1","name":"Bash","input":{"command":"ls","description":"List workspace files"},"caller":{"type":"direct"}}],"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":1,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"},"context_management":null},"parent_tool_use_id":null,"session_id":"5e97e975-1041-4e40-8e40-000000000002","uuid":"5e975e97-0000-4000-8000-000000000003"}} +{"type":"emit_inbound","label":"user:ls_result","frame":{"type":"user","message":{"role":"user","content":[{"tool_use_id":"toolu_01segmentfixturels1","type":"tool_result","content":"package.json\ntsconfig.json","is_error":false}]},"parent_tool_use_id":null,"session_id":"5e97e975-1041-4e40-8e40-000000000002","uuid":"5e975e97-0000-4000-8000-000000000004","tool_use_result":{"stdout":"package.json\ntsconfig.json","stderr":"","interrupted":false,"isImage":false,"noOutputExpected":false}}} +{"type":"emit_inbound","label":"assistant:segment_two","frame":{"type":"assistant","message":{"model":"claude-sonnet-4-6","id":"msg_01segmentfixture3","type":"message","role":"assistant","content":[{"type":"text","text":"Two files found: package.json and tsconfig.json."}],"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":1,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"},"context_management":null},"parent_tool_use_id":null,"session_id":"5e97e975-1041-4e40-8e40-000000000002","uuid":"5e975e97-0000-4000-8000-000000000005"}} +{"type":"emit_inbound","label":"result:1","frame":{"type":"result","subtype":"success","is_error":false,"api_error_status":null,"duration_ms":4000,"duration_api_ms":3500,"num_turns":2,"result":"Two files found: package.json and tsconfig.json.","stop_reason":"end_turn","session_id":"5e97e975-1041-4e40-8e40-000000000002","total_cost_usd":0.001,"usage":{"input_tokens":2,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":2,"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"inference_geo":"","iterations":[],"speed":"standard"},"modelUsage":{"claude-sonnet-4-6":{"inputTokens":2,"outputTokens":2,"cacheReadInputTokens":0,"cacheCreationInputTokens":0,"webSearchRequests":0,"costUSD":0.001,"contextWindow":200000,"maxOutputTokens":32000}},"permission_denials":[],"terminal_reason":"completed","fast_mode_state":"off","uuid":"5e975e97-0000-4000-8000-000000000006"}} +{"type":"runtime_exit","status":"success"} diff --git a/apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/input.ts b/apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/input.ts new file mode 100644 index 0000000000..0e322dec8f --- /dev/null +++ b/apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/input.ts @@ -0,0 +1,17 @@ +import type { OrchestratorFixtureInput } from "../shared.ts"; + +export const CLAUDE_TEXT_SEGMENTS_PROMPT = "List the workspace files, narrating before and after."; + +/** + * Regression for merged assistant text (audit plan #11, thread + * thread:mcp:6d618dc4 on build fc23be8184): interleaved assistant text + * segments were accumulated and emitted as ONE item at result time — text + * joined with no separator and ordered after all tool calls, losing the + * narrate → tool → narrate structure. Each SDK assistant message uuid must + * project its own assistant_message item at its position in the stream. + */ +export function claudeTextSegmentsInput(): OrchestratorFixtureInput { + return { + steps: [{ type: "message", text: CLAUDE_TEXT_SEGMENTS_PROMPT }], + }; +} diff --git a/apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/output.ts b/apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/output.ts new file mode 100644 index 0000000000..04126ecbad --- /dev/null +++ b/apps/server/src/orchestration-v2/testkit/fixtures/claude_text_segments/output.ts @@ -0,0 +1,40 @@ +import { assert } from "@effect/vitest"; +import type { ProviderReplayTranscript } from "@t3tools/contracts"; + +import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts"; +import { + assertBaseProjection, + assertSemanticProjectionIntegrity, + assertUserMessagesInclude, + projectionFor, +} from "../shared.ts"; +import { CLAUDE_TEXT_SEGMENTS_PROMPT } from "./input.ts"; + +export function assertClaudeTextSegmentsOutput( + result: OrchestratorV2ScenarioResult, + transcript: ProviderReplayTranscript, +) { + assertBaseProjection({ + result, + transcript, + runCount: 1, + runStatuses: ["completed"], + }); + + const projection = projectionFor(result, transcript.scenario); + assertSemanticProjectionIntegrity(projection); + assertUserMessagesInclude(projection, [CLAUDE_TEXT_SEGMENTS_PROMPT]); + + // The stream interleaved text → tool → text. Each assistant message uuid + // must be its own item, ordered around the command — never one merged + // blob after all tools. + const ordered = [...projection.turnItems] + .sort((a, b) => a.ordinal - b.ordinal) + .filter((item) => item.type === "assistant_message" || item.type === "command_execution") + .map((item) => (item.type === "assistant_message" ? `text:${item.text}` : "command")); + assert.deepEqual(ordered, [ + "text:Listing the workspace now.", + "command", + "text:Two files found: package.json and tsconfig.json.", + ]); +} diff --git a/apps/server/src/orchestration-v2/testkit/fixtures/index.ts b/apps/server/src/orchestration-v2/testkit/fixtures/index.ts index 510b85c4c4..7a533d93b2 100644 --- a/apps/server/src/orchestration-v2/testkit/fixtures/index.ts +++ b/apps/server/src/orchestration-v2/testkit/fixtures/index.ts @@ -6,6 +6,8 @@ import { claudeLocalBashTaskInput } from "./claude_local_bash_task/input.ts"; import { assertClaudeLocalBashTaskOutput } from "./claude_local_bash_task/output.ts"; import { claudeResultIsErrorInput } from "./claude_result_is_error/input.ts"; import { assertClaudeResultIsErrorOutput } from "./claude_result_is_error/output.ts"; +import { claudeTextSegmentsInput } from "./claude_text_segments/input.ts"; +import { assertClaudeTextSegmentsOutput } from "./claude_text_segments/output.ts"; import { grokSubagentLineageInput } from "./grok_subagent_lineage/input.ts"; import { assertGrokSubagentLineageOutput } from "./grok_subagent_lineage/output.ts"; import { assertClaudeMessageSteeringOutput } from "./message_steering/claude_output.ts"; @@ -123,6 +125,14 @@ export const ORCHESTRATOR_REPLAY_FIXTURES = [ ), modelSelection: CLAUDE_MODEL_SELECTION, assertOutput: assertClaudeResultIsErrorOutput, + name: "claude_text_segments", + buildInput: claudeTextSegmentsInput, + providers: [ + { + driver: ProviderDriverKind.make("claudeAgent"), + transcriptFile: new URL("./claude_text_segments/claude_transcript.ndjson", import.meta.url), + modelSelection: CLAUDE_MODEL_SELECTION, + assertOutput: assertClaudeTextSegmentsOutput, }, ], },