fix: resolve 4 bugs in termui - #3678
Conversation
📝 WalkthroughWalkthroughThe changes adjust percentage and FPS rounding with ChangesFloating-point rounding fixes
Weather refresh scheduling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/pomodoro-timer/src/index.tsx`:
- Line 185: Update the percent-label rounding in
examples/pomodoro-timer/src/index.tsx at lines 185-185 to add Number.EPSILON
scaled relative to this._value * 100 before Math.round; apply the same
magnitude-aware epsilon pattern to the fps * 10 rounding in
packages/dev-server/src/devtools.ts at lines 81-81.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3f2298c8-80d8-4799-82bb-e64195c824a7
📒 Files selected for processing (3)
examples/pomodoro-timer/src/index.tsxexamples/weather/src/index.tsxpackages/dev-server/src/devtools.ts
| const attrs = styleToCellAttrs(this._style); | ||
|
|
||
| const label = this._showLabel ? ` ${Math.round(this._value * 100)}%` : ''; | ||
| const label = this._showLabel ? ` ${Math.round(this._value * 100 + Number.EPSILON)}%` : ''; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate files =="
fd -a 'index.tsx|devtools.ts' . | sed 's#^\./##'
echo "== relevant lines =="
sed -n '170,190p' examples/pomodoro-timer/src/index.tsx 2>/dev/null || true
sed -n '70,90p' packages/dev-server/src/devtools.ts 2>/dev/null || true
echo "== surrounding declarations/usages =="
rg -n "_showLabel|_value|fps:|Number\.EPSILON|0\.145|toFixed|Math\.round" examples/pomodoro-timer/src/index.tsx packages/dev-server/src/devtools.ts packages -g '*.{ts,tsx}' 2>/dev/null | head -200
echo "== JS numeric behavior probe =="
node - <<'JS'
const cases = [
{name:'progress 0.145', value:0.145, scale:100},
{name:'fps 14.5', value:14.5, scale:10},
{name:'boundary around .5', value:0.5, scale:1},
{name:'negative scaled .5', value:-0.5, scale:10},
];
for (const c of cases) {
const scaled = c.value * c.scale;
const current = Math.round(c.value * c.scale * 100 + Number.EPSILON) / 100;
const naive = Math.round(scaled + Number.EPSILON);
const magnitudeAware = Math.round(scaled + Number.EPSILON * Math.max(1, Math.abs(scaled)));
const epsilonBefore = Math.round((c.value + Number.EPSILON) * c.scale);
console.log(JSON.stringify({
name:c.name, scaled, current, naive, magnitudeAware, epsilonBefore,
}));
}
console.log({
exact0145Scaled: 0.145*100,
eps: Number.EPSILON,
roundScalesEps: Math.round(0.145*100 + Number.EPSILON),
roundScalesEpsTimes100: Math.round(0.145*100 + Number.EPSILON) / 100,
});
JSRepository: Karanjot786/TermUI
Length of output: 22481
Use a magnitude-aware epsilon in both rounding paths.
Add epsilon relative to the scaled operand so the fix covers floating-point rounding errors across the full numeric range.
examples/pomodoro-timer/src/index.tsx#L185: Roundthis._value * 100with a scaled epsilon before rendering the percent label.packages/dev-server/src/devtools.ts#L81: Roundfps * 10with the same scaled epsilon pattern.
📍 Affects 2 files
examples/pomodoro-timer/src/index.tsx#L185-L185(this comment)packages/dev-server/src/devtools.ts#L81-L81
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@examples/pomodoro-timer/src/index.tsx` at line 185, Update the percent-label
rounding in examples/pomodoro-timer/src/index.tsx at lines 185-185 to add
Number.EPSILON scaled relative to this._value * 100 before Math.round; apply the
same magnitude-aware epsilon pattern to the fps * 10 rounding in
packages/dev-server/src/devtools.ts at lines 81-81.
Description
This PR fixes real bugs found in the codebase:
Number.EPSILONtoMath.round: prevents floating-point drift (e.g.1.005 * 100rounding to 100 instead of 101).trim()to''misses whitespace-only input;.trim().length === 0is explicit.Number.EPSILONtoMath.round: prevents floating-point drift (e.g.1.005 * 100rounding to 100 instead of 101).Type of Change
How Has This Been Tested?
Checklist
Related Issue
Ref: #3677
Summary by CodeRabbit