Skip to content

F-027: fix(history): round percentage conversion instead of truncating#27

Open
Sephyi wants to merge 1 commit intodevelopmentfrom
audit/f-027-history-round-cast
Open

F-027: fix(history): round percentage conversion instead of truncating#27
Sephyi wants to merge 1 commit intodevelopmentfrom
audit/f-027-history-round-cast

Conversation

@Sephyi
Copy link
Copy Markdown
Owner

@Sephyi Sephyi commented Apr 22, 2026

Summary

fix(history): round percentage conversion instead of truncating.

Audit context

Closes audit entry F-027 from #3.

Verification

  • cargo fmt --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-targets

Note: one pre-existing test porcelain_exits_within_timeout_with_no_staged_changes is a known macOS cold-start flake that reproduces on unmodified development — unrelated to this change.

The commit-type percentage shown in the project-style prompt section
was computed by truncating a float cast (`as u32`), which discards the
fractional part — 66.666% became 66% instead of 67%. Replace the
truncating cast with `.round() as u32` so percentages round to the
nearest integer, matching what users reading the prompt would expect.

Add a unit test covering the round-up case (2/3 → 67%) alongside the
exact-percentage case (1/3 → 33%) to guard against accidental
regression to truncation.

Closes audit entry F-027 from #3.
Copilot AI review requested due to automatic review settings April 22, 2026 19:51
@Sephyi Sephyi added the audit Codebase audit cleanup (issue #3) label Apr 22, 2026
@Sephyi Sephyi self-assigned this Apr 22, 2026
Copy link
Copy Markdown

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 addresses audit finding F-027 by changing how commit-type distribution percentages are computed in the history prompt section: percentages are now rounded instead of truncated, improving accuracy in the generated style summary.

Changes:

  • Update type distribution percentage calculation to use rounding (round()) rather than truncation via float-to-int cast.
  • Add a regression test ensuring to_prompt_section() reflects rounded percentages (e.g., 2/3 → 67%).

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit Codebase audit cleanup (issue #3)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants