Skip to content

[aw][test audit] Group-level --path option propagation to subcommands is untested #60

@microsasa

Description

@microsasa

Root Cause

Each subcommand (summary, session, cost, live) contains this fallback line:

path = path or ctx.obj.get("path")

This allows users to pass --path at the group level (e.g. copilot-usage --path /dir summary) instead of at the subcommand level. The main group stores the option in ctx.obj["path"], and each subcommand reads it back when its own --path is absent.

Every existing test passes --path directly to the subcommand:

runner.invoke(main, ["summary", "--path", str(tmp_path)])  # subcommand-level ✓
runner.invoke(main, ["cost",    "--path", str(tmp_path)])  # subcommand-level ✓

No test ever passes --path at the group level and omits it from the subcommand:

runner.invoke(main, ["--path", str(tmp_path), "summary"])  # group-level — untested ✗

If the path = path or ctx.obj.get("path") line were removed from any subcommand, or if ctx.ensure_object(dict) / ctx.obj["path"] = path were accidentally dropped from main, all existing tests would still pass — the regression would be invisible.

Expected Behaviour to Assert

The group-level --path must propagate identically to the subcommand-level --path for all four subcommands.

Tests to add in tests/copilot_usage/test_cli.py:

def test_summary_group_path_propagation(tmp_path: Path) -> None:
    """summary reads --path from group level when not provided at subcommand level."""
    _write_session(tmp_path, "grp10000-0000-0000-0000-000000000000", name="GroupPath")
    runner = CliRunner()
    # --path before subcommand name → stored in ctx.obj, not subcommand
    result = runner.invoke(main, ["--path", str(tmp_path), "summary"])
    assert result.exit_code == 0
    assert "GroupPath" in result.output


def test_cost_group_path_propagation(tmp_path: Path) -> None:
    _write_session(tmp_path, "grp20000-0000-0000-0000-000000000000", name="CostGroup")
    runner = CliRunner()
    result = runner.invoke(main, ["--path", str(tmp_path), "cost"])
    assert result.exit_code == 0


def test_live_group_path_propagation(tmp_path: Path) -> None:
    _write_session(
        tmp_path, "grp30000-0000-0000-0000-000000000000", name="LiveGroup", active=True
    )
    runner = CliRunner()
    result = runner.invoke(main, ["--path", str(tmp_path), "live"])
    assert result.exit_code == 0


def test_session_group_path_propagation(tmp_path: Path) -> None:
    sid = "grp40000-0000-0000-0000-000000000000"
    _write_session(tmp_path, sid, name="SessGroup")
    runner = CliRunner()
    # session needs the session_id positional argument
    result = runner.invoke(main, ["--path", str(tmp_path), "session", sid[:8]])
    assert result.exit_code == 0

Regression Scenarios

  • User runs copilot-usage --path /my/dir summary from the CLI — group-level path must propagate correctly
  • If ctx.obj["path"] = path were accidentally removed from main, all subcommands would fall back to their default path (None → user's ~/.copilot/session-state) even when --path was explicitly specified at group level

Generated by Test Suite Analysis ·

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • pypi.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "pypi.org"

See Network Configuration for more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    awCreated by agentic workflowaw-dispatchedIssue has been dispatched to implementertest-auditTest coverage gaps

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions