Skip to content

test: cover untested branches in cli.py (#59)#61

Closed
microsasa wants to merge 1 commit intomainfrom
fix/59-untested-cli-branches-fee71a584adc1b7a
Closed

test: cover untested branches in cli.py (#59)#61
microsasa wants to merge 1 commit intomainfrom
fix/59-untested-cli-branches-fee71a584adc1b7a

Conversation

@microsasa
Copy link
Owner

Closes #59

Adds 14 new tests covering all untested branches identified in the issue:

1. Auto-refresh branches (_interactive_loop lines 169–185)

  • test_auto_refresh_home_view — pre-sets change_event while in home view, asserts _draw_home is re-called
  • test_auto_refresh_cost_view — navigates to cost view, fires change_event, asserts render_cost_view called twice
  • test_auto_refresh_detail_view — navigates to detail view, fires change_event, asserts _show_session_by_index called twice

2. Uppercase commands (Q, C, R)

  • test_interactive_quit_uppercase — input "Q\n", exit code 0
  • test_interactive_cost_view_uppercase — input "C\nq\n", asserts "Cost" in output
  • test_interactive_refresh_uppercase — input "R\nq\n", exit code 0

3. events_path=None branch

  • test_show_session_by_index_events_path_noneSessionSummary(events_path=None) → "No events path" message

4. Group-level --path propagation

  • test_group_path_propagates_to_summary
  • test_group_path_propagates_to_session
  • test_group_path_propagates_to_cost
  • test_group_path_propagates_to_live

5. _ensure_aware unit tests

  • test_none_returns_noneNoneNone
  • test_aware_datetime_unchanged — already-aware → same object
  • test_naive_datetime_gets_utc — naive → UTC-attached

Results

  • All 394 tests pass (51 in test_cli.py)
  • Coverage: 78% → 98% (well above 80% threshold)
  • ruff checkruff formatpyright

Generated by Issue Implementer ·

Warning

⚠️ Firewall blocked 1 domain

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

  • astral.sh

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

network:
  allowed:
    - defaults
    - "astral.sh"

See Network Configuration for more information.

@microsasa microsasa added the aw Created by agentic workflow label Mar 15, 2026
Copilot AI review requested due to automatic review settings March 15, 2026 05:36
@microsasa microsasa enabled auto-merge March 15, 2026 05:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the CLI test suite to cover previously untested branches in copilot_usage/cli.py (interactive auto-refresh paths, uppercase commands, events_path=None, group-level --path propagation, and _ensure_aware).

Changes:

  • Add direct unit tests for _ensure_aware and _show_session_by_index when events_path=None.
  • Add interactive-mode tests for uppercase commands and auto-refresh behavior across views.
  • Add tests intended to verify group-level --path propagation to subcommands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +848 to +851
return original_start_observer(session_path, change_event)

monkeypatch.setattr("copilot_usage.cli._start_observer", _capture_event_start)

Comment on lines +682 to +685
result = runner.invoke(main, ["--path", str(tmp_path), "summary"])
assert result.exit_code == 0
assert "GroupSum" in result.output or "Summary" in result.output

Comment on lines +691 to +700
def _fake_discover(_base_path: Path | None = None) -> list[Path]:
return sorted(
tmp_path.glob("*/events.jsonl"),
key=lambda p: p.stat().st_mtime,
reverse=True,
)

monkeypatch.setattr("copilot_usage.cli.discover_sessions", _fake_discover)
runner = CliRunner()
result = runner.invoke(main, ["--path", str(tmp_path), "session", "grpd0000"])
)
runner = CliRunner()
result = runner.invoke(main, ["--path", str(tmp_path), "live"])
assert result.exit_code == 0
_write_session(tmp_path, "upq00000-0000-0000-0000-000000000000", name="QuitUpper")
runner = CliRunner()
result = runner.invoke(main, ["--path", str(tmp_path)], input="Q\n")
assert result.exit_code == 0
)
runner = CliRunner()
result = runner.invoke(main, ["--path", str(tmp_path)], input="R\nq\n")
assert result.exit_code == 0
Comment on lines +762 to +763
return original_start_observer(session_path, change_event)

Comment on lines +792 to +797
session_path: Path, change_event: threading.Event
) -> object:
nonlocal event_ref
event_ref = change_event
return original_start_observer(session_path, change_event)

Add tests for:
- Auto-refresh branches (home, cost, detail views)
- Uppercase interactive commands (Q, C, R)
- _show_session_by_index with events_path=None
- Group-level --path propagation to all subcommands
- _ensure_aware unit tests (None, aware, naive)

Coverage increased from 78% to 98%.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa force-pushed the fix/59-untested-cli-branches-fee71a584adc1b7a branch from ffe1a3b to a000e9b Compare March 15, 2026 05:53
@microsasa microsasa requested a review from Copilot March 15, 2026 05:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds targeted tests to cover previously untested branches in copilot_usage/cli.py, addressing Issue #59 and significantly increasing branch coverage for interactive-mode behaviors and small helper branches.

Changes:

  • Add unit tests for _ensure_aware and _show_session_by_index when events_path=None.
  • Add interactive-mode tests for uppercase commands (Q, C, R) and auto-refresh behavior across home/cost/detail views.
  • Add tests validating group-level --path propagation to subcommands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +753 to +760
event_ref: threading.Event | None = None
original_start_observer = cli_mod._start_observer # pyright: ignore[reportPrivateUsage]

def _capture_event_and_start(
session_path: Path, change_event: threading.Event
) -> object:
nonlocal event_ref
event_ref = change_event
_write_session(tmp_path, "upq00000-0000-0000-0000-000000000000", name="QuitUpper")
runner = CliRunner()
result = runner.invoke(main, ["--path", str(tmp_path)], input="Q\n")
assert result.exit_code == 0
)
runner = CliRunner()
result = runner.invoke(main, ["--path", str(tmp_path)], input="R\nq\n")
assert result.exit_code == 0
runner = CliRunner()
result = runner.invoke(main, ["--path", str(tmp_path), "summary"])
assert result.exit_code == 0
assert "GroupSum" in result.output or "Summary" in result.output
runner = CliRunner()
result = runner.invoke(main, ["--path", str(tmp_path), "cost"])
assert result.exit_code == 0
assert "Cost" in result.output or "Total" in result.output
Comment on lines +730 to +731


@microsasa
Copy link
Owner Author

Closing stale PR. Will re-dispatch implementer once pipeline improvements land (issue #86).

@microsasa microsasa closed this Mar 15, 2026
auto-merge was automatically disabled March 15, 2026 18:52

Pull request was closed

@microsasa microsasa deleted the fix/59-untested-cli-branches-fee71a584adc1b7a branch March 15, 2026 18:52
microsasa pushed a commit that referenced this pull request Mar 15, 2026
Remove labels: ["aw"] from issue-implementer create-pull-request
config. The config-level labels feature has a gh-aw runtime bug where
the post-creation label API call fails with a node ID resolution error.
This caused PR #104 to be created without the aw label.

Reverts the labels portion of PR #97. The agent instruction to add the
aw label remains and works reliably (worked for PRs #61-91).

Closes #107, refs #108

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow

Projects

None yet

2 participants