Skip to content

fix(cmd): return error when config add flags are partially provided - #3826

Merged
knative-prow[bot] merged 3 commits into
knative:mainfrom
Ankitsinghsisodya:fix/cli-config-add-partial-flags
Nov 24, 2026
Merged

knative-prow[bot] merged 3 commits into
knative:mainfrom
Ankitsinghsisodya:fix/cli-config-add-partial-flags

Conversation

@Ankitsinghsisodya

@Ankitsinghsisodya Ankitsinghsisodya commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Note: Re-submission of #3762, accidentally closed when the head repository was deleted.

Problem

config envs add --name=KEY (without --value) silently writes fn.Env{Name: &"KEY", Value: nil} to func.yaml. This entry is invisible in config envs list, renders as KEY= (empty string) at deploy time, and fails ValidateEnvs at build time with "env entry #N is missing value field". The OR condition in the non-interactive guard allowed the partial set to bypass the interactive prompt and go straight to Save.

config labels add --name=Foo (without --value) silently drops the flag and launches the interactive prompt with no explanation, because the AND condition means the non-interactive block is never entered.

Changes

cmd/config_envs.go

  • Added guard: if --name is provided but --value is not, return --value is required when --name is provided before calling Save.
  • Bulk-import usage (--value='{{ secret:S }}' without --name) is unaffected — the guard only triggers when name is set and value is nil.

cmd/config_labels.go

  • Added guards before the interactive fallback: if only --name or only --value is provided, return a clear error rather than silently entering interactive mode.

Tests

Added to cmd/config_test.go:

  • TestEnvsAddNameWithoutValue — verifies error is returned and Save is not called.
  • TestLabelsAddNameWithoutValue — verifies error when --name is given without --value.
  • TestLabelsAddValueWithoutName — verifies error when --value is given without --name.

Copilot AI review requested due to automatic review settings May 21, 2026 11:20
@knative-prow
knative-prow Bot requested review from dsimansk and jrangelramos May 21, 2026 11:20
@knative-prow knative-prow Bot added size/M 🤖 PR changes 30-99 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 21, 2026
@knative-prow

knative-prow Bot commented May 21, 2026

Copy link
Copy Markdown

Hi @Ankitsinghsisodya. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds validation and tests to prevent config envs/labels add from accepting incomplete flag pairs (e.g., --name without --value) which would otherwise write broken config entries.

Changes:

  • Add a regression test ensuring config envs add --name without --value fails and does not save.
  • Add regression tests for config labels add when --name/--value are provided without the other.
  • Add CLI-side validation for config labels add when flags are incomplete.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cmd/config_test.go Adds tests for missing --name/--value combinations and a helper to build the labels command.
cmd/config_labels.go Adds validation intended to require --name and --value together.
cmd/config_envs.go Adds validation to require --value when --name is provided for envs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/config_labels.go
Comment on lines +96 to +99
if np != nil {
return errors.New("--value is required when --name is provided")
}
if vp != nil {
Comment thread cmd/config_test.go
Comment on lines +150 to +159
// TestLabelsAddNameWithoutValue ensures that providing --name without --value returns an error.
func TestLabelsAddNameWithoutValue(t *testing.T) {
mock := common.NewMockLoaderSaver()
mock.LoadFn = func(path string) (fn.Function, error) {
return fn.Function{}, nil
}
mock.SaveFn = func(f fn.Function) error {
t.Error("Save must not be called when validation fails")
return nil
}
@lkingland lkingland added ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels May 22, 2026
@lkingland

Copy link
Copy Markdown
Member

Seems fine to me. I think Copilot mis-read the labels order.

/lgtm
/approve

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Aug 20, 2026
@knative-prow

knative-prow Bot commented Aug 20, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Ankitsinghsisodya, lkingland

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added the approved 🤖 PR has been approved by an approver from all required OWNERS files. label Aug 20, 2026
@lkingland

Copy link
Copy Markdown
Member

/override codecov/project

@knative-prow

knative-prow Bot commented Aug 24, 2026

Copy link
Copy Markdown

@lkingland: Overrode contexts on behalf of lkingland: codecov/project

Details

In response to this:

/override codecov/project

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Ankitsinghsisodya
Ankitsinghsisodya force-pushed the fix/cli-config-add-partial-flags branch from a7b1858 to 857da5a Compare August 31, 2026 14:42
@knative-prow knative-prow Bot removed the lgtm 🤖 PR is ready to be merged. label Aug 31, 2026
Ankitsinghsisodya and others added 3 commits November 24, 2026 14:01
Added validation to ensure that the --name flag cannot be provided without the --value flag, and vice versa, in both environment and label commands. This prevents the creation of invalid configurations. Added corresponding unit tests to verify the expected error behavior when these flags are misused.
Updated error handling in the label command to use errors.New instead of fmt.Errorf for consistency in flag validation messages. This change improves clarity and maintains uniformity in error reporting when required flags are missing.
Replaced the buffer writer in the config command setup from ci.NewBufferWriter to github.NewBufferWriter for improved integration. Additionally, introduced a test CI generator factory using fnCmd.NewTestCIGeneratorFactory to enhance testing capabilities for the command. This change aims to streamline the configuration setup process and improve test reliability.
@lkingland
lkingland force-pushed the fix/cli-config-add-partial-flags branch from b49378d to d511e37 Compare November 24, 2026 05:03
@lkingland

Copy link
Copy Markdown
Member

Thanks @Ankitsinghsisodya. We rebased this onto current main; your three commits are unchanged.

/lgtm

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Nov 24, 2026
@knative-prow
knative-prow Bot merged commit e0299a5 into knative:main Nov 24, 2026
45 checks passed
@github-project-automation github-project-automation Bot moved this from New to Done in Functions Traige Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. lgtm 🤖 PR is ready to be merged. ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants