Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/static-site-deploy/__tests__/cli.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 13 additions & 6 deletions packages/static-site-deploy/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ async function promptForConfig(site: string, allowPrompt: boolean) {
}
}

function runProvisioner(site: string, config: SiteConfig, provision: Record<string, string>, 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;
Expand Down Expand Up @@ -113,7 +120,7 @@ async function main() {
console.log(`Saved local deploy settings for ${site}. No AWS credentials were stored.`);
}

const provision: Record<string, string> = {
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,
Expand All @@ -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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Blank values skip required provisioning prompts

The question filter provision[question.name] === undefined (packages/static-site-deploy/src/cli.ts:146) treats an empty or whitespace-only value (e.g. AWS_ACCOUNT_ID="" or --reviewer ' ') as present, so the required prompt never appears.
At spawn time the trim provision.SITE_REVIEWER?.trim() || undefined (cli.ts:60) discards the whitespace-only reviewer, and blank AWS values flow into provision.sh, whose unset-only required check does not catch them — producing an opaque provisioning failure instead of the intended interactive re-prompt.

📋 Prompt for AI Agents

In packages/static-site-deploy/src/cli.ts at line 146, change the filter from provision[question.name] === undefined to !provision[question.name]?.trim() so empty or whitespace-only --reviewer/--account-id/--role-name values (or their env equivalents) still prompt the user, instead of being silently dropped by the trim at line 60 or passed blank into provision.sh. Add a test asserting that a whitespace-only SITE_REVIEWER env value still produces the reviewer prompt.

const answers = questions.length ? await prompter.prompt<Partial<ProvisionSettings>>({}, questions.map(question => ({
...question,
type: 'text',
}))) : {};
Expand Down
Loading