Files
buzz/desktop/src-tauri/src/migration_test_support.rs
Will Pfleger 4201311821 fix: make managed-agent spawn and teardown portable to Windows (#1097)
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
2026-06-17 18:49:01 -04:00

53 lines
1.7 KiB
Rust

//! Shared helpers for the migration test modules.
use std::path::Path;
/// Build the native-separator `<base>/agents/teams/<id>` string the way
/// production does (per-component `Path::join`), so test expectations match
/// reconcile output on Windows as well as Unix.
pub(crate) fn team_dir(base: &Path, id: &str) -> String {
base.join("agents")
.join("teams")
.join(id)
.display()
.to_string()
}
/// Native-separator `<base>/agents/packs/<id>` — the pre-migration layout used
/// as reconcile input. See [`team_dir`] for why per-component join matters.
pub(crate) fn pack_dir(base: &Path, id: &str) -> String {
base.join("agents")
.join("packs")
.join(id)
.display()
.to_string()
}
pub(crate) fn write_agents_json(dir: &Path, records: &serde_json::Value) {
std::fs::create_dir_all(dir.join("agents")).unwrap();
std::fs::write(
dir.join("agents/managed-agents.json"),
serde_json::to_vec_pretty(records).unwrap(),
)
.unwrap();
}
pub(crate) fn read_agents_json(dir: &Path) -> Vec<serde_json::Value> {
let content = std::fs::read_to_string(dir.join("agents/managed-agents.json")).unwrap();
serde_json::from_str(&content).unwrap()
}
pub(crate) fn write_personas_json(dir: &Path, records: &serde_json::Value) {
std::fs::create_dir_all(dir.join("agents")).unwrap();
std::fs::write(
dir.join("agents/personas.json"),
serde_json::to_vec_pretty(records).unwrap(),
)
.unwrap();
}
pub(crate) fn read_personas_json(dir: &Path) -> Vec<serde_json::Value> {
let content = std::fs::read_to_string(dir.join("agents/personas.json")).unwrap();
serde_json::from_str(&content).unwrap()
}