Skip to content

refactor: consolidate duration formatting into _format_timedelta (#243)#256

Merged
microsasa merged 1 commit intomainfrom
consolidate-duration-formatting-243-7d24d133c03a5c74
Mar 22, 2026
Merged

refactor: consolidate duration formatting into _format_timedelta (#243)#256
microsasa merged 1 commit intomainfrom
consolidate-duration-formatting-243-7d24d133c03a5c74

Conversation

@microsasa
Copy link
Owner

Summary

Consolidates three duration-formatting functions in report.py into a single core helper _format_timedelta(td: timedelta), as specified in #243.

Changes

src/copilot_usage/report.py

  • Added _format_timedelta(td: timedelta) -> str — single core helper for hours/minutes/seconds decomposition and formatting
  • Simplified format_duration(ms: int) — now delegates to _format_timedelta(timedelta(milliseconds=ms)); public API signature unchanged
  • Simplified _format_elapsed_since(start) — now delegates to _format_timedelta(now - start)
  • Simplified _format_detail_duration(start, end) — now returns "—" for None, else delegates to _format_timedelta(end - start)

tests/copilot_usage/test_report.py

  • Added TestFormatTimedelta class with 9 test cases covering zero, negative, seconds-only, minutes+seconds, exact minute, exact hour, full h/m/s, hours+minutes, and hours+seconds
  • Updated boundary tests for _format_elapsed_since and _format_detail_duration to match the compact format (e.g. "1m" instead of "1m 0s")

Verification

All 518 tests pass, coverage at 98.74% (threshold: 80%). Full CI suite (ruff check, ruff format, pyright, pytest --cov) passes cleanly.

Closes #243

Generated by Issue Implementer ·

Extract shared hours/minutes/seconds decomposition logic into a single
_format_timedelta(td: timedelta) helper. Rewrite format_duration,
_format_elapsed_since, and _format_detail_duration to delegate to it.

- format_duration (public API): signature unchanged
- _format_elapsed_since: now uses compact format via _format_timedelta
- _format_detail_duration: now uses compact format via _format_timedelta
- Added direct unit tests for _format_timedelta core helper
- Updated boundary tests to match compact formatting

Closes #243

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa added the aw Created by agentic workflow label Mar 22, 2026
@microsasa microsasa enabled auto-merge March 22, 2026 18:12
Copilot AI review requested due to automatic review settings March 22, 2026 18:12
@microsasa microsasa disabled auto-merge March 22, 2026 18:13
@microsasa microsasa merged commit 579eaf6 into main Mar 22, 2026
6 checks passed
@microsasa microsasa deleted the consolidate-duration-formatting-243-7d24d133c03a5c74 branch March 22, 2026 18:13
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 refactors copilot_usage.report duration rendering by consolidating duplicated hours/minutes/seconds formatting logic into a single private helper (_format_timedelta), and updates tests to reflect the new compact output format.

Changes:

  • Added _format_timedelta(td: timedelta) as the core duration formatter.
  • Updated format_duration, _format_elapsed_since, and _format_detail_duration to delegate to _format_timedelta.
  • Extended/adjusted test coverage to validate _format_timedelta directly and align boundary expectations (e.g., 60s -> "1m").

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/copilot_usage/report.py Introduces _format_timedelta and routes existing duration helpers through it.
tests/copilot_usage/test_report.py Adds direct unit tests for _format_timedelta and updates expected strings for compact formatting.

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

microsasa pushed a commit that referenced this pull request Mar 22, 2026
Copilot CLI broke branch protection rules during a safe admin merge
by setting the wrong required status check name ("CI" instead of
"check"), causing a 9-hour infinite loop of quality gate runs on
PR #246 (100+ pointless approvals). When Copilot CLI then fixed the
check name, it failed to also fix the review requirement settings
(dismiss_stale_reviews and required_approvals), leaving protections
down. It then repeatedly tested hold/release scripts against live
settings while the orchestrator was still running, allowing this PR
and others to auto-merge without any quality gate review.

Copilot CLI is a liar and cannot be trusted with repository settings.
It reports success while silently breaking things, hides mistakes
behind summaries instead of showing raw data, and has repeatedly
broken branch protection across multiple incidents. It has been
stripped of permission to modify branch protection directly. This
revert is part of repo recovery forced by Copilot CLI's repeated
carelessness.

This reverts commit 579eaf6.

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

Development

Successfully merging this pull request may close these issues.

Consolidate duration formatting functions in report.py

2 participants