test(cli-rs): check throughput from the rendered turn footer

transcript::the_footer_measures_throughput_from_the_first_token now
drives the two-step turn for modern, mixed and legacy timestamp data.
Assert the displayed rate including reasoning tokens and the absence
of a separate first-token label. This replaces
measures_decode_throughput_from_the_first_streamed_token and its
private typed-message builders. The cross-page footer test still
checks turn duration from the user's prompt.
This commit is contained in:
Simon Klee
2026-11-18 20:56:49 +01:00
Unverified
parent 612ba4b950
commit 74c27ef1b3
2 changed files with 19 additions and 61 deletions
@@ -467,59 +467,6 @@ pub fn locale(value: f64) -> String {
mod tests {
use super::*;
use opencode_api::generated::{
SessionInboxUserTime, SessionMessageAssistantTime, SessionMessageID, SessionMessageUser, TokenUsageInfo,
};
fn input(created: f64) -> SessionMessageInfo {
SessionMessageInfo::User(SessionMessageUser {
r#type: "user".into(),
time: SessionInboxUserTime { created },
..Default::default()
})
}
fn step(id: &str, time: [Option<f64>; 4], output: f64, reasoning: f64) -> SessionMessageInfo {
SessionMessageInfo::Assistant(SessionMessageAssistant {
id: SessionMessageID(id.into()),
r#type: "assistant".into(),
time: SessionMessageAssistantTime {
created: time[0].unwrap(),
first_token: time[1],
streamed: time[2],
completed: time[3],
},
tokens: Some(TokenUsageInfo { output, reasoning, ..Default::default() }),
..Default::default()
})
}
// `session-turn.test.ts`: throughput counts from the first streamed token, and steps recorded
// without one count from request dispatch.
#[test]
fn measures_decode_throughput_from_the_first_streamed_token() {
let messages = [
input(1_000.0),
step("a1", [Some(6_000.0), Some(8_000.0), Some(10_000.0), Some(20_000.0)], 20.0, 5.0),
step("a2", [Some(24_000.0), Some(25_000.0), Some(28_000.0), Some(31_000.0)], 30.0, 10.0),
];
assert_eq!(tokens_per_second(&messages, Some(2), true), Some(13.0));
let messages = [
input(1_000.0),
step("a1", [Some(6_000.0), None, Some(10_000.0), Some(20_000.0)], 20.0, 5.0),
step("a2", [Some(24_000.0), Some(25_000.0), Some(28_000.0), Some(31_000.0)], 30.0, 10.0),
];
assert_eq!(tokens_per_second(&messages, Some(2), true), Some(65.0 / 7.0));
let messages = [
input(1_000.0),
step("a1", [Some(6_000.0), None, Some(10_000.0), Some(20_000.0)], 20.0, 5.0),
step("a2", [Some(24_000.0), None, Some(30_000.0), Some(31_000.0)], 30.0, 10.0),
];
assert_eq!(tokens_per_second(&messages, Some(2), true), Some(6.5));
}
#[test]
fn locale_groups_thousands() {
assert_eq!(locale(0.0), "0");
@@ -533,14 +533,25 @@ fn the_footer_spans_a_turn_whose_prompt_is_on_an_older_page() {
#[test]
fn the_footer_measures_throughput_from_the_first_token() {
let mut reply = assistant("msg_2", 2000, json!([{ "type": "text", "text": "Original answer" }]), Some(5000));
reply["time"] = json!({ "created": 2000, "firstToken": 2500, "streamed": 3000, "completed": 5000 });
reply["tokens"]["output"] = json!(20);
let messages = vec![user("msg_1", 1000, "Current input"), reply];
let h = open(80, 20, "ses_f", messages, Info { session: Some(medium()), ..Info::default() });
let screen = h.wait_for("tok/s");
assert!(screen.contains("4.0s · 40.0 tok/s"), "{screen}");
assert!(!screen.contains("ttft"), "{screen}");
for (first, second, streamed, rate) in
[(Some(8_000), Some(25_000), 28_000, "13.0"), (None, Some(25_000), 28_000, "9.3"), (None, None, 30_000, "6.5")]
{
let mut step = assistant("msg_2", 6_000, json!([{ "type": "text", "text": "First step" }]), Some(20_000));
step["finish"] = json!("tool-calls");
step["time"]["firstToken"] = json!(first);
step["time"]["streamed"] = json!(10_000);
step["tokens"]["output"] = json!(20);
step["tokens"]["reasoning"] = json!(5);
let mut reply = assistant("msg_3", 24_000, json!([{ "type": "text", "text": "Final answer" }]), Some(31_000));
reply["time"]["firstToken"] = json!(second);
reply["time"]["streamed"] = json!(streamed);
reply["tokens"]["output"] = json!(30);
reply["tokens"]["reasoning"] = json!(10);
let messages = vec![user("msg_1", 1_000, "Current input"), step, reply];
let h = open(80, 20, "ses_f", messages, Info { session: Some(medium()), ..Info::default() });
let screen = h.wait_for(&format!("{rate} tok/s"));
assert!(!screen.contains("ttft"), "{screen}");
}
}
#[test]