test(snapshot): help, eval json, rpc sequence, trace pinned with insta
de91dcc15aca678bca0017aa8a792370dd092431
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: f97b510237a7
There are many coding harnesses - but this one is fast
de91dcc15aca678bca0017aa8a792370dd092431
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+272 / −31 text lines
+37 / −0 text lines
+1 / −0 text lines
+2 / −9 text lines
new file mode 100644+32 / −0 text lines
//! Help text of the built `smith` binary, pinned as snapshots//! (`SMH-SPEC-SPEC0001`, Interface modes).//!//! Selection variables are removed: clap prints their current values in//! `[env: …]`, which would leak the caller's environment into the snapshot.use assert_cmd::Command;fn help(args: &[&str]) -> String { let output = Command::cargo_bin("smith") .unwrap() .args(args) .env_remove("SMITH_PROVIDER") .env_remove("SMITH_MODEL") .env_remove("SMITH_BASE_URL") .env_remove("CLICOLOR_FORCE") .output() .unwrap(); assert!(output.status.success(), "{output:?}"); assert!(output.stderr.is_empty(), "{output:?}"); String::from_utf8(output.stdout).unwrap()}#[test]fn help_top_level() { insta::assert_snapshot!(help(&["--help"]));}#[test]fn help_eval() { insta::assert_snapshot!(help(&["eval", "--help"]));}+23 / −22 text lines
let line = line.unwrap(); let value = serde_json::from_str(&line) .unwrap_or_else(|error| panic!("stdout line is not JSON ({error}): {line}")); if sender.send(Some(value)).is_err() { if sender.send(Some(line.unwrap())).is_err() { transcript: Vec::new(), self.transcript.push(format!("> {line}")); Ok(Some(value)) => value, Ok(Some(value)) => panic!("unexpected rpc line after close: {value}"), Ok(Some(line)) => panic!("unexpected rpc line after close: {line}"), let end = rpc.next(); assert_eq!(end["id"], 1); assert_eq!(end["event"], "end"); assert_eq!(end["error"]["code"], "TURN_FAILED"); assert_eq!(end["error"]["message"], "operation cancelled"); assert!(end.get("text").is_none(), "{end}"); rpc.next(); assert_eq!(rpc.next(), json!({"id": 4, "settled": true}));new file mode 100644+5 / −0 text lines
new file mode 100644+41 / −0 text lines
---source: smith-cli/tests/e2e_help.rsexpression: "help(&[\"eval\", \"--help\"])"---Run one prompt without the TUIUsage: smith eval [OPTIONS] <PROMPT>Arguments: <PROMPT> The prompt to runOptions: --json Print the structured outcome as JSON --mock Use the scripted mock provider instead of a real endpoint --provider <PROVIDER> Provider kind; required for real endpoints Possible values: - openai: OpenAI-compatible endpoints - anthropic: Anthropic Messages API - google: Google Gemini API [env: SMITH_PROVIDER=] --model <MODEL> Model id; required for real endpoints [env: SMITH_MODEL=] --base-url <BASE_URL> Endpoint base URL override [env: SMITH_BASE_URL=] -h, --help Print help (see a summary with '-h')new file mode 100644+17 / −0 text lines
---source: smith-cli/tests/e2e_help.rsexpression: "help(&[\"--help\"])"---Smith, a fast coding-agent runtimeUsage: smith <COMMAND>Commands: auth Manage stored provider credentials eval Run one prompt without the TUI rpc Serve LF-delimited JSON-RPC on standard input and output help Print this message or the help of the given subcommand(s)Options: -h, --help Print help -V, --version Print versionnew file mode 100644+13 / −0 text lines
---source: smith-cli/tests/e2e_rpc.rsexpression: "rpc.transcript.join(\"\\n\")"---> {"id": 1, "method": "prompt", "params": {"input": "block"}}< {"id":1,"event":"start"}> {"id": 2, "method": "abort"}< {"id":2,"aborting":true}< {"id":1,"event":"end","error":{"code":"TURN_FAILED","message":"operation cancelled"}}> {"id": 3, "method": "wait"}< {"id":3,"settled":true}> {"id": 4, "method": "status"}< {"id":4,"settled":true}+1 / −0 text lines
new file mode 100644+13 / −0 text lines
---source: smith-core/tests/trace_snapshot.rsexpression: redacted_trace(&session)---{"timestamp_ms":0,"session_id":"<session>","kind":"SessionCreated","event_ref":"branch:<branch>"}{"timestamp_ms":"<timestamp>","session_id":"<session>","kind":"MessageStreamed","event_ref":"message:<message-0>"}{"timestamp_ms":"<timestamp>","session_id":"<session>","kind":"ToolCallEmitted","event_ref":"call:00000000-0000-0000-0000-000000000001"}{"timestamp_ms":"<timestamp>","session_id":"<session>","kind":"ToolResultReceived","event_ref":"result:00000000-0000-0000-0000-000000000001:ok"}{"timestamp_ms":"<timestamp>","session_id":"<session>","kind":"ToolCallEmitted","event_ref":"call:00000000-0000-0000-0000-000000000002"}{"timestamp_ms":"<timestamp>","session_id":"<session>","kind":"ToolResultReceived","event_ref":"result:00000000-0000-0000-0000-000000000002:failed"}{"timestamp_ms":"<timestamp>","session_id":"<session>","kind":"MessageStreamed","event_ref":"message:<message-5>"}{"timestamp_ms":"<timestamp>","session_id":"<session>","kind":"Compaction","event_ref":"meta:compaction:<entry-6>"}{"timestamp_ms":"<timestamp>","session_id":"<session>","kind":"EntryAdded","event_ref":"meta:<entry-7>"}new file mode 100644+87 / −0 text lines
//! The trace of a small session, pinned as a snapshot (`SMH-SPEC-SPEC0001`,//! Sessions).//!//! Session, branch, entry, and message ids and entry timestamps differ every//! run; they are redacted to placeholders before snapshotting. Call ids are//! chosen by the test and stay literal.use serde_json::Value;use smith::id::ToolCallId;use smith::message::{Message, Role};use smith_core::session::{COMPACTION_KIND, EntryContent, EntryKind, Session};use smith_core::trace::build_trace;/// One JSON line per record, with every run-specific value replaced.fn redacted_trace(session: &Session) -> String { let branch = session.active_branch(); let mut placeholders = vec![ (session.id().to_string(), "<session>".to_string()), (branch.id().to_string(), "<branch>".to_string()), ]; for (index, entry) in branch.entries().iter().enumerate() { placeholders.push((entry.id.to_string(), format!("<entry-{index}>"))); if let EntryKind::Message { id, .. } = entry.kind { placeholders.push((id.to_string(), format!("<message-{index}>"))); } } let redact = |text: &str| { placeholders .iter() .fold(text.to_string(), |text, (id, placeholder)| { text.replace(id, placeholder) }) }; build_trace(session) .iter() .map(|record| { let mut line = serde_json::to_value(record).unwrap(); if line["timestamp_ms"] != 0 { line["timestamp_ms"] = Value::from("<timestamp>"); } redact(&line.to_string()) }) .collect::<Vec<_>>() .join("\n")}#[test]fn trace_of_message_tool_round_trip_and_compaction() { let call = ToolCallId::from_u128(1); let failed_call = ToolCallId::from_u128(2); let mut session = Session::new(); for content in [ EntryContent::Message(Message::with_text(Role::User, "list files")), EntryContent::ToolCall { name: "ls".to_string(), input: serde_json::json!({"path": "."}), call_id: call, }, EntryContent::ToolResult { ok: true, output: "a.txt".to_string(), call_id: call, }, EntryContent::ToolCall { name: "read".to_string(), input: serde_json::json!({"path": "missing.txt"}), call_id: failed_call, }, EntryContent::ToolResult { ok: false, output: "not found".to_string(), call_id: failed_call, }, EntryContent::Message(Message::with_text(Role::Assistant, "a.txt")), EntryContent::Meta { kind: COMPACTION_KIND.to_string(), detail: serde_json::json!({}), }, EntryContent::Meta { kind: "branch".to_string(), detail: serde_json::json!({}), }, ] { session.append(&content).unwrap(); } insta::assert_snapshot!(redacted_trace(&session));}