Skip to content

test: add CLI integration tests with assert_cmd #161

@rocketman-code

Description

@rocketman-code

Context

Parent: #160

The binary crate has ~320 lines of CLI dispatch logic in main.rs with ~1% test coverage. Functions like run_trace(), run_diff(), run_packages(), build_snapshot_from_working_tree(), and build_snapshot_from_ref() have zero tests. Three of eleven v0.4.0 bugs lived here (#142, #148, #150).

Expected Behavior

End-to-end tests that invoke the chainsaw binary with real arguments and assert on stdout, stderr, and exit codes.

Scope

  • Add assert_cmd (and optionally predicates) as dev-dependencies
  • Create tests/cli.rs integration test file
  • Cover at minimum:
    • trace <entry> produces expected output format
    • trace --json <entry> produces valid JSON with expected field names
    • trace --chain <entry> <target> finds import chains
    • trace --cut <entry> <target> finds cut points
    • trace --max-weight <n> <entry> returns error when exceeded
    • diff <ref> with --entry produces diff output
    • diff --json <ref> --entry <entry> produces valid JSON
    • packages <entry> lists packages
    • packages --json <entry> produces valid JSON
    • Invalid flag combinations return non-zero exit code with helpful error message
    • Missing entry file returns non-zero exit code
  • Use a small fixture project (2-3 .ts files) committed under tests/fixtures/

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Critical priorityenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions