fabro/lib/crates/fabro-cli/tests/it/cmd/system_df.rs
Bryan Helmkamp 19939c5f07
lint(clippy): disallow blocking std::fs on Tokio paths
Phase 2/3 of the std::fs lint initiative (Phase 1 refactors landed in
commit 9d1c0d98c).

clippy.toml additions (appended to disallowed-methods):
  std::fs::read, read_to_string, write, read_dir, copy, canonicalize
  std::fs::File::open, File::create, File::create_new
  std::fs::OpenOptions::open

File::options was deliberately excluded — it returns an OpenOptions
builder with no syscall. OpenOptions::open is where the block happens.
Non-blocking std::fs items (metadata, exists, create_dir_all, remove_*,
rename, and all std::fs types) remain legal.

Annotation policy (per updated plan):
  - Mixed async/sync production source: function- or statement-scoped
    #[expect(...)] so future accidental Tokio-path regressions in the
    same file still fire.
  - Fully-sync production source, test modules, integration tests,
    build.rs: file-level #![expect(...)].
  - Every #[expect] has a specific reason identifying the sync context.

Annotations added in ~90 files across the workspace. Notable narrow
placements: fabro-server server.rs current_server_target,
build_disk_usage_response, create_test_app_state_with_session_key;
fabro-server install.rs read_to_string rollback snapshot;
fabro-sandbox local.rs list_recursive; fabro-agent cli.rs FOLLOW-UP on
the JSON-stdout writer; fabro-llm providers/common.rs FOLLOW-UP for
load_file_as_base64 (7 translator call sites; revisit if file:// URL
usage grows).

build.rs blanket allows: fabro-api/build.rs, fabro-util/build.rs.

Pre-existing unrelated nightly-clippy warnings fixed under scope:
fabro-sandbox sandbox_spec.rs (unused_imports, unused_async),
reconnect.rs (unused_variables, unused_async).

Verified: cargo +nightly-2026-04-14 clippy --workspace --all-targets
-- -D warnings passes; fmt clean; 4129/4131 tests pass (two known
flakes under parallel nextest load, both pass individually and are
unrelated to this change).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 17:22:21 -04:00

120 lines
3.9 KiB
Rust

#![expect(
clippy::disallowed_methods,
reason = "integration tests stage fixtures with sync std::fs; test infrastructure, not Tokio-hot path"
)]
use fabro_test::{fabro_snapshot, test_context};
use serde_json::Value;
use super::support::setup_completed_fast_dry_run;
#[test]
fn help() {
let context = test_context!();
let mut cmd = context.command();
cmd.args(["system", "df", "--help"]);
fabro_snapshot!(context.filters(), cmd, @"
success: true
exit_code: 0
----- stdout -----
Show disk usage
Usage: fabro system df [OPTIONS]
Options:
--json Output as JSON [env: FABRO_JSON=]
--storage-dir <STORAGE_DIR> Local storage directory (default: ~/.fabro/storage) [env: FABRO_STORAGE_DIR=]
--debug Enable DEBUG-level logging (default is INFO) [env: FABRO_DEBUG=]
--server <SERVER> Fabro server target: http(s) URL or absolute Unix socket path [env: FABRO_SERVER=]
--no-upgrade-check Disable automatic upgrade check [env: FABRO_NO_UPGRADE_CHECK=true]
-v, --verbose Show per-run breakdown
--quiet Suppress non-essential output [env: FABRO_QUIET=]
-h, --help Print help
----- stderr -----
");
}
#[test]
fn system_df_summarizes_runs_and_logs() {
let context = test_context!();
setup_completed_fast_dry_run(&context);
std::fs::create_dir_all(context.storage_dir.join("logs")).unwrap();
std::fs::write(context.storage_dir.join("logs/cli.log"), b"log line\n").unwrap();
let output = context
.command()
.args(["system", "df"])
.output()
.expect("command should run");
assert!(output.status.success(), "system df failed");
let stdout = String::from_utf8(output.stdout).expect("stdout should be valid UTF-8");
assert!(
stdout.contains("Runs"),
"system df should summarize runs: {stdout}"
);
assert!(
stdout.contains("Logs"),
"system df should summarize logs: {stdout}"
);
assert!(
stdout.contains("Data directory:"),
"system df should print the storage directory: {stdout}"
);
}
#[test]
fn system_df_verbose_lists_runs_with_reclaimable_marker() {
let context = test_context!();
let run = setup_completed_fast_dry_run(&context);
let output = context
.command()
.args(["system", "df", "-v"])
.output()
.expect("command should run");
assert!(output.status.success(), "system df -v failed");
let stdout = String::from_utf8(output.stdout).expect("stdout should be valid UTF-8");
assert!(
stdout.contains("RUN ID"),
"verbose system df should print the run table: {stdout}"
);
assert!(
stdout.contains(&run.run_id[..12]),
"verbose system df should include the current test run: {stdout}"
);
assert!(
stdout.contains("Simple"),
"verbose system df should include the workflow name: {stdout}"
);
assert!(
stdout.contains("succeeded"),
"verbose system df should include the run status: {stdout}"
);
assert!(
stdout.contains("* = reclaimable"),
"verbose system df should include the reclaimable marker legend: {stdout}"
);
}
#[test]
fn system_df_json_verbose_includes_runs() {
let context = test_context!();
let run = setup_completed_fast_dry_run(&context);
let output = context
.command()
.args(["--json", "system", "df", "--verbose"])
.output()
.expect("command should run");
assert!(output.status.success());
let value: Value = serde_json::from_slice(&output.stdout).expect("system df JSON should parse");
assert!(value["summary"].is_array());
assert!(
value["runs"]
.as_array()
.is_some_and(|runs| runs.iter().any(|entry| entry["run_id"] == run.run_id))
);
}