Skip to content

test(hosting,blocks): keep CLI and adapter output off the test runner's stdout - #1330

Open
xyos wants to merge 3 commits into
mainfrom
test/hosting-secret-cli-deserialize
Open

xyos wants to merge 3 commits into
mainfrom
test/hosting-secret-cli-deserialize

Conversation

@xyos

@xyos xyos commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Problem

packages/hosting unit tests sometimes fail a whole file in under a second, and pass on rerun:

test at dist/secret-cli.test.js:1:1
✖ dist/secret-cli.test.js (120.431378ms)
  Error: Unable to deserialize cloned data due to invalid or unsupported version.
      at #processRawBuffer (node:internal/test_runner/runner:354:20)
      at FileTest.parseMessage (node:internal/test_runner/runner:290:27)
      at Socket.<anonymous> (node:internal/test_runner/runner:400:15)

Just before it, the log shows the CLI's own output: ♻️ secret 'ZZ_DBG' was scheduled for deletion; restored it. and 🔐 secret 'ZZ_DBG' set (blocks/secrets/ZZ_DBG).

Cause. node --test runs each file in a child that sends its results to the parent as framed messages (FF 0F, a 4-byte length, a v8-serialized value) on the child's stdout. Other text the file writes to stdout shares that pipe. On Node 22 (CI runs 22.23.4) and 24, after a complete frame #processRawBuffer reads bytes 2–5 of whatever follows as the next frame's length, without checking for the header. When the test's own text arrives in the same read as the frame before it, those bytes come from the text. In ♻️ (e2 99 bb ef b8 8f) the length is 0xbbefb88f, a negative int32. The parser then thinks it already holds the whole frame, gives the text to the deserializer, and readHeader() throws. The text never goes inside a frame: a capture of the child's stdout has 218 intact frames plus exactly one non-frame range, those two lines. Whether the text and the frame share a read depends on timing, so the failure is a flake that load makes more likely. Node fixed the parser on main in nodejs/node#66273 (issue nodejs/node#66164). 22.x does not have the fix.

The test that writes those lines is runValueCli() — Secrets Manager edge cases › restores a secret that remove scheduled for deletion, then sets it. It lets setValue's console.log reach the real stdout. The CLI is right to print its result to stdout. The test is not right to let it reach the runner's channel.

Changes

Tests only. They no longer let the code under test write to the test process's stdout:

  • packages/hosting/src/secret-cli.test.ts: the restore test captures console.log with mock.method, as the file's other store tests do, and checks that the restore is reported.
  • packages/hosting/src/adapters/{nextjs,nitro,sveltekit}.test.ts: 10 tests reach the adapters' stdout progress lines (🔗 Detected … basePath/baseURL/paths.base/assetPrefix, 🚀 Lifted N redirect(s)…). They now mute process.stdout.write only around the synchronous adapter call. Nothing else can write during a synchronous call, so the runner's frames are never swallowed. These files pass today only because the output comes before the runner's first frame, which the parser handles. Any earlier async test would move it after a frame.
  • sveltekit.test.ts, does NOT throw when the only adapter reference is a commented-out incompatible adapter: this test ran a real npm run build with stdio: 'inherit', so a second process wrote straight to the runner's pipe. The build is now stubbed (t.mock.method(spawn, 'sync', …)) to fail, as it did without a toolchain. The assertion that the error is not the incompatible-adapter error is unchanged.
  • packages/blocks/src/cli/help-safety.test.ts: the two tests that run the real secret and config CLIs through to a store call printed 🗑️ … removed after frames, the same crash shape as the secret CLI test. They now capture console.log through a small helper, which the file's existing --help capture also uses now.

The adapters' stdout lines and the value CLI's console.log results are unchanged. The cdk-blocks CLI routes child-tool output to stderr in --output json mode, and secret/config have no JSON mode, so neither breaks a machine-readable stdout contract.

Validation

Node 22.23.1 locally, the closest available to CI's 22.23.4. #processRawBuffer is the same in both.

  • Deterministic reproduction. I captured the child stream (NODE_TEST_CONTEXT=child-v8 node dist/secret-cli.test.js) and replayed it with one writeSync(1, …) from a file run under node --test. Before the fix this gives the exact CI error. The same bytes in two reads, split before the stray text, pass. ASCII-only stray text after a frame passes. After the fix the capture has 218 frames and no other bytes, and the replay passes.

  • Loop, 300 × node --test dist/secret-cli.test.js from packages/hosting:

    condition before after
    idle 24/300 0/300 (with the full build and test suite running at the same time)
    pinned to 2 CPUs with 4 busy loops 183/300 0/300

    Every failure before the fix was Unable to deserialize cloned data ….

  • Audit. I ran every packages/hosting test file (76), packages/blocks/dist/cli/*.test.js (9) and the core secret/config tests (3) as child-v8 children and listed the stdout bytes that are not frames. Before the fix: secret-cli, nextjs, nitro, sveltekit and help-safety. After the fix: none.

  • npm run build && npm run lint && npm run lint:deps && npm test && npm run test:e2e:local on Node 22.23.1 with AWS credentials unset all passed. Unit: 44 workspace runs, 8775 tests, 0 failed, 7 skipped. e2e (local): 4 suites, 426 tests, 0 failed, 4 skipped.

  • Changed files alone: hosting secret-cli + nextjs/nitro/sveltekit adapters 261/261, blocks cli/help-safety 16/16.

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced): not applicable, tests only

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…'s stdout

node --test runs each file in a child that reports its results as framed
messages on that child's stdout. On Node 22 (and 24), when a file's own
stdout text arrives in the same read as one of those messages, the runner
reads bytes 2-5 of the text as the next frame's length. A non-ASCII byte
there (the emoji in "🔐 secret 'ZZ_DBG' set (…)") makes the length
negative, the text goes to the deserializer, and the whole file fails with
"Unable to deserialize cloned data due to invalid or unsupported version."
Node fixed the parser upstream (nodejs/node#66273); 22.x does not have it.

The secret CLI test "restores a secret that remove scheduled for deletion,
then sets it" let runValueCli print its result there. It now captures it,
as the file's other store tests do, and checks that the restore is
reported.

The same pattern, in tests that pass today only because their output comes
before the runner's first message:
- Next.js, Nuxt and SvelteKit adapter tests that reach the adapters'
  stdout progress lines ("🔗 Detected …", "🚀 Lifted …") mute stdout around
  the synchronous adapter call.
- A SvelteKit bridge-guard test ran a real `npm run build` with inherited
  stdio. The build is now stubbed to fail, as it did without a toolchain.
- The cdk-blocks help-safety tests that run the real secret and config
  CLIs through to a store call capture their console.log, like the file's
  help tests.
@xyos
xyos requested a review from a team as a code owner November 6, 2026 16:43
@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0ec7a73

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@aws-blocks/hosting Patch
@aws-blocks/blocks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch was previously deployed

2 inactive deployments
e2e — 0ec7a73d Deployed Nov 10, 2026 by xyos via E2E Teardown Verify #5868
agent-bench — 0ec7a73d Deployed Nov 10, 2026 by xyos via bench / summary #5120
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