ci: patch inquirer baseUI to fix Node 24 ERR_USE_AFTER_CLOSE in Gen 1 e2e - #3503
ci: patch inquirer baseUI to fix Node 24 ERR_USE_AFTER_CLOSE in Gen 1 e2e#3503sarayev wants to merge 1 commit into
Conversation
… e2e
Gen 1 e2e tests that drive `amplify add function` (function_migration,
http_migration, custom_query_mutation_extension) crash on Node 24. After
the nexpect harness answers the "Do you want to edit the local lambda
function now?" confirm prompt and immediately sends EOF, EOF closes the
readline. The legacy inquirer bundled with @aws-amplify/cli-internal then
runs baseUI.js close(), which calls this.rl.pause() on the already-closed
readline. On Node <= 22 that was a silent no-op; on Node 24 it throws
ERR_USE_AFTER_CLOSE, surfacing as "There was an error adding the function
resource" and failing the test.
Add codebuild_specs/scripts/patch-inquirer-baseui.js, an idempotent
post-install patch that guards the pause() call
(this.rl.pause(); -> if (!this.rl.closed) { this.rl.pause(); }), and invoke
it from shared-scripts.sh _installCLIFromLocalRegistry right after the CLI
is installed globally. The patch is rooted at `npm root -g` and matches
hoisted or nested inquirer installs.
This is intentionally category-api-only and does not require republishing
@aws-amplify/cli-internal. The upstream inquirer-usage fix
(confirmPrompt -> confirmContinue) is a separate, lower-urgency amplify-cli
follow-up.
Validated locally on Node 24.14.0: reproduced the crash with the unpatched
inquirer, confirmed `amplify add function` exits 0 after applying the guard.
---
Prompt: Node-24 fix for amplify-category-api Gen1 e2e: validate locally
that guarding inquirer baseUI close()'s rl.pause() flips
function_migration/http_migration/custom_query_mutation_extension from
crash to success on Node 24, then implement as a committed idempotent
post-install patch invoked from shared-scripts.sh after the cli-internal
install, and open a draft PR off release-api-plugin-stable.
|
Closing as superseded. This PR was a test-infra stopgap that post-install-patched the e2e harness's inquirer baseUI to keep Gen1 e2e green on Node 24. The real product fix now lives in amplify-cli: aws-amplify/amplify-cli#14949 ( |
Description of changes
Gen 1 e2e tests that drive
amplify add function—function_migration,http_migration, andcustom_query_mutation_extension— fail on Node 24.Root cause. These tests use the vendored nexpect harness, which answers the
"Do you want to edit the local lambda function now?" confirm prompt and then
immediately sends EOF (
sendConfirmNo().sendEof()). EOF closes the underlyingreadline interface. The legacy
inquirerbundled with the installed@aws-amplify/cli-internalthen runs its teardown inlib/ui/baseUI.js#close(),which calls
this.rl.pause()on the now-closed readline. On Node ≤ 22 that was asilent no-op; on Node 24 it throws
ERR_USE_AFTER_CLOSE: readline was closed,which surfaces to the user as
🛑 There was an error adding the function resourceand fails the test.
Fix. A committed, idempotent post-install patch of the installed CLI's
inquirer
baseUI.js. The patch guards thepause()call:Why a post-install patch (category-api-only, no CLI republish)
The crash lives in
inquireras consumed by@aws-amplify/cli-internal, whichis installed from the local registry during e2e setup and is out of this repo's
control. Patching it post-install keeps the fix entirely within
amplify-category-api and avoids republishing
@aws-amplify/cli-internal. Theproper upstream fix (migrating the Gen 1
confirmPromptusage toconfirmContinue) is a separate, lower-urgency follow-up in amplify-cli.Changes
New post-install patch helper
codebuild_specs/scripts/patch-inquirer-baseui.js— idempotent: given one ormore
baseUI.jspaths it rewrites the unguardedthis.rl.pause();to theguarded form, and no-ops if already patched, not found, or no match. Heavily
commented to explain the Node 24
ERR_USE_AFTER_CLOSEreason.Wire patch into CLI install
shared-scripts.sh_installCLIFromLocalRegistry()— after thenpm install -g @aws-amplify/cli-internalline, afindrooted at$(npm root -g)matches hoisted or nested inquirer installs and invokes thehelper on each
baseUI.js.Issue #, if available
N/A
Description of how you validated changes
Validated locally on Node 24.14.0 against an installed
cli-internal@14.5.1:addFunctionhelper (sendConfirmNo().sendEof()) and a directprintf 'N\n\x04' | amplify add function. Output:Error [ERR_USE_AFTER_CLOSE]: readline was closed at Interface.pause ... at PromptUI.close (inquirer/lib/ui/baseUI.js:60:13),🛑 There was an error adding the function resource, exit code 1.returns
SUCCESS.patched"), patches both hoisted and nested layouts, and safely no-ops on
missing files.
bash -n shared-scripts.shpasses.Checklist
yarn testpasses