Skip to content

test: fix Node 26 flake in 'group parts with same name to an array' - #646

Merged
Tony133 merged 1 commit into
mainfrom
fix/node-26-group-parts-flake
Sep 21, 2026
Merged

Tony133 merged 1 commit into
mainfrom
fix/node-26-group-parts-flake

Conversation

@mcollina

@mcollina mcollina commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes a deterministic test failure on Node 26 (CI Test (26, ubuntu-latest)):

test at test/multipart.test.js:127:1
✖ should group parts with the same name to an array
  'plan expected 15 assertions but received 16'

This is unrelated to any behaviour change; it is a test-only flake. The docs PR (#645) shows the same failure with no runtime changes.

Root cause

The test used t.plan(15) and asserted the number of times the streaming loop observed a grouped array via conditional t.assert.ok() calls:

if (Array.isArray(part.fields.upload)) {
  t.assert.ok('multiple fields are grouped by array')
}
if (Array.isArray(part.fields.hello)) {
  t.assert.ok('multiple files are grouped by array')
}

How many times these fire depends on when busboy turns a repeated field name into an array, which is timing-sensitive. Under Node 26 the timing shifts and one extra assertion fires, so the plan of 15 is exceeded (16 received).

Fix

Track whether the grouping was observed in flags during the loop, then assert the result once and deterministically after the loop:

let seenUploadArray = false
let seenHelloArray = false
for await (const part of parts) {
  t.assert.ok(part)
  if (Array.isArray(part.fields.upload)) seenUploadArray = true
  if (Array.isArray(part.fields.hello)) seenHelloArray = true
  if (part.file) await streamToNull(part.file)
}
t.assert.ok(seenUploadArray)
t.assert.ok(seenHelloArray)

The per-part t.assert.ok(part) count (6 parts) and the two response-handler assertions are unchanged; the plan is now 10 and no longer depends on streaming timing.

Verification

  • node --test test/multipart.test.js — 13/13 pass
  • npm run test:unit — 92/92 pass, 100% coverage maintained
  • npm run lint — clean

The test asserted the number of times the streaming loop observed a
grouped array via conditional t.assert.ok() calls, so its plan (15)
depended on when busboy turned a repeated field name into an array. Under
Node 26 the timing differs and one extra assertion fires, failing with
'plan expected 15 assertions but received 16'.

Track the grouped-array observation in flags and assert the result once,
deterministically, after the loop. The per-part t.assert.ok(part) count
(6 parts) and the response handler assertions are unchanged; plan is now 10.
@Tony133
Tony133 merged commit ee36838 into main Sep 21, 2026
20 checks passed
@Tony133
Tony133 deleted the fix/node-26-group-parts-flake branch September 21, 2026 12:46
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.

2 participants