Repository navigation
test(config): pin DECDN_* env vars wire to run args (#268) - #292
Merged
Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new test case, run_subcommand_args_are_wired_to_decdn_env_vars, in crates/node/src/config/mod.rs. The test utilizes clap introspection to verify that CLI arguments for the run subcommand are correctly mapped to their corresponding DECDN_ environment variables, ensuring that configuration overrides via environment variables are properly maintained and documented. I have no feedback to provide.
Issue #217 covers the TOML file vs. default-value leg of the three- layer merge, and existing resolve_*_cli_overrides_file_* tests cover the CLI-args-beat-file leg. The env-var leg — that clap populates RunArgs from DECDN_* environment variables so those values are available to beat the file — had no coverage: a dropped `env =` attr or a renamed field would silently break operators' env-based configs. Declarative rather than runtime test because std::env::set_var is `unsafe` under edition 2024 and the workspace forbids unsafe_code. Walking clap's Command introspection pins each run-subcommand arg ID to its expected DECDN_* env name, and a length assertion catches the reverse drift (a new env-bearing arg added without updating the expected list). Closes #268. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alpergundogdu
force-pushed
the
tests/268-env-shadows-toml
branch
from
April 22, 2026 16:23
a7437f5 to
d2c447a
Compare
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.
Summary
Adds one unit test,
run_subcommand_args_are_wired_to_decdn_env_vars, that pins everyDECDN_*environment variable to the correspondingrunsubcommand arg ID using clap'sCommandintrospection. Combined with the existingresolve_*_cli_overrides_file*tests, this closes the env-var leg of the three-layer merge (CLI/env > TOML > default) that #268 flagged as untested.Closes #268.
Why declarative and not runtime
The issue's obvious framing is "set
DECDN_RATE_PER_MB=100, load a TOML withrate_per_mb = 42, assert resolved == 100." That's not safely doable in this workspace:std::env::set_varisunsafeunder edition 2024.unsafe_code = "forbid"(Cargo.toml:82).temp-env/serial_testdev-dep would work but adds a crate for one test's worth of runtime coverage that's already transitively proven by existing tests.The declarative approach asks a cheaper question ("is clap wired to pick up
DECDN_*?") that, when combined with the already-testedcli.foo = Some(x)→resolved.foo == xbehavior, gives the same guarantee. If the env attribute gets dropped or renamed, this test fails in CI; if operators' env-based configs silently stop overriding TOML, this test catches why.What it pins
18
(arg_id, env_name)pairs covering everyDECDN_*env var on therunsubcommand:DECDN_DATA_DIR,DECDN_REGIONDECDN_BIND_PORT,DECDN_RELAY_URLDECDN_RPC_URL,DECDN_ETH_KEYSTORE,DECDN_PAYMENT_CHANNEL_ADDRESS,DECDN_STAKING_REGISTRY_ADDRESSDECDN_CACHE_DIR,DECDN_CACHE_SIZE_MB,DECDN_MAX_BLOB_SIZE_MB,DECDN_ORIGIN_URL,DECDN_ORIGIN_PATHDECDN_RATE_PER_MBDECDN_LOG_LEVEL,DECDN_LOG_FORMAT,DECDN_METRICS_PORT,DECDN_OTLP_ENDPOINTBi-directional: the test also asserts that the total env-bearing-arg count matches the expected list length, so a newly-added
#[arg(env = "DECDN_*")]that wasn't added to the expected list also fails — pins both "don't remove" and "don't silently add undocumented."Test plan
cargo test -p decdn-node --lib config::tests::run_subcommand_args_are_wired_to_decdn_env_vars→ passescargo test -p decdn-node→ 55 unit + integration tests passcargo clippy -p decdn-node --all-targets -- -D warnings→ cleancargo fmt -- --check crates/node/src/config/mod.rs→ clean🤖 Generated with Claude Code