fabro/lib/crates/fabro-workflow/tests/materialize_run.rs
Bryan Helmkamp 57e0385c98
fix(workflow): use configured providers for default models
Derive configured providers from env and vault when choosing default
models during run creation and materialization, and thread the resolved
run provider through execution handlers instead of recomputing it.

Also return a user-facing error when fabro-agent cannot infer a default
model for the selected provider.
2026-04-15 08:19:04 -04:00

90 lines
2.5 KiB
Rust

use fabro_graphviz::graph::Graph;
use fabro_graphviz::parser;
use fabro_model::{Catalog, Provider};
use fabro_types::settings::run::{RunGoalLayer, RunLayer, RunModelLayer, RunPullRequestLayer};
use fabro_types::settings::{InterpString, SettingsLayer};
use fabro_workflow::run_materialization::materialize_run;
fn graph(source: &str) -> Graph {
parser::parse(source).expect("graph should parse")
}
#[test]
fn materialize_run_applies_graph_and_catalog_defaults() {
let source = r#"digraph Test {
graph [goal="Build feature"]
start [shape=Mdiamond]
exit [shape=Msquare]
start -> exit
}"#;
let settings = SettingsLayer {
run: Some(RunLayer {
model: Some(RunModelLayer {
name: Some(InterpString::parse("sonnet")),
..RunModelLayer::default()
}),
pull_request: Some(RunPullRequestLayer {
enabled: Some(false),
..RunPullRequestLayer::default()
}),
..RunLayer::default()
}),
..SettingsLayer::default()
};
let materialized = materialize_run(settings, &graph(source), Catalog::builtin(), &[]);
let resolved = fabro_config::resolve_run_from_file(&materialized).unwrap();
assert_eq!(
resolved
.model
.name
.as_ref()
.map(InterpString::as_source)
.as_deref(),
Some("claude-sonnet-4-6")
);
assert_eq!(
resolved
.model
.provider
.as_ref()
.map(InterpString::as_source)
.as_deref(),
Some("anthropic")
);
assert_eq!(
materialized.run.as_ref().and_then(|run| run.goal.as_ref()),
Some(&RunGoalLayer::Inline(InterpString::parse("Build feature")))
);
assert!(resolved.pull_request.is_none());
}
#[test]
fn materialize_run_uses_configured_provider_defaults() {
let source = r#"digraph Test {
graph [goal="Build feature"]
start [shape=Mdiamond]
exit [shape=Msquare]
start -> exit
}"#;
let materialized = materialize_run(
SettingsLayer::default(),
&graph(source),
Catalog::builtin(),
&[Provider::OpenAi],
);
let resolved = fabro_config::resolve_run_from_file(&materialized).unwrap();
assert_eq!(
resolved
.model
.provider
.as_ref()
.map(InterpString::as_source)
.as_deref(),
Some("openai")
);
}