Skip to content

fix: repair failing utility tests and implement missing functions - #336

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2172-1789000640
Open

fix: repair failing utility tests and implement missing functions#336
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2172-1789000640

Conversation

@stooit

@stooit stooit commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 previously-failing tests (60/60 pass, tsc --noEmit clean). Changes are confined to src/; no test files were modified and no dependencies added.

Changes

  • calculator.tsdivide now throws on a zero divisor (b === 0, catches -0) instead of returning Infinity.
  • string-utils.tswordCount splits the trimmed string on /\s+/ (fixes consecutive spaces, tabs, newlines). truncate implemented: returns unchanged when str.length <= maxLength; otherwise reserves 3 chars for "...", cuts at the last word boundary within budget, trims trailing whitespace, and clamps negative maxLength to "".
  • task-manager.tsremove delegates to Map.delete; update returns false for unknown ids and applies only supplied keys; sortBy ranks priority (high>medium>low) and status, numeric compare on createdAt (stable sort preserves insertion order).
  • date-utils.ts — day bucket uses Math.round(Math.abs(diffHours)/24) (abs before round), fixing the off-by-one so 36h reads "2 days ago" and future dates are symmetric.
  • validator.tsisEmail accepts arbitrarily many dot-separated domain labels with 2+ char TLDs (still rejects empty labels, trailing dots, bare domains); isUrl drops the spurious port === "" condition while keeping the protocol allowlist.

Testing

`bun test` → 60 pass / 0 fail. Independent review pass confirmed no logical/coincidental-pass issues (verdict: no blockers).

Assumptions & notes

  • Fixed only what the tests require, per task constraints. Left `isUsername`/`isAustralianPhone` untouched (their tests already passed).
  • `sortBy("status")` ordering (in_progress > pending > completed) is not covered by a test; chose "most active first".
  • `isEmail`/`isUrl` are format validators, not sanitisers/SSRF gates — callers guarding a trust boundary need a separate host allowlist and output encoding.

- calculator: divide throws on zero divisor instead of returning Infinity
- string-utils: wordCount splits on whitespace runs; implement truncate at
  word boundary with ellipsis counting toward maxLength (clamp negative len)
- task-manager: implement remove/update/sortBy semantics
- date-utils: round day bucket (abs before round) fixing off-by-one
- validator: isEmail accepts multi-label domains; isUrl drops spurious port check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant