Add mapbox doctor: a read-only snapshot of the environment - #40
Open
mattpodwysocki wants to merge 10 commits into
Open
mattpodwysocki wants to merge 10 commits into
mattpodwysocki wants to merge 10 commits into
Conversation
auth whoami already answers which token the next command will use; this answers the rest of what commonly goes wrong before a real command finds out the hard way: a proxy variable silently not doing what someone thinks, or the update-check/telemetry switches resolving to something other than what was intended. Reuses auth::resolve_source for the token report rather than re-deriving the precedence — that function is the one place the order is decided, and auth::whoami's own docs explain why a second opinion here would be worse than none. token_expires_at and token_usage move from private to pub(crate) for this; token_account and load_credentials were already public. --verify additionally checks that api.mapbox.com is reachable, through the same http::client() (and therefore the same proxy handling) every other request in this crate uses. Nothing is sent otherwise — the same precedent auth whoami --verify already sets: a diagnostic command should not itself be the request that reveals the problem it exists to describe. MAPBOX_INTERNAL_DOCTOR_URL overrides the checked host, for the same reason update_check.rs's MAPBOX_INTERNAL_UPDATE_URL exists: without a seam, --verify could only ever be tested against the real network. tests/doctor.rs drives both the reachable and unreachable cases through a loopback server, and confirms nothing is sent at all when --verify is absent. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
zmofei
added this pull request to stack #41
September 23, 2026 11:49
zmofei
removed this pull request from stack #41
September 23, 2026 11:58
zmofei
requested changes
Sep 23, 2026
zmofei
left a comment
Member
There was a problem hiding this comment.
A few correctness bugs in doctor's diagnostics, plus one design question and one cleanup suggestion.
Bugs: - PROXY_VARS now lists both cases (HTTPS_PROXY and https_proxy, etc.) — reqwest reads both, curl's own convention, and the old list only had the uppercase spelling. Documented the remaining gap against the true question rather than closing it silently: this still answers "is a variable set", not "would this request use one" (NO_PROXY can exempt a host, a scheme-specific variable only applies to that scheme), since reqwest has no public API to ask "was a proxy applied" directly. - The reported update-check state now depends on telemetry_allowed too, not just the persisted setting and the dedicated env switch. MAPBOX_CLI_NO_TELEMETRY silences the update check as well (see update_check.rs's module docs), which the first version of this line forgot, so MAPBOX_CLI_NO_TELEMETRY=1 alone printed "Update check: on" for a check that would not run. - --verify now threads http::requested(matches) through instead of a hardcoded 5-second budget, so --timeout/MAPBOX_TIMEOUT affect it like any other request. Falls back to 5 seconds — a diagnostic someone is waiting on, not a request a command line's payload bounds — only when neither was given. - The connectivity JSON's error field is now omitted outside --debug via skip_serializing_if, rather than present and set to null. Structural fix requested in review: lines and JSON used to be built independently from the same underlying values, which is exactly how the telemetry bug above happened — the JSON read three raw switches while the text line's own condition asked only two of them. Report and its four constituent structs are now the one source both the text and the JSON renderer read from, so the same drift can't happen twice. tests/doctor.rs covers all four bugs: a lowercase proxy variable, telemetry alone turning the reported update check off, an explicit --timeout cutting a hung connection short, and the error field's presence keyed to --debug. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
Author
|
Thanks for the thorough review. Addressed everything:
New tests for all four bugs in |
Windows environment variables are case-insensitive, so HTTPS_PROXY and https_proxy are the same variable there. Checking both spellings as independent PROXY_VARS entries reported a single value set once under both names on Windows CI — caught by the platform's own test run, not locally on macOS where the two are genuinely distinct. PROXY_VARS is now four (uppercase, lowercase) pairs; either being set reports one entry, always spelled with the uppercase name. This also answers a cleaner question than four-to-eight independent checks did: "is a proxy configured for this concern" rather than "list every spelling that happens to be set", which nobody was asking for anyway. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Verified against hyper-util's own source rather than assumed from curl's reputation: get_first_env(&["HTTPS_PROXY", "https_proxy"]) checks exactly those two spellings and nothing else, so a mixed-case Https_Proxy is not a gap in this list — it would not be honored by the client either, on a case-sensitive OS. The real fourth gap, worth naming: on macOS, hyper-util falls back to the system's Dynamic Store proxy settings when no env var is set at all, and this reads only the environment, so a proxy configured solely through Network settings is invisible to `mapbox doctor` even though reqwest would still use it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mattpodwysocki
changed the base branch from
feat/177-config-list-unset
to
main
September 23, 2026 14:21
Contributor
Author
|
Closing and reopening to force a CI run — the base-branch retarget didn't trigger one and neither did two follow-up pushes. |
# Conflicts: # CHANGELOG.md
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
Stacked on #39 (
mapbox config list/unset), which is itself stacked on #35 (mapbox config get/set). Base branch isfeat/177-config-list-unset, so this diff is just the incremental change — rebase ontomainonce #35 and #39 merge.mapbox doctor— a read-only snapshot of what the next command would see: which token wins and its state, which proxy variables are in effect, and where the update-check/telemetry switches currently stand.--verifyadditionally checks thatapi.mapbox.comis reachable, through the samehttp::client()(and therefore the same proxy handling) every other request in this crate uses. Nothing is sent otherwise — same precedentauth whoami --verifyalready sets.auth::resolve_sourcefor the token report rather than re-deriving the precedence.token_expires_at/token_usagemoved from private topub(crate)for this;token_account/load_credentialswere already public.MAPBOX_INTERNAL_DOCTOR_URLoverrides the checked host — undocumented, for the same reasonupdate_check.rs'sMAPBOX_INTERNAL_UPDATE_URLexists: without a seam,--verifycould only ever be tested against the real network.Test plan
cargo build,cargo fmt,cargo clippy --all-targets -- -D warnings,cargo test— all cleantests/doctor.rs: bare state, a token in the environment, both switches (persisted + env), a proxy variable, and — through a loopback server — both the reachable and unreachable--verifyoutcomes, plus a timing assertion that no request happens at all without--verifydocs/commands.mdand CHANGELOG updatedapi.mapbox.comtoo (not just the loopback server)