fix: resolve 4 bugs in termui - #3712
Conversation
📝 WalkthroughWalkthroughThe PR updates calculator empty-expression validation and adds ChangesNumeric edge-case handling
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: Replace the scaled-value-plus-Number.EPSILON rounding at
examples/pomodoro-timer/src/index.tsx:185 and
packages/dev-server/src/devtools.ts:81 with a shared deterministic
two-decimal-place rounding/formatting helper; update the label calculation in
the visible label expression and the corresponding sibling expression,
preserving percentage output while avoiding unscaled epsilon arithmetic.
🪄 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: d38e01af-ad19-4918-aaf6-78735fe08de8
📒 Files selected for processing (3)
examples/calculator/src/index.tsxexamples/pomodoro-timer/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
printf 'Relevant file locations and lines:\n'
fd -a 'index.tsx|devtools.ts' . | sed 's#^\./##' | while read -r f; do
case "$f" in
examples/pomodoro-timer/src/index.tsx|packages/dev-server/src/devtools.ts)
echo "== $f =="
nl -ba "$f" | sed -n '75,90p;175,192p'
;;
esac
done
printf '\nSearch for Number.EPSILON usage:\n'
rg -n "Number\.EPSILON|FPS|_value|fps" examples/pomodoro-timer/src/index.tsx packages/dev-server/src/devtools.ts || true
printf '\nBehavioral probe for edge/floating cases:\n'
node - <<'JS'
const inputs = {
percentage: [0.2929999999999997, 0.293, 0.9940000000000002],
fps: [14.144999999999997, 14.145, 14.144000000000002],
};
for (const [name, values] of Object.entries(inputs)) {
console.log(name);
for (const v of values) {
let out;
if (name === 'percentage') {
out = {current: Math.round(v * 100 + Number.EPSILON), proposed: Math.round((v + Number.EPSILON) * 100)};
} else {
out = {current: Math.round(v * 10 + Number.EPSILON) / 10, proposed: Math.round((v + Number.EPSILON) * 10) / 10};
}
console.log(`${v} -> current ${out.current}, proposed ${out.proposed}`);
}
}
JSRepository: Karanjot786/TermUI
Length of output: 1818
Use a deterministic rounding helper instead of adding Number.EPSILON after scaling.
Both expressions multiply the value, add one unscaled epsilon, then round. That works at the tested boundary values, but unscaled Number.EPSILON is too small to correct errors after scaling is applied. A deterministic 2 decimal-places formatter/rounding helper is clearer and avoids similar edge-case rounding mistakes.
📍 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, Replace the
scaled-value-plus-Number.EPSILON rounding at
examples/pomodoro-timer/src/index.tsx:185 and
packages/dev-server/src/devtools.ts:81 with a shared deterministic
two-decimal-place rounding/formatting helper; update the label calculation in
the visible label expression and the corresponding sibling expression,
preserving percentage output while avoiding unscaled epsilon arithmetic.
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).trim()to''misses whitespace-only input;.trim().length === 0is explicit.Type of Change
How Has This Been Tested?
Checklist
Related Issue
Ref: #3711
Summary by CodeRabbit