Repository navigation
fix(cli): warn when a profile or flag overrides a set VOLTAGE_* variable - #128
Draft
thebrandonlucas wants to merge 2 commits into
Draft
thebrandonlucas wants to merge 2 commits into
thebrandonlucas wants to merge 2 commits into
Conversation
Under --profile, or with a flag such as --wallet, commands ignored set VOLTAGE_* scope, key, and directory variables without saying so; only `voltage context` listed them. The voltage-api skill's helper lets the same variables win, so the two tools could reach different wallets in one shell. Every command that reads the configuration now prints one stderr warning per ignored variable before it prompts or sends a request, from the same list `voltage context` reports. --quiet keeps it, as it keeps other warnings; stdout is unchanged.
…save Both commands save the organization, environment, and account their flags name, so warning that those flags override VOLTAGE_* variables was noise. They still warn about a profile or --config-dir. The staging and local wrappers now pass their directory as VOLTAGE_CONFIG_DIR instead of --config-dir, so the hint after `profiles create` no longer names a flag the wrappers refuse.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes DEV-2956
Closes #121
Problem
With
--profile, or with a flag such as--wallet, the CLI ignores a setVOLTAGE_ORGANIZATION_ID,VOLTAGE_ENVIRONMENT_ID,VOLTAGE_WALLET_ID,VOLTAGE_API_KEY, orVOLTAGE_CONFIG_DIR. Onlyvoltage contextsaid so, inignored_variables. Thevoltage-apiskill's helper reads the same names and lets them win, so in one shell the helper and the CLI could act on different wallets without any sign.Behavior
Every command that reads the configuration prints one stderr line per ignored variable, before it prompts or sends a request:
VOLTAGE_ORGANIZATION_ID,VOLTAGE_ENVIRONMENT_ID,VOLTAGE_WALLET_ID--profileis selected, or--org/--env/--walletis given--profile NAME is selected, or--org is given(and so on)VOLTAGE_API_KEY--profileor--account--profile NAME is selectedor--account is givenVOLTAGE_CONFIG_DIR--config-dir--config-dir is given--jsonresults are unchanged. The warning is a stderr line,warning:in the caution color on a terminal, plain when redirected.--quietkeeps it.--quiethides optional progress and notices;docs/guides/scripting.mdsays it never hides warnings, and the offset-pagination deprecation already follows that. A silent override is what this issue is about, so hiding it behind--quietwould bring the problem back for scripts.price,convert,completions, and barevoltageread no scope, so they never warn.Design notes
config::ignored_variablesnow returnsIgnoredVariable { name, precedence }, wherePrecedenceisFlag("--wallet")orProfile, decided from the sameScopeSourcesas before.auth::ignored_api_keyreplacesignores_ambient_api_keythe same way.context::ignored_variablesjoins the two lists.voltage contextmaps it to names (its JSON is unchanged), andSession::openpasses it tocontext::warn_ignoredright after the scope is resolved. One list feeds both, so the warning andvoltage contextcannot disagree.Line::text, which scrubs control characters.error.detailof--jsonerrors. That changes the error contract, so it is left for a follow-up if wanted.Try it on staging
The wrapper drops
VOLTAGE_*variables exported in your shell and passes only the ones in.env. These steps needVOLTAGE_ORGANIZATION_IDandVOLTAGE_ENVIRONMENT_IDset in.env(add them if they are not there; any valid UUIDs show the warning).Expect: no warning.
organization_idandenvironment_idsshow sourceenvironment.Expect, before the wallet table:
warning: VOLTAGE_ORGANIZATION_ID is set but ignored because --org is given. Use your real organization ID so the list succeeds.voltage profiles create try-it --account me --org ORG_ID --env ENV_ID voltage wallets list --profile try-it --quiet voltage wallets list --profile try-it --json | head -c 80 voltage profiles delete try-itExpect: both lists start with one
warning: … is set but ignored because --profile try-it is selectedline for eachVOLTAGE_*variable in.env,--quietincluded. With--json, stdout is still the JSON envelope (the warnings are on stderr). The delete removes the profile.Validation
cargo fmt --check,cargo clippy --locked --all-targets -- -D warnings,cargo machete --with-metadata,cargo test --locked(200 unit, 150 integration), andpython3 scripts/check-coverage.pyall pass.context: the warning text for a profile, a flag, and--account; the sentence without a profile name; and that a profile name with escape characters is scrubbed (checked on the unstripped line).profile_credentials_override_ambient_key_and_scopenow checks the exact stderr under--profile --quiet(organization, environment, and API key, in that order) and that stdout is still the JSON result. Newa_flag_over_a_set_variable_warns_and_a_used_variable_does_notchecks--orgover a set variable, and no warning when the variable is used.scripts/crap-report.sh, cargo-llvm-cov 0.8.5, knots 1.16.0): 848 of 1059 functions measured, 0 violations. The highest score is 18.10,wait_for_paymentinsrc/api.rs, which this PR does not change. Changed functions:context::inspect12.01,Session::open5.0,ignored_api_key4.0,config::ignored_variables3.0,ignored_warningandwarn_ignored2.0.Checklist
docs/andCHANGELOG.md(Unreleased) are updated. (docs/guides/login-and-profiles.md,docs/reference/environment.md)docs/development.mdpasses.voltage-pr-reviewskill, and every new error and early-return path has a test.wait_for_payment, unchanged); no function at or above 20.important_linepath.