use super::*;
use serde_json::json;
fn view() -> RunView {
serde_json::from_value(json!({
"id":"run-legacy",
"repoPath":"repo",
"stateDir":"state",
"status":"RUNNING",
"createdAt":"2026-01-01T00:00:00Z",
"completedAt":null,
"selection":{"kind":"all"},
"validation":null,
"error":null,
"requests":[
{
"id":"run-legacy-1",
"runId":"run-legacy",
"evalId":"app/check",
"target":"app",
"title":"Check",
"profile":{"kind":"runtime","command":"fixture","args":[]},
"requestedProfile":{
"kind":"runtime",
"command":"fixture",
"args":[],
"timeoutMs":null,
},
"evalDefHash":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
"executionId":"execution-source-1",
"provenance":{
"repoPath":"source",
"runId":"run-source",
"requestId":"run-source-1",
"evalId":"app/check",
"evalDefHash":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
"completedAt":"2026-01-01T00:00:01Z",
},
"usage":null,
"reusedUsage":[
{
"turn":1,
"attempt":1,
"usage":{"inputTokens":17,"vendorDetail":{"cache":true}},
},
],
"payload":{},
"references":{},
"deps":[],
"status":"GREEN",
"createdAt":"2026-01-01T00:00:00Z",
"startedAt":null,
"completedAt":"2026-01-01T00:00:01Z",
"cwd":"repo",
"runDir":null,
"argv":null,
"child":null,
"result":{"verdict":"GREEN"},
"error":null,
"errorCode":null,
"blockedReason":null,
},
],
}))
.unwrap()
}
#[test]
fn supplied_time_is_deterministic_and_profile_omission_is_not_null() {
let now = "2026-01-01T00:00:05Z"
.parse::<crate::types::Timestamp>()
.unwrap()
.time();
let view = view();
let output = serde_json::to_value(run_output(&view, now)).unwrap();
assert_eq!(output["summary"]["wallMs"], 5000);
assert_eq!(output["summary"]["reused"]["otherProfile"], 1);
assert_eq!(output["summary"]["reused"]["runtime"], 1);
assert_eq!(output["summary"]["attempts"], 0);
assert_eq!(output["usage"]["saved"], json!({"inputTokens":17}));
assert_eq!(
serde_json::to_value(run_output(&view, now)).unwrap(),
output
);
assert_eq!(
wall_time("2026-01-01T00:00:06Z".parse().unwrap(), None, now),
Some(Duration::ZERO)
);
let request = RequestView {
request: view.requests[0].clone(),
claim: None,
execution: None,
definition: None,
};
assert_eq!(request_output(&request, now)["summary"]["wallMs"], 1000);
assert_eq!(
serde_json::to_value(&request.request.profile).unwrap(),
json!({"kind":"runtime","command":"fixture","args":[]})
);
assert_eq!(
serde_json::to_value(&request.request.requested_profile).unwrap(),
json!({"kind":"runtime","command":"fixture","args":[],"timeoutMs":null})
);
}