use super::Error;
use crate::types::FailureCode;
#[test]
fn failure_identity_comes_from_the_variant_not_owner_diagnostic_text() {
let preparation = Error::Preparation("INPUT_CHANGED: text from a command".into());
assert_eq!(preparation.code(), FailureCode::PreparationFailed);
let changed = Error::InputChanged("declarations changed after acceptance.".into());
assert_eq!(changed.code(), FailureCode::InputChanged);
assert_eq!(
changed.to_string(),
"INPUT_CHANGED: declarations changed after acceptance."
);
}
#[tokio::test]
async fn a_reserved_run_and_its_requests_use_the_released_id_shape() {
use super::{Selection, VerifyOptions, reserve, store};
use crate::runs::Origin;
let root = crate::test_os::tempdir();
let repo = root.path().join("repo");
let state = root.path().join("state");
let definitions = repo.join(".artifactize");
std::fs::create_dir_all(&definitions).unwrap();
std::fs::write(repo.join("README.md"), "Review fixture\n").unwrap();
std::fs::write(
definitions.join("app.artf"),
r#"artf app : markdown = {
path = "README.md"
eval review : human = {
title = "Review"
instruction = "Inspect."
}
}"#,
)
.unwrap();
let (run, _) = reserve(
&repo,
Some(&state),
&Selection::All,
&VerifyOptions::default(),
None,
None,
&Origin::Cli,
)
.await
.unwrap();
let suffix = run.as_str().strip_prefix("run-").unwrap();
assert_eq!(suffix.len(), 6);
assert!(suffix.bytes().all(|byte| byte.is_ascii_alphanumeric()));
assert!(state.join("runs").join(run.as_str()).is_dir());
let saved = store::read_run_snapshot(&state, run.as_str())
.await
.unwrap();
let [request] = saved.requests.as_slice() else {
panic!("expected one request for the reserved Run");
};
assert_eq!(request.id.as_str(), format!("{run}-1"));
}