use super::tests::{Fx, SWITCHED_WORKFLOW, head};
use super::{ConfigSource, resolve_worker};
use crate::template::{GitRunner, RealGit};
use crate::workspace::{self, fixture, workflow_mark};
use std::path::Path;
#[test]
fn a_marked_commit_failing_the_version_guard_declines_resolution() {
let (_h, ws) = fixture::workspace();
fixture::spawn_root(&ws, "20260101-r1");
fixture::amend_config(
&ws,
&[
("version", "not-a-version\n"),
("workflow.yaml", SWITCHED_WORKFLOW),
],
);
let fx = Fx::new();
workflow_mark::write(&ws, "20260101-r1", &head(&ws), &fx.git).unwrap();
let err = match resolve_worker(&ws, ConfigSource::Agent("20260101-r1"), &fx.deps()) {
Err(err) => err,
Ok(_) => panic!("a marked commit with a bad version must decline"),
};
assert!(err.to_string().contains("version"), "{err}");
}
#[test]
fn a_marked_commit_whose_workflow_does_not_parse_declines_resolution() {
let (_h, ws) = fixture::workspace();
fixture::spawn_root(&ws, "20260101-r1");
fixture::amend_config(
&ws,
&[(
"workflow.yaml",
"events:\n user_message: [not_an_action]\n",
)],
);
let fx = Fx::new();
workflow_mark::write(&ws, "20260101-r1", &head(&ws), &fx.git).unwrap();
assert!(resolve_worker(&ws, ConfigSource::Agent("20260101-r1"), &fx.deps()).is_err());
}
#[test]
fn a_mark_at_a_commit_with_no_workflow_declines_as_a_control_read() {
let (_h, ws) = fixture::workspace();
fixture::spawn_root(&ws, "20260101-r1");
let fx = Fx::new();
let orphan = orphan_commit(&ws, &fx.git);
workflow_mark::write(&ws, "20260101-r1", &orphan, &fx.git).unwrap();
assert!(resolve_worker(&ws, ConfigSource::Agent("20260101-r1"), &fx.deps()).is_err());
}
fn orphan_commit(ws: &Path, git: &RealGit) -> String {
let repo = workspace::repo_git(ws);
let tree = git
.run_capture(&repo, &["mktree"])
.unwrap()
.trim()
.to_string();
git.run_capture(&repo, &["commit-tree", "-m", "empty", &tree])
.unwrap()
.trim()
.to_string()
}