Repository navigation
fix(dg): warn when DASH_FORGE_NETWORK is overridden by a higher layer - #698
Conversation
…overrode dg takes flags, the repository's git config and config.toml over DASH_FORGE_NETWORK / DASH_FORGE_DEVNET_NAME, while git-remote-dash reads the environment first. A user signed in on mainnet who set DASH_FORGE_NETWORK=testnet got dg writes on mainnet and git pushes on testnet, with no hint. Keep the precedence, and print one stderr warning naming the ignored value, the network in use and where it came from. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…riable set Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ncluded Co-Authored-By: Claude Opus 5.5 <[email protected]>
PastaPastaPasta
left a comment
There was a problem hiding this comment.
Verdict: approve
d58003a fixes the should-fix and the nit from the second review, and it also closes item 3 from the first review (the test helper now builds the env layer the way from_env does). I found nothing that blocks the merge. I checked this from the source only. I did not run cargo, as the brief said not to; I relied on the author's boat run (clippy clean, 610/0).
Verified
- The raw trimming matches forge-core's
non_empty.crates/forge-core/src/network.rs:721-723isv.map(|s| s.trim().to_string()).filter(|s| !s.is_empty()).from_env→from_lookupfeeds itstd::env::var(k).ok(). The newraw_envclosure (crates/dg/src/context.rs:430-435) isstd::env::var(key).ok().map(|v| v.trim().to_string()).filter(|v| !v.is_empty()). Those are the same expression: a non-UTF-8 value becomesNoneboth ways, an empty or all-blank value becomesNone, and surrounding whitespace is trimmed. Soraw.clone().normalized()(split_devnet_keyover values that are already non-empty and trimmed) gives exactly thenetwork/devnet_namethatfrom_envbuilds. The comparison insideignored_env_networktherefore sees the same values as before. Only the text of the message changed. - No change in which network is used. The stack's env layer is still
NetworkSettings::from_env()(context.rs:411). The only change there isenv.clone()→env, a move. The raw read happens afterresolve, in the existing not-doctor block, and only feeds the warning. In the tests,env_warningpassesenv.clone().normalized()tostack, which matchesfrom_lookupfor the untrimmed test inputs, and it passes the unsplit value toignored_env_network, which matches the call site. Moving the warning under the single!matches!(…Doctor…)block also takes care of the cosmetic nit from the second review: the warning is no longer built for doctor and then thrown away. - The message is right for every case in the tests. I traced each one through
split_devnet_key→ label/flag →agrees→set/verb/unset→ hint:mainnetover config testnet →… is ignored; using testnet from config.toml (pass --network mainnet to use mainnet, or unset DASH_FORGE_NETWORK).testnetunder repository devnet-sakura →…, but git push here reads testnet (unset DASH_FORGE_NETWORK). The nit about "reads" is fixed.testnetunder--network mainnet→ no hint.DASH_FORGE_DEVNET_NAME=palomaalone over config devnet-sakura:overlaydrops the env's name because it differs, so devnet-sakura is used. The label is devnet-paloma and only that one variable is listed. Correct.devnet+sakuraover mainnet → both variables listed,are, with both inunset.- A bare
devnetover mainnet →DASH_FORGE_NETWORK=devnet is ignored, with the<name>hint. - New:
devnet-sakuraalone over mainnet →DASH_FORGE_NETWORK=devnet-sakura is ignored; … (pass --network devnet --devnet-name sakura to use devnet-sakura, or unset DASH_FORGE_NETWORK). It is quoted as set, with one variable and oneunset. Before this change the same input was split and the warning named two variables. TESTNET→ quoted asTESTNET, with the label folded totestnet.tesnet→ no flag hint,unsetonly.- No warning when the environment agrees (
Mainnet), when a baredevnetgoes with a higher devnet, when the environment decided, when nothing is set, or when the source is Key.
- Inputs not in the tests, traced by hand:
devnet-sakura+DASH_FORGE_DEVNET_NAME=sakuralists both variables as set, and the label is devnet-sakura.DEVNET-sakurasplits case-insensitively and is quoted as set.devnet-sakura+DASH_FORGE_DEVNET_NAME=palomais left unsplit, asfrom_envleaves it. Over mainnet the warning lists both variables and gives onlyunset. That is fine, because the helper refuses that pair anyway. None of these cases changed in behavior with this commit.
Nits (optional)
raw_envrepeats forge-core's privatenon_empty. Apub fnin forge-core that returns the two env values unsplit (or makingnon_emptypublic) would keep the two from drifting apart. They are the same today, so this is optional.- The trimming on the raw path is not tested, because the closure lives in
Ctx::resolve. Something likeDASH_FORGE_NETWORK=" mainnet "would only be covered by the wiring test deferred in the second review. Please mention it in that follow-up issue.
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
dgsilently ignoresDASH_FORGE_NETWORKoncedg auth loginhas saved a network in config.toml, butgit push(git-remote-dash) reads the variable first. QA reproduced it:DASH_FORGE_NETWORK=mainnet dg repo listreturned testnet data with no hint. After the mainnet launch, someone logged in on mainnet who setsDASH_FORGE_NETWORK=testnet"to try something" would makedgwrites on mainnet while their pushes go to testnet.This keeps the documented precedence (flag > repo git config > config.toml > env). When the env names a different network than the one a higher layer chose,
dgnow prints one warning on stderr that quotes the variables as set and gives the fix:ignored_env_networkwith unit tests; printed once per process; stdout and--jsonstay clean; skipped fordg doctor, which has its own row for this.dg --network Xcall.Testing (boat sandbox):
cargo fmt --check,cargo clippy --locked -p dg --all-targets -D warnings,cargo test --locked -p dg(610 passed). The new test fails with the warning disabled. Live: config.toml on testnet +DASH_FORGE_NETWORK=mainnet dg --json repo list→ warning on stderr, clean JSON on stdout.Follow-ups, not in this PR: an integration test for the call site (printed once, stderr only), and sharing forge-core's
non_emptyhelper.🤖 Generated with Claude Code
Summary by CodeRabbit
dgandgit-remote-dashhandle environment network settings.