1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Tests for [`super::refresh_resume_compiled_prompt`] (#4752).
//!
//! Why: the resume path never runs `prepare_session*`, so this helper is the
//! ONLY thing standing between a resumed session and a stale (or absent)
//! compiled prompt. It is also fatal, so its failure message is operator-facing
//! and must be assertable.
//! What: covers the success write and the actionable-failure message.
//! Test: this file IS the test suite.
use super::*;
/// A fixed managed id for the resume-refresh tests.
///
/// Why (#4832): the compiled prompt is now per-session, so the test must name
/// the same session the call under test is given — otherwise it would assert
/// against a path nothing wrote.
fn test_session_id() -> ManagedSessionId {
ManagedSessionId::new()
}
#[test]
fn refresh_resume_compiled_prompt_writes_the_project_local_file() {
// Why (#4752 review, HIGH 3): before this helper existed, resume ran a
// prompt that never reached the compiled path. FIXTURE: pre-seed a stale
// sentinel so "the file exists" cannot pass — only a real refresh can.
let tmp = tempfile::tempdir().expect("tempdir");
let id = test_session_id();
let dest = crate::core::instruction_pipeline::compiled_prompt_path(tmp.path(), &id.to_string());
std::fs::create_dir_all(dest.parent().unwrap()).expect("create parent");
const STALE: &str = "STALE-FROM-A-PREVIOUS-START";
std::fs::write(&dest, STALE).expect("seed stale");
// #7514: root-taking seam, so the fold lands under `root` and not in the
// operator's own `~/.trusty-mpm/usage/`.
let root = tempfile::tempdir().expect("framework root");
refresh_resume_compiled_prompt_in(root.path(), tmp.path(), &id).expect("refresh succeeds");
let on_disk = std::fs::read_to_string(&dest).expect("readable");
assert_ne!(
on_disk, STALE,
"resume must overwrite a stale compiled prompt"
);
assert!(
on_disk.contains("# PM Agent -- Trusty MPM"),
"must hold the resolved PM prompt, not a fragment: {on_disk}"
);
// Project-local, never global.
assert!(dest.starts_with(tmp.path()));
}
#[test]
fn refresh_resume_compiled_prompt_reports_an_actionable_failure() {
// Why (#4752 ruling follow-up 1): the write is fatal, so a refused resume
// must name the path and say the session did not start — not surface a bare
// io error. FIXTURE: a directory planted at the exact path so only this
// write fails.
let tmp = tempfile::tempdir().expect("tempdir");
let id = test_session_id();
let dest = crate::core::instruction_pipeline::compiled_prompt_path(tmp.path(), &id.to_string());
std::fs::create_dir_all(&dest).expect("plant a directory at the compiled path");
// #7514: root-taking seam — see the sibling test above.
let root = tempfile::tempdir().expect("framework root");
let msg = refresh_resume_compiled_prompt_in(root.path(), tmp.path(), &id)
.expect_err("a failed compiled write must refuse the resume");
assert!(
msg.contains(&dest.display().to_string()),
"must name the path: {msg}"
);
assert!(
msg.contains("was NOT started"),
"must say it did not start: {msg}"
);
assert!(msg.contains("permissions"), "must point at a remedy: {msg}");
}