Skip to content

Commit 59e178b

Browse files
Reorder config precedence: global flag beats environment variable (#1308)
* Make --client-version flag override CLIENT_VERSION env var The pmm-framework resolved CLIENT_VERSION from the environment before the global --client-version flag, so a run passing --client-version=3.5.0 with CLIENT_VERSION=3.6.0 exported (e.g. by CI) still installed 3.6.0. An explicit CLI flag must beat an ambient env var: reorder resolve_value() to check GLOBAL_CLIENT_VERSION first for the CLIENT_VERSION key. Update the precedence test and the README/ARCHITECTURE docs to match. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0111eoWF5ABrxakfE2AbFsEk Signed-off-by: Claude <noreply@anthropic.com> * Address review: trim narrating comments from precedence fix Drop the rationale paragraph from resolve_value() (the precedence list already states the flag wins; the why lives in the PR/commit) and the per-assertion comments from the cli.bats precedence test, matching the repo's minimal-comments house style and the file's comment-free tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0111eoWF5ABrxakfE2AbFsEk Signed-off-by: Claude <noreply@anthropic.com> --------- Signed-off-by: Claude <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 51c924d commit 59e178b

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

qa-integration/pmm_qa/pmm-framework/ARCHITECTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Four sources can supply a value. Highest wins:
168168

169169
```mermaid
170170
flowchart LR
171-
A["1. environment variable<br/>SETUP_TYPE=gr ./pmm-framework ..."] --> B["2. global flag<br/>--client-version<br/>(CLIENT_VERSION only)"]
171+
A["1. global flag<br/>--client-version<br/>(CLIENT_VERSION only)"] --> B["2. environment variable<br/>SETUP_TYPE=gr ./pmm-framework ..."]
172172
B --> C["3. spec option<br/>--database ps,SETUP_TYPE=gr"]
173173
C --> D["4. registered default<br/>lib/config.sh"]
174174
```

qa-integration/pmm_qa/pmm-framework/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,14 @@ and `sentinel`/`sentinels` for Valkey.
112112

113113
Configuration precedence is:
114114

115-
1. Environment variable
116-
2. Global `--client-version` (for `CLIENT_VERSION`)
115+
1. Global `--client-version` flag (for `CLIENT_VERSION`)
116+
2. Environment variable
117117
3. Per-database option
118118
4. Registered default
119119

120+
The `--client-version` flag comes first so an explicit override beats an
121+
ambient `CLIENT_VERSION` in the environment (e.g. one exported by CI).
122+
120123
Each registration in `lib/config.sh` pins the version used when a spec omits
121124
one with an explicit `DEFAULT_VERSION=` entry. It is not a user-settable
122125
option, and the order of the version list carries no meaning. Registering

qa-integration/pmm_qa/pmm-framework/lib/config.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ database_default_value() {
205205
# e.g. setup_type=$(resolve_value PS SETUP_TYPE DB_CONFIG)
206206
#
207207
# Precedence, highest first:
208-
# 1. an existing shell/environment variable named KEY
209-
# 2. the global --client-version, for KEY == CLIENT_VERSION only
208+
# 1. the global --client-version flag, for KEY == CLIENT_VERSION only
209+
# 2. an existing shell/environment variable named KEY
210210
# 3. the per-database option parsed from the --database spec
211211
# 4. the default registered above
212212
#
213-
# Step 1 mirrors the Python framework's `os.environ.get(KEY)`, so an exported
213+
# Step 2 mirrors the Python framework's `os.environ.get(KEY)`, so an exported
214214
# but *empty* variable deliberately wins and yields ''. Contrast with
215215
# resolved_version() in lib/runners.sh, which mirrors `os.getenv(...) or ...`
216216
# and therefore skips empty values -- the two rules are intentionally
@@ -222,10 +222,10 @@ database_default_value() {
222222
resolve_value() {
223223
local type=$1 key=$2 config_name=$3
224224
local -n config_ref=$config_name
225-
if [[ -v $key ]]; then
226-
printf '%s' "${!key}"
227-
elif [[ $key == CLIENT_VERSION && -n ${GLOBAL_CLIENT_VERSION:-} ]]; then
225+
if [[ $key == CLIENT_VERSION && -n ${GLOBAL_CLIENT_VERSION:-} ]]; then
228226
printf '%s' "$GLOBAL_CLIENT_VERSION"
227+
elif [[ -v $key ]]; then
228+
printf '%s' "${!key}"
229229
elif [[ -v "config_ref[$key]" ]]; then
230230
printf '%s' "${config_ref[$key]}"
231231
else

qa-integration/pmm_qa/pmm-framework/tests/cli.bats

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,21 @@ load helpers/test_helper
3838
[[ $(resolved_version PS_VERSION PS "$DB_VERSION") == 8.0 ]]
3939
}
4040

41-
@test "value precedence is environment then global then database then default" {
41+
@test "value precedence is global flag then environment then database then default" {
4242
parse_database_spec 'ps,CLIENT_VERSION=from-spec,QUERY_SOURCE=slowlog'
4343
GLOBAL_CLIENT_VERSION=from-global
4444
[[ $(resolve_value PS CLIENT_VERSION DB_CONFIG) == from-global ]]
4545
[[ $(resolve_value PS QUERY_SOURCE DB_CONFIG) == slowlog ]]
4646

4747
CLIENT_VERSION=from-env
48+
[[ $(resolve_value PS CLIENT_VERSION DB_CONFIG) == from-global ]]
49+
50+
GLOBAL_CLIENT_VERSION=''
4851
[[ $(resolve_value PS CLIENT_VERSION DB_CONFIG) == from-env ]]
4952
unset CLIENT_VERSION
5053

51-
GLOBAL_CLIENT_VERSION=''
54+
[[ $(resolve_value PS CLIENT_VERSION DB_CONFIG) == from-spec ]]
55+
5256
unset 'DB_CONFIG[QUERY_SOURCE]'
5357
[[ $(resolve_value PS QUERY_SOURCE DB_CONFIG) == perfschema ]]
5458
}

0 commit comments

Comments
 (0)