Skip to content

test(config): pin DECDN_* env vars wire to run args (#268) - #292

Merged
alpergundogdu merged 1 commit into
mainfrom
tests/268-env-shadows-toml
Apr 22, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
tests/268-env-shadows-toml

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

Adds one unit test, run_subcommand_args_are_wired_to_decdn_env_vars, that pins every DECDN_* environment variable to the corresponding run subcommand arg ID using clap's Command introspection. Combined with the existing resolve_*_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 with rate_per_mb = 42, assert resolved == 100." That's not safely doable in this workspace:

  • std::env::set_var is unsafe under edition 2024.
  • The workspace has unsafe_code = "forbid" (Cargo.toml:82).
  • A temp-env / serial_test dev-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-tested cli.foo = Some(x) → resolved.foo == x behavior, 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 every DECDN_* env var on the run subcommand:

  • Identity: DECDN_DATA_DIR, DECDN_REGION
  • Network: DECDN_BIND_PORT, DECDN_RELAY_URL
  • Blockchain: DECDN_RPC_URL, DECDN_ETH_KEYSTORE, DECDN_PAYMENT_CHANNEL_ADDRESS, DECDN_STAKING_REGISTRY_ADDRESS
  • Cache: DECDN_CACHE_DIR, DECDN_CACHE_SIZE_MB, DECDN_MAX_BLOB_SIZE_MB, DECDN_ORIGIN_URL, DECDN_ORIGIN_PATH
  • Payment: DECDN_RATE_PER_MB
  • Observability: DECDN_LOG_LEVEL, DECDN_LOG_FORMAT, DECDN_METRICS_PORT, DECDN_OTLP_ENDPOINT

Bi-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 → passes
  • cargo test -p decdn-node → 55 unit + integration tests pass
  • cargo clippy -p decdn-node --all-targets -- -D warnings → clean
  • cargo fmt -- --check crates/node/src/config/mod.rs → clean
  • Pre-commit hooks (fmt / clippy / deny / markdownlint / etc.) → all passed

🤖 Generated with Claude Code

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
alpergundogdu force-pushed the tests/268-env-shadows-toml branch from a7437f5 to d2c447a Compare April 22, 2026 16:23
@alpergundogdu
alpergundogdu merged commit ef4e3d9 into main Apr 22, 2026
9 checks passed
@alpergundogdu
alpergundogdu deleted the tests/268-env-shadows-toml branch April 22, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: no unit tests for the three-layer config merge when environment variables shadow TOML file values

1 participant