Skip to content

fix: repair all failing tests in utility library - #300

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2526-1787414863
Open

fix: repair all failing tests in utility library#300
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2526-1787414863

Conversation

@stooit

@stooit stooit commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across the 5 utility modules. Result: 60 pass / 0 fail (bun test), tsc --noEmit clean. No test files modified, no dependencies added.

Changes

  • src/calculator.tsdivide throws on a zero divisor instead of returning Infinity (b === 0 also catches -0).
  • src/string-utils.ts — implemented truncate (returns unchanged within limit; reserves 3 chars for ellipsis; cuts at last word boundary within budget, hard-cuts when no space or maxLength <= 3, output length never exceeds maxLength). wordCount now splits on /\s+/ so consecutive whitespace collapses.
  • src/task-manager.ts — implemented remove (bool via Map.delete), update (returns false for unknown id; applies only fields present in changes), and sortBy (priority high>medium>low, createdAt oldest-first; sorts a copy, does not mutate state).
  • src/date-utils.tsformatRelative day calc uses Math.round instead of Math.floor, fixing the off-by-one so 36h → "2 days ago".
  • src/validator.tsisEmail TLD quantifier relaxed {2,4}{2,} (allows .museum); isUrl no longer requires an empty port, so http://localhost:3000 validates.

Verification

  • bun test: 60 pass / 0 fail, stable across repeated runs
  • tsc --noEmit: clean
  • Reviewed by review subagent: verdict COMMENT, no blockers — confirmed fixes address root causes with general logic, not test-input pattern-matching, and no test files were touched.

Assumptions & notes (non-blocking)

  • sortBy("createdAt") includes a numeric-id tiebreaker for determinism when two tasks land in the same millisecond. Relies on add() generating numeric string ids.
  • sortBy status ordering (in_progress < pending < completed) is unspecified by tests — a reasonable default chosen for completeness.
  • update uses !== undefined checks (patch semantics), so optional fields can't be cleared to undefined via a partial update.
  • isEmail remains a permissive shape check, not RFC 5322 validation — consistent with the test expectations.

- calculator: divide now throws on zero divisor instead of returning Infinity
- string-utils: implement truncate; wordCount collapses consecutive whitespace
- task-manager: implement remove/update/sortBy methods
- date-utils: formatRelative uses Math.round to fix off-by-one at day boundaries
- validator: isEmail allows long TLDs (.museum); isUrl allows 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