use crate::harness::{agent, human, plan_of, World};
use serde_json::{json, Value};
fn prompt_of(event: &Value) -> Option<String> {
let args = event["payload"]["args"].as_array()?;
let at = args.iter().position(|arg| arg == "--prompt")?;
args.get(at + 1)?.as_str().map(str::to_string)
}
fn open_second_round(world: &World, run: &str, node: Value) {
world.script("driver.wait", "hold");
let path = world.plan(run, &plan_of(run, vec![human("approve", &[]), node]));
world
.run(&["start", &path.to_string_lossy(), "--detach"])
.exited(0);
world.run(&["round", "run", run]).exited(1);
world.run(&["attest", run, "approve"]).exited(0);
world
.run(&["round", "next", run])
.exited(0)
.out_has("continuing");
}
#[test]
fn relative_default_graphs_dispatch_from_the_launch_directory() {
let world = World::new("real-relative-defaults");
world.write_graphs();
let path = world.plan(
"relative-defaults",
&plan_of("relative-defaults", vec![agent("build", &[])]),
);
let mut command = world.agentgraph_cmd(&["start", &path.to_string_lossy(), "--attach"]);
command
.current_dir(&world.root)
.env_remove("ONEPIPELINE_DAG_GRAPH")
.env_remove("ONEPIPELINE_NODE_GRAPH");
let started = world.run_on(command, "start relative defaults");
started.exited(0).settled();
assert!(
world
.journal("relative-defaults")
.iter()
.filter_map(prompt_of)
.any(|prompt| prompt.contains("Do build.")),
"the node-scope graph did not dispatch its member: {}",
world.dump()
);
let launch = world.run_json("relative-defaults", "launch.json");
for field in ["graph", "node_graph"] {
assert!(
std::path::Path::new(launch[field].as_str().expect("a graph path")).is_absolute(),
"{field} was not resolved at launch: {launch}"
);
}
assert_eq!(launch["dir"], json!(world.root));
let announced = world
.journal("relative-defaults")
.into_iter()
.find(|event| event["kind"] == "graph-started" && event["labels"]["node"].is_null())
.expect("the driver announced itself into the merged store");
assert_eq!(
launch["graph_run"], announced["labels"]["run_id"],
"the record names a different graph run from the one that drove the run"
);
}
#[test]
fn relative_node_and_step_graph_overrides_dispatch_from_the_launch_directory() {
let world = World::new("real-relative-plan-overrides");
world.write_graphs();
world.repository("local-direct", &["true"]);
for (source, target) in [
("node-scope.yaml", "node-override.yaml"),
("node-scope.yaml", "step-override.yaml"),
] {
std::fs::copy(world.graphs().join(source), world.root.join(target))
.expect("the relative graph override is written");
}
std::fs::copy(
world.graphs().join("oneharness.toml"),
world.root.join("oneharness.toml"),
)
.expect("the relative graphs' harness config is written");
let node = json!({
"id": "service",
"repo": "service",
"agent_graph": "node-override.yaml",
"steps": [
{"id": "implement", "persona": "engineer", "task": "## What\nimplement"},
{
"id": "review",
"persona": "reviewer",
"task": "## What\nreview",
"deps": ["implement"],
"agent_graph": "step-override.yaml",
},
],
});
let path = world.plan(
"relative-plan-overrides",
&plan_of("relative-plan-overrides", vec![node]),
);
let mut command = world.agentgraph_cmd(&["start", &path.to_string_lossy(), "--attach"]);
command.current_dir(&world.root);
world
.run_on(command, "start relative plan graph overrides")
.exited(0)
.settled();
for (step, graph) in [
("implement", world.root.join("node-override.yaml")),
("review", world.root.join("step-override.yaml")),
] {
let graph = graph
.canonicalize()
.expect("the expected relative graph path resolves");
assert!(
world
.journal("relative-plan-overrides")
.iter()
.any(|event| {
event["kind"] == "graph-started"
&& event["labels"]["node"] == "service"
&& event["labels"]["step"] == step
&& event["payload"]["graph"].as_str().is_some_and(|actual| {
std::fs::canonicalize(actual)
.map(|actual| actual == graph)
.unwrap_or(false)
})
}),
"{step} did not dispatch with its resolved graph: {}",
world.dump()
);
}
}
#[test]
fn lifecycle_and_title_drafting_keep_the_node_graph_resolved_at_launch() {
let world = World::new("lifecycle-recorded-default-graph");
world.repository("local-direct", &["true"]);
world.script("driver.wait", "hold");
world.script("service.work", "the worker wrote this\n");
let launch_graph = crate::harness::repo_file("graphs/node-scope.yaml");
let later_graph = world.root.join("later-node-scope.yaml");
std::fs::copy(&launch_graph, &later_graph).expect("the later graph is written");
let mut service = crate::harness::lifecycle("service", &["approve"]);
service["deps"] = json!(["approve"]);
let path = world.plan(
"recorded-lifecycle-graph",
&plan_of(
"recorded-lifecycle-graph",
vec![human("approve", &[]), service],
),
);
let mut start = world.cmd(&["start", &path.to_string_lossy(), "--detach"]);
start.env("ONEPIPELINE_NODE_GRAPH", &launch_graph);
world
.run_on(start, "start recorded lifecycle graph")
.exited(0);
world
.run(&["round", "run", "recorded-lifecycle-graph"])
.exited(1);
world
.run(&["attest", "recorded-lifecycle-graph", "approve"])
.exited(0);
world
.run(&["round", "next", "recorded-lifecycle-graph"])
.exited(0);
let mut round = world.cmd(&["round", "run", "recorded-lifecycle-graph"]);
round.env("ONEPIPELINE_NODE_GRAPH", &later_graph);
world
.run_on(round, "round with changed live node graph")
.exited(0);
world.release("driver.go");
let invocations = world.invocations();
let relevant: Vec<&Value> = invocations
.iter()
.filter(|call| {
call["tool"] == "oneagentgraph"
&& call["args"]
.as_array()
.is_some_and(|args| args.iter().any(|arg| arg == "onepipeline.node=service"))
})
.collect();
assert!(
relevant
.iter()
.any(|call| call["args"].as_array().is_some_and(|args| {
args.iter()
.any(|arg| arg == "onepipeline.persona=pr-author")
})),
"the title drafting dispatch did not run: {relevant:?}"
);
assert!(
relevant
.iter()
.all(|call| call["args"][1] == launch_graph.to_string_lossy().as_ref()),
"a lifecycle dispatch re-read the live graph instead of launch state: {relevant:?}"
);
}
#[test]
fn an_unreadable_relative_graph_names_its_launch_base() {
let world = World::new("relative-graph-error");
let path = world.plan(
"relative-error",
&plan_of("relative-error", vec![agent("build", &[])]),
);
let mut command = world.agentgraph_cmd(&["start", &path.to_string_lossy(), "--attach"]);
command
.current_dir(&world.root)
.env("ONEPIPELINE_DAG_GRAPH", "graphs/missing-dag.yaml");
let failed = world.run_on(command, "start missing relative graph");
failed.exited(crate::harness::REFUSED);
failed.err_has("graphs/missing-dag.yaml");
failed.err_has(&world.root.to_string_lossy());
}
#[test]
fn an_unreadable_relative_node_graph_names_its_launch_base() {
let world = World::new("relative-node-graph-error");
world.write_graphs();
let path = world.plan(
"relative-node-error",
&plan_of("relative-node-error", vec![agent("build", &[])]),
);
let mut command = world.agentgraph_cmd(&["start", &path.to_string_lossy(), "--attach"]);
command
.current_dir(&world.root)
.env("ONEPIPELINE_NODE_GRAPH", "graphs/missing-node.yaml");
let failed = world.run_on(command, "start missing relative node graph");
failed.exited(crate::harness::REFUSED);
failed.err_has("graphs/missing-node.yaml");
failed.err_has(&world.root.to_string_lossy());
}
#[test]
fn unreadable_relative_plan_graphs_name_their_path_and_launch_base() {
let world = World::new("relative-plan-graph-errors");
world.write_graphs();
world.repository("local-direct", &["true"]);
let cases = [
(
"missing-node-override",
json!({
"id": "build",
"persona": "engineer",
"task": "## What\nbuild",
"agent_graph": "graphs/missing-node-override.yaml",
}),
"graphs/missing-node-override.yaml",
),
(
"missing-step-override",
json!({
"id": "service",
"repo": "service",
"steps": [{
"id": "implement",
"persona": "engineer",
"task": "## What\nimplement",
"agent_graph": "graphs/missing-step-override.yaml",
}],
}),
"graphs/missing-step-override.yaml",
),
];
for (name, node, missing) in cases {
let path = world.plan(name, &plan_of(name, vec![node]));
let mut command = world.agentgraph_cmd(&["start", &path.to_string_lossy(), "--attach"]);
command.current_dir(&world.root);
let failed = world.run_on(command, &format!("start {name}"));
failed.exited(crate::harness::REFUSED);
failed.err_has(missing);
failed.err_has(&world.root.to_string_lossy());
}
}
#[test]
fn broken_launch_records_refuse_rounds_before_direct_or_lifecycle_dispatch() {
let direct = World::new("corrupt-launch-direct");
let mut build = agent("build", &["approve"]);
build["deps"] = json!(["approve"]);
open_second_round(&direct, "corrupt-direct", build);
std::fs::write(direct.run_file("corrupt-direct", "launch.json"), "not json")
.expect("the launch record is corrupted");
direct
.run(&["round", "run", "corrupt-direct"])
.exited(crate::harness::REFUSED)
.err_has("launch.json");
direct.release("driver.go");
let lifecycle_world = World::new("missing-launch-lifecycle");
lifecycle_world.repository("local-direct", &["true"]);
let mut service = crate::harness::lifecycle("service", &["approve"]);
service["deps"] = json!(["approve"]);
open_second_round(&lifecycle_world, "missing-lifecycle", service);
std::fs::remove_file(lifecycle_world.run_file("missing-lifecycle", "launch.json"))
.expect("the launch record is removed");
lifecycle_world
.run(&["round", "run", "missing-lifecycle"])
.exited(crate::harness::REFUSED)
.err_has("launch.json");
lifecycle_world.release("driver.go");
}
#[test]
fn a_legacy_launch_without_a_node_graph_fails_instead_of_reading_live_environment() {
let world = World::new("legacy-empty-node-graph");
let mut build = agent("build", &["approve"]);
build["deps"] = json!(["approve"]);
open_second_round(&world, "legacy-empty", build);
let path = world.run_file("legacy-empty", "launch.json");
let mut launch: Value =
serde_json::from_str(&std::fs::read_to_string(&path).expect("the launch record reads"))
.expect("the launch record parses");
launch["node_graph"] = json!("");
std::fs::write(&path, serde_json::to_vec_pretty(&launch).unwrap())
.expect("the legacy launch record is written");
let mut round = world.cmd(&["round", "run", "legacy-empty"]);
round.env(
"ONEPIPELINE_NODE_GRAPH",
world.graphs().join("node-scope.yaml"),
);
world
.run_on(round, "round run legacy-empty")
.exited(crate::harness::REFUSED)
.err_has("has no resolved node graph");
world.release("driver.go");
}
#[test]
fn launch_overrides_reach_the_graphs_that_actually_run() {
let world = World::new("real-overrides");
world.write_graphs();
std::fs::write(
world.graphs().join("dag-override.toml"),
"run_mode = \"fallback\"\nharnesses = [\"claude-code\"]\n# DAG_OVERRIDE\n",
)
.expect("the dag override config is written");
std::fs::write(
world.graphs().join("node-override.toml"),
"run_mode = \"fallback\"\nharnesses = [\"claude-code\"]\n# NODE_OVERRIDE\n",
)
.expect("the node override config is written");
let path = world.plan(
"overrides",
&plan_of("overrides", vec![agent("build", &[])]),
);
let started = world.run_on_agentgraph(&[
"start",
&path.to_string_lossy(),
"--attach",
"--set",
"members.orchestrator.oneharness_config=./dag-override.toml",
"--node-set",
"members.worker.oneharness_config=./node-override.toml",
]);
started.exited(0).settled();
let configs: Vec<Value> = world
.invocations()
.into_iter()
.filter(|call| call["tool"] == "oneharness-config")
.collect();
assert!(
configs.iter().any(|call| {
call["args"][0]
.as_str()
.is_some_and(|prompt| prompt.contains("onepipeline round run"))
&& call["args"][1]
.as_str()
.is_some_and(|config| config.contains("DAG_OVERRIDE"))
}),
"the running dag member did not receive its override: {configs:?}"
);
assert!(
configs.iter().any(|call| {
call["args"][0]
.as_str()
.is_some_and(|prompt| prompt.contains("Do build."))
&& call["args"][1]
.as_str()
.is_some_and(|config| config.contains("NODE_OVERRIDE"))
}),
"the running node member did not receive its override: {configs:?}"
);
}
#[test]
fn a_plan_persona_reaches_the_member_that_actually_runs() {
let world = World::new("real-plan-persona");
world.write_graphs();
std::fs::write(
world.graphs().join("requested-reviewer.yaml"),
"agent:\n name: requested-reviewer\n instructions: Review the change.\nuser:\n persona: Demand evidence.\n",
)
.expect("the requested persona is written");
let mut node = agent("review", &[]);
node["persona"] = Value::from("./requested-reviewer.yaml");
let path = world.plan("plan-persona", &plan_of("plan-persona", vec![node]));
let started = world.run_on_agentgraph(&["start", &path.to_string_lossy(), "--attach"]);
started.exited(0).settled();
let invocations: Vec<Value> = world
.invocations()
.into_iter()
.filter(|call| {
call["tool"] == "oneharness-config"
&& call["args"][0]
.as_str()
.is_some_and(|prompt| prompt.contains("Do review."))
})
.collect();
assert!(
!invocations.is_empty(),
"the node's member never ran: {invocations:?}"
);
let records: Vec<Value> = std::fs::read_dir(world.root.join("graph-state"))
.expect("oneagentgraph wrote its state root")
.filter_map(Result::ok)
.filter_map(|entry| std::fs::read_to_string(entry.path().join("record.json")).ok())
.filter_map(|text| serde_json::from_str(&text).ok())
.collect();
assert!(
records
.iter()
.any(|record| record["refs"].as_array().is_some_and(|refs| refs
.iter()
.any(|reference| { reference["origin"] == "./requested-reviewer.yaml" }))),
"the graph that dispatched the member did not resolve the plan's persona: {records:?}"
);
}
#[test]
fn adoption_retains_node_overrides_for_later_dispatches() {
let world = World::new("real-adopted-node-override");
world.write_graphs();
world.script("driver.wait", "hold");
std::fs::write(
world.graphs().join("adopted-node.toml"),
"run_mode = \"fallback\"\nharnesses = [\"claude-code\"]\n# ADOPTED_NODE_OVERRIDE\n",
)
.expect("the adopted node config is written");
let path = world.plan(
"adopted-override",
&plan_of("adopted-override", vec![agent("build", &[])]),
);
let mut start = world.agentgraph_cmd(&[
"start",
&path.to_string_lossy(),
"--detach",
"--node-set",
"members.worker.oneharness_config=./adopted-node.toml",
]);
start
.current_dir(&world.root)
.env("ONEPIPELINE_DAG_GRAPH", "graphs/dag-scope.yaml")
.env("ONEPIPELINE_NODE_GRAPH", "graphs/node-scope.yaml");
world.run_on(start, "start adopted-override").exited(0);
world.until("the original driver to park before dispatch", |world| {
let mut status = world.agentgraph_cmd(&["status", "adopted-override"]);
status.env("ONEPIPELINE_PARKED_AFTER_SECONDS", "1");
String::from_utf8_lossy(&status.output().expect("status runs").stdout).contains("PARKED")
});
std::fs::remove_file(world.root.join("fakes/driver.wait")).expect("the adoption is not held");
let mut adopt = world.agentgraph_cmd(&["adopt", "adopted-override"]);
adopt
.current_dir(&world.project)
.env("ONEPIPELINE_DAG_GRAPH", "missing-dag.yaml")
.env("ONEPIPELINE_NODE_GRAPH", "missing-node.yaml")
.env("ONEPIPELINE_PARKED_AFTER_SECONDS", "1");
let adopted = world.run_on(adopt, "adopt adopted-override");
adopted.exited(0).settled();
let configs = world.invocations();
assert!(
configs.iter().any(|call| {
call["tool"] == "oneharness-config"
&& call["args"][0]
.as_str()
.is_some_and(|prompt| prompt.contains("Do build."))
&& call["args"][1]
.as_str()
.is_some_and(|config| config.contains("ADOPTED_NODE_OVERRIDE"))
}),
"the node dispatched after adoption did not run under its retained override: {configs:?}"
);
world.release("driver.go");
}
#[test]
fn a_plan_dispatches_through_the_real_oneagentgraph_and_its_members_run() {
let world = World::new("real-dispatch");
world.write_graphs();
let path = world.plan("real", &plan_of("real", vec![agent("build", &[])]));
let started = world.run_on_agentgraph(&["start", &path.to_string_lossy(), "--attach"]);
started.exited(0).settled();
let run = started.json()["run_id"]
.as_str()
.expect("the launch named its run")
.to_string();
let launches: Vec<String> = world
.journal(&run)
.iter()
.filter(|event| event["kind"] == "member-started")
.filter_map(prompt_of)
.collect();
assert!(
launches
.iter()
.any(|task| task.contains("onepipeline round run")),
"no member was launched to drive the run: {launches:?}"
);
assert!(
launches.iter().any(|task| task.contains("Do build.")),
"the node's own task never reached a member: {launches:?}"
);
assert!(
world
.journal(&run)
.iter()
.any(|event| event["source"] == "agentgraph"
&& event["kind"] == "graph-started"
&& event["labels"]["node"].is_null()),
"the driver's own start never reached the merged store: {}",
world.dump()
);
assert!(
world
.journal(&run)
.iter()
.any(|event| event["kind"] == "turn-activity"),
"no member reported a turn: {}",
world.dump()
);
assert_eq!(
world.run_json(&run, "round-01/result.json")["state"],
"complete",
"the run did not settle: {}",
world.dump()
);
let relayed: Vec<serde_json::Value> = world
.journal(&run)
.into_iter()
.filter(|event| event["source"] == "agentgraph" && event["labels"]["node"] == "build")
.collect();
assert!(
!relayed.is_empty(),
"no relayed envelope belongs to the node: {}",
world.dump()
);
for event in relayed {
assert_eq!(
event["labels"]["onepipeline.run_id"],
run.as_str(),
"{event}"
);
assert_ne!(
event["labels"]["run_id"],
run.as_str(),
"the graph run's own id was overwritten by this run's: {event}"
);
}
}
fn events_reported(status: &str, node: &str) -> u64 {
let line = status
.lines()
.find(|line| line.trim_start().starts_with(&format!("{node}: running")))
.unwrap_or_else(|| panic!("`status` has no in-flight line for {node}:\n{status}"));
let at = line
.find(" event(s)")
.unwrap_or_else(|| panic!("`{line}` carries no event count"));
let digits: String = line[..at]
.chars()
.rev()
.take_while(char::is_ascii_digit)
.collect();
digits
.chars()
.rev()
.collect::<String>()
.parse()
.unwrap_or_else(|e| panic!("`{line}` carries no readable count: {e}"))
}
#[test]
fn status_says_what_a_live_dispatch_is_doing_and_the_readout_advances() {
let world = World::new("real-activity");
world.write_graphs();
world.script("turn.hold", "hold");
let path = world.plan("watched", &plan_of("watched", vec![agent("build", &[])]));
world
.run_on_agentgraph(&["start", &path.to_string_lossy(), "--detach"])
.exited(0);
world.until("the dispatch to report a turn", |world| {
!world.events_of("watched", "turn-activity").is_empty()
});
let first = world.run(&["status", "watched"]);
first
.exited(0)
.out_has("build: running")
.out_has("now bash echo the turn ran")
.out_has("event(s)")
.out_has("ago");
let before = events_reported(&first.stdout, "build");
world.release("turn.go");
world.until("the dispatch to report a second turn", |world| {
world.events_of("watched", "turn-activity").len() > 1
});
let second = world.run(&["status", "watched"]);
second
.exited(0)
.out_has("build: running")
.out_has("now bash cargo llvm-cov --workspace");
assert!(
events_reported(&second.stdout, "build") > before,
"the readout did not advance while the node was still in flight:\n{}",
second.stdout
);
world.release("turn.settle");
world.until("the run to settle", |world| {
!world.events_of("watched", "round-finished").is_empty()
});
}
#[test]
fn transcript_renders_a_real_dispatched_turns_tools_and_words() {
let world = World::new("real-transcript");
world.write_graphs();
let path = world.plan("read", &plan_of("read", vec![agent("build", &[])]));
world
.run_on_agentgraph(&["start", &path.to_string_lossy(), "--attach"])
.exited(0)
.settled();
let transcript = world.run(&["transcript", "read", "build"]);
transcript.exited(0).out_has("read build");
transcript.out_has("tool_call bash echo the turn ran");
transcript.out_has("report ");
transcript.out_has("Ran what the task asked for.");
assert!(
!transcript.stdout.contains("unreadable from this host"),
"the retained report was named and not read:\n{}",
transcript.stdout
);
world
.run(&["transcript", "read", "nowhere"])
.exited(crate::harness::REFUSED)
.err_has("has recorded nothing for node 'nowhere'")
.err_has("build");
}
#[test]
fn a_launch_the_graph_refuses_fails_with_the_graphs_own_words() {
let world = World::new("real-refusal");
let path = world.plan("refused", &plan_of("refused", vec![agent("build", &[])]));
for form in ["--detach", "--attach"] {
let started = world.run_on_agentgraph(&["start", &path.to_string_lossy(), form]);
started.exited(crate::harness::REFUSED);
started.err_has("oneagentgraph");
started.err_has("dag-scope.yaml");
assert!(
!started.stdout.contains("\"pid\""),
"`start {form}` still printed a pid to drive:\n{}",
started.stdout
);
}
}
#[test]
fn an_adoption_the_graph_refuses_fails_rather_than_leaving_the_run_undriven() {
let world = World::new("real-adopt-refusal");
world.write_graphs();
let path = world.plan(
"orphaned",
&plan_of("orphaned", vec![human("approve", &[])]),
);
world
.run_on_agentgraph(&["start", &path.to_string_lossy(), "--detach"])
.exited(0);
world.until("the driver to be gone", |world| {
world
.run_on_agentgraph(&["status", "orphaned"])
.stdout
.contains("DRIVER DEAD")
});
std::fs::remove_file(world.graphs().join("dag-scope.yaml")).expect("the graph is removed");
let adopted = world.run_on_agentgraph(&["adopt", "orphaned"]);
adopted.exited(crate::harness::REFUSED);
adopted.err_has("oneagentgraph");
assert!(
world.events_of("orphaned", "driver-adopted").len() == 1,
"the adoption was recorded more than once: {:?}",
world.events_of("orphaned", "driver-adopted")
);
}
#[test]
fn the_run_state_this_crate_places_is_where_the_sibling_looks_for_it() {
let world = World::new("state-dir-drift");
world.write_graphs();
let state = world.root.join("graph-state");
let path = world.plan(
"state-drift",
&plan_of("state-drift", vec![agent("build", &[])]),
);
world
.run_on_agentgraph(&["start", &path.to_string_lossy(), "--attach"])
.exited(0)
.settled();
let listed = std::process::Command::new(crate::harness::oneagentgraph_binary())
.arg("history")
.env("ONEAGENTGRAPH_STATE_DIR", &state)
.output()
.expect("the real oneagentgraph runs");
let listed = String::from_utf8_lossy(&listed.stdout);
assert!(
listed.lines().any(|line| line.contains("node-scope")),
"the sibling found no run where this crate placed one — the state-directory variable, \
or the fallback around it, has drifted on one side:\n{listed}\n{}",
world.dump()
);
}
#[test]
fn the_siblings_own_refusals_still_exit_with_the_codes_this_crate_maps_onto() {
let world = World::new("exit-code-drift");
let missing = world.root.join("no-such-graph.yaml");
let refused = std::process::Command::new(crate::harness::oneagentgraph_binary())
.args(["run", &missing.to_string_lossy(), "--task", "anything"])
.env("ONEAGENTGRAPH_STATE_DIR", world.root.join("graph-state"))
.output()
.expect("the real oneagentgraph runs");
assert_eq!(
refused.status.code(),
Some(oneagentgraph::error::EXIT_INVALID_CONFIG),
"an unreadable graph is no longer the invalid-config exit this crate maps \
`Error::InvalidConfig` onto: {}",
String::from_utf8_lossy(&refused.stderr)
);
}
#[test]
fn the_sibling_still_takes_its_harness_from_the_variable_this_crate_restates() {
let world = World::new("harness-bin-drift");
world.write_graphs();
let path = world.plan(
"harness-bin",
&plan_of("harness-bin", vec![agent("build", &[])]),
);
let mut command = world.agentgraph_cmd(&["start", &path.to_string_lossy(), "--attach"]);
command.env(
"ONEAGENTGRAPH_ONEHARNESS_BIN",
"oneharness-that-is-not-installed",
);
let started = world.run_on(command, "start --attach");
started.settled();
let failed: Vec<_> = world
.journal("harness-bin")
.into_iter()
.filter(|event| {
let rendered = event.to_string();
rendered.contains("oneharness-that-is-not-installed")
})
.collect();
assert!(
!failed.is_empty(),
"no event named the harness the graph was told to drive, so the variable was not read \
— it has drifted:\n{}",
world.dump()
);
}
#[test]
fn a_note_delivered_through_the_real_sibling_records_what_its_lever_answered() {
let world = World::new("real-context");
world.write_graphs();
world.script("turn.hold", "hold");
let path = world.plan("noted", &plan_of("noted", vec![agent("build", &[])]));
world
.run_on_agentgraph(&["start", &path.to_string_lossy(), "--detach"])
.exited(0);
world.until("the dispatch to report a turn", |world| {
!world.events_of("noted", "turn-activity").is_empty()
});
let note = "the fixture moved to tests/data; stop editing src/old.rs";
let submitted = world.run_with_stdin(
&["reply", "noted"],
&json!({
"version": 1,
"commands": [{"op": "context", "id": "build", "note": note}],
})
.to_string(),
);
submitted.exited(0);
world.until("the note to be reconciled", |world| {
!world.events_of("noted", "edit-committed").is_empty()
});
let committed = world.events_of("noted", "edit-committed");
assert_eq!(
committed[0]["payload"]["operations"][0]["delivery"],
json!("deferred"),
"a note the sibling could not land live was not deferred onto the next dispatch: {:?}",
committed
);
let interrupted = world.events_of("noted", "turn-interrupted");
assert_eq!(
interrupted.len(),
1,
"the lever was pulled and the run does not say so: {}",
world.dump()
);
assert_eq!(interrupted[0]["payload"]["delivered"], json!(false));
assert_eq!(interrupted[0]["payload"]["member"], json!("worker"));
assert_eq!(
interrupted[0]["payload"]["input_bytes"],
json!(note.len()),
"the envelope does not say how much redirection was offered"
);
assert!(
interrupted[0]["payload"]["reason"].is_string(),
"an interrupt that did not land carries no reason: {}",
interrupted[0]
);
assert_eq!(
interrupted[0]["labels"]["node"],
json!("build"),
"the envelope is not stamped with the node it is about — its producer cannot know it, \
so this crate has to"
);
world.release("turn.go");
world.release("turn.settle");
}
#[test]
fn consuming_a_surface_restarts_the_real_pacemakers_clock() {
let world = World::new("real-pacemaker");
world.write_graphs_with_pacemaker();
let path = world.plan("paced", &plan_of("paced", vec![human("approve", &[])]));
world
.run_on_agentgraph(&["start", &path.to_string_lossy(), "--detach"])
.exited(0);
let graph_run = world.run_json("paced", "launch.json")["graph_run"]
.as_str()
.expect("the launch record names the graph run driving this run")
.to_string();
assert_ne!(graph_run, "paced");
world
.run_on_agentgraph(&[
"surface",
"paced",
"--kind",
"check-in",
"--message",
"steady",
])
.exited(0);
let read = world.run_on(world.agentgraph_cmd(&["next", "paced"]), "next paced");
read.exited(0).out_has("\"surface\"");
assert!(
!read
.stderr
.contains("could not reset the check-in pacemaker"),
"the real sibling refused the reset: {}",
read.stderr
);
let signalled = world
.graph_state()
.join(&graph_run)
.join("signals")
.join("check-in.reset");
assert!(
signalled.is_file(),
"the reset did not reach the run's own signal directory: {}",
signalled.display()
);
}
#[test]
fn a_view_renders_with_the_health_block_read_through_the_library() {
let world = World::new("real-health");
world.write_graphs();
let path = world.plan("probed", &plan_of("probed", vec![agent("build", &[])]));
world
.run_on_agentgraph(&["start", &path.to_string_lossy(), "--attach"])
.exited(0)
.settled();
let status = world.run_on(world.agentgraph_cmd(&["status", "probed"]), "status probed");
status.exited(0).out_has("probed").out_has("SETTLED");
assert!(
!status.stdout.contains("fake-provider"),
"the view carried the override's health block on the default path:\n{}",
status.stdout
);
}