From 9a49622b51c04c8af7956c6248a409334a980ae9 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 11:35:34 +0000 Subject: [PATCH 1/6] fix(functions): send the number given to res.send as the response body res.send(42) made functions:serve answer 500 because Express treats a number as a deprecated status argument. Deployed functions send the number as the body with a 200 status, so convert a number to its string before Express sees it. --- .talismanrc | 2 +- src/functions/cloud-functions.test.ts | 20 ++++++++++++++++++++ src/functions/cloud-functions.ts | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.talismanrc b/.talismanrc index 94226f3..956a2d2 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: 1f3d5d2fe7d9d820e405bb016a3cfd2119a0126e14632432361add738540bf51 + checksum: 98c30edaed70a464499c0e076d2a8fcf07a1ca6cd0a6b8853370c16380b51a79 - filename: src/functions/function.errors.ts checksum: a24194bef73c8db8c28b8ac104955f2f22abdc8c8d0608fa36a39032055bda57 - filename: src/transport/proxy.test.ts diff --git a/src/functions/cloud-functions.test.ts b/src/functions/cloud-functions.test.ts index 728ff58..1d2c159 100644 --- a/src/functions/cloud-functions.test.ts +++ b/src/functions/cloud-functions.test.ts @@ -556,6 +556,26 @@ describe('CloudFunctions serve routing', () => { expect((await sendRequest(port, '/cached')).cacheControl).toBe('max-age=60'); }); + it('sends the number given to res.send as the body with a 200 status, as deployed functions do', async () => { + writeFunctionFile('count.js', 'export default function count(request, response) { response.send(42); }'); + writeFunctionFile('zero.js', 'export default function zero(request, response) { response.send(0); }'); + writeFunctionFile('teapot.js', 'export default function teapot(request, response) { response.status(201).send(418); }'); + const port = await freePort(); + + await new CloudFunctions(workspace).serve(port); + const count = await sendRequest(port, '/count'); + const zero = await sendRequest(port, '/zero'); + const teapot = await sendRequest(port, '/teapot'); + + expect(count.status).toBe(200); + expect(count.body).toBe('42'); + expect(zero.status).toBe(200); + expect(zero.body).toBe('0'); + expect(teapot.status).toBe(201); + expect(teapot.body).toBe('418'); + 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 c8f413a..52f70b6 100755 --- a/src/functions/cloud-functions.ts +++ b/src/functions/cloud-functions.ts @@ -173,6 +173,13 @@ function redirectLikeDeployedFunctions(_request: Request, response: Response, ne next(); } +function sendNumbersAsBody(_request: Request, response: Response, next: NextFunction): void { + const send = response.send.bind(response); + response.send = ((body?: unknown): Response => + send(typeof body === 'number' ? String(body) : body)) as Response['send']; + next(); +} + export function answerRequestError( error: Error & { status?: number; type?: string }, _request: Request, @@ -192,6 +199,7 @@ function applyRequestMiddleware(app: Express): void { app.use(defaultToNoStore); app.use(attachCookies); app.use(redirectLikeDeployedFunctions); + app.use(sendNumbersAsBody); app.use(express.json({ limit: DEPLOYED_PAYLOAD_LIMIT })); app.use(express.urlencoded({ extended: true, limit: DEPLOYED_PAYLOAD_LIMIT })); app.use(express.text({ limit: DEPLOYED_PAYLOAD_LIMIT })); From ca94be56a3fec1a2d14079bf8346e8b13c918c9f Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 06:56:07 +0000 Subject: [PATCH 2/6] fix(functions): keep the two-argument res.send forms when sending a number Forward every argument to Express's send and convert only a lone number, so res.send(404, 'x') and res.send('x', 404) keep their status. Record the res.redirect and res.send(number) behaviour in the approved V1 differences. --- .talismanrc | 2 +- AGENTS.md | 4 ++++ src/functions/cloud-functions.test.ts | 16 ++++++++++++++++ src/functions/cloud-functions.ts | 6 ++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.talismanrc b/.talismanrc index 956a2d2..60b0ce3 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: 98c30edaed70a464499c0e076d2a8fcf07a1ca6cd0a6b8853370c16380b51a79 + checksum: afaf280da52d35a04ec83e9043f4de8f3f2aa182df5c71f432c8ec5731252f16 - filename: src/functions/function.errors.ts checksum: a24194bef73c8db8c28b8ac104955f2f22abdc8c8d0608fa36a39032055bda57 - filename: src/transport/proxy.test.ts diff --git a/AGENTS.md b/AGENTS.md index 96f0e8f..46f5bfb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -537,6 +537,10 @@ The approved differences from V1 are these, and only these: The project `.env` is loaded before the functions are bundled. Azure and GCP still run the vendored V1 server, which leaves text and octet-stream bodies unparsed; locally a handler that reads the raw request stream for those two types gets an empty stream. + `res.redirect(url)` answers a bare 307 with the location as given, and `res.send(number)` + sends the number as the body with the current status (CL-8970); the two-argument + `res.send(status, body)` and `res.send(body, status)` forms keep Express's status. Azure and + GCP (V1) still answer `res.redirect(url)` with a 302 and a body, and `res.send(number)` with 500. - **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 1d2c159..75827a6 100644 --- a/src/functions/cloud-functions.test.ts +++ b/src/functions/cloud-functions.test.ts @@ -576,6 +576,22 @@ describe('CloudFunctions serve routing', () => { expect(loggedErrors).toEqual([]); }); + it('keeps the status of the two-argument res.send forms, as Express does', async () => { + writeFunctionFile('missing.js', 'export default function missing(request, response) { response.send(404, "Not here"); }'); + writeFunctionFile('gone.js', 'export default function gone(request, response) { response.send("gone", 410); }'); + const port = await freePort(); + + await new CloudFunctions(workspace).serve(port); + const missing = await sendRequest(port, '/missing'); + const gone = await sendRequest(port, '/gone'); + + expect(missing.status).toBe(404); + expect(missing.body).toBe('Not here'); + expect(gone.status).toBe(410); + expect(gone.body).toBe('gone'); + 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 52f70b6..2ebcd59 100755 --- a/src/functions/cloud-functions.ts +++ b/src/functions/cloud-functions.ts @@ -175,8 +175,10 @@ function redirectLikeDeployedFunctions(_request: Request, response: Response, ne function sendNumbersAsBody(_request: Request, response: Response, next: NextFunction): void { const send = response.send.bind(response); - response.send = ((body?: unknown): Response => - send(typeof body === 'number' ? String(body) : body)) as Response['send']; + response.send = ((...args: unknown[]): Response => { + const [body] = args; + return args.length === 1 && typeof body === 'number' ? send(String(body)) : send(...(args as [unknown])); + }) as Response['send']; next(); } From 4f058aa4e6d9e917d9c519f85cc620302c561207 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 10:28:24 +0000 Subject: [PATCH 3/6] fix(functions): send a res.send number as JSON and ignore a second argument Deployed functions (lambda-node-bridge, the same helpers as Vercel's @vercel/node) take one argument in res.send and send a number through json(): res.send(42) answers 200 with 42 as application/json, NaN as null, and res.send(404, 'x') ignores the 'x'. Match that instead of sending the number as text/html and honouring Express's two-argument forms, and correct the approved V1 differences in AGENTS.md. --- .talismanrc | 2 +- AGENTS.md | 11 ++++++---- src/functions/cloud-functions.test.ts | 30 +++++++++++++++------------ src/functions/cloud-functions.ts | 10 ++++----- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/.talismanrc b/.talismanrc index 60b0ce3..f865c59 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: afaf280da52d35a04ec83e9043f4de8f3f2aa182df5c71f432c8ec5731252f16 + checksum: cecfa3d38671f42c1dd47c908836d9b618b95f33a0eafb7538486488327b3ed1 - filename: src/functions/function.errors.ts checksum: a24194bef73c8db8c28b8ac104955f2f22abdc8c8d0608fa36a39032055bda57 - filename: src/transport/proxy.test.ts diff --git a/AGENTS.md b/AGENTS.md index 46f5bfb..65cd6b5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -537,10 +537,13 @@ The approved differences from V1 are these, and only these: The project `.env` is loaded before the functions are bundled. Azure and GCP still run the vendored V1 server, which leaves text and octet-stream bodies unparsed; locally a handler that reads the raw request stream for those two types gets an empty stream. - `res.redirect(url)` answers a bare 307 with the location as given, and `res.send(number)` - sends the number as the body with the current status (CL-8970); the two-argument - `res.send(status, body)` and `res.send(body, status)` forms keep Express's status. Azure and - GCP (V1) still answer `res.redirect(url)` with a 302 and a body, and `res.send(number)` with 500. + `res.redirect(url)` answers a bare 307 with the location as given (CL-8970). `res.send` + takes one argument, as on AWS and Vercel: 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. - **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 75827a6..0bd7711 100644 --- a/src/functions/cloud-functions.test.ts +++ b/src/functions/cloud-functions.test.ts @@ -556,27 +556,33 @@ describe('CloudFunctions serve routing', () => { expect((await sendRequest(port, '/cached')).cacheControl).toBe('max-age=60'); }); - it('sends the number given to res.send as the body with a 200 status, as deployed functions do', async () => { + it('sends a number given to res.send as JSON with the current status, as deployed functions do', async () => { writeFunctionFile('count.js', 'export default function count(request, response) { response.send(42); }'); writeFunctionFile('zero.js', 'export default function zero(request, response) { response.send(0); }'); writeFunctionFile('teapot.js', 'export default function teapot(request, response) { response.status(201).send(418); }'); + writeFunctionFile('nan.js', 'export default function nan(request, response) { response.send(Number.NaN); }'); + writeFunctionFile( + 'typed.js', + 'export default function typed(request, response) { response.setHeader("content-type", "text/plain"); response.send(7); }', + ); const port = await freePort(); await new CloudFunctions(workspace).serve(port); const count = await sendRequest(port, '/count'); const zero = await sendRequest(port, '/zero'); const teapot = await sendRequest(port, '/teapot'); - - expect(count.status).toBe(200); - expect(count.body).toBe('42'); - expect(zero.status).toBe(200); - expect(zero.body).toBe('0'); - expect(teapot.status).toBe(201); - expect(teapot.body).toBe('418'); + const nan = await sendRequest(port, '/nan'); + const typed = await sendRequest(port, '/typed'); + + expect(count).toMatchObject({ status: 200, body: '42', contentType: 'application/json; charset=utf-8' }); + expect(zero).toMatchObject({ status: 200, body: '0', contentType: 'application/json; charset=utf-8' }); + expect(teapot).toMatchObject({ status: 201, body: '418', contentType: 'application/json; charset=utf-8' }); + expect(nan).toMatchObject({ status: 200, body: 'null', contentType: 'application/json; charset=utf-8' }); + expect(typed).toMatchObject({ status: 200, body: '7', contentType: 'text/plain; charset=utf-8' }); expect(loggedErrors).toEqual([]); }); - it('keeps the status of the two-argument res.send forms, as Express does', async () => { + it('ignores a second argument to res.send, as deployed functions do', async () => { writeFunctionFile('missing.js', 'export default function missing(request, response) { response.send(404, "Not here"); }'); writeFunctionFile('gone.js', 'export default function gone(request, response) { response.send("gone", 410); }'); const port = await freePort(); @@ -585,10 +591,8 @@ describe('CloudFunctions serve routing', () => { const missing = await sendRequest(port, '/missing'); const gone = await sendRequest(port, '/gone'); - expect(missing.status).toBe(404); - expect(missing.body).toBe('Not here'); - expect(gone.status).toBe(410); - expect(gone.body).toBe('gone'); + expect(missing).toMatchObject({ status: 200, body: '404', contentType: 'application/json; charset=utf-8' }); + expect(gone).toMatchObject({ status: 200, body: 'gone', contentType: 'text/html; charset=utf-8' }); expect(loggedErrors).toEqual([]); }); diff --git a/src/functions/cloud-functions.ts b/src/functions/cloud-functions.ts index 2ebcd59..1145144 100755 --- a/src/functions/cloud-functions.ts +++ b/src/functions/cloud-functions.ts @@ -173,12 +173,10 @@ function redirectLikeDeployedFunctions(_request: Request, response: Response, ne next(); } -function sendNumbersAsBody(_request: Request, response: Response, next: NextFunction): void { +function sendLikeDeployedFunctions(_request: Request, response: Response, next: NextFunction): void { const send = response.send.bind(response); - response.send = ((...args: unknown[]): Response => { - const [body] = args; - return args.length === 1 && typeof body === 'number' ? send(String(body)) : send(...(args as [unknown])); - }) as Response['send']; + response.send = ((body?: unknown): Response => + typeof body === 'number' ? response.json(body) : send(body)) as Response['send']; next(); } @@ -201,7 +199,7 @@ function applyRequestMiddleware(app: Express): void { app.use(defaultToNoStore); app.use(attachCookies); app.use(redirectLikeDeployedFunctions); - app.use(sendNumbersAsBody); + app.use(sendLikeDeployedFunctions); app.use(express.json({ limit: DEPLOYED_PAYLOAD_LIMIT })); app.use(express.urlencoded({ extended: true, limit: DEPLOYED_PAYLOAD_LIMIT })); app.use(express.text({ limit: DEPLOYED_PAYLOAD_LIMIT })); From f03298707fb81436a7eb9a6ee455076a23785c8c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 10:33:23 +0000 Subject: [PATCH 4/6] docs(functions): name CL-8970 on the res.send entry in the approved V1 differences --- AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 65cd6b5..e51c6da 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -538,7 +538,7 @@ The approved differences from V1 are these, and only these: vendored V1 server, which leaves text and octet-stream bodies unparsed; locally a handler that reads the raw request stream for those two types gets an empty stream. `res.redirect(url)` answers a bare 307 with the location as given (CL-8970). `res.send` - takes one argument, as on AWS and Vercel: a number is sent as JSON with the current status + 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 From 1962d9070efccf26177b9e936bedb45fa9befcb8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 10:34:23 +0000 Subject: [PATCH 5/6] docs(functions): wrap the res.send entry in the approved V1 differences --- AGENTS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index e51c6da..8a88865 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -538,9 +538,9 @@ The approved differences from V1 are these, and only these: vendored V1 server, which leaves text and octet-stream bodies unparsed; locally a handler that reads the raw request stream for those two types gets an empty stream. `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 + 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. From 7b4558f3533b6ef4f8cbbbc6cf4f4edf685df3b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 10:34:47 +0000 Subject: [PATCH 6/6] chore: refresh .talismanrc checksum for AGENTS.md The res.send note in AGENTS.md is prose; Talisman flags its punctuation as low-severity patterns. No credentials. --- .talismanrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.talismanrc b/.talismanrc index f865c59..d45f9fc 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: f5d6ea83004c5b7187512e86e4e9635511792dd292e861db18e16982d2d27539 + checksum: f846e00049c0c27e378702832fdbeee8f65647b75f285ea5fc2f8ded51757c1f 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\\)`"