Skip to content

fix: repair 16 failing tests across utility library - #316

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2169-1788366048
Open

fix: repair 16 failing tests across utility library#316
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2169-1788366048

Conversation

@stooit

@stooit stooit commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across 5 source files in the utility library. bun test now reports 60 pass / 0 fail. No test files were modified and no dependencies were added.

Changes

  • src/calculator.tsdivide throws Error("Division by zero") on a zero divisor instead of returning Infinity.
  • src/string-utils.ts
    • wordCount splits on /\s+/ against the trimmed string so consecutive/mixed whitespace collapses correctly.
    • truncate implemented: returns input unchanged when within maxLength; otherwise cuts to the last word boundary and appends "...", keeping the result within maxLength. Hard-slices when maxLength <= 3.
  • src/task-manager.ts — implemented remove (returns hit/miss), update (partial update, guards each field, false on unknown id), and sortBy (priority high>medium>low, status pending>in_progress>completed, createdAt oldest first; sorts a copy to avoid mutating internal order).
  • src/date-utils.tsformatRelative uses Math.round on the hour delta instead of Math.floor, fixing the day off-by-one (36h now reads "2 days ago").
  • src/validator.ts
    • isEmail allows subdomains and TLDs of 2+ letters (e.g. .museum) while still rejecting non-emails.
    • isUrl allows URLs with a port (e.g. http://localhost:3000); protocol still restricted to http:/https:.

Assumptions (tests underspecify)

  • truncate prefers the word-boundary rule over maximising length (matches the asserted "hello..." result).
  • sortBy ties rely on V8's stable sort (insertion order preserved for equal keys); no explicit tie-break added.

Verification

  • bun test → 60 pass, 0 fail
  • tsc --noEmit → clean

Follow-up note

The isEmail/isUrl regexes touch input validation. A security review of the email pattern for ReDoS characteristics would be reasonable before use on untrusted input at scale.

… and validators

Fix 16 failing tests across 5 source files:
- calculator.divide: throw on division by zero instead of returning Infinity
- string-utils.wordCount: collapse consecutive/mixed whitespace via /\s+/
- string-utils.truncate: implement word-boundary truncation with ellipsis budget
- task-manager: implement remove, update (partial), and sortBy (priority/status/createdAt)
- date-utils.formatRelative: use Math.round to fix day off-by-one (36h -> 2 days ago)
- validator.isEmail: allow subdomains and long TLDs (e.g. .museum)
- validator.isUrl: allow URLs with 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