fix: resolve 4 bugs in termui - #3503
Conversation
📝 WalkthroughWalkthroughThis change updates four isolated behaviors: whitespace-only paragraph detection, floating-point percentage rounding, reload error logging, and numeric sorting in ChangesChat parsing
Pomodoro rounding
Reload error logging
TreeSelect comparison
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Biome (2.5.5)packages/dev-server/src/server.tsFile contains syntax errors that prevent linting: Line 383: Expected a parenthesis '(' but instead found '=>'. 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: 2
🤖 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 `@packages/dev-server/src/server.ts`:
- Line 383: Fix the rejection handler in the exitedPromise flow by adding a
valid arrow-function parameter and passing the captured rejection reason to
console.error, preserving the existing catch behavior.
In `@packages/ui/src/TreeSelect.ts`:
- Line 185: Update _valuesEqual so both sorted arrays use the same explicit
numeric comparator, replacing the existing sortedA comparator and applying
Number(left) - Number(right) to sortedB as well. Preserve the existing equality
comparison and handling of multi-digit string values.
🪄 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: 939d566f-2da7-41df-96f9-2946f9f08d2f
📒 Files selected for processing (4)
examples/chat-app/src/index.tsxexamples/pomodoro-timer/src/index.tsxpackages/dev-server/src/server.tspackages/ui/src/TreeSelect.ts
| this._killChild(); | ||
|
|
||
| await exitedPromise.catch(() => {}); | ||
| await exitedPromise.catch( => console.error()); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Fix the invalid arrow function syntax.
The arrow function ( => console.error()) is missing its parameter list. This is a syntax error and will fail to parse.
Biome confirms this: "Expected a parenthesis '(' but instead found '=>'."
Also pass the rejection reason to console.error, otherwise the log gives no information about the failure.
🐛 Proposed fix
- await exitedPromise.catch( => console.error());
+ await exitedPromise.catch((err) => console.error(err));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| await exitedPromise.catch( => console.error()); | |
| await exitedPromise.catch((err) => console.error(err)); |
🧰 Tools
🪛 Biome (2.5.5)
[error] 383-383: Expected a parenthesis '(' but instead found '=>'.
(parse)
🤖 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 `@packages/dev-server/src/server.ts` at line 383, Fix the rejection handler in
the exitedPromise flow by adding a valid arrow-function parameter and passing
the captured rejection reason to console.error, preserving the existing catch
behavior.
Source: Linters/SAST tools
| function _valuesEqual(a: string[], b: string[]): boolean { | ||
| if (a.length !== b.length) return false; | ||
| const sortedA = [...a].sort(); | ||
| const sortedA = [...a].sort((a, b) => a - b); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
file="packages/ui/src/TreeSelect.ts"
# Confirm both arrays use the same comparator.
rg -n -C 2 'sortedA|sortedB|sort\(' "$file"
# Locate the repository's declared type-check command.
rg -n '"(typecheck|type-check|build)"' package.json packages/ui/package.json 2>/dev/null || trueRepository: Karanjot786/TermUI
Length of output: 740
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
file="packages/ui/src/TreeSelect.ts"
sed -n '160,195p' "$file"
echo '---'
sed -n '1,60p' "$file"
echo '---'
node - <<'JS'
const a = ["2", "10"];
const b = ["10", "2"];
const sortedA = [...a].sort((x, y) => x - y);
const sortedB = [...b].sort();
console.log(JSON.stringify({a, b, sortedA, sortedB}));
console.log(sortedA.every((v, i) => v === sortedB[i]));
JSRepository: Karanjot786/TermUI
Length of output: 3502
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
node - <<'TS'
// Read-only behavioral probe for JavaScript subtraction order on strings.
// This does not execute repository code; it only exercises runtime semantics.
const cases = [
[
["2", "10"],
["10", "2"]
],
[
["10", "2"],
["2", "10"]
],
[
["1", "20", "3"],
["3", "20", "1"],
],
];
for (const [a, b] of cases) {
const sortedA = [...a].sort((a, b) => a - b);
const sortedB = [...b].sort();
console.log(JSON.stringify({
a,
b,
sortedA,
sortedB,
equal: sortedA.every((v, i) => v === sortedB[i])
}));
}
TSRepository: Karanjot786/TermUI
Length of output: 436
Use a shared numeric comparator for both value arrays.
_valuesEqual uses different sort orders: sortedA uses numeric coercion through subtraction, while sortedB uses default lexicographic ordering. Equal selections with multi-digit values, such as ["2", "10"] and ["10", "2"], compare unequal. Replace the string subtraction with an explicit Number(left) - Number(right) comparator applied to both arrays.
🤖 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 `@packages/ui/src/TreeSelect.ts` at line 185, Update _valuesEqual so both
sorted arrays use the same explicit numeric comparator, replacing the existing
sortedA comparator and applying Number(left) - Number(right) to sortedB as well.
Preserve the existing equality comparison and handling of multi-digit string
values.
Source: Coding guidelines
Description
This PR fixes real bugs found in the codebase:
.sort()coerces elements to strings, so[10, 9, 2]sorts as[10, 2, 9]; numeric comparator sorts correctly.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: #3502
Summary by CodeRabbit