Update test dependencies and fix Next.js API route compatibility#201
Update test dependencies and fix Next.js API route compatibility#201dex-the-ai wants to merge 3 commits into
Conversation
|
Owner ping for this maintenance PR: @ejscribner Requesting review from the manifest-listed owner(s) where GitHub does not already show a pending review request. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code Review
This pull request replaces the external uuid dependency with Node's native node:crypto randomUUID, updates next-test-api-route-handler to version 5.0.5 (updating test parameters accordingly), refactors request body parsing in the API handler, and adds scanConsistency: 'request_plus' to Couchbase query options. The reviewer feedback suggests wrapping the JSON parsing in a try...catch block to gracefully handle malformed payloads and making the scanConsistency option configurable via environment variables to prevent performance bottlenecks in production.
| const body = !req.body | ||
| ? null | ||
| : typeof req.body === 'string' | ||
| ? JSON.parse(req.body) | ||
| : req.body; |
There was a problem hiding this comment.
Parsing req.body directly using JSON.parse without a try...catch block can cause the API route to crash or return a 500 Internal Server Error if the client sends malformed JSON. It is safer to wrap the parsing in a try...catch block and return a 400 Bad Request status code with a clear error message.
let body = null;
if (req.body) {
if (typeof req.body === 'string') {
try {
body = JSON.parse(req.body);
} catch (error) {
return res.status(400).json({ statusCode: 400, message: 'Invalid JSON body' });
}
} else {
body = req.body;
}
}There was a problem hiding this comment.
Fixed in 39599c4. The route now accepts either parsed object bodies or raw string bodies, and malformed JSON returns a 400 instead of falling through to a server error. I re-ran npm test, npm run check, and a local invalid-JSON POST against the built app.
| const options = { | ||
| scanConsistency: 'request_plus', |
There was a problem hiding this comment.
Using scanConsistency: 'request_plus' unconditionally in production can cause significant performance bottlenecks because Couchbase must wait for the indexer to catch up with all recent mutations before executing the query. It is recommended to make this configurable (e.g., via an environment variable) so that it is only enabled during tests or when strictly necessary, defaulting to undefined (which uses the default not_bounded consistency) in production.
| const options = { | |
| scanConsistency: 'request_plus', | |
| const options = { | |
| scanConsistency: process.env.COUCHBASE_SCAN_CONSISTENCY || undefined, |
There was a problem hiding this comment.
Fixed in 39599c4. I kept request_plus for the Jest path and made production use opt-in consistency via COUCHBASE_SCAN_CONSISTENCY, so we are not forcing stronger query consistency on every runtime request. I also re-ran the local create/search/delete walkthrough with the env override to confirm the intended test-style flow still works.
|
Pushed one more follow-up commit ( |
Summary
next-test-api-route-handlerupgrade from Dependabot PR Bump cookie and next-test-api-route-handler #186 into a single Dex-maintained branchuuiddependency instead of carrying the breakinguuid@14jump from PR Bump uuid from 9.0.1 to 14.0.0 #194, using Node's built-inrandomUUID()in the API route and testsnext-test-api-route-handlerpagesHandlerAPI and correct the GET test coveragepages/api/user.jsso it accepts either parsed object bodies or raw string bodies, and make the GET query path use request-plus consistency so fresh writes are visible to the query testsVerification
npm run init-db:defaultnpm testnpm run checkcp .env.default .env.local && npm run init-db:localnpm run load-sample-datasource .env.local && npm run buildPORT=3001 npm run startPOST /api/user→GET /api/user?search=dex→DELETE /api/user?pid=<created-id>Evidence
4 passed / 6 assertions)Media evidence
Screenshot
Video
Open the walkthrough video
Key verification notes
next-test-api-route-handler@5.0.5pulls in the updatedcookie@1.1.1chain that was failing in PR Bump cookie and next-test-api-route-handler #186 until the tests were moved topagesHandler.uuid@14was failing under Jest because of the ESM-only distribution path. Replacing the direct dependency withnode:crypto'srandomUUID()keeps the route/test behavior intact while removing the incompatible package entirely.npm run load-sample-datalogsDocumentExistsError: document existswhen the sample docs are already present; the app still builds and the manual CRUD verification succeeds.tutorial-maintenance/runs/couchbase-examples__nextjs-quickstart/2026-05-28-combined-pr/Notes
npm auditstill reports 2 moderate vulnerabilities throughnext -> postcss; the suggested auto-fix would downgrade Next.js to9.3.3, so I left that out of scope for this pass.