Skip to content

Commit 2de27ff

Browse files
silehtclaude
andcommitted
refactor(auth): read the environment through the funnel
`mergify-auth` landed while this stack was in flight and its production side already reads through `mergify_core::env`, since `var_non_empty` predates the funnel. Only its tests were left: `machine`'s `COMPUTERNAME` / `HOSTNAME` chain, `browser`'s `SSH_CONNECTION` / `DISPLAY` / `WAYLAND_DISPLAY` probes, and `with_mergify_token`. They install an overlay now, like everywhere else, so the crate stops mutating the process environment and drops its `temp-env` dependency. `with_mergify_token` keeps its shape: the overlay is on this thread and the `current_thread` runtime it builds drives the future on that same thread, so the closure form still works and no call site changes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Change-Id: I7d4c755cee8cc90db511ea671e5c23215300c03c
1 parent 7d63c95 commit 2de27ff

5 files changed

Lines changed: 15 additions & 25 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/mergify-auth/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ url = { workspace = true }
2525
mergify-core = { path = "../mergify-core", features = ["test-support"] }
2626
mergify-test-support = { path = "../mergify-test-support" }
2727
serde_json = { workspace = true }
28-
temp-env = { workspace = true }
2928
tempfile = { workspace = true }
3029
tokio = { workspace = true, features = ["rt-multi-thread"] }
3130
wiremock = { workspace = true }

crates/mergify-auth/src/browser.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ mod tests {
231231
#[cfg(target_os = "macos")]
232232
#[test]
233233
fn macos_opens_the_url_with_open() {
234-
let command = temp_env::with_vars(
234+
let command = mergify_core::env::testing::with_vars(
235235
[("SSH_CONNECTION", None::<&str>), ("SSH_TTY", None::<&str>)],
236236
|| command_for("https://dashboard.mergify.com/device"),
237237
)
@@ -246,7 +246,7 @@ mod tests {
246246
#[cfg(all(unix, not(target_os = "macos")))]
247247
#[test]
248248
fn a_graphical_session_gets_xdg_open() {
249-
let command = temp_env::with_vars(
249+
let command = mergify_core::env::testing::with_vars(
250250
[("DISPLAY", Some(":0")), ("WAYLAND_DISPLAY", None::<&str>)],
251251
|| command_for("https://dashboard.mergify.com/device"),
252252
)
@@ -263,7 +263,7 @@ mod tests {
263263
#[cfg(target_os = "macos")]
264264
#[test]
265265
fn an_ssh_session_to_a_mac_opens_nothing() {
266-
let opened = temp_env::with_vars(
266+
let opened = mergify_core::env::testing::with_vars(
267267
[
268268
("SSH_CONNECTION", Some("10.0.0.1 52000 10.0.0.2 22")),
269269
("SSH_TTY", None),
@@ -281,7 +281,7 @@ mod tests {
281281
#[cfg(all(unix, not(target_os = "macos")))]
282282
#[test]
283283
fn a_headless_session_opens_nothing() {
284-
let opened = temp_env::with_vars(
284+
let opened = mergify_core::env::testing::with_vars(
285285
[("DISPLAY", None::<&str>), ("WAYLAND_DISPLAY", None::<&str>)],
286286
|| command_for("https://dashboard.mergify.com/device").is_ok(),
287287
);

crates/mergify-auth/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ mod testing {
4141
/// Run `body` to completion with `MERGIFY_TOKEN` forced to
4242
/// `value`.
4343
///
44-
/// `temp_env` cannot wrap an `.await`, so the future is driven
45-
/// inside the closure instead. Without this the wiring that
46-
/// reads the variable is untestable, and untestable wiring is
47-
/// wiring a future edit can delete with the suite still green:
48-
/// asserting on the renderer alone proves only that the renderer
49-
/// can print a note, never that anything asks it to.
44+
/// The overlay is installed on this thread and the future is
45+
/// driven on it, by a `current_thread` runtime built here.
46+
/// Without this the wiring that reads the variable is
47+
/// untestable, and untestable wiring is wiring a future edit can
48+
/// delete with the suite still green: asserting on the renderer
49+
/// alone proves only that the renderer can print a note, never
50+
/// that anything asks it to.
5051
pub fn with_mergify_token<F: std::future::Future>(value: Option<&str>, body: F) -> F::Output {
5152
let runtime = tokio::runtime::Builder::new_current_thread()
5253
.enable_all()
5354
.build()
5455
.unwrap();
55-
temp_env::with_var("MERGIFY_TOKEN", value, || runtime.block_on(body))
56+
mergify_core::env::testing::with_var("MERGIFY_TOKEN", value, || runtime.block_on(body))
5657
}
5758
}

crates/mergify-auth/src/machine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mod tests {
111111
// the variable instead.
112112
#[test]
113113
fn the_variables_are_the_fallback() {
114-
let from_windows = temp_env::with_vars(
114+
let from_windows = mergify_core::env::testing::with_vars(
115115
[
116116
("COMPUTERNAME", Some("WIN-BOX")),
117117
("HOSTNAME", Some("ignored")),
@@ -120,13 +120,13 @@ mod tests {
120120
);
121121
assert_eq!(from_windows.as_deref(), Some("WIN-BOX"));
122122

123-
let from_shell = temp_env::with_vars(
123+
let from_shell = mergify_core::env::testing::with_vars(
124124
[("COMPUTERNAME", None), ("HOSTNAME", Some("build-42"))],
125125
from_env,
126126
);
127127
assert_eq!(from_shell.as_deref(), Some("build-42"));
128128

129-
let from_nothing = temp_env::with_vars(
129+
let from_nothing = mergify_core::env::testing::with_vars(
130130
[("COMPUTERNAME", None::<&str>), ("HOSTNAME", None)],
131131
from_env,
132132
);

0 commit comments

Comments
 (0)