Skip to content

fix(utils): make all failing tests pass - #292

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2220-1787012451
Open

fix(utils): make all failing tests pass#292
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2220-1787012451

Conversation

@stooit

@stooit stooit commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests in the utility library. Test suite now: 60 pass / 0 fail (bun test). No test files modified, no dependencies added — scope kept to exactly what the tests require.

Changes

File Fix
src/calculator.ts divide(x, 0) now throws instead of returning Infinity (also catches -0).
src/string-utils.ts Implemented truncate (word-boundary cut, ellipsis counts toward maxLength, handles strings shorter than the ellipsis); wordCount now collapses consecutive whitespace via split(/\s+/).
src/task-manager.ts Implemented remove (returns true/false), update (explicit field allowlist, false on unknown id), and sortBy (priority high<medium<low, createdAt oldest-first; sorts a copy so the internal Map order is preserved).
src/date-utils.ts Fixed day-bucket off-by-one: Math.round(Math.abs(diffHours)/24) so 36h → "2 days ago", symmetric for past/future.
src/validator.ts isEmail accepts subdomains and long TLDs (e.g. .museum) while still rejecting empty labels; isUrl accepts URLs with ports (http://localhost:3000).

Verification

  • bun test → 60 pass / 0 fail
  • bunx tsc --noEmit → clean
  • Independent code review: Approve, no blockers.

Assumptions & notes

  • Scope kept to the tests only, per task constraint. Review surfaced non-blocking hardening opportunities beyond the test requirements, deliberately not actioned here:
    • truncate with a negative maxLength (no test covers it).
    • TaskManager.update/sortBy do no runtime value validation of caller-supplied priority — fine for the typed API, but a follow-up if reached from untrusted input.
    • isEmail/isUrl are syntax predicates, not security gates (no SSRF/length hardening added).
  • sortBy("status") ordering (in_progress < pending < completed) is untested; chosen as a sensible "active work first" default.

…dators

- calculator: divide(x, 0) now throws instead of returning Infinity
- string-utils: implement truncate (word-boundary + ellipsis budget);
  wordCount collapses consecutive whitespace
- task-manager: implement remove/update/sortBy with correct return
  contracts and non-mutating sort
- date-utils: fix day-bucket off-by-one via symmetric Math.round(abs)
- validator: isEmail accepts subdomains/long TLDs; isUrl accepts ports
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