fabro/lib/apps/fabro-cli/tests/it/cmd/graph.rs
Bryan Helmkamp af38d68942
Delete fabro-validate and fabro-acp; validate on Petri's check
Petri judges a workflow at admission, so Fabro's lint rules go:
`fabro-validate` (its 35 rules and the `LintRule` trait) is deleted, and
with it `fabro-acp` (only a rule and two legacy executor tests used it),
the model-resolution transform, the legacy `create`, `compile_create_run`
and `materialize_create_run` stages, and `fabro-graphviz`'s `condition`
and `fidelity` modules. `Diagnostic`, `RelatedDiagnostic` and `Severity`
move to `fabro_types::diagnostic`, the one shape every diagnostic takes.

Validation is now the same question the create handler asks. A new
server module, `petri_check`, builds Petri's check request from a
workflow bundle and the run's settings (every workflow of the bundle at
its bundle-relative path, the inputs, the run variables, the launch),
runs the check, and maps the diagnostics; Fabro adds one rule of its
own, `fabro.model.no_ready_provider`, refusing a model node when no
provider is ready. Admission, the validate and preflight endpoints and
the offline `fabro validate` all go through it:

- `validate_prepared_manifest` runs Fabro's structural pass (parse and
  transform, whose diagnostics stay) and then Petri's check, on the
  blocking pool from the handlers;
- the offline `validate_manifest` checks with no model client and with
  an unbound input as a warning (`CheckRequest.unbound_is_warning`), so
  a workflow validates before its inputs exist; a collected workflow
  before upload checks with unbound inputs as errors, as before;
- preflight resolves each LLM node's selector against the ready
  providers and the catalog for its probe, as the deleted transform did,
  and no longer probes a model Petri refused;
- the graph render endpoint needs only the structural pass;
- a run manifest now carries its `[run.goal] file`, which Petri reads
  from the bundle as it does for a version.

The transforms keep the authored model selector (`sonnet` stays
`sonnet`): Petri pins the catalog model in the admitted graph, not in
the graph Fabro displays or in the settings snapshot. Tests assert that,
and the CLI's validate, preflight and graph snapshots carry Petri's
diagnostics (`attractor.no_start`, `attractor.undeclared_node`,
`attractor.bad_on_failure`, ...) in place of the lint rules' text.

Known gaps, Petri's side: a `workflow.toml` whose `[run.environment]`
names an environment the server catalog defines but the file does not
is refused (`unsupported.workflow_toml.run.environment`), as admission
already refused it; an unbound input inside an included template
partial is a render error rather than the unbound-input warning.

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

123 lines
3.3 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use fabro_test::{fabro_snapshot, test_context};
use super::support::{fixture, read_text};
#[test]
fn help() {
let context = test_context!();
let mut cmd = context.command();
cmd.args(["graph", "--help"]);
fabro_snapshot!(context.filters(), cmd, @"
success: true
exit_code: 0
----- stdout -----
Render a workflow graph as SVG
Usage: fabro graph [OPTIONS] <WORKFLOW>
Arguments:
<WORKFLOW>
Path to the .fabro workflow file, .toml task config, or project workflow name
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=]
--format <FORMAT>
Output format
[default: svg]
[possible values: svg]
--no-upgrade-check
Disable automatic upgrade check
[env: FABRO_NO_UPGRADE_CHECK=true]
-o, --output <OUTPUT>
Output file path (defaults to stdout)
-d, --direction <DIRECTION>
Graph layout direction (overrides the DOT file's rankdir)
Possible values:
- lr: Left to right
- tb: Top to bottom
--quiet
Suppress non-essential output
[env: FABRO_QUIET=]
--allow-invalid
Render even when workflow validation reports errors
--verbose
Enable verbose output
[env: FABRO_VERBOSE=]
-h, --help
Print help (see a summary with '-h')
----- stderr -----
");
}
#[test]
fn graph_allow_invalid_renders_after_diagnostics() {
let context = test_context!();
let workflow = fixture("invalid.fabro");
let output_path = context.temp_dir.join("invalid.svg");
let mut cmd = context.command();
cmd.args([
"graph",
"--allow-invalid",
"-o",
output_path.to_str().unwrap(),
workflow.to_str().unwrap(),
]);
fabro_snapshot!(context.filters(), cmd, @"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
error: [FIXTURES]/invalid.fabro:1:9: the workflow has no start node (`shape=Mdiamond`, `type=start`, or an id of `start`) (attractor.no_start)
");
let svg = read_text(&output_path);
assert!(
svg.contains("<svg") && svg.contains("Invalid"),
"expected invalid workflow to render as SVG, got: {}",
&svg[..svg.len().min(200)]
);
}
#[test]
fn graph_invalid_workflow_fails_after_diagnostics() {
let context = test_context!();
let workflow = fixture("invalid.fabro");
let mut cmd = context.command();
cmd.args(["graph", workflow.to_str().unwrap()]);
fabro_snapshot!(context.filters(), cmd, @"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
error: [FIXTURES]/invalid.fabro:1:9: the workflow has no start node (`shape=Mdiamond`, `type=start`, or an id of `start`) (attractor.no_start)
× Validation failed
");
}