Skip to content

refactor(cli): assert the clap env hook is absent without mutating the environment - #1841

Merged
mergify[bot] merged 1 commit into
mainfrom
devs/sileht/test-env-access-ub/assert-clap-env-hook-absent-without-mutating-env--512c50f3
Sep 21, 2026
Merged

mergify[bot] merged 1 commit into
mainfrom
devs/sileht/test-env-access-ub/assert-clap-env-hook-absent-without-mutating-env--512c50f3

Conversation

@sileht

@sileht sileht commented Sep 18, 2026

Copy link
Copy Markdown
Member

The two tests that pinned "clap must not read MERGIFY_* itself"
each exported one variable empty and parsed one argv. They were the
last two temp_env calls in mergify-cli, and the only ones whose
reader was a dependency rather than our own code.

They are two tests now, at the two altitudes the rule lives at. A
walk over the built clap::Command tree asserts that no argument
anywhere declares env = "…", which catches the hook at declaration
and covers every argument rather than --config and
--test-exit-code. A parse of each of those two argvs asserts the
observable property the deleted tests asserted, because the walk
only sees that one spelling: default_value_t = std::env::var(…).unwrap_or_default() reproduces monorepo#33423
exactly and declares no hook. Neither test needs an environment.

MERGIFY_BASE_URL joins the rest in treating exported-but-empty as
unset. install.sh already guards the same lever with [ -n … ], so
the two halves of one feature disagreed: an empty value built the URL
/latest-release.json, which reqwest rejects as relative, instead of
falling back to the default host.

The rest is plumbing: MERGIFY_CLI_TESTING_UTF8_MODE, NO_COLOR /
FORCE_COLOR / CLICOLOR_FORCE and self_update's
MERGIFY_BASE_URL read through mergify_core::env. That is the
env in scope in both files now; args() and current_exe() are
spelled std::env::, since neither is the environment.

Co-Authored-By: Claude Opus 5 noreply@anthropic.com

@sileht

sileht commented Sep 18, 2026 •

Copy link
Copy Markdown
Member Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 refactor(cli): assert the clap env hook is absent without mutating the environment #1841 👈
2 refactor(auth): read the environment through the funnel #1842
3 chore(lint): make the next process-environment read fail the build #1843

@mergify

mergify Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 6 merge protections satisfied — ready to merge.

Show 6 satisfied protections

🟢 🤖 Continuous Integration

  • all of:
    • check-success=ci-gate

🟢 👀 Review Requirements

  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|internal|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?!?:

🟢 🔎 Reviews

  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

  • body ~= (?ms:.{48,})

🟢 🚦 Auto-queue

When all merge protections are satisfied, this pull request will be queued automatically.

@mergify
mergify Bot requested a review from a team September 18, 2026 07:14
Copilot AI lite review requested due to automatic review settings September 18, 2026 07:38
@sileht
sileht force-pushed the devs/sileht/test-env-access-ub/assert-clap-env-hook-absent-without-mutating-env--512c50f3 branch from 7c98c5e to 7d63c95 Compare September 18, 2026 07:38
@sileht
sileht deployed to func-tests-live September 18, 2026 07:39 — with GitHub Actions Active
@sileht

sileht commented Sep 18, 2026 •

Copy link
Copy Markdown
Member Author

Revision history

# Type Changes Reason Date
1 initial 7c98c5e 2026-09-18 07:38 UTC
2 content 7c98c5e → 7d63c95 2026-09-18 07:38 UTC
3 content 7d63c95 → 083b61b 2026-09-18 08:13 UTC
4 rebase 083b61b → befb4f4 (rebase only) 2026-09-21 05:43 UTC

@mergify
mergify Bot had a problem deploying to Mergify Merge Protections September 18, 2026 07:39 Failure

Copilot AI 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.

🟡 Changes recommended

Two review comments remain regarding documentation and regression-test coverage.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Refactors CLI environment handling through mergify_core::env, removes environment-mutating tests, and treats empty MERGIFY_BASE_URL as unset.

Changes:

  • Adds Clap command-tree and parsing assertions.
  • Updates environment access in CLI and self-update code.
  • Removes the unused temp-env dependency.
File summaries
File Summary
crates/mergify-cli/src/self_update.rs Handles empty base URLs; add focused regression tests.
crates/mergify-cli/src/main.rs Updates environment access and Clap tests; refresh the stale deleted-test reference.
crates/mergify-cli/Cargo.toml Removes temp-env.
Cargo.lock Updates dependency metadata.
Review details
  • Files reviewed: 3/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/mergify-cli/src/main.rs
Comment thread crates/mergify-cli/src/self_update.rs
@sileht
sileht force-pushed the devs/sileht/test-env-access-ub/assert-clap-env-hook-absent-without-mutating-env--512c50f3 branch from 7d63c95 to 083b61b Compare September 18, 2026 08:13
@sileht
sileht deployed to func-tests-live September 18, 2026 08:13 — with GitHub Actions Active
@mergify
mergify Bot had a problem deploying to Mergify Merge Protections September 18, 2026 08:14 Failure
@sileht
sileht marked this pull request as ready for review September 18, 2026 08:17
kozlek
kozlek previously approved these changes Sep 20, 2026
@mergify
mergify Bot requested a review from a team September 20, 2026 20:40
Base automatically changed from devs/sileht/test-env-access-ub/read-env-funnel--1a360878 to main September 20, 2026 20:49
@mergify

mergify Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

@sileht this pull request is now in conflict 😩

@mergify mergify Bot added the conflict label Sep 20, 2026
…e environment

The two tests that pinned "clap must not read `MERGIFY_*` itself"
each exported one variable empty and parsed one argv. They were the
last two `temp_env` calls in `mergify-cli`, and the only ones whose
reader was a dependency rather than our own code.

They are two tests now, at the two altitudes the rule lives at. A
walk over the built `clap::Command` tree asserts that no argument
anywhere declares `env = "…"`, which catches the hook at declaration
and covers every argument rather than `--config` and
`--test-exit-code`. A parse of each of those two argvs asserts the
observable property the deleted tests asserted, because the walk
only sees that one spelling: `default_value_t =
std::env::var(…).unwrap_or_default()` reproduces monorepo#33423
exactly and declares no hook. Neither test needs an environment.

`MERGIFY_BASE_URL` joins the rest in treating exported-but-empty as
unset. `install.sh` already guards the same lever with `[ -n … ]`, so
the two halves of one feature disagreed: an empty value built the URL
`/latest-release.json`, which reqwest rejects as relative, instead of
falling back to the default host.

The rest is plumbing: `MERGIFY_CLI_TESTING_UTF8_MODE`, `NO_COLOR` /
`FORCE_COLOR` / `CLICOLOR_FORCE` and `self_update`'s
`MERGIFY_BASE_URL` read through `mergify_core::env`. That is the
`env` in scope in both files now; `args()` and `current_exe()` are
spelled `std::env::`, since neither is the environment.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Change-Id: I512c50f33a89380f3d9f4a8f7a37725a875d6804
@sileht
sileht force-pushed the devs/sileht/test-env-access-ub/assert-clap-env-hook-absent-without-mutating-env--512c50f3 branch from 083b61b to befb4f4 Compare September 21, 2026 05:43
@sileht
sileht deployed to func-tests-live September 21, 2026 05:43 — with GitHub Actions Active
@mergify
mergify Bot dismissed kozlek’s stale review September 21, 2026 05:44

Pull request has been modified.

@mergify
mergify Bot deployed to Mergify Merge Protections September 21, 2026 05:44 Active
@mergify mergify Bot removed the conflict label Sep 21, 2026
@mergify
mergify Bot requested a review from a team September 21, 2026 07:09
@mergify

mergify Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-21 08:21 UTC · Rule: default · triggered by merge protections
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-21 08:21 UTC · at c50a1cc7365989ce9f57d81ae23722b34f01aca2 · squash

This pull request spent 20 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify mergify Bot added the queued label Sep 21, 2026
@mergify
mergify Bot merged commit c50a1cc into main Sep 21, 2026
22 checks passed
@mergify
mergify Bot deleted the devs/sileht/test-env-access-ub/assert-clap-env-hook-absent-without-mutating-env--512c50f3 branch September 21, 2026 08:21
@mergify mergify Bot removed the queued label Sep 21, 2026

This branch was successfully deployed

2 active deployments
Mergify Merge Protections — befb4f43 Deployed Sep 21, 2026 by mergify[bot]
func-tests-live — befb4f43 Deployed Sep 21, 2026 by sileht via live-tests #1939
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants