From da5fb87b86884a0302257c09ed043d1f2af8b0e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 11:12:32 +0000 Subject: [PATCH 1/4] fix(functions): ignore a second argument to res.json, as deployed functions do Deployed functions (lambda-node-bridge and Vercel's @vercel/node) define res.json with one argument and keep the current status. Express 4 still honours its deprecated res.json(status, body) and res.json(body, status) forms, so serve answered 404 or 500 where a deployed function answers 200. Pass only the first argument on, and record it in the approved V1 differences. --- AGENTS.md | 11 +++++++---- src/functions/cloud-functions.test.ts | 20 ++++++++++++++++++++ src/functions/cloud-functions.ts | 2 ++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 8a88865..d40e523 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -540,10 +540,13 @@ The approved differences from V1 are these, and only these: `res.redirect(url)` answers a bare 307 with the location as given (CL-8970). `res.send` takes one argument, as on AWS and Vercel (CL-8970, chosen by the ticket owner): a number is sent as JSON with the current status (`res.send(42)` → `42`, - `application/json; charset=utf-8`; `NaN` → `null`), and a second argument is ignored, so Express's `res.send(status, body)` and `res.send(body, status)` forms - do not set the status. Azure and GCP (V1, Express 4) still answer `res.redirect(url)` with a - 302 and a body, treat `res.send(404)` as a 404 status and an invalid one such as - `res.send(42)` as a 500, and honour the two-argument forms. + `application/json; charset=utf-8`; `NaN` → `null`), and a second argument is ignored, so + Express's `res.send(status, body)` and `res.send(body, status)` forms do not set the status. + `res.json` takes one argument too and keeps the current status, so `res.json(404, body)` and + `res.json(body, 500)` answer 200 (CL-8970). Azure and GCP (V1, Express 4) still answer + `res.redirect(url)` with a 302 and a body, treat `res.send(404)` as a 404 status and an + invalid one such as `res.send(42)` as a 500, and honour the two-argument forms of `res.send` + and `res.json`. - **A function that reaches a file outside `functions/` is warned about, not refused**, naming the function file that crosses the boundary. - **Errors name the user's file.** A function that fails to bundle or load stops serve with diff --git a/src/functions/cloud-functions.test.ts b/src/functions/cloud-functions.test.ts index 0bd7711..65d45d6 100644 --- a/src/functions/cloud-functions.test.ts +++ b/src/functions/cloud-functions.test.ts @@ -596,6 +596,26 @@ describe('CloudFunctions serve routing', () => { expect(loggedErrors).toEqual([]); }); + it('ignores a second argument to res.json and keeps the current status, as deployed functions do', async () => { + writeFunctionFile('missing.js', 'export default function missing(request, response) { response.json(404, { error: "missing" }); }'); + writeFunctionFile('failed.js', 'export default function failed(request, response) { response.json({ ok: false }, 500); }'); + writeFunctionFile( + 'created.js', + 'export default function created(request, response) { response.status(201).json({ id: "a1" }); }', + ); + const port = await freePort(); + + await new CloudFunctions(workspace).serve(port); + const missing = await sendRequest(port, '/missing'); + const failed = await sendRequest(port, '/failed'); + const created = await sendRequest(port, '/created'); + + expect(missing).toMatchObject({ status: 200, body: '404', contentType: 'application/json; charset=utf-8' }); + expect(failed).toMatchObject({ status: 200, body: '{"ok":false}', contentType: 'application/json; charset=utf-8' }); + expect(created).toMatchObject({ status: 201, body: '{"id":"a1"}', contentType: 'application/json; charset=utf-8' }); + expect(loggedErrors).toEqual([]); + }); + it('answers res.redirect(url) with a bare 307 and the location exactly as given, as deployed functions do', async () => { writeFunctionFile('go.js', 'export default function go(request, response) { response.redirect("/target?from=a b"); }'); const port = await freePort(); diff --git a/src/functions/cloud-functions.ts b/src/functions/cloud-functions.ts index 1145144..35a7363 100755 --- a/src/functions/cloud-functions.ts +++ b/src/functions/cloud-functions.ts @@ -175,6 +175,8 @@ function redirectLikeDeployedFunctions(_request: Request, response: Response, ne function sendLikeDeployedFunctions(_request: Request, response: Response, next: NextFunction): void { const send = response.send.bind(response); + const json = response.json.bind(response); + response.json = ((body?: unknown): Response => json(body)) as Response['json']; response.send = ((body?: unknown): Response => typeof body === 'number' ? response.json(body) : send(body)) as Response['send']; next(); From df9c88019426a5ad45c3c099c25c60ffbc768d21 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 11:12:58 +0000 Subject: [PATCH 2/4] chore: refresh .talismanrc checksums for cloud-functions.test.ts and AGENTS.md Test code and prose; no credentials. --- .talismanrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.talismanrc b/.talismanrc index d45f9fc..beb55f0 100644 --- a/.talismanrc +++ b/.talismanrc @@ -240,7 +240,7 @@ fileignoreconfig: - "a project name passed on argv to the project resolver" - "expect\\(Object.keys\\(DEPENDENCIES\\)\\).toEqual\\(\\['project', 'env'\\]\\)" - filename: AGENTS.md - checksum: f846e00049c0c27e378702832fdbeee8f65647b75f285ea5fc2f8ded51757c1f + checksum: d9ece4c45007c65054469efcd50de93573c756ad9664a6a2d7658db021a5078c allowed_patterns: - "Do not add an exemption to a guard to make a new file pass" - "passes its own error wording to `client.request\\(req, MESSAGES\\)`" @@ -287,7 +287,7 @@ fileignoreconfig: - filename: test/integration/projects-list-command.test.ts checksum: 038f5cd182e1fd0105e6e10dde7f5068a0c15883222450f72ea3904890a56c0c - filename: src/functions/cloud-functions.test.ts - checksum: cecfa3d38671f42c1dd47c908836d9b618b95f33a0eafb7538486488327b3ed1 + checksum: 7ffa6988667be571fa6ef03f130269af2cb6e2d752004cbdb254e7a94f600b66 - filename: src/functions/function.errors.ts checksum: a24194bef73c8db8c28b8ac104955f2f22abdc8c8d0608fa36a39032055bda57 - filename: src/transport/proxy.test.ts From c247da82b2216fe7b6024dd84b026b9c0ccf4d75 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 11:16:51 +0000 Subject: [PATCH 3/4] test(functions): keep a content type already set when res.json sends --- src/functions/cloud-functions.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/functions/cloud-functions.test.ts b/src/functions/cloud-functions.test.ts index 65d45d6..93663cd 100644 --- a/src/functions/cloud-functions.test.ts +++ b/src/functions/cloud-functions.test.ts @@ -603,16 +603,22 @@ describe('CloudFunctions serve routing', () => { 'created.js', 'export default function created(request, response) { response.status(201).json({ id: "a1" }); }', ); + writeFunctionFile( + 'plain.js', + 'export default function plain(request, response) { response.type("text/plain").json({ a: 1 }); }', + ); const port = await freePort(); await new CloudFunctions(workspace).serve(port); const missing = await sendRequest(port, '/missing'); const failed = await sendRequest(port, '/failed'); const created = await sendRequest(port, '/created'); + const plain = await sendRequest(port, '/plain'); expect(missing).toMatchObject({ status: 200, body: '404', contentType: 'application/json; charset=utf-8' }); expect(failed).toMatchObject({ status: 200, body: '{"ok":false}', contentType: 'application/json; charset=utf-8' }); expect(created).toMatchObject({ status: 201, body: '{"id":"a1"}', contentType: 'application/json; charset=utf-8' }); + expect(plain).toMatchObject({ status: 200, body: '{"a":1}', contentType: 'text/plain; charset=utf-8' }); expect(loggedErrors).toEqual([]); }); From fb35e9e363283a2a159904ed923f449b34cf1704 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 11:17:13 +0000 Subject: [PATCH 4/4] chore: refresh .talismanrc checksum for cloud-functions.test.ts Test code; no credentials. --- .talismanrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.talismanrc b/.talismanrc index beb55f0..8e8cadf 100644 --- a/.talismanrc +++ b/.talismanrc @@ -287,7 +287,7 @@ fileignoreconfig: - filename: test/integration/projects-list-command.test.ts checksum: 038f5cd182e1fd0105e6e10dde7f5068a0c15883222450f72ea3904890a56c0c - filename: src/functions/cloud-functions.test.ts - checksum: 7ffa6988667be571fa6ef03f130269af2cb6e2d752004cbdb254e7a94f600b66 + checksum: ca4e03b4ae6d4e39fe5ad654f781b002deb37f2f30ebf58c27feeb162696c562 - filename: src/functions/function.errors.ts checksum: a24194bef73c8db8c28b8ac104955f2f22abdc8c8d0608fa36a39032055bda57 - filename: src/transport/proxy.test.ts