fix: repair 16 failing tests across utility library - #301
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide now throws on division by zero instead of returning Infinity - string-utils: wordCount splits on \s+ (collapses consecutive whitespace); implement truncate with word-boundary breaking, ellipsis budget, and guaranteed output length <= maxLength - task-manager: implement TaskManager.remove, update, and sortBy (priority/status/createdAt ordering) - date-utils: formatRelative rounds day deltas (Math.round on abs hours) so 36h reads as '2 days ago' and past/future are symmetric - validator: isEmail accepts long TLDs and multi-level subdomains; isUrl accepts URLs with ports (protocol allow-list still enforced) All 60 tests pass. No test files or dependencies modified.
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
Fixes all 16 failing tests across the TypeScript utility library. 60/60 tests now pass (was 44 pass / 16 fail). No test files modified, no dependencies added.
Changes by file
src/calculator.ts—dividethrowsError("Division by zero")when the divisor is0instead of returningInfinity. Theb === 0guard also covers-0.src/string-utils.tswordCountsplits on/\s+/against the trimmed string, so consecutive spaces/tabs/newlines collapse correctly.truncateimplemented: returns input unchanged when withinmaxLength; otherwise takes amaxLength - 3budget, backs up to the last whitespace (regex/\s\S*$/, consistent withwordCount), and appends"...". Output is guaranteed<= maxLength, including whenmaxLength <= 3.src/task-manager.ts— implemented three stubbed methods:remove— deletes by id, returnstrue/false.update— returnsfalsefor unknown ids; applies only explicitly-present fields (!== undefined) so omitted keys don't clobber existing values.sortBy— rank tables forpriority(high→medium→low) andstatus, timestamp comparison forcreatedAt. Non-mutating (copies before sort); stable sort preserves insertion order on ties.src/date-utils.ts—formatRelativerounds day deltas withMath.round(Math.abs(diffHours) / 24), so 36 hours reads as "2 days ago" and past/future directions are symmetric.src/validator.tsisEmail— TLD cap widened from{2,4}to{2,}and domain modelled as explicit labels, so.museumand multi-level subdomains validate; labels can't start/end with a hyphen.isUrl— dropped theport === ""restriction (it wrongly rejectedhttp://localhost:3000); thehttp/httpsprotocol allow-list still enforces the intended restriction.Verification
bun test→ 60 pass, 0 fail (70 assertions, 5 files)tsc --noEmit→ cleanreviewsubagent (verdict: no blockers). Two consistency Warnings it raised —formatRelativefuture-direction asymmetry andtruncatewhitespace handling — were fixed in the second commit.Assumptions
sortBy("status")ordering (pending→in_progress→completed) is not covered by tests; chose the natural lifecycle order.updatecannot clear a field toundefined(an absent key and an explicitundefinedare indistinguishable) — only matters if clearing is ever required.Notes for follow-up (out of scope, not blocking)
isEmail/isUrlare syntactic format checks, not security boundaries —isUrlaccepts any http(s) host and should not be relied on as an SSRF control.