Skip to content

fix(functions): use param defaults in non-interactive deploys - #11546

Open
yeegz wants to merge 5 commits into
firebase:mainfrom
yeegz:fix/11523-noninteractive-param-defaults
Open

yeegz wants to merge 5 commits into
firebase:mainfrom
yeegz:fix/11523-noninteractive-param-defaults

Conversation

@yeegz

@yeegz yeegz commented Nov 18, 2026

Copy link
Copy Markdown

Description

Fixes #11523.

With --non-interactive, a Functions param that wasn't in a .env file failed the deploy even if it had a default. As discussed on the issue, it now uses the default in that case. Params without a default still fail with the same error, which now lists only those params.

Defaults go through the same CEL resolution and type check as the interactive prompt, so both modes give the same value. Interactive mode doesn't change.

Scenarios Tested

Added tests in params.spec.ts:

  • string, false, int, list and CEL defaults resolve without prompting
  • a .env value still beats the default
  • with one param that has a default and one that doesn't, the error names only the second

The new tests fail on main and pass with this change. The rest of the functions tests pass too.

Sample Commands

firebase deploy --only functions --non-interactive with defineString('GREETING', { default: 'hello' }) and no .env now deploys with GREETING=hello.

@google-cla

google-cla Bot commented Nov 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where firebase deploy --non-interactive fails for Functions parameters that have a default value. In non-interactive mode, parameters with defaults are now resolved to their default values instead of throwing an error, while parameters without defaults still trigger a failure. Comprehensive unit tests have been added to verify this behavior. The review feedback suggests a minor improvement to paramValueFromDefault to reduce nesting by removing unnecessary else statements after early returns, aligning with the repository's style guide.

Comment on lines +494 to +502
if (param.type === "string") {
return new ParamValue(String(resolvedDefault), false, { string: true });
} else if (param.type === "int") {
return new ParamValue(String(resolvedDefault), false, { number: true });
} else if (param.type === "boolean") {
return new ParamValue(String(resolvedDefault), false, { boolean: true });
} else if (param.type === "list") {
return ParamValue.fromList(resolvedDefault as string[], param.delimiter);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the repository style guide, we should reduce nesting as much as possible. Since each conditional block in paramValueFromDefault returns early, we can remove the else keywords to flatten the control flow and improve readability.

  if (param.type === "string") {
    return new ParamValue(String(resolvedDefault), false, { string: true });
  }
  if (param.type === "int") {
    return new ParamValue(String(resolvedDefault), false, { number: true });
  }
  if (param.type === "boolean") {
    return new ParamValue(String(resolvedDefault), false, { boolean: true });
  }
  if (param.type === "list") {
    return ParamValue.fromList(resolvedDefault as string[], param.delimiter);
  }
References
  1. Reduce nesting as much as possible: Code should avoid unnecessarily deep nesting or long periods of nesting. Use early returns, continue, and break statements in functions and loops to handle edge cases early and keep main logic flat. (link)

@yeegz
yeegz force-pushed the fix/11523-noninteractive-param-defaults branch from 0992c31 to e1b3f6a Compare November 18, 2026 10:53
In non-interactive mode, resolveParams failed for every param that was not
set in a dotenv file, even when the param had a default. Resolve such
params to their default instead (with the same CEL resolution and type
check as the interactive path), and only report params that have no
default. Interactive mode is unchanged.

Fixes firebase#11523
@yeegz
yeegz force-pushed the fix/11523-noninteractive-param-defaults branch from bf00fd7 to f31eeee Compare November 19, 2026 07:47

@IzaakGough IzaakGough left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@yeegz Thanks for the contribution! The approach looks right to me.

I've left a couple of small requests inline.

Comment thread src/deploy/functions/params.ts Resolved
Comment thread src/deploy/functions/params.ts Resolved
Comment thread src/deploy/functions/params.ts Resolved
In non-interactive mode, report params with neither a dotenv value nor a
default before resolving any default, so a default that refers to a
missing param still gets the message that names it. Apply the same
validationRegex and nonEmpty checks the prompt uses to the default, and
update the resolveParams and promptParam doc comments.
@yeegz

yeegz commented Nov 19, 2026

Copy link
Copy Markdown
Author

Thanks @IzaakGough! Done in the latest commit:

  • updated both doc comments
  • missing params are now reported before any default gets resolved, so your API_HOST / URL example gives the "no value for API_HOST" message again. Added that as a test
  • defaults now go through the same validationRegex and nonEmpty checks as the prompt. Since there's no one to re-prompt in non-interactive mode, a bad default fails with an error that names the param

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 9 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@a75d703). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/deploy/functions/params.ts 75.00% 7 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11546   +/-   ##
=======================================
  Coverage        ?   61.13%           
=======================================
  Files           ?      870           
  Lines           ?    51087           
  Branches        ?    10313           
=======================================
  Hits            ?    31234           
  Misses          ?    18718           
  Partials        ?     1135           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ive-param-defaults

# Conflicts:
#	CHANGELOG.md
…ive-param-defaults

# Conflicts:
#	CHANGELOG.md

This branch has not been deployed

No deployments
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.

Functions params: a param with a default still fails deploy in --non-interactive mode

3 participants