Files
optimclaw/tests/e2e_trace_file_tools.rs
T
cf96a3253c fix(tests): replace hardcoded /tmp paths with tempdir + add 300 unit tests (#659)
* test: add unit tests across 20 modules for coverage push

Add 300+ unit tests covering config, context, evaluation, extensions,
LLM, secrets, tools/builder, and tools/mcp modules. All tests are
pure unit tests (no mocks) exercising serde roundtrips, edge cases,
error paths, and business logic.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(tests): replace hardcoded /tmp paths with tempfile::tempdir

The e2e_metrics_test::test_metrics_collected_from_tool_trace test was
failing because setup_test_dir() created /tmp/ironclaw_metrics_test but
the fixture referenced /tmp/ironclaw_e2e_test/hello.txt (path mismatch).

Added LlmTrace::replace_paths() to substitute fixture paths at runtime,
then converted all 12 test files from hardcoded /tmp/ironclaw_* paths to
tempfile::tempdir(). Tests are now isolated, parallel-safe, and leave no
debris on disk.

Regression test: test_metrics_collected_from_tool_trace now passes
consistently regardless of prior /tmp state.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
2026-03-07 08:24:24 +00:00

46 lines
1.5 KiB
Rust

//! E2E trace test: validates that the agent can execute `write_file` and
//! `read_file` tool calls driven by a TraceLlm trace.
#[cfg(feature = "libsql")]
mod support;
#[cfg(feature = "libsql")]
mod tests {
use std::time::Duration;
use crate::support::test_rig::TestRigBuilder;
use crate::support::trace_llm::LlmTrace;
const EXPECTED_CONTENT: &str = "Hello, E2E test!";
#[tokio::test]
async fn test_file_write_and_read_flow() {
let tmp = tempfile::tempdir().expect("create temp dir");
let fixture_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/fixtures/llm_traces/file_write_read.json"
);
let mut trace = LlmTrace::from_file(fixture_path).expect("failed to load trace fixture");
trace.replace_paths("/tmp/ironclaw_e2e_test", tmp.path().to_str().unwrap());
let rig = TestRigBuilder::new()
.with_trace(trace.clone())
.build()
.await;
rig.send_message("Please write a greeting to a file and read it back.")
.await;
let responses = rig.wait_for_responses(1, Duration::from_secs(15)).await;
rig.verify_trace_expects(&trace, &responses);
// Extra: verify file on disk (can't express in expects).
let file_content = std::fs::read_to_string(tmp.path().join("hello.txt"))
.expect("hello.txt should exist after write_file");
assert_eq!(file_content, EXPECTED_CONTENT);
rig.shutdown();
}
}