From 04dd0daa37c336b7e7be45dab233cbbff646aa75 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Wed, 25 Nov 2026 01:02:25 +0000 Subject: [PATCH] fix(static-site-deploy): handle blank reviewer input --- .../static-site-deploy/__tests__/cli.test.cjs | 20 +++++++++++++++++++ packages/static-site-deploy/src/cli.ts | 19 ++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/static-site-deploy/__tests__/cli.test.cjs b/packages/static-site-deploy/__tests__/cli.test.cjs index 64bc2ee..6102b4f 100644 --- a/packages/static-site-deploy/__tests__/cli.test.cjs +++ b/packages/static-site-deploy/__tests__/cli.test.cjs @@ -242,6 +242,26 @@ test('dry run plans site-specific IAM and GitHub settings without mutating the s const noReviewerArgs = provisionArgs.filter((arg, index) => arg !== '--reviewer' && provisionArgs[index - 1] !== '--reviewer'); const reviewerPlanError = 'gh: Failed to create the environment protection rule. Please ensure the billing plan supports the required reviewers protection rule. (HTTP 422)'; +test.each([null, '', ' '])('a blank reviewer prompt (%j) does not look up a GitHub user', answer => { + const { cwd, cliRun } = fixture(); + const preload = join(cwd, 'prompt.cjs'); + writeFileSync(preload, ` +const { createRequire } = require('node:module'); +const { Inquirerer } = createRequire(${JSON.stringify(cli)})('inquirerer'); +process.stdin.isTTY = process.stdout.isTTY = true; +Inquirerer.prototype.text = async question => { + if (question.name !== 'SITE_REVIEWER' || question.required) throw new Error('Expected an optional reviewer prompt'); + return ${JSON.stringify(answer)}; +}; +`); + const result = cliRun([...noReviewerArgs.filter(arg => arg !== '--yes'), '--dry-run'], { + ...targets, NODE_OPTIONS: `--require="${preload}"`, + }); + assert.equal(result.status, 0, result.stderr); + assert.doesNotMatch(result.stdout, /users\/|reviewers/); + assert.match(result.stderr, /no required reviewer/); +}); + test('plans and checks configuration without a reviewer', () => { const { cliRun } = fixture(); const result = cliRun([...noReviewerArgs, '--dry-run'], targets); diff --git a/packages/static-site-deploy/src/cli.ts b/packages/static-site-deploy/src/cli.ts index 7a2f592..d00dcd1 100644 --- a/packages/static-site-deploy/src/cli.ts +++ b/packages/static-site-deploy/src/cli.ts @@ -47,10 +47,17 @@ async function promptForConfig(site: string, allowPrompt: boolean) { } } -function runProvisioner(site: string, config: SiteConfig, provision: Record, dryRun: boolean) { +type ProvisionSettings = { + SITE_REVIEWER?: string | null; + AWS_ACCOUNT_ID?: string; + AWS_DEPLOY_ROLE_NAME?: string; + SITE_BRANCH: string; +}; + +function runProvisioner(site: string, config: SiteConfig, provision: ProvisionSettings, dryRun: boolean) { const { AWS_PROFILE: _profile, ...targets } = config; const result = spawnSync('bash', [join(__dirname, 'provision.sh'), ...(dryRun ? ['--dry-run'] : [])], { - env: { ...awsEnvironment(config), ...targets, ...provision, SITE_REPO: site }, + env: { ...awsEnvironment(config), ...targets, ...provision, SITE_REVIEWER: provision.SITE_REVIEWER?.trim() || undefined, SITE_REPO: site }, stdio: 'inherit', }); if (result.error) throw result.error; @@ -113,7 +120,7 @@ async function main() { console.log(`Saved local deploy settings for ${site}. No AWS credentials were stored.`); } - const provision: Record = { + const provision: ProvisionSettings = { SITE_REVIEWER: options.reviewer ?? process.env.SITE_REVIEWER, AWS_ACCOUNT_ID: options['account-id'] ?? process.env.AWS_ACCOUNT_ID, AWS_DEPLOY_ROLE_NAME: options['role-name'] ?? process.env.AWS_DEPLOY_ROLE_NAME, @@ -132,12 +139,12 @@ async function main() { }]); if (!configure) return; } - const questions = [ + const questions = ([ { name: 'SITE_REVIEWER', message: 'GitHub reviewer login (optional)', required: false }, { name: 'AWS_ACCOUNT_ID', message: 'AWS account ID', required: true }, { name: 'AWS_DEPLOY_ROLE_NAME', message: 'Dedicated IAM deploy role name', required: true }, - ].filter(question => provision[question.name] === undefined); - const answers = questions.length ? await prompter.prompt({}, questions.map(question => ({ + ] as const).filter(question => provision[question.name] === undefined); + const answers = questions.length ? await prompter.prompt>({}, questions.map(question => ({ ...question, type: 'text', }))) : {};