test(cli-rs): check successful ACP compaction on the wire

streams_a_compact_turns_summary_and_completes_it_with_the_full_summary
compares every update, including both streamed chunks, the session and
compaction IDs and the final summary. Its companion,
treats_a_null_compaction_capability_as_unsupported, compares the two
marker updates. Run both against the same event sequence and drop the
two weaker assertions on the fold. Keep early, empty, failed, cancelled
and child compactions in the translation table.
This commit is contained in:
Simon Klee
2026-11-18 12:11:12 +01:00
Unverified
parent 31fe0e9f90
commit 32dc2aad08
2 changed files with 26 additions and 77 deletions
@@ -5,13 +5,13 @@ use std::sync::Arc;
use serde_json::{Value, json};
use tokio::sync::Notify;
use crate::wire::{Wire, WireOptions, durable_event, enqueued, ephemeral_event, lock, start_session, turn};
use crate::wire::{Wire, WireOptions, durable_event, enqueued, ephemeral_event, start_session, turn};
const SUMMARY: &str = "Summary of the earlier conversation";
/// Holds the compact response so the test can publish the turn's events while the request is in
/// flight. Returns the wire, the compaction ID, and the prompt response.
async fn compact_turn(events: impl Fn(&str, &str) -> Vec<Value>, capabilities: Value) -> (Wire, String, Value) {
async fn compact_turn(capabilities: Value) -> (Wire, String, Value) {
let release = Arc::new(Notify::new());
let held = release.clone();
let acp = start_session(
@@ -45,50 +45,39 @@ async fn compact_turn(events: impl Fn(&str, &str) -> Vec<Value>, capabilities: V
.map(|request| request["body"]["id"].as_str().unwrap().to_owned())
})
.await;
acp.server.send(&turn(&acp.session_id, &id, events(&acp.session_id, &id)));
let session = &acp.session_id;
acp.server.send(&turn(
session,
&id,
vec![
durable_event(
"session.compaction.started",
json!({ "sessionID": session, "reason": "manual", "inputID": id }),
),
ephemeral_event("session.compaction.delta", json!({ "sessionID": session, "text": "Summary of " })),
ephemeral_event(
"session.compaction.delta",
json!({ "sessionID": session, "text": "the earlier conversation" }),
),
durable_event(
"session.compaction.ended",
json!({ "sessionID": session, "reason": "manual", "text": SUMMARY }),
),
],
));
release.notify_one();
let response = response.await.unwrap().unwrap();
(acp, id, response)
}
fn turn_updates(acp: &Wire) -> Vec<Value> {
lock(&acp.updates)
.iter()
.filter(|item| {
!matches!(item["update"]["sessionUpdate"].as_str(), Some("available_commands_update" | "usage_update"))
})
.cloned()
.collect()
}
#[tokio::test]
async fn streams_a_compact_turns_summary_and_completes_it_with_the_full_summary() {
let (acp, id, response) = compact_turn(
|session, id| {
vec![
durable_event(
"session.compaction.started",
json!({ "sessionID": session, "reason": "manual", "inputID": id }),
),
ephemeral_event("session.compaction.delta", json!({ "sessionID": session, "text": "Summary of " })),
ephemeral_event(
"session.compaction.delta",
json!({ "sessionID": session, "text": "the earlier conversation" }),
),
durable_event(
"session.compaction.ended",
json!({ "sessionID": session, "reason": "manual", "text": SUMMARY }),
),
]
},
json!({ "session": { "compaction": {} } }),
)
.await;
let (acp, id, response) = compact_turn(json!({ "session": { "compaction": {} } })).await;
let session = acp.session_id.clone();
let chunk = |text: &str| json!({ "sessionId": session, "update": { "sessionUpdate": "compaction_summary_chunk", "compactionId": id, "content": { "type": "text", "text": text } } });
assert_eq!(
turn_updates(&acp),
acp.turn_updates(),
vec![
json!({ "sessionId": session, "update": { "sessionUpdate": "compaction_update", "compactionId": id, "status": "in_progress" } }),
chunk("Summary of "),
@@ -104,23 +93,7 @@ async fn streams_a_compact_turns_summary_and_completes_it_with_the_full_summary(
#[tokio::test]
async fn treats_a_null_compaction_capability_as_unsupported() {
let (acp, id, _) = compact_turn(
|session, id| {
vec![
durable_event(
"session.compaction.started",
json!({ "sessionID": session, "reason": "manual", "inputID": id }),
),
ephemeral_event("session.compaction.delta", json!({ "sessionID": session, "text": SUMMARY })),
durable_event(
"session.compaction.ended",
json!({ "sessionID": session, "reason": "manual", "text": SUMMARY }),
),
]
},
json!({ "session": { "compaction": null } }),
)
.await;
let (acp, id, _) = compact_turn(json!({ "session": { "compaction": null } })).await;
let marker = |status: &str| {
json!({ "sessionId": acp.session_id, "update": {
@@ -128,5 +101,5 @@ async fn treats_a_null_compaction_capability_as_unsupported() {
"_meta": { "opencode/compaction": { "status": status, "messageId": id, "reason": "manual" } },
} })
};
assert_eq!(turn_updates(&acp), vec![marker("started"), marker("completed")]);
assert_eq!(acp.turn_updates(), vec![marker("started"), marker("completed")]);
}
@@ -559,23 +559,6 @@ fn tool_location_and_compaction_rows() {
live(vec![compaction_started(ROOT)]),
json!({ "abandoned": [{ "sessionUpdate": "compaction_update", "compactionId": "msg_compact", "status": "cancelled" }] }),
),
(
"streams a compaction's summary and completes it with the full summary",
true,
false,
live(vec![
compaction_started(ROOT),
compaction_delta("Sum", ROOT),
compaction_delta("mary", ROOT),
compaction_ended("Summary", ROOT),
]),
json!({ "updates": [
{ "sessionUpdate": "compaction_update", "compactionId": "msg_compact", "status": "in_progress" },
{ "sessionUpdate": "compaction_summary_chunk", "compactionId": "msg_compact", "content": { "text": "Sum" } },
{ "sessionUpdate": "compaction_summary_chunk", "compactionId": "msg_compact", "content": { "text": "mary" } },
{ "status": "completed", "summary": [{ "type": "text", "text": "Summary" }] },
] }),
),
(
"clears the summary of a compaction that completes without a readable one",
true,
@@ -673,13 +656,6 @@ fn tool_location_and_compaction_rows() {
live(vec![compaction_ended("Summary", ROOT)]),
json!({ "updates": [] }),
),
(
"marks a compaction without forwarding its summary when the client lacks the capability",
false,
false,
live(vec![compaction_started(ROOT), compaction_delta("Summary", ROOT), compaction_ended("Summary", ROOT)]),
json!({ "updates": [marker(json!({ "status": "started" })), marker(json!({ "status": "completed" }))] }),
),
(
"marks a failed compaction with the full error",
false,