Skip to content

fix: implement missing utils and correct edge-case bugs - #324

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2215-1788927519
Open

fix: implement missing utils and correct edge-case bugs#324
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2215-1788927519

Conversation

@stooit

@stooit stooit commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests in the TypeScript utility library. 60/60 tests now pass, tsc --noEmit clean. No test files modified, no dependencies added.

Changes

  • src/calculator.tsdivide returned Infinity on a zero divisor; now throws. (-0 is also caught since -0 === 0.)
  • src/string-utils.ts
    • wordCount split on the literal " ", so consecutive spaces produced empty elements. Now trims and splits on /\s+/ (also handles tabs/newlines).
    • truncate was unimplemented. Truncates at a word boundary with "..." counting toward maxLength; returns input unchanged when within limit. Any whitespace is treated as a boundary, with a fallback to the hard slice so whitespace-led input never returns a bare ellipsis. Length contract (result.length <= maxLength) verified via fuzzing.
  • src/task-manager.ts — implemented remove (delegates to Map.delete), update (returns false for unknown id; applies only fields explicitly present), and sortBy (priority high>medium>low, status in_progress>pending>completed, createdAt ascending; sort is stable so ties keep insertion order).
  • src/date-utils.ts — day bucket used Math.floor(diffHours / 24) (36h → "1 day ago"); now Math.round, fixing the off-by-one.
  • src/validator.tsisEmail capped the TLD at 4 chars (rejected .museum); widened to {2,} while keeping user@example / a@.com rejected. isUrl required an empty port (rejected http://localhost:3000); dropped that clause while retaining the http/https-only allowlist.

Verification

  • bun test → 60 pass / 0 fail
  • bunx tsc --noEmit → exit 0
  • Independent review pass: all 5 headline bugs confirmed genuinely fixed (boundary-probed and fuzzed), no regressions, no blockers.

Assumptions / notes

  • isEmail is a pragmatic form validator, not RFC 5322 — accepts some addresses that would bounce and rejects some exotic-but-legal ones. Fine for form validation.
  • truncate with maxLength < 3 returns a clipped ellipsis (e.g. truncate("abc", 2) === ".."); no test covers it and the length contract holds, so behaviour was left as-is.
  • A couple of latent API edge cases beyond the test contract were left untouched per the "fix only what the tests require" constraint (e.g. update cannot clear an optional field via undefined). Worth a follow-up if those behaviours matter.

- calculator.divide: throw on zero divisor instead of returning Infinity
- string-utils.wordCount: split on /\s+/ to handle consecutive whitespace
- string-utils.truncate: implement word-boundary truncation with ellipsis
  counting toward maxLength, plus whitespace-led fallback
- task-manager: implement remove, update, and sortBy
- date-utils: use Math.round for day bucket (off-by-one fix)
- validator.isEmail: widen TLD length; validator.isUrl: allow 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