mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-20 00:11:34 +00:00
Extends the stage 6.1 WIP into a compiling state across the workspace.
Most crates and their unit/integration tests now read run.* / cli.* /
server.* v2 layers directly or through targeted bridge helpers.
Key moves in this commit:
fabro-server
- AppState.settings: Arc<RwLock<SettingsFile>> -- all helpers,
create_app_state_with_* factories, and tests updated.
- api_server_settings bridges SettingsFile -> legacy Settings via the
transitional bridge so /api/v1/settings still emits the legacy DTO
shape until Stage 6.6 replaces it with an allow-list DTO.
- get_system_info, get_system_df, get_github_repo, webhook startup, and
other read sites use the v2 accessors (github_app_id_str,
server_web, run_sandbox, run_model_*).
- web_auth.rs wraps each oauth / register / setup-status handler in a
local `bridged` helper that produces a legacy Settings from the v2
state, so the complex oauth mutation flow keeps working until its
Stage 6.6 rewrite.
- diagnostics::check_github_app reads via github_*_str accessors;
check_crypto bridges to the legacy shape inline.
- serve.rs: load_settings returns SettingsFile; apply_serve_overrides /
apply_runtime_settings mutate v2 subtrees directly; the config poll
loop and TLS/webhook startup use bridged() for legacy-shape reads.
- Tests in tests/it/{helpers,api/*,scenario/*} rewritten to construct
SettingsFile via ConfigLayer::parse or v2 struct literals.
fabro-workflow
- Every test fixture in pipeline/{finalize,initialize,pull_request,retro,
execute,persist}, operations/{create,rebuild_meta,start}, run_lookup,
runtime_store, handler/manager_loop, and tests/it/{integration,
daytona_integration}.rs now uses SettingsFile.
- start.rs hooks into the bridge helpers directly via use-imports.
- run_graph / run_graph_from_checkpoint / initialize / finalize /
pull_request calls are Box::pin'd to stay under clippy's large-future
threshold after the v2 tree brought RunOptions size up.
- resolve_run_settings writes resolved model/provider back into
run.model as InterpStrings; tests assert via run_model_*_str().
- preprocess_and_validate pulls vars from run_inputs_as_strings().
fabro-cli
- manifest_builder uses ConfigLayer.combine(...).into() to get a v2
SettingsFile for the manifest goal resolution path; file-based
goal_file handling is deferred to 6.6 when the manifest schema catches
up.
- runner::maybe_build_github_app_credentials and
tests/it/cmd/{create,runner}.rs read from v2 accessors.
- commands/config/mod.rs::merged_config returns SettingsFile; the
server-side retrieve_server_settings is bridged via a stopgap
legacy_settings_to_v2 shim that Stage 6.6 replaces.
- commands/store/dump.rs sample_run_record constructs SettingsFile.
fabro-store, fabro-checkpoint
- Test fixtures constructing RunRecord values updated to SettingsFile.
- fabro-checkpoint/src/author.rs stays (v2 From impl landed in a
previous additive commit).
fabro-config
- effective_settings.rs rewrite compiles and passes its unit tests.
- project::resolve_working_directory takes &SettingsFile.
Build status: `cargo build --workspace --tests`, `cargo clippy
--workspace -- -D warnings`, and `cargo fmt --check --all` all pass.
`cargo nextest run --workspace` passes 3,749 of 3,764 tests; the 15
remaining failures are fabro-cli integration tests whose snapshot +
TOML fixture shapes still need manual updates:
- cmd::config::* (seven tests): fixture TOML files still use v1
top-level keys and the snapshot outputs expect the legacy flat JSON
shape.
- cmd::inspect::* (four tests): run-record JSON snapshots embed the
flat Settings shape.
- cmd::run::dry_run_persists_event_history_in_store and
json_run_implies_auto_approve_for_human_gates: check `settings.dry_run
== Some(true)` directly on the v2 file; should assert
dry_run_enabled() instead.
- cmd::attach::attach_json_errors_without_prompting_for_human_input:
unrelated insta snapshot drift caused by the new SettingsFile JSON
shape leaking into an events-log snapshot.
Follow-up work for this stage also includes:
- Rewriting web_auth.rs register flow to emit v2 TOML directly and to
re-parse the written file back into state.settings so in-memory
state doesn't lag the on-disk file.
- Removing the legacy_settings_to_v2 shim in fabro-cli/config once
the server-side settings endpoint returns v2 shapes (Stage 6.6).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
457 lines
14 KiB
Rust
457 lines
14 KiB
Rust
use httpmock::MockServer;
|
|
use insta::assert_snapshot;
|
|
use serde_json::json;
|
|
|
|
use fabro_test::{fabro_snapshot, test_context};
|
|
|
|
use crate::support::{fabro_json_snapshot, unique_run_id};
|
|
|
|
use super::support::{fixture, output_stdout, resolve_run, run_count_for_test_case, run_state};
|
|
|
|
fn run_status_response(run_id: &str, status: &str) -> serde_json::Value {
|
|
serde_json::json!({
|
|
"id": run_id,
|
|
"status": status,
|
|
"created_at": "2026-04-05T12:00:00Z"
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn help() {
|
|
let context = test_context!();
|
|
let mut cmd = context.command();
|
|
cmd.args(["create", "--help"]);
|
|
fabro_snapshot!(context.filters(), cmd, @"
|
|
success: true
|
|
exit_code: 0
|
|
----- stdout -----
|
|
Create a workflow run (allocate run dir, persist spec)
|
|
|
|
Usage: fabro create [OPTIONS] <WORKFLOW>
|
|
|
|
Arguments:
|
|
<WORKFLOW> Path to a .fabro workflow file or .toml task config
|
|
|
|
Options:
|
|
--json Output as JSON [env: FABRO_JSON=]
|
|
--server <SERVER> Fabro server target: http(s) URL or absolute Unix socket path [env: FABRO_SERVER=]
|
|
--debug Enable DEBUG-level logging (default is INFO) [env: FABRO_DEBUG=]
|
|
--dry-run Execute with simulated LLM backend
|
|
--auto-approve Auto-approve all human gates
|
|
--no-upgrade-check Disable automatic upgrade check [env: FABRO_NO_UPGRADE_CHECK=true]
|
|
--goal <GOAL> Override the workflow goal (exposed as $goal in prompts)
|
|
--quiet Suppress non-essential output [env: FABRO_QUIET=]
|
|
--goal-file <GOAL_FILE> Read the workflow goal from a file
|
|
--model <MODEL> Override default LLM model
|
|
--provider <PROVIDER> Override default LLM provider
|
|
-v, --verbose Enable verbose output
|
|
--sandbox <SANDBOX> Sandbox for agent tools [possible values: local, docker, daytona]
|
|
--label <KEY=VALUE> Attach a label to this run (repeatable, format: KEY=VALUE)
|
|
--no-retro Skip retro generation after the run
|
|
--preserve-sandbox Keep the sandbox alive after the run finishes (for debugging)
|
|
-d, --detach Run the workflow in the background and print the run ID
|
|
-h, --help Print help
|
|
----- stderr -----
|
|
");
|
|
}
|
|
|
|
#[test]
|
|
fn create_uses_explicit_server_target_and_prints_remote_run_id() {
|
|
let context = test_context!();
|
|
let server = MockServer::start();
|
|
let run_id = unique_run_id();
|
|
let mock = server.mock(|when, then| {
|
|
when.method("POST").path("/api/v1/runs");
|
|
then.status(201)
|
|
.header("Content-Type", "application/json")
|
|
.body(run_status_response(run_id.as_str(), "submitted").to_string());
|
|
});
|
|
|
|
let output = context
|
|
.create_cmd()
|
|
.args([
|
|
"--server",
|
|
&format!("{}/api/v1", server.base_url()),
|
|
"--dry-run",
|
|
fixture("simple.fabro").to_str().unwrap(),
|
|
])
|
|
.output()
|
|
.expect("command should execute");
|
|
|
|
assert!(
|
|
output.status.success(),
|
|
"command failed:\nstdout:\n{}\nstderr:\n{}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
mock.assert();
|
|
assert_eq!(output_stdout(&output).trim(), run_id.as_str());
|
|
}
|
|
|
|
#[test]
|
|
fn create_uses_configured_server_target_without_server_flag() {
|
|
let context = test_context!();
|
|
let server = MockServer::start();
|
|
let run_id = unique_run_id();
|
|
let mock = server.mock(|when, then| {
|
|
when.method("POST").path("/api/v1/runs");
|
|
then.status(201)
|
|
.header("Content-Type", "application/json")
|
|
.body(run_status_response(run_id.as_str(), "submitted").to_string());
|
|
});
|
|
context.write_home(
|
|
".fabro/settings.toml",
|
|
format!(
|
|
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
|
server.base_url()
|
|
),
|
|
);
|
|
|
|
let output = context
|
|
.create_cmd()
|
|
.args(["--dry-run", fixture("simple.fabro").to_str().unwrap()])
|
|
.output()
|
|
.expect("command should execute");
|
|
|
|
assert!(
|
|
output.status.success(),
|
|
"command failed:\nstdout:\n{}\nstderr:\n{}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
mock.assert();
|
|
assert_eq!(output_stdout(&output).trim(), run_id.as_str());
|
|
}
|
|
|
|
#[test]
|
|
fn create_rejects_storage_dir_flag() {
|
|
let context = test_context!();
|
|
let output = context
|
|
.create_cmd()
|
|
.args([
|
|
"--storage-dir",
|
|
"/tmp/fabro-create",
|
|
"--dry-run",
|
|
fixture("simple.fabro").to_str().unwrap(),
|
|
])
|
|
.output()
|
|
.expect("command should execute");
|
|
|
|
assert!(
|
|
!output.status.success(),
|
|
"command should reject --storage-dir"
|
|
);
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
assert!(stderr.contains("unexpected argument '--storage-dir'"));
|
|
}
|
|
|
|
#[test]
|
|
fn create_cli_server_target_overrides_configured_server_target() {
|
|
let context = test_context!();
|
|
let config_server = MockServer::start();
|
|
let config_mock = config_server.mock(|when, then| {
|
|
when.method("POST").path("/api/v1/runs");
|
|
then.status(500)
|
|
.body("configured-server-should-not-be-used");
|
|
});
|
|
let cli_server = MockServer::start();
|
|
let run_id = unique_run_id();
|
|
let cli_mock = cli_server.mock(|when, then| {
|
|
when.method("POST").path("/api/v1/runs");
|
|
then.status(201)
|
|
.header("Content-Type", "application/json")
|
|
.body(run_status_response(run_id.as_str(), "submitted").to_string());
|
|
});
|
|
context.write_home(
|
|
".fabro/settings.toml",
|
|
format!(
|
|
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
|
config_server.base_url()
|
|
),
|
|
);
|
|
|
|
let output = context
|
|
.create_cmd()
|
|
.args([
|
|
"--server",
|
|
&format!("{}/api/v1", cli_server.base_url()),
|
|
"--dry-run",
|
|
fixture("simple.fabro").to_str().unwrap(),
|
|
])
|
|
.output()
|
|
.expect("command should execute");
|
|
|
|
assert!(
|
|
output.status.success(),
|
|
"command failed:\nstdout:\n{}\nstderr:\n{}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
cli_mock.assert();
|
|
config_mock.assert_calls(0);
|
|
assert_eq!(output_stdout(&output).trim(), run_id.as_str());
|
|
}
|
|
|
|
#[test]
|
|
fn create_persists_directory_workflow_slug_and_cached_graph() {
|
|
let context = test_context!();
|
|
let run_id = unique_run_id();
|
|
let workflow_path = context.temp_dir.join("sluggy/workflow.fabro");
|
|
|
|
context.write_temp(
|
|
"sluggy/workflow.fabro",
|
|
"\
|
|
digraph BarBaz {
|
|
start [shape=Mdiamond, label=\"Start\"]
|
|
exit [shape=Msquare, label=\"Exit\"]
|
|
start -> exit
|
|
}
|
|
",
|
|
);
|
|
|
|
context
|
|
.command()
|
|
.args([
|
|
"create",
|
|
"--dry-run",
|
|
"--auto-approve",
|
|
"--run-id",
|
|
run_id.as_str(),
|
|
workflow_path.to_str().unwrap(),
|
|
])
|
|
.assert()
|
|
.success();
|
|
|
|
let run_dir = context.find_run_dir(&run_id);
|
|
let state = run_state(&run_dir);
|
|
let run = state.run.as_ref().expect("run record should exist");
|
|
fabro_json_snapshot!(
|
|
context,
|
|
serde_json::json!({
|
|
"workflow_slug": run.workflow_slug,
|
|
"graph_name": run.graph.name,
|
|
"cached_graph_lines": state.graph_source.as_ref().expect("graph should exist").lines().collect::<Vec<_>>(),
|
|
}),
|
|
@r#"
|
|
{
|
|
"workflow_slug": "sluggy",
|
|
"graph_name": "BarBaz",
|
|
"cached_graph_lines": [
|
|
"digraph BarBaz {",
|
|
" start [shape=Mdiamond, label=\"Start\"]",
|
|
" exit [shape=Msquare, label=\"Exit\"]",
|
|
" start -> exit",
|
|
"}"
|
|
]
|
|
}
|
|
"#
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn create_persists_file_stem_slug_for_standalone_file() {
|
|
let context = test_context!();
|
|
let run_id = unique_run_id();
|
|
let workflow_path = context.temp_dir.join("alpha.fabro");
|
|
|
|
context.write_temp(
|
|
"alpha.fabro",
|
|
"\
|
|
digraph FooWorkflow {
|
|
start [shape=Mdiamond, label=\"Start\"]
|
|
exit [shape=Msquare, label=\"Exit\"]
|
|
start -> exit
|
|
}
|
|
",
|
|
);
|
|
|
|
context
|
|
.command()
|
|
.args([
|
|
"create",
|
|
"--dry-run",
|
|
"--auto-approve",
|
|
"--run-id",
|
|
run_id.as_str(),
|
|
workflow_path.to_str().unwrap(),
|
|
])
|
|
.assert()
|
|
.success();
|
|
|
|
let run_dir = context.find_run_dir(&run_id);
|
|
let state = run_state(&run_dir);
|
|
let run = state.run.as_ref().expect("run record should exist");
|
|
fabro_json_snapshot!(
|
|
context,
|
|
serde_json::json!({
|
|
"workflow_slug": run.workflow_slug,
|
|
"graph_name": run.graph.name,
|
|
"cached_graph_lines": state.graph_source.as_ref().expect("graph should exist").lines().collect::<Vec<_>>(),
|
|
}),
|
|
@r#"
|
|
{
|
|
"workflow_slug": "alpha",
|
|
"graph_name": "FooWorkflow",
|
|
"cached_graph_lines": [
|
|
"digraph FooWorkflow {",
|
|
" start [shape=Mdiamond, label=\"Start\"]",
|
|
" exit [shape=Msquare, label=\"Exit\"]",
|
|
" start -> exit",
|
|
"}"
|
|
]
|
|
}
|
|
"#
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn create_persists_requested_overrides_into_store() {
|
|
let context = test_context!();
|
|
let workflow = fixture("simple.fabro");
|
|
let mut cmd = context.command();
|
|
cmd.args([
|
|
"create",
|
|
"--dry-run",
|
|
"--auto-approve",
|
|
"--goal",
|
|
"Ship the release",
|
|
"--model",
|
|
"gpt-5",
|
|
"--provider",
|
|
"openai",
|
|
"--sandbox",
|
|
"local",
|
|
"--label",
|
|
"env=dev",
|
|
"--label",
|
|
"team=cli",
|
|
"--verbose",
|
|
"--no-retro",
|
|
"--preserve-sandbox",
|
|
workflow.to_str().unwrap(),
|
|
]);
|
|
let output = cmd.output().expect("command should execute");
|
|
assert!(
|
|
output.status.success(),
|
|
"command failed:\nstdout:\n{}\nstderr:\n{}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
|
|
let stdout = output_stdout(&output);
|
|
let run_id = stdout
|
|
.lines()
|
|
.find(|line| !line.trim().is_empty())
|
|
.map(str::trim)
|
|
.expect("create should print a run ID")
|
|
.to_string();
|
|
let run = resolve_run(&context, &run_id);
|
|
let state = run_state(&run.run_dir);
|
|
let run_record = state.run.as_ref().expect("run record should exist");
|
|
let labels = json!({
|
|
"env": run_record.labels.get("env"),
|
|
"team": run_record.labels.get("team"),
|
|
});
|
|
let settings = &run_record.settings;
|
|
let compact = json!({
|
|
"workflow_slug": run_record.workflow_slug,
|
|
"settings": {
|
|
"goal": settings.run_goal_str(),
|
|
"dry_run": settings.dry_run_enabled(),
|
|
"auto_approve": settings.auto_approve_enabled(),
|
|
"no_retro": settings.no_retro_enabled(),
|
|
"verbose": settings.verbose_enabled(),
|
|
"llm": {
|
|
"model": settings.run_model_name_str(),
|
|
"provider": settings.run_model_provider_str(),
|
|
},
|
|
"sandbox": {
|
|
"provider": settings.run_sandbox().and_then(|sb| sb.provider.clone()),
|
|
"preserve": settings.preserve_sandbox_enabled(),
|
|
},
|
|
},
|
|
"labels": labels,
|
|
});
|
|
|
|
assert_snapshot!(serde_json::to_string_pretty(&compact).unwrap(), @r###"
|
|
{
|
|
"workflow_slug": "simple",
|
|
"settings": {
|
|
"goal": "Ship the release",
|
|
"dry_run": true,
|
|
"auto_approve": true,
|
|
"no_retro": true,
|
|
"verbose": true,
|
|
"llm": {
|
|
"model": "gpt-5",
|
|
"provider": "openai"
|
|
},
|
|
"sandbox": {
|
|
"provider": "local",
|
|
"preserve": true
|
|
}
|
|
},
|
|
"labels": {
|
|
"env": "dev",
|
|
"team": "cli"
|
|
}
|
|
}
|
|
"###);
|
|
}
|
|
|
|
#[test]
|
|
fn create_json_implies_auto_approve() {
|
|
let context = test_context!();
|
|
let workflow = fixture("simple.fabro");
|
|
let output = context
|
|
.command()
|
|
.args(["--json", "create", "--dry-run", workflow.to_str().unwrap()])
|
|
.output()
|
|
.expect("command should execute");
|
|
|
|
assert!(
|
|
output.status.success(),
|
|
"command failed:\nstdout:\n{}\nstderr:\n{}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
|
|
let value: serde_json::Value =
|
|
serde_json::from_slice(&output.stdout).expect("create JSON should parse");
|
|
let run_id = value["run_id"]
|
|
.as_str()
|
|
.expect("create JSON should include run_id");
|
|
let run = resolve_run(&context, run_id);
|
|
|
|
assert!(
|
|
run_state(&run.run_dir)
|
|
.run
|
|
.as_ref()
|
|
.expect("run record should exist")
|
|
.settings
|
|
.auto_approve_enabled()
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn create_invalid_workflow_fails_without_creating_run() {
|
|
let context = test_context!();
|
|
let workflow = fixture("invalid.fabro");
|
|
let initial_run_count = run_count_for_test_case(&context);
|
|
let mut cmd = context.create_cmd();
|
|
cmd.arg(workflow.to_str().unwrap());
|
|
|
|
fabro_snapshot!(context.filters(), cmd, @"
|
|
success: false
|
|
exit_code: 1
|
|
----- stdout -----
|
|
----- stderr -----
|
|
error: Validation failed
|
|
");
|
|
|
|
let run_count = run_count_for_test_case(&context);
|
|
assert_eq!(
|
|
run_count, initial_run_count,
|
|
"invalid create should not persist a run for this test case"
|
|
);
|
|
}
|