use std::path::Path;
use assay_core::errors::diagnostic::{codes, Diagnostic};
use crate::cli::args::common::OutputFormat;
use crate::cli::args::DoctorArgs;
use crate::exit_codes::{ReasonCode, RunOutcome};
use super::run_doctor_fix;
fn fix_args(config: &Path, trace_file: &Path) -> DoctorArgs {
DoctorArgs {
config: Some(config.to_path_buf()),
trace_file: Some(trace_file.to_path_buf()),
baseline: None,
db: None,
replay_strict: false,
format: OutputFormat::Text,
out: None,
fix: true,
yes: true,
dry_run: false,
}
}
#[tokio::test]
async fn a_config_that_no_longer_loads_after_a_repair_reports_the_registry_class() {
let dir = tempfile::tempdir().expect("tempdir");
let config = dir.path().join("eval.yaml");
std::fs::write(&config, "suite: [unterminated\n").expect("write config");
let trace = dir.path().join("traces/absent.jsonl");
let args = fix_args(&config, &trace);
let diagnostics = vec![Diagnostic::new(
codes::E_PATH_NOT_FOUND,
format!("Trace file not found: {}", trace.display()),
)];
let exit = run_doctor_fix(&args, &config, &diagnostics, false)
.await
.expect("run_doctor_fix");
assert!(
trace.exists(),
"the repair did not run, so this test is not driving the post-repair re-load."
);
let registry_class = RunOutcome::from_reason(ReasonCode::ECfgParse, None, None).exit_code;
assert_eq!(
exit, registry_class,
"a config that does not load after a repair returned exit {exit}, while the reason code for \
an unloadable config is exit {registry_class}. One condition, one class, whether or not a \
repair ran first."
);
}