Skip to content

fix(dg): warn when DASH_FORGE_NETWORK is overridden by a higher layer - #698

Merged
PastaPastaPasta merged 3 commits into
masterfrom
fix/dg-env-network-warn
Nov 24, 2026
Merged

PastaPastaPasta merged 3 commits into
masterfrom
fix/dg-env-network-warn

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

dg silently ignores DASH_FORGE_NETWORK once dg auth login has saved a network in config.toml, but git push (git-remote-dash) reads the variable first. QA reproduced it: DASH_FORGE_NETWORK=mainnet dg repo list returned testnet data with no hint. After the mainnet launch, someone logged in on mainnet who sets DASH_FORGE_NETWORK=testnet "to try something" would make dg writes 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, dg now prints one warning on stderr that quotes the variables as set and gives the fix:

warning: DASH_FORGE_NETWORK=mainnet is ignored; using testnet from config.toml (pass --network mainnet to use mainnet, or unset DASH_FORGE_NETWORK)
warning: DASH_FORGE_NETWORK=testnet is ignored; using devnet-sakura from this repository's git config, but git push here reads testnet (unset DASH_FORGE_NETWORK)
  • Pure decision function ignored_env_network with unit tests; printed once per process; stdout and --json stay clean; skipped for dg doctor, which has its own row for this.
  • git-remote-dash is unchanged on purpose: dg, forge-import and forge-runner pass their chosen network to git through these same variables, so a helper-side warning would fire on every dg --network X call.
  • BUILDING.md says dg warns.

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_empty helper.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a warning when network environment settings conflict with a higher-priority selection, identifying the selected network and suggesting how to resolve the mismatch.
  • Documentation
    • Clarified network precedence and the difference in how dg and git-remote-dash handle environment network settings.

PastaPastaPasta and others added 3 commits November 24, 2026 08:34
…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]>

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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-723 is v.map(|s| s.trim().to_string()).filter(|s| !s.is_empty()). from_env → from_lookup feeds it std::env::var(k).ok(). The new raw_env closure (crates/dg/src/context.rs:430-435) is std::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 becomes None both ways, an empty or all-blank value becomes None, and surrounding whitespace is trimmed. So raw.clone().normalized() (split_devnet_key over values that are already non-empty and trimmed) gives exactly the network/devnet_name that from_env builds. The comparison inside ignored_env_network therefore 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 is env.clone() → env, a move. The raw read happens after resolve, in the existing not-doctor block, and only feeds the warning. In the tests, env_warning passes env.clone().normalized() to stack, which matches from_lookup for the untrimmed test inputs, and it passes the unsplit value to ignored_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:
    • mainnet over config testnet → … is ignored; using testnet from config.toml (pass --network mainnet to use mainnet, or unset DASH_FORGE_NETWORK).
    • testnet under repository devnet-sakura → …, but git push here reads testnet (unset DASH_FORGE_NETWORK). The nit about "reads" is fixed.
    • testnet under --network mainnet → no hint.
    • DASH_FORGE_DEVNET_NAME=paloma alone over config devnet-sakura: overlay drops 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 + sakura over mainnet → both variables listed, are, with both in unset.
    • A bare devnet over mainnet → DASH_FORGE_NETWORK=devnet is ignored, with the <name> hint.
    • New: devnet-sakura alone 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 one unset. Before this change the same input was split and the warning named two variables.
    • TESTNET → quoted as TESTNET, with the label folded to testnet. tesnet → no flag hint, unset only.
    • No warning when the environment agrees (Mainnet), when a bare devnet goes 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=sakura lists both variables as set, and the label is devnet-sakura. DEVNET-sakura splits case-insensitively and is quoted as set. devnet-sakura + DASH_FORGE_DEVNET_NAME=paloma is left unsplit, as from_env leaves it. Over mainnet the warning lists both variables and gives only unset. That is fine, because the helper refuses that pair anyway. None of these cases changed in behavior with this commit.

Nits (optional)

  1. raw_env repeats forge-core's private non_empty. A pub fn in forge-core that returns the two env values unsplit (or making non_empty public) would keep the two from drifting apart. They are the same today, so this is optional.
  2. The trimming on the raw path is not tested, because the closure lives in Ctx::resolve. Something like DASH_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.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

dg now warns when a higher-precedence network setting conflicts with DASH_FORGE_NETWORK or DASH_FORGE_DEVNET_NAME. The warning is suppressed when the environment agrees with or selects the resolved network, and it does not run during dg doctor.

Changes: Network override warning

Layer / File(s) Summary
Detect and report network overrides
crates/dg/src/context.rs, docs/BUILDING.md
Ctx::resolve retains environment network settings and warns once per process when higher-precedence settings select a different network. Tests cover conflicts and suppression cases. The documentation describes the warning and contrasts it with git-remote-dash behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Suggested reviewers: claude

Merge Risk: Minimal · up to d5800

This adds a stderr warning when the DASH_FORGE_NETWORK or DASH_FORGE_DEVNET_NAME environment variables are overridden by a higher-precedence network setting. Network selection and stdout/JSON output are unchanged. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: dg now warns when a higher-precedence layer overrides DASH_FORGE_NETWORK. The raw summary, the objectives, and the description all describe this warning. The title use…
Description check Passed The description explains the problem and the change. It gives the reproduction, the reasoning for keeping the documented precedence, sample warning output, the decision not to change git-remote-dash, …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: dg now warns when a higher-precedence layer overrides DASH_FORGE_NETWORK. The raw summary, the objectives, and the description all describe this warning. The title uses the conventional fix(dg) prefix and stays under 70 characters.

Full details: Description check

Explanation

The description explains the problem and the change. It gives the reproduction, the reasoning for keeping the documented precedence, sample warning output, the decision not to change git-remote-dash, and the test and live verification steps. It also lists follow-ups. It does not follow the repository template exactly. The 'What and why' and 'How it was tested' headings are only implied, and the checklist items are not addressed. The description does not state whether make check-rust and make check-web were run, and it does not mention rule vectors or docs/guides updates. The screenshots section is not needed for this CLI change. It does not link an issue.

Resolution

Optionally add explicit 'What and why' and 'How it was tested' headings. State whether make check-rust was run, or note that it was not run. Confirm that the docs/guides requirement is met, since BUILDING.md is in docs/ but not docs/guides. Note that the rule-vector and web checks do not apply, if they do not.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 194d5018-21dd-459a-acc0-316b409c249f
Commits

Reviewing files that changed from the base of the PR and between 1e382b5 and d58003a.

Files selected for processing: 2

  • crates/dg/src/context.rs
  • docs/BUILDING.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@PastaPastaPasta
PastaPastaPasta merged commit 1432e9f into master Nov 24, 2026
20 checks passed
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.

1 participant