fix(desktop): clamp Goal.progress to its documented 0-100 range#8003
Draft
eulicesl wants to merge 3 commits into
Draft
fix(desktop): clamp Goal.progress to its documented 0-100 range#8003eulicesl wants to merge 3 commits into
eulicesl wants to merge 3 commits into
Conversation
current_value below min_value produced a negative percentage that leaked into the goal progress ring (Path.trim) and the "% complete" prompt text. Callers only clamped the upper bound, so clamp at the source instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K6oBTTKdSzfrvKNg1yXnuB
Adds GoalProgressTests: mid-range, below-min clamps to 0 (the regression), overachievement clamps to 100, and the target==min divide-by-zero guard. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K6oBTTKdSzfrvKNg1yXnuB
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K6oBTTKdSzfrvKNg1yXnuB
11644e8 to
ec9eb41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Goal.progress(indesktop/macos/Desktop/Sources/APIClient.swift) is documented as returning a percentage in the range 0-100, but it only guarded against divide-by-zero — it did not clamp the result:When
currentValueis belowminValue(e.g. a goal whose baseline is above zero, or a value that regresses below its starting point), this returns a negative percentage. Consumers only clamp the upper bound:MainWindow/Components/GoalsWidget.swift:164→min(goal.progress / 100.0, 1.0)MainWindow/Components/GoalsWidget.swift:775→.trim(from: 0, to: min(goal.progress / 100, 1.0))ProactiveAssistants/.../TaskPrioritizationService.swift:185→"(\(Int(goal.progress))% complete)"So a negative value passes straight through:
Path.trim(from: 0, to: <negative>)renders an empty/inverted arc, and the prompt text reads e.g."(-40% complete)".Fix
Clamp at the source so the getter honors its own
0-100contract:For all in-range values the output is identical — only out-of-range inputs change, toward the documented contract. Existing caller-side upper-bound clamps are left in place (harmless/defensive).
Tests
Adds
Desktop/Tests/GoalProgressTests.swift(decoder-based, matching the repo's existing test style):currentValue < minValue→ 0 (the regression)currentValue > targetValue→ 100targetValue == minValue→ 0 (divide-by-zero guard)Verification
xcrun swift test --package-path Desktop --filter GoalProgressTests) / CI to confirm.Draft until a macOS build/test pass confirms it green.
🤖 Generated with Claude Code
Generated by Claude Code