Skip to content

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

Open
Ankitsinghsisodya wants to merge 2 commits into
knative:mainfrom
Ankitsinghsisodya:fix/cli-config-add-partial-flags
Open

fix(cmd): return error when config add flags are partially provided#3762
Ankitsinghsisodya wants to merge 2 commits into
knative:mainfrom
Ankitsinghsisodya:fix/cli-config-add-partial-flags

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

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.

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.
Copilot AI review requested due to automatic review settings May 16, 2026 12:37
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 16, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ankitsinghsisodya
Once this PR has been reviewed and has the lgtm label, please assign matejvasek for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 requested review from dsimansk and jrangelramos May 16, 2026 12:37
@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 16, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 16, 2026

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 CLI validation to prevent creating labels/envs with missing name/value pairs, and introduces regression tests to ensure invalid flag combinations fail fast.

Changes:

  • Add input validation for config labels add when only one of --name/--value is provided.
  • Add input validation for config envs add when --name is provided without --value.
  • Add tests covering the new validation behavior for labels and envs.

Reviewed changes

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

File Description
cmd/config_test.go Adds regression tests for invalid --name/--value combinations and a helper for labels command setup.
cmd/config_labels.go Rejects labels add invocations where only one of --name/--value is specified.
cmd/config_envs.go Rejects envs add when --name is provided without --value.

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

Comment thread cmd/config_envs.go
Comment thread cmd/config_test.go
Comment thread cmd/config_labels.go
@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.43%. Comparing base (2bbf9fe) to head (a7b1858).

❗ There is a different number of reports uploaded between BASE (2bbf9fe) and HEAD (a7b1858). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (2bbf9fe) HEAD (a7b1858)
e2e 3 2
integration 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3762      +/-   ##
==========================================
- Coverage   57.06%   51.43%   -5.64%     
==========================================
  Files         181      181              
  Lines       21145    21154       +9     
==========================================
- Hits        12067    10881    -1186     
- Misses       7855     9234    +1379     
+ Partials     1223     1039     -184     
Flag Coverage Δ
e2e 22.65% <0.00%> (-13.27%) ⬇️
e2e go 31.45% <0.00%> (-0.02%) ⬇️
e2e node 27.23% <0.00%> (-0.02%) ⬇️
e2e python 31.82% <0.00%> (-0.02%) ⬇️
e2e quarkus 27.35% <0.00%> (-0.02%) ⬇️
e2e rust 26.76% <0.00%> (-0.02%) ⬇️
e2e springboot 25.27% <0.00%> (-0.02%) ⬇️
e2e typescript 27.34% <0.00%> (-0.02%) ⬇️
e2e-config-ci 28.29% <0.00%> (-0.02%) ⬇️
integration ?
unit macos-14 45.14% <100.00%> (+0.08%) ⬆️
unit macos-latest 45.14% <100.00%> (+0.08%) ⬆️
unit ubuntu-24.04-arm 45.37% <100.00%> (+0.05%) ⬆️
unit ubuntu-latest 46.07% <100.00%> (+0.05%) ⬆️
unit windows-latest 45.18% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants