fix: repair 16 failing tests across utility-library modules - #288
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator.divide: throw on division by zero instead of returning Infinity - string-utils.wordCount: split on /\s+/ (trimmed) to ignore consecutive spaces - string-utils.truncate: implement word-boundary truncation with ellipsis budget - task-manager: implement remove/update (unknown-id false) and sortBy ranking - date-utils.formatRelative: round hours->days so 36h reads as 2 days ago - validator.isEmail: accept subdomains and long TLDs; validator.isUrl: allow ports
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.
Summary
Repairs all 16 failing tests across the 5 utility modules so the full suite passes (60 pass, 0 fail). No test files were modified and no dependencies were added — each fix targets the documented root cause the tests exercise.
Changes
src/calculator.ts—dividethrowsError("Division by zero")when the divisor is0(previously returnedInfinity). Guard placed before the division so-0divisors are also caught.src/string-utils.tswordCountsplits the trimmed string on/\s+/, so runs of consecutive spaces no longer count as phantom words.truncateimplemented: returns input unchanged when withinmaxLength; otherwise reserves 3 chars for the ellipsis, cuts back to the last word boundary within budget (hard cut when no space), and appends"...". Result is always<= maxLength.src/task-manager.ts—removereturnstrue/falseon hit/miss;updatereturnsfalsefor unknown ids and applies only explicitly-present fields;sortBysorts a copy using explicit priority/status rank maps and ascendingcreatedAt, relying on stable sort for tie order.src/date-utils.ts—formatRelativerounds hours→days (Math.round(abs/24)) so exactly 36h reads as "2 days ago";abskeeps past/future symmetric.src/validator.ts—isEmailaccepts dot-separated subdomains and long alphabetic TLDs (e.g..museum) with hyphen-anchored labels;isUrldrops the spurious empty-port check while keeping the http/https allowlist.Verification
bun test→ 60 pass, 0 fail (5 files)npx tsc --noEmit→ cleansrc/files changed; no test files touched.Review notes (out of scope — tests do not require)
A review pass flagged edge cases beyond the test suite, left unaddressed to keep this change tightly scoped to "fix only what the tests require". Worth a follow-up if these paths matter:
truncate+ non-ASCII —sliceoperates on UTF-16 code units, so a budget landing mid-surrogate-pair can emit a lone surrogate (e.g. splitting an emoji). Use code-point-safe slicing if inputs may contain non-BMP characters.updatecannot clear an optional field — the!== undefinedguard meansupdate(id, { description: undefined })is a no-op; there's no way to unset a description. Switch to an"description" in changescheck if clearing should be supported. (Semantic decision, deliberately left to maintainers.)truncatetiny budget — whenmaxLength < ~4the ellipsis is dropped, so truncated output is indistinguishable from a complete string. Defensible but undocumented.isEmail/isUrlare validators, not security guards —isEmailaccepts anything non-space in the local part (not an XSS escaper);isUrlreturns true forhttp://localhost:3000and internal hosts (not an SSRF guard). If either validates untrusted input the server then acts on, add the appropriate allowlist/escaping separately.Assumptions