test(cli-rs): assert ACP stream and error translation on the wire

streams_an_admitted_turn_and_resolves_with_usage_after_its_terminal_event
already drives the same tool, reasoning and terminal events. Check the
remaining thought texts and pending tool metadata in its transcript.
maps_failures_to_acp_errors checks the client-visible RPC error for
step authentication, execution authentication and rate limiting. Drop
the duplicate translation rows, keeping retry and cancellation cases.
This commit is contained in:
Simon Klee
2026-11-18 21:09:51 +01:00
Unverified
parent 4e4c5a0104
commit a36ca0aaf6
2 changed files with 6 additions and 65 deletions
@@ -151,6 +151,10 @@ async fn streams_an_admitted_turn_and_resolves_with_usage_after_its_terminal_eve
json!(["tool_call_update", "call_fail", "failed"]),
]
);
for (index, expected) in [(0, "think-1"), (1, " continued"), (3, "think-2")] {
assert_eq!(updates[index]["update"]["content"]["text"], expected);
}
assert_matches(&updates[4]["update"], &json!({"name": "shell", "kind": "execute"}));
assert_eq!(
updates[2]["update"],
json!({ "sessionUpdate": "agent_message_chunk", "messageId": "msg_assistant", "content": { "type": "text", "text": "hello" } })
@@ -1,10 +1,9 @@
use opencode_acp::paths::resolve_from;
use opencode_acp::translate::{self, Output, StartKind, Terminal, TurnContext, TurnStart, TurnState};
use serde_json::{Value, json};
use crate::wire::{
assert_matches, background_shell, child_created, delivered, durable_event, failed, reasoning_delta, shell_notice,
step_ended, succeeded, text_delta, tool_called, tool_failed, tool_progress, tool_started, tool_succeeded, usage,
assert_matches, background_shell, child_created, delivered, durable_event, failed, shell_notice, step_ended,
succeeded, text_delta, tool_called, tool_failed, tool_progress, tool_started, tool_succeeded, usage,
};
const ROOT: &str = "ses_root";
@@ -120,26 +119,6 @@ fn turn_translation() {
]),
json!({ "updates": [{ "sessionUpdate": "agent_message_chunk", "messageId": "msg_ok" }] }),
),
(
"streams text and reasoning with one message ID per reasoning ordinal",
false,
live(vec![
reasoning_delta(ROOT, "msg_a", "think", 0),
text_delta(ROOT, "msg_a", "answer", 1),
reasoning_delta(ROOT, "msg_a", "more", 1),
]),
json!({ "updates": [
{ "sessionUpdate": "agent_thought_chunk", "messageId": "msg_a:reasoning:0", "content": { "text": "think" } },
{ "sessionUpdate": "agent_message_chunk", "messageId": "msg_a", "content": { "text": "answer" } },
{ "sessionUpdate": "agent_thought_chunk", "messageId": "msg_a:reasoning:1", "content": { "text": "more" } },
] }),
),
(
"ends a normal turn with end_turn",
false,
live(vec![step_ended(ROOT, "msg_1", "stop", usage(1, 1, 0, 0, 0)), succeeded(ROOT)]),
json!({ "response": { "stopReason": "end_turn", "usage": { "inputTokens": 1, "outputTokens": 1, "totalTokens": 2 } } }),
),
(
"ends a length-limited step with max_tokens",
false,
@@ -173,24 +152,6 @@ fn turn_translation() {
live(vec![failed(ROOT, json!({ "type": "aborted", "message": "interrupted" }))]),
json!({ "response": { "stopReason": "cancelled" }, "failure": null }),
),
(
"fails an execution auth failure as auth required",
false,
live(vec![failed(ROOT, json!({ "type": "provider.auth", "message": "missing key" }))]),
json!({ "failure": "ACPAuthRequiredError" }),
),
(
"fails a step auth failure as auth required even when the execution succeeds",
false,
live(vec![step_failed(json!({ "type": "provider.auth", "message": "expired" }), None), succeeded(ROOT)]),
json!({ "terminal": "succeeded", "failure": "ACPAuthRequiredError" }),
),
(
"fails other execution failures as service failures",
false,
live(vec![failed(ROOT, json!({ "type": "provider.rate-limit", "message": "slow down" }))]),
json!({ "failure": "ACPServiceFailureError" }),
),
(
"sums usage across steps and reports thought and cache tokens",
false,
@@ -246,30 +207,6 @@ fn turn_translation() {
"context": usage(20, 7, 0, 0, 0),
}),
),
(
"streams a tool call from pending through progress to completion",
false,
live(vec![
tool_started(ROOT, "call_ok", "shell"),
tool_called(ROOT, "call_ok", json!({ "command": "printf done", "workdir": "sub" })),
tool_progress(ROOT, "call_ok", json!({ "phase": 1 })),
tool_succeeded(ROOT, "call_ok", json!({ "exit": 0 }), "done"),
]),
json!({ "updates": [
{ "sessionUpdate": "tool_call", "toolCallId": "call_ok", "name": "shell", "status": "pending", "kind": "execute" },
{
"sessionUpdate": "tool_call_update", "status": "in_progress", "title": "printf done",
"locations": [{ "path": resolve_from("/workspace", "sub") }],
"rawInput": { "command": "printf done", "workdir": "sub" },
},
{ "sessionUpdate": "tool_call_update", "status": "in_progress" },
{
"sessionUpdate": "tool_call_update", "status": "completed",
"content": [{ "type": "content", "content": { "type": "text", "text": "done" } }],
"rawOutput": { "metadata": { "exit": 0 } },
},
] }),
),
(
"fails a tool call with its partial content and error",
false,