Skip to content

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

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2227-1789402727
Open

stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2227-1789402727

Conversation

@stooit

@stooit stooit commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across the TypeScript utility library. Test suite now: 60 pass, 0 fail; tsc --noEmit clean.

Only source files were changed — no test files modified, no dependencies added.

Fixes by file

  • src/calculator.ts — divide now throws on a zero divisor instead of returning Infinity.
  • src/string-utils.ts — wordCount collapses consecutive whitespace (splits on /\s+/ after trim); truncate implemented per its TODO: unchanged when str.length <= maxLength, otherwise truncates at a word boundary with "..." counting toward maxLength.
  • src/task-manager.ts — implemented remove (false on unknown id), update (partial field updates, false on unknown id), and sortBy (priority high→low, createdAt oldest-first, plus status).
  • src/date-utils.ts — fixed off-by-one in formatRelative: day bucketing uses Math.round on the absolute hour difference (36h → "2 days ago").
  • src/validator.ts — isEmail accepts long TLDs and subdomains; isUrl accepts URLs with an explicit port.

Assumptions

  • truncate reserves 3 chars for the ellipsis and backs up to the last word boundary; a maxLength <= 3 guard avoids a negative slice budget.
  • sortBy on status (in the type union but not under test) was implemented rather than left to throw.
  • update uses per-field !== undefined checks so a partial changes object can't blank unmentioned fields.

Non-blocking notes for follow-up

  • isEmail is a syntactic check only — pair with a confirmation flow before treating an address as verified.
  • update accepts caller-supplied values without length/content bounds; worth a security pass if this feeds a service storing personal data.

Testing

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

- calculator: divide throws on division by zero instead of returning Infinity
- string-utils: wordCount collapses consecutive whitespace; implement truncate at word boundary with ellipsis counted toward maxLength
- task-manager: implement remove, update, and sortBy (priority/createdAt/status)
- date-utils: fix off-by-one in formatRelative day bucketing (round, not floor)
- validator: isEmail accepts long TLDs/subdomains; isUrl accepts 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