Skip to content

fix: repair failing tests and type errors across api and shared packages - #146

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2220-1787674589
Open

fix: repair failing tests and type errors across api and shared packages#146
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2220-1787674589

Conversation

@stooit

@stooit stooit commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 9 failing tests and all tsc --noEmit type errors in the multi-package Hono API repo. bun test22 pass / 0 fail; tsc --noEmit exits clean.

Root causes fixed

  • Pagination stub (packages/shared/src/utils/pagination.ts): paginate() threw not implemented. Implemented per the test contract (out-of-range page → empty data, empty array → total/totalPages: 0). Added finite-input clamping so NaN/Infinity page/size coerce to sensible defaults (≥1 integers) rather than propagating.
  • Inconsistent shared type (packages/shared/src/types.ts): User.userName renamed to username to match the API routes and tests (tests are the source of truth and use username). Resolved the TS2561 errors.
  • Missing import (packages/api/src/routes/users.ts): badRequest was called but never imported → ReferenceError → 500 instead of 400. Added to the existing ../lib/errors import.
  • Auth middleware case bug (packages/api/src/middleware/auth.ts): public-methods list had "post" (lowercase); Request.method is always uppercase, so POST /users wrongly required a token (401). Fixed to "POST".
  • tsconfig (tsconfig.json): added "types": ["bun-types"] so bun:test and process resolve (both already in node_modules, no new deps).

Constraints respected

  • No test files modified.
  • No new dependencies added (only wired up already-installed bun-types via tsconfig).
  • Minimal scope — a redundant lib tsconfig entry flagged in review was removed to keep to "fix only what tests require".

Assumptions

  • Canonical user field is username (per tests), so the shared type was the incorrect side, not the routes.
  • POST being unauthenticated is intentional per auth.test.ts and the middleware policy comment. Note for follow-up (out of scope): this permits unauthenticated writes to /users and /posts — worth revisiting for a production posture, but mandated by the tests here.

Verification

  • Implementation and both review follow-ups delegated to specialist agents; diff independently reviewed.
  • bun test && npx tsc --noEmit verified green after every change.

- Implement paginate() stub in shared with finite-input clamping
- Rename User.userName -> username in shared types to match API/tests
- Import missing badRequest in users route (400 instead of 500)
- Fix HTTP-method case bug in auth middleware (POST public)
- Add bun-types to tsconfig types so bun:test and process resolve
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