fabro/lib/foundation/fabro-api/tests/run_graph_round_trip.rs
Bryan Helmkamp bd59f52e22
Build the run's display graph from Petri's admission
The rest of the change whose deletions the previous commit carries (its
`git add` stopped at an already-removed path): `fabro_types::RunGraph`
and the `fabro-petri` builder that reads it off the admitted graph, the
server's create, validate, preflight and render paths on Petri's check
alone, the consumers moved to the new shape, the OpenAPI `RunGraph`
schemas with their parity tests, the regenerated TS client, and the
docs naming Petri's diagnostic codes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-19 11:41:58 -04:00

54 lines
1.6 KiB
Rust

use std::any::{TypeId, type_name};
use fabro_api::types::{
RunGraph as ApiRunGraph, RunGraphEdge as ApiRunGraphEdge, RunGraphNode as ApiRunGraphNode,
};
use fabro_types::{RunGraph, RunGraphEdge, RunGraphNode, StageHandler};
use serde_json::json;
#[test]
fn the_run_graph_reuses_canonical_types() {
assert_same_type::<ApiRunGraph, RunGraph>();
assert_same_type::<ApiRunGraphNode, RunGraphNode>();
assert_same_type::<ApiRunGraphEdge, RunGraphEdge>();
}
#[test]
fn the_run_graph_round_trips_the_schema_shape() {
let value = json!({
"name": "Ship",
"goal": "Ship the feature",
"nodes": {
"plan": { "label": "Plan rollout", "kind": "agent" },
"start": { "label": "Start", "kind": "start" }
},
"edges": [
{ "from": "start", "to": "plan" }
]
});
let graph: RunGraph = serde_json::from_value(value.clone()).unwrap();
assert_eq!(graph.name, "Ship");
assert_eq!(graph.goal(), "Ship the feature");
assert_eq!(
graph.node("plan").map(|node| node.kind),
Some(StageHandler::Agent)
);
assert_eq!(graph.edges.len(), 1);
assert_eq!(serde_json::to_value(&graph).unwrap(), value);
}
#[test]
fn a_graph_with_only_a_name_is_the_schema_minimum() {
let graph: RunGraph = serde_json::from_value(json!({ "name": "Bare" })).unwrap();
assert_eq!(graph, RunGraph::new("Bare"));
}
fn assert_same_type<T: 'static, U: 'static>() {
assert_eq!(
TypeId::of::<T>(),
TypeId::of::<U>(),
"{} should be the same type as {}",
type_name::<T>(),
type_name::<U>()
);
}