Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

test: fold the mock stub into the wt binary (#3712)

Maximilian Roosdd453304edf5
diff --git a/.config/nextest.toml b/.config/nextest.toml
index d35bb509f..c47be1a1d 100644
--- a/.config/nextest.toml
+++ b/.config/nextest.toml
@@ -3,17 +3,12 @@
# 0.9.118 (https://github.com/nextest-rs/nextest/issues/2878).
nextest-version = "0.9.118"
-# Enable setup-scripts (still experimental in nextest) so the build-bins script
-# below can run before any test starts.
-#
-# Nothing in this file may change what a test observes — no `[env]`, no
-# `$NEXTEST_ENV` from a setup script. `cargo test`, `cargo llvm-cov`, `cargo
-# bench` and the Nix derivation run this same suite and would silently disagree.
-# Environment belongs in the hermetic latch (`shell_exec::enable_hermetic_test_env`)
-# and `.cargo/config.toml`, behavior in the fixture. See
-# tests/CLAUDE.md → One Result Per Test, Whatever Runs It; build-bins below is a
-# build step, not an exception to it.
-experimental = ["setup-scripts"]
+# Nothing in this file may change what a test observes — no `[env]`, no setup
+# scripts. `cargo test`, `cargo llvm-cov`, `cargo bench` and the Nix derivation
+# run this same suite and would silently disagree. Environment belongs in the
+# hermetic latch (`shell_exec::enable_hermetic_test_env`) and
+# `.cargo/config.toml`, behavior in the fixture. See
+# tests/CLAUDE.md → One Result Per Test, Whatever Runs It.
[profile.default]
slow-timeout = { period = "180s", terminate-after = 1 }
@@ -22,47 +17,3 @@ success-output = "never"
[profile.default.junit]
path = "junit.xml"
-
-# Build the `mock-stub` helper binary before any test runs.
-#
-# It lives in a separate workspace package so cargo-dist doesn't ship it
-# (see tests/helpers/mock-stub/Cargo.toml for the rationale). The
-# `default-members` setting builds it under unfiltered `cargo nextest run`,
-# but a target filter like `--test integration` overrides default-members and
-# the helper is skipped — so tests that spawn it fail. (wt-perf, the other
-# helper package, needs no such treatment: its CLI tests live in-package, so
-# cargo builds its binary whenever its tests run.)
-#
-# Under `cargo llvm-cov nextest`, nextest doesn't propagate the outer
-# --target-dir as a CARGO_TARGET_DIR env var, so a plain `cargo build` would
-# write to target/ rather than target/llvm-cov-target/ and the test binary
-# would still find no helper. Derive the right target-dir from
-# LLVM_PROFILE_FILE (cargo-llvm-cov sets it to a path inside its target dir)
-# and pass it through with --target-dir. Worktrunk already requires bash for
-# shell-integration tests on every platform, so bash here is fine.
-#
-# TODO: collapse this whole layer once cargo-dist supports per-binary
-# exclusion. The chain — the separate `tests/helpers/mock-stub` package, the
-# dummy `tests/builds.rs` trick that makes `default-members` build it, this
-# setup-script, and `workspace_bin()` in src/testing/mod.rs — exists only
-# because cargo-dist (≤ 0.30.x at time of writing) ships every `[[bin]]` in
-# the main crate and offers no per-binary opt-out. PR #127 (commit d21925692)
-# documented the failure modes: `required-features` on `[[bin]]` still trips
-# cargo-dist's "bin not found", and `[package.metadata.dist] dist = false`
-# excludes the entire package, not individual binaries. When cargo-dist gains
-# per-binary exclusion (or we move off cargo-dist), pull mock-stub back into
-# the worktrunk crate as a `[[bin]]` target, use `CARGO_BIN_EXE_<name>`, and
-# delete this script along with `workspace_bin()` and the helper package.
-[scripts.setup.build-bins]
-command = [
- "bash",
- "-c",
- 'if [ -n "${LLVM_PROFILE_FILE:-}" ]; then cargo build --bin mock-stub --target-dir "$(dirname "$LLVM_PROFILE_FILE")"; else cargo build --bin mock-stub; fi',
-]
-
-[[profile.default.scripts]]
-# Only the `integration` test binary calls `workspace_bin()` (via MockConfig),
-# so don't pay the helper-build cost on `--lib`, `--bin wt`, doctest, or
-# bench runs.
-filter = "binary(integration)"
-setup = "build-bins"
diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml
index 6fc4c95d4..16ba5c9c6 100644
--- a/.github/workflows/nightly.yaml
+++ b/.github/workflows/nightly.yaml
@@ -107,8 +107,7 @@ jobs:
# `required-features = ["cli", "syntax-highlighting"]` (Cargo.toml) because
# it execs the `wt` binary and snapshots its highlighted output, so cargo
# runs it only on combinations that satisfy both and runs lib + doc tests
- # everywhere. No target filter, so default-members builds the mock-stub
- # helper bin the lib suite shells out to.
+ # everywhere.
needs: gate
if: needs.gate.outputs.run == 'true'
runs-on: ubuntu-24.04
diff --git a/Cargo.lock b/Cargo.lock
index 6288f6640..d9b276caf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1853,14 +1853,6 @@ dependencies = [
"windows-sys 0.61.2",
]
-[[package]]
-name = "mock-stub"
-version = "0.1.0"
-dependencies = [
- "serde",
- "serde_json",
-]
-
[[package]]
name = "nix"
version = "0.28.0"
diff --git a/Cargo.toml b/Cargo.toml
index e18edf777..293eab3ef 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,9 +1,8 @@
[workspace]
-members = ["tests/helpers/wt-perf", "tests/helpers/mock-stub"]
-# Include the helper packages so a workspace `cargo test` builds their
-# binaries: mock-stub via its dummy tests/builds.rs, wt-perf via its real
-# in-package CLI tests.
-default-members = [".", "tests/helpers/mock-stub", "tests/helpers/wt-perf"]
+members = ["tests/helpers/wt-perf"]
+# Include the helper package so a workspace `cargo test` runs its in-package
+# CLI tests (which build its binary).
+default-members = [".", "tests/helpers/wt-perf"]
# cargo-affected input→test rules. cargo-affected selects tests by Rust-line
# coverage overlap, so a file a test reads at *runtime* (never recorded in
diff --git a/Taskfile.yaml b/Taskfile.yaml
index 94b155230..864d60a5a 100644
--- a/Taskfile.yaml
+++ b/Taskfile.yaml
@@ -21,8 +21,8 @@ tasks:
- cargo nextest run --no-run --features shell-integration-tests
# bash's `time` keyword counts every reaped child. Task's own interpreter
# (mvdan/sh) parses `time` but reports user/sys as zero, and /usr/bin/time
- # is an extra package on minimal Linux; bash is already required on every
- # platform (see .config/nextest.toml's build-bins).
+ # is an extra package on minimal Linux; bash is present on every dev and
+ # CI platform (Git Bash on Windows).
- bash -c 'time "$@"' bash cargo nextest run --features shell-integration-tests {{.CLI_ARGS}}
- echo "per-test timings in target/nextest/default/junit.xml"
diff --git a/src/commands/list/ci_status/mod.rs b/src/commands/list/ci_status/mod.rs
index 305c32e30..c0eb869b9 100644
--- a/src/commands/list/ci_status/mod.rs
+++ b/src/commands/list/ci_status/mod.rs
@@ -121,7 +121,7 @@ pub(crate) fn non_interactive_cmd(program: &str) -> Cmd {
/// Check if a CLI tool is available
///
/// On Windows, CreateProcessW (via Cmd) searches PATH for .exe files.
-/// We provide .exe mocks in tests via mock-stub, so this works consistently.
+/// Tests provide `.exe` mocks via `testing::mock_commands`, so this works consistently.
pub(crate) fn tool_available(tool: &str, args: &[&str]) -> bool {
Cmd::new(tool)
.args(args.iter().copied())
diff --git a/src/main.rs b/src/main.rs
index 7edb20669..a94ae8360 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1061,6 +1061,12 @@ fn print_help_to_stderr() {
}
fn main() {
+ // Mock-command playback for the test suite: when the harness linked this
+ // binary onto PATH under another name (`gh`, `glab`, …), play back the
+ // mock config and exit instead of running wt. Inert without
+ // WORKTRUNK_TEST_MOCK_CONFIG_DIR; see `worktrunk::testing::mock_stub`.
+ worktrunk::testing::mock_stub::maybe_run();
+
// Capture startup state before anything else: the working directory
// (used by shell_exec to resolve relative `GIT_*` path variables
// inherited from a parent `git` — e.g. when invoked via `git wt ...`
diff --git a/src/testing/mock_commands.rs b/src/testing/mock_commands.rs
index 7704c431f..9415c1495 100644
--- a/src/testing/mock_commands.rs
+++ b/src/testing/mock_commands.rs
@@ -1,15 +1,18 @@
// Cross-platform mock command helpers
//
// These helpers create mock executables that work on both Unix and Windows.
-// Mock behavior is defined via JSON config files, read by the mock-stub binary.
+// Mock behavior is defined via JSON config files, played back by the `wt`
+// binary itself: `main()` dispatches to `testing::mock_stub` when
+// `WORKTRUNK_TEST_MOCK_CONFIG_DIR` is set, argv[0] isn't wt's own name, and
+// the config dir holds a `<argv0>.json`.
//
-// On Unix: mock-stub is copied as the command name (e.g., `gh`)
-// On Windows: mock-stub.exe is copied as `gh.exe`
+// On Unix: `wt` is symlinked as the command name (e.g., `gh`)
+// On Windows: `wt.exe` is hard-linked (or copied) as `gh.exe`
//
// Both platforms read `<command>.json` for configuration.
//
// This approach:
-// - Single Rust binary for all platforms
+// - The mocks are the binary under test, so they can't be missing or stale
// - No bash dependency
// - Config is just JSON - easy to generate and debug
@@ -18,44 +21,6 @@ use std::collections::HashMap;
use std::fs;
use std::path::Path;
-/// Path to the mock-stub binary.
-///
-/// `workspace.default-members` builds it under an unfiltered `cargo test` /
-/// `cargo nextest run`, and `.config/nextest.toml`'s setup-script builds it
-/// under filtered nextest (including `cargo llvm-cov nextest`). A bare
-/// `cargo test --test integration` builds neither path — a target filter
-/// overrides `default-members`, and `cargo test` ignores nextest setup-scripts
-/// — so the binary is absent on a clean `target/`, and always absent under
-/// `cargo llvm-cov --test integration` since cargo-llvm-cov uses its own
-/// target dir. Asserting here surfaces the fix; the alternative is an opaque
-/// failure later inside a mock spawn (ENOENT on a dangling symlink, or a
-/// silently-dropped CI indicator when `tool_available("tea")` returns false).
-///
-/// Folding the helper bins back into the worktrunk crate would let
-/// `cargo test --test integration` build them automatically and delete this
-/// whole layer — it's blocked on cargo-dist; see `.config/nextest.toml` and
-/// `tests/helpers/mock-stub/Cargo.toml`.
-fn mock_stub_binary() -> std::path::PathBuf {
- let path = super::workspace_bin("mock-stub");
- assert_mock_stub_present(&path);
- path
-}
-
-/// Panic with build instructions if `path` (the resolved mock-stub location)
-/// doesn't exist. Split out so a unit test can drive the missing-binary arm
-/// without depending on whether the real binary happens to be built.
-fn assert_mock_stub_present(path: &Path) {
- assert!(
- path.exists(),
- "mock-stub binary not found at {}\n\n\
- Build it once with `cargo build -p mock-stub`, or use a runner that builds\n\
- the test helper bins:\n\
- \n cargo nextest run --features shell-integration-tests --test integration ...\
- \n cargo llvm-cov nextest --features shell-integration-tests --test integration ...\n",
- path.display(),
- );
-}
-
/// Builder for mock command configuration.
///
/// Example:
@@ -173,6 +138,17 @@ impl MockResponse {
impl MockConfig {
/// Create a new mock config for the given command name.
pub fn new(name: &str) -> Self {
+ // Playback dispatches on argv[0] (see `testing::mock_stub`), and wt's
+ // own names are reserved for wt itself — a mock under either name
+ // would silently run the real binary. Case-insensitive to match the
+ // dispatch's own guard: the config lookup goes through a filesystem
+ // that is case-insensitive on macOS and Windows, so a `WT.json` *is*
+ // `wt.json` there.
+ assert!(
+ !name.eq_ignore_ascii_case("wt") && !name.eq_ignore_ascii_case("git-wt"),
+ "a mock command cannot be named {name:?}: the mocks are the wt \
+ binary dispatching on argv[0]"
+ );
Self {
name: name.to_string(),
version: None,
@@ -236,18 +212,32 @@ pub fn mock_calls(log_dir: &Path, name: &str) -> Vec<String> {
.unwrap_or_default()
}
-/// Create mock binary in bin_dir with the given name.
+/// Create mock binary in bin_dir with the given name: a link to the `wt`
+/// binary, whose argv\[0\] dispatch plays back the mock config
+/// (`testing::mock_stub`).
+///
+/// Private on purpose: `MockConfig::write` is the only caller, and it writes
+/// `<name>.json` before linking. A link therefore can't exist without its
+/// config, which is what lets the dispatch treat a foreign argv\[0\] with no
+/// config as wt itself rather than a broken mock.
+///
/// Uses symlinks on Unix (instant, works across filesystems).
-/// Uses hard links on Windows (symlinks require admin privileges).
-pub fn copy_mock_binary(bin_dir: &Path, name: &str) {
- let stub = mock_stub_binary();
+/// Uses hard links on Windows (symlinks require admin privileges), falling
+/// back to a copy when the link fails — hard links can't cross drives, and
+/// the debug `wt.exe` is large enough that a copy per mock is the fallback
+/// rather than the default. CI keeps the fallback rare by pinning TEMP to
+/// the workspace volume (ci.yaml's Windows TEMP step); on a machine whose
+/// temp dir is on another drive, mock setup degrades to a full copy per
+/// mock but still works.
+fn copy_mock_binary(bin_dir: &Path, name: &str) {
+ let stub = super::wt_bin();
#[cfg(unix)]
{
let dest = bin_dir.join(name);
// Remove existing (config may have changed)
let _ = fs::remove_file(&dest);
- std::os::unix::fs::symlink(&stub, &dest).expect("failed to symlink mock-stub binary");
+ std::os::unix::fs::symlink(&stub, &dest).expect("failed to symlink wt as mock binary");
}
#[cfg(windows)]
@@ -255,9 +245,9 @@ pub fn copy_mock_binary(bin_dir: &Path, name: &str) {
let dest = bin_dir.join(format!("{}.exe", name));
// Remove existing (config may have changed)
let _ = fs::remove_file(&dest);
- // Copy on Windows - hard links fail across drives (common on CI),
- // and symlinks require admin privileges
- fs::copy(&stub, &dest).expect("failed to copy mock-stub.exe");
+ if fs::hard_link(&stub, &dest).is_err() {
+ fs::copy(&stub, &dest).expect("failed to copy wt.exe as mock binary");
+ }
}
}
@@ -343,42 +333,19 @@ API authentication.
#[cfg(test)]
mod tests {
use super::*;
- use crate::testing::test_tempdir;
#[test]
- fn test_mock_config_write() {
- let temp = test_tempdir();
- let bin_dir = temp.path();
-
- MockConfig::new("test-cmd")
- .version("test-cmd version 1.0")
- .command("foo", MockResponse::output("hello"))
- .command("bar", MockResponse::exit(42))
- .command(
- "gated",
- MockResponse::output("released").wait_for_file("release"),
- )
- .write(bin_dir);
-
- // Check config file exists and is valid JSON
- let config_path = bin_dir.join("test-cmd.json");
- assert!(config_path.exists());
- let content = fs::read_to_string(&config_path).unwrap();
- let parsed: serde_json::Value = serde_json::from_str(&content).unwrap();
- assert_eq!(parsed["version"], "test-cmd version 1.0");
- assert_eq!(parsed["commands"]["gated"]["wait_for_file"], "release");
-
- // Check binary exists
- #[cfg(unix)]
- assert!(bin_dir.join("test-cmd").exists());
-
- #[cfg(windows)]
- assert!(bin_dir.join("test-cmd.exe").exists());
+ #[should_panic(expected = "a mock command cannot be named")]
+ fn mock_config_rejects_wt_as_name() {
+ MockConfig::new("wt");
}
+ /// The filesystem the dispatch probes is case-insensitive on macOS and
+ /// Windows — `WT.json` there *is* `wt.json` — so the name guard must be
+ /// case-insensitive too.
#[test]
- #[should_panic(expected = "mock-stub binary not found at")]
- fn assert_mock_stub_present_panics_when_absent() {
- assert_mock_stub_present(Path::new("/nonexistent/mock-stub"));
+ #[should_panic(expected = "a mock command cannot be named")]
+ fn mock_config_rejects_wt_case_insensitively() {
+ MockConfig::new("WT");
}
}
diff --git a/tests/helpers/mock-stub/src/main.rs b/src/testing/mock_stub.rs
similarity index 60%
rename from tests/helpers/mock-stub/src/main.rs
rename to src/testing/mock_stub.rs
index e7159c3f3..48c71ae0c 100644
--- a/tests/helpers/mock-stub/src/main.rs
+++ b/src/testing/mock_stub.rs
@@ -1,11 +1,20 @@
-//! Config-driven mock executable for integration tests.
+//! Config-driven playback mode for the mock commands the test suite puts on
+//! `PATH`.
//!
-//! Reads a JSON config file to determine responses. When invoked as `gh`,
-//! looks for `gh.json` and responds based on config.
+//! [`mock_commands`](super::mock_commands) links the `wt` binary itself into a
+//! test's mock bin dir under names like `gh` or `glab`. `main()` calls
+//! [`maybe_run`] before anything else, and an invocation whose argv\[0\] is such
+//! a name plays back the JSON config instead of running wt. The mocks being
+//! the binary under test is what keeps them fresh: every runner rebuilds `wt`
+//! whenever the integration tests build, so there is no separate helper
+//! binary to go missing or stale.
//!
-//! Config location: `WORKTRUNK_TEST_MOCK_CONFIG_DIR` env var (set by test harness)
+//! Config location: `WORKTRUNK_TEST_MOCK_CONFIG_DIR` env var, set by the test
+//! harness on the wt under test and inherited by the commands it spawns.
+//! Production wt never sees the variable, so the dispatch is inert outside the
+//! suite.
//!
-//! Config format:
+//! Config format (`<command>.json` in the config dir):
//! ```json
//! {
//! "version": "gh version 2.0.0 (mock)",
@@ -40,7 +49,7 @@ use std::collections::HashMap;
use std::env;
use std::fs;
use std::io::{self, Write};
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use std::process::exit;
use std::thread::sleep;
use std::time::Duration;
@@ -62,21 +71,61 @@ struct CommandResponse {
wait_for_file: Option<String>,
}
-/// Get command name from argv\[0\].
-fn command_name() -> String {
- let argv0 = env::args().next().expect("mock: no argv[0]");
- std::path::Path::new(&argv0)
- .file_stem()
- .expect("mock: argv[0] has no file stem")
- .to_string_lossy()
- .into_owned()
+/// Play back the mock config and exit when this invocation is a mock command:
+/// `WORKTRUNK_TEST_MOCK_CONFIG_DIR` is set, argv\[0\] is not wt's own name, and
+/// the config dir holds a `<argv0>.json` for it. Returns (doing nothing)
+/// otherwise. Must run before argument parsing — a mock's arguments are the
+/// mocked tool's, not wt's.
+pub fn maybe_run() {
+ let Some(dir) = env::var_os("WORKTRUNK_TEST_MOCK_CONFIG_DIR") else {
+ return;
+ };
+ let Some(name) = command_name() else {
+ return;
+ };
+ // The wt under test runs with the variable set too (that's how its mock
+ // children inherit it); its own names never select playback, whatever a
+ // config dir contains — a `wt.json` would otherwise shadow the binary
+ // under test. Case-insensitive, because the config probe below goes
+ // through the filesystem, which matches names case-insensitively on
+ // macOS and Windows — an exact comparison would let argv[0] `WT` reach
+ // a `wt.json`. `MockConfig::new` rejects these names on the harness side.
+ if name.eq_ignore_ascii_case("wt") || name.eq_ignore_ascii_case("git-wt") {
+ return;
+ }
+ let config_dir = PathBuf::from(dir);
+ // Playback is only for commands the harness registered, and a registered
+ // mock always has its config: `MockConfig::write` writes `<name>.json`
+ // before linking the binary, and is the only way to create a mock link.
+ // So a foreign argv[0] with no config is not a half-configured mock —
+ // it's wt itself under another name, e.g. the argv0-validation tests'
+ // `wt;touch` symlink, and it must run as wt.
+ if !config_dir.join(format!("{name}.json")).exists() {
+ return;
+ }
+ run(&name, &config_dir);
}
-fn config_dir() -> PathBuf {
- PathBuf::from(
- env::var_os("WORKTRUNK_TEST_MOCK_CONFIG_DIR")
- .expect("mock: WORKTRUNK_TEST_MOCK_CONFIG_DIR not set"),
- )
+/// Command name from argv\[0\]: the link name the harness gave this binary,
+/// with the platform's executable suffix (`.exe`) stripped. Stripping the
+/// suffix rather than taking `file_stem` keeps a dotted mock name
+/// (`python3.11`) intact, and identical across platforms. `None` when
+/// argv\[0\] is missing or degenerate — the caller treats that as "not a
+/// mock" rather than panicking inside wt's `main()`.
+///
+/// The bin crate's `invocation::binary_name` reads the same argv\[0\] to name
+/// wt in its own help output; keep the two derivations aligned.
+fn command_name() -> Option<String> {
+ // args_os, not args: `env::args()` panics during iteration on a
+ // non-Unicode argument, and this runs inside wt's `main()` on every
+ // invocation. A non-UTF8 argv[0] lossily converts, matches no config
+ // name, and falls through to "not a mock".
+ let argv0 = env::args_os().next()?;
+ let name = Path::new(&argv0).file_name()?.to_string_lossy();
+ let name = name
+ .strip_suffix(std::env::consts::EXE_SUFFIX)
+ .unwrap_or(&name);
+ (!name.is_empty()).then(|| name.to_string())
}
/// Append this invocation's argv to
@@ -107,12 +156,18 @@ fn log_invocation(cmd_name: &str, args: &[String]) {
}
}
-fn main() {
- let cmd_name = command_name();
- let config_dir = config_dir();
+fn run(cmd_name: &str, config_dir: &Path) -> ! {
let config_path = config_dir.join(format!("{}.json", cmd_name));
- log_invocation(&cmd_name, &env::args().skip(1).collect::<Vec<_>>());
+ // Lossy for the same reason as `command_name`: a non-UTF8 argument can't
+ // match a config key (JSON keys are UTF-8), and the mock must not panic
+ // on one.
+ let args: Vec<String> = env::args_os()
+ .skip(1)
+ .map(|a| a.to_string_lossy().into_owned())
+ .collect();
+
+ log_invocation(cmd_name, &args);
let content = fs::read_to_string(&config_path).unwrap_or_else(|e| {
eprintln!("mock: failed to read {}: {}", config_path.display(), e);
@@ -124,8 +179,6 @@ fn main() {
exit(1);
});
- let args: Vec<String> = env::args().skip(1).collect();
-
// Handle --version flag
if args.first().map(|s| s.as_str()) == Some("--version")
&& let Some(version) = &config.version
diff --git a/src/testing/mod.rs b/src/testing/mod.rs
index aa7aaf574..80d598419 100644
--- a/src/testing/mod.rs
+++ b/src/testing/mod.rs
@@ -53,6 +53,7 @@
//! terminal width, all per command — no test mutates process-global state.
pub mod mock_commands;
+pub mod mock_stub;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
@@ -67,39 +68,23 @@ use self::mock_commands::{MockConfig, MockResponse, tea_api_include_stderr};
/// Path to the `wt` binary built by Cargo.
///
-/// Tries compile-time `option_env!()` first (works for unit tests in this
-/// crate), then falls back to runtime `std::env::var()` (works for
-/// integration tests that import via `worktrunk::testing`).
+/// Resolved at runtime from `CARGO_BIN_EXE_wt`, which cargo and nextest both
+/// provide to integration-test processes, naming the binary the same
+/// invocation just built — so the path can never be stale. Unit-test targets
+/// get neither this variable nor a compile-time `option_env!` value (cargo
+/// sets `CARGO_BIN_EXE_<name>` only for integration tests and benches), so
+/// code that spawns `wt` — `mock_commands` included — belongs in integration
+/// tests.
///
-/// Panics if neither is available (only set during `cargo test`).
+/// Panics when the variable is absent (the test binary run outside a cargo
+/// runner) rather than deriving a path that could name a stale binary.
pub fn wt_bin() -> PathBuf {
- if let Some(path) = option_env!("CARGO_BIN_EXE_wt") {
- return PathBuf::from(path);
- }
PathBuf::from(
std::env::var("CARGO_BIN_EXE_wt")
.expect("CARGO_BIN_EXE_wt not set — only available during `cargo test`"),
)
}
-/// Path to a workspace member binary (`mock-stub`).
-///
-/// Binaries from other workspace packages (not the main `wt` crate) have no
-/// `CARGO_BIN_EXE_<name>` in the main crate's tests. Derives the path from
-/// the test executable's location in `target/debug/deps/`.
-pub fn workspace_bin(name: &str) -> PathBuf {
- let mut path = std::env::current_exe().expect("failed to get test executable path");
- path.pop(); // Remove test binary name
- path.pop(); // Remove deps/
-
- #[cfg(windows)]
- path.push(format!("{name}.exe"));
-
- #[cfg(not(windows))]
- path.push(name);
-
- path
-}
use tempfile::TempDir;
/// Bump when [`build_standard_fixture`] changes, so stale templates under
@@ -617,8 +602,7 @@ pub const COVERAGE_ENV_VARS: &[&str] = &["CARGO_LLVM_COV", "CARGO_LLVM_COV_TARGE
/// Returns the inherited value when the parent is running under
/// `cargo llvm-cov` (so coverage data lands where the runner expects). When
/// nothing is inherited, returns a per-binary, per-pid path under the system
-/// temp dir so an instrumented child (e.g. a stale `mock-stub` left
-/// instrumented by an earlier coverage build) can't fall back to writing
+/// temp dir so an instrumented child can't fall back to writing
/// `default_<hash>_<pid>.profraw` into the subprocess's cwd. That cwd is the
/// test worktree for any `wt list` snapshot that spawns a mock, and a stray
/// profraw there flips `wt list` to "1 with changes" and flakes the snapshot.
@@ -2415,7 +2399,7 @@ impl TestRepo {
.command("mr list", MockResponse::file("mr_list_data.json"));
// Parse MR array and create iid-specific view commands
- // Triple match: "mr view 1" matches before "mr view" (see mock-stub)
+ // Triple match: "mr view 1" matches before "mr view" (see `mock_stub`)
if let Ok(parsed) = serde_json::from_str::<serde_json::Value>(mr_json)
&& let Some(arr) = parsed.as_array()
{
@@ -2437,7 +2421,7 @@ impl TestRepo {
};
// Configure glab mock with compound command matching
- // "mr view <iid>" is matched before "mr view" (see mock-stub triple matching)
+ // "mr view <iid>" is matched before "mr view" (see `mock_stub` triple matching)
mock_config
.command("repo", MockResponse::output(&project_id_response))
.command("ci", MockResponse::output("[]"))
@@ -2638,7 +2622,7 @@ impl TestRepo {
/// - `tea api --include repos/{owner}/{repo}/commits/{head_sha}/status` →
/// `status`
///
- /// `owner`/`repo_name`/`head_sha` are needed because mock-stub matches the
+ /// `owner`/`repo_name`/`head_sha` are needed because the mock playback matches the
/// invocation's leading arguments verbatim, and `tea api --include <path>`
/// passes the whole API path as a single argument — so the exact path
/// string must be registered.
@@ -2773,14 +2757,14 @@ impl TestRepo {
/// Must call `setup_mock_gh()` first. Prepends the mock bin directory to PATH
/// so gh/glab commands are intercepted.
///
- /// On Windows, the mock commands have .exe files (via mock-stub) so they're
+ /// On Windows, the mock commands have .exe files (see `mock_commands`) so they're
/// found directly by CreateProcessW without needing PATHEXT manipulation.
///
/// Metadata redactions keep PATH private in snapshots, so we can reuse the
/// caller's PATH instead of a hardcoded minimal list.
pub fn configure_mock_commands(&self, cmd: &mut Command) {
if let Some(mock_bin) = &self.mock_bin_path {
- // Tell mock-stub where to find config files directly, avoiding PATH search
+ // Tell the mock playback where to find config files directly, avoiding PATH search
cmd.env("WORKTRUNK_TEST_MOCK_CONFIG_DIR", mock_bin);
// On Windows, env vars are case-insensitive but Rust stores them
diff --git a/tests/CLAUDE.md b/tests/CLAUDE.md
index 55833b0ba..cbca06b8b 100644
--- a/tests/CLAUDE.md
+++ b/tests/CLAUDE.md
@@ -12,7 +12,7 @@ cargo test --test integration # integration
cargo test --test integration --features shell-integration-tests # + shell tests
```
-A target filter (`--lib`, `--test integration`, …) never builds `mock-stub`, so the run gets whatever sits in `target/`: a fresh tree has none and panics with "mock-stub binary not found", and a warm one runs the tests against a stale stub, whose failures reflect the code it was built from rather than the change under test. Fix: `cargo build -p mock-stub`, or use `cargo nextest run` / `cargo llvm-cov nextest`.
+Every binary the suite spawns is `wt` itself — the mock commands are the same binary linked under other names, dispatching on argv[0] (`testing::mock_stub`) — so no run can spawn missing or stale code: cargo rebuilds a package's own binaries whenever its integration tests build, under every runner and filter, and the `CARGO_BIN_EXE_wt` the harness resolves at runtime names that just-built binary; outside a cargo runner the suite panics ("CARGO_BIN_EXE_wt not set") rather than guessing a path. `cargo build --bin wt` recompiling right after a test run is the bin-only build being a separate cached unit (a different feature graph), not evidence the tests ran stale code.
**Claude Code web:** `task setup-web` installs zsh/fish/nushell, `gh`, and dev tools. Install `task` first if needed: `sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/bin` then `export PATH="$HOME/bin:$PATH"`. The permission tests (`test_permission_error_prevents_save`, `test_approval_prompt_permission_error`) skip automatically when running as root.
@@ -24,12 +24,10 @@ A target filter (`--lib`, `--test integration`, …) never builds `mock-stub`, s
Five runners execute this suite — `cargo test`, `cargo nextest run`, `cargo llvm-cov nextest`, `cargo bench`, and the Nix `worktrunk-tests` derivation — and CI uses several of them on the same commit. **A test's result must not depend on which one started it.**
-So `.config/nextest.toml` carries no setting that changes what a test observes: no `[env]`, and no setup script exporting through `$NEXTEST_ENV`. Anything load-bearing goes where every runner sees it — the harness-latched floor in `shell_exec` for git environment (see Git Config Isolation), `.cargo/config.toml` for `COLUMNS`, the fixture for behavior.
+So `.config/nextest.toml` carries no setting that changes what a test observes: no `[env]`, no setup scripts. Anything load-bearing goes where every runner sees it — the harness-latched floor in `shell_exec` for git environment (see Git Config Isolation), `.cargo/config.toml` for `COLUMNS`, the fixture for behavior.
A nextest-only knob doesn't fail loudly when another runner misses it. It yields a *different result*, and the runner that disagrees is typically `cargo llvm-cov` — whose numbers gate a merge, and whose disagreement therefore reads as a coverage regression rather than as missing configuration.
-The one setup script here, `build-bins`, is a build step rather than a behavior setting: it compiles the `mock-stub` helper a target-filtered run would otherwise skip, and the same gap under plain `cargo test` is handled by `default-members` (see Running the Suite). It carries its own TODO to disappear once cargo-dist supports per-binary exclusion. It is not precedent.
-
## Profiling the Suite
```bash
@@ -167,10 +165,11 @@ somewhere else.
**Name it `WORKTRUNK_TEST_*`.** `isolate_subprocess_env` scrubs the parent
environment by prefix — `GIT_*` and `WORKTRUNK_*` — so the prefix is what makes
a variable hermetic; an unprefixed name inherits from whatever shell ran the
-suite. The rule covers the test-only protocol between the harness and its helper
-binaries, not just knobs `wt` itself reads: the harness sets
-`WORKTRUNK_TEST_MOCK_CONFIG_DIR` and only `mock-stub` reads it. A variable `wt`
-reads in production drops `TEST` and keeps `WORKTRUNK_`.
+suite. The rule covers the test-only protocol between the harness and the mock
+playback, not just knobs that change wt's own behavior:
+`WORKTRUNK_TEST_MOCK_CONFIG_DIR` is read only by the playback dispatch
+(`testing::mock_stub`). A variable `wt` reads in production drops `TEST` and
+keeps `WORKTRUNK_`.
## Git Config Isolation
diff --git a/tests/helpers/mock-stub/Cargo.toml b/tests/helpers/mock-stub/Cargo.toml
deleted file mode 100644
index b08e0d067..000000000
--- a/tests/helpers/mock-stub/Cargo.toml
+++ /dev/null
@@ -1,30 +0,0 @@
-# Config-driven mock executable for integration tests.
-#
-# Reads a JSON config file to determine responses. When invoked as `gh`,
-# looks for `gh.json` in the same directory and responds based on config.
-#
-# Works on all platforms (no bash dependency).
-#
-# WHY A SEPARATE PACKAGE?
-# cargo-dist automatically discovers all [[bin]] entries and expects to distribute
-# them. Moving test-only binaries to separate packages with `publish = false`
-# prevents them from being included in releases.
-#
-# HOW THE BINARY GETS BUILT:
-# Has a dummy integration test (tests/builds.rs) that triggers binary compilation
-# when running `cargo test`. Combined with `workspace.default-members` including
-# this package, `cargo test` automatically builds the binary.
-[package]
-name = "mock-stub"
-version = "0.1.0"
-edition = "2024"
-publish = false
-
-[dependencies]
-serde = { version = "1.0.228", features = ["derive"] }
-serde_json = "1.0.145"
-
-[[bin]]
-name = "mock-stub"
-path = "src/main.rs"
-test = false
diff --git a/tests/helpers/mock-stub/tests/builds.rs b/tests/helpers/mock-stub/tests/builds.rs
deleted file mode 100644
index 5992cd9e0..000000000
--- a/tests/helpers/mock-stub/tests/builds.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-//! Dummy test that triggers binary compilation.
-//! See mock-stub/Cargo.toml for why this is needed.
-
-#[test]
-fn builds() {}
diff --git a/tests/helpers/wt-perf/Cargo.toml b/tests/helpers/wt-perf/Cargo.toml
index 39176bf0a..02fb05982 100644
--- a/tests/helpers/wt-perf/Cargo.toml
+++ b/tests/helpers/wt-perf/Cargo.toml
@@ -29,7 +29,8 @@ criterion = "0.8"
# masking gating bugs in lib code that uses `cli`-gated dependencies.
worktrunk = { path = "../../..", default-features = false }
-[dev-dependencies]
+# For parsing cargo's --message-format=json artifact report (resolve_wt_binary);
+# also used by the CLI tests.
serde_json = "1.0.145"
[lib]
diff --git a/tests/helpers/wt-perf/src/main.rs b/tests/helpers/wt-perf/src/main.rs
index 4233b2562..7afe91736 100644
--- a/tests/helpers/wt-perf/src/main.rs
+++ b/tests/helpers/wt-perf/src/main.rs
@@ -3,7 +3,7 @@
//! Run `wt-perf --help` (and `wt-perf <subcommand> --help`) for usage.
use std::io::{IsTerminal, Read};
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::time::{Duration, Instant};
@@ -232,25 +232,82 @@ fn main() {
}
}
-/// Resolve the `wt` binary as a sibling of the current executable
-/// (`target/{debug,release}/wt-perf` → `target/{debug,release}/wt`).
-/// `EXE_SUFFIX` keeps this correct on Windows, where Cargo builds
-/// `wt-perf.exe` next to `wt.exe`.
+/// Build the `wt` binary and return the path to the artifact. `cargo run -p
+/// wt-perf` rebuilds wt-perf and the worktrunk lib but not the `wt` bin
+/// target, so without this build a timeline run after a `src/` edit would
+/// silently measure a stale binary. The path comes from cargo's own artifact
+/// report (`--message-format=json`) rather than a derived sibling location,
+/// so a `CARGO_TARGET_DIR`, config `build.target-dir`, or default-target
+/// override can't divert the build away from where it's resolved. The
+/// profile follows the running wt-perf's own profile dir, so a release
+/// wt-perf measures a release wt; other layouts (an installed wt-perf) have
+/// no enclosing workspace to rebuild from and are rejected.
fn resolve_wt_binary() -> PathBuf {
let me = std::env::current_exe().unwrap_or_else(|e| {
eprintln!("Failed to resolve current executable: {e}");
std::process::exit(1);
});
- let exe = format!("wt{}", std::env::consts::EXE_SUFFIX);
- let candidate = me.parent().map(|p| p.join(&exe)).unwrap_or_default();
- if !candidate.is_file() {
- eprintln!(
- "wt binary not found at {} — run `cargo build --release --bin wt` (or `cargo build --bin wt`) first.",
- candidate.display()
- );
- std::process::exit(1);
+ let profile = match me
+ .parent()
+ .and_then(|p| p.file_name())
+ .and_then(|n| n.to_str())
+ {
+ Some("debug") => "dev",
+ Some("release") => "release",
+ _ => {
+ eprintln!(
+ "wt-perf must run from a cargo target dir (`cargo run -p wt-perf`, or \
+ target/{{debug,release}}/wt-perf): {} isn't one, so it can't rebuild wt \
+ from the workspace.",
+ me.display()
+ );
+ std::process::exit(1);
+ }
+ };
+ let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR"))
+ .ancestors()
+ .nth(3)
+ .expect("wt-perf crate sits three levels below the workspace root");
+ // $CARGO names the exact cargo that built wt-perf (set for `cargo run`
+ // children); PATH lookup is the fallback for a directly-executed binary.
+ let cargo = std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into());
+ // stderr stays inherited: a real rebuild can take a while, and cargo's
+ // progress there is what shows it isn't hung. stdout carries the JSON
+ // artifact messages, so the timeline's own stdout contract (`--chrome`
+ // pipes JSON) is untouched.
+ let output = Command::new(&cargo)
+ .current_dir(workspace_root)
+ .args(["build", "--bin", "wt", "--profile", profile])
+ .arg("--message-format=json")
+ .stdin(Stdio::null())
+ .stdout(Stdio::piped())
+ .stderr(Stdio::inherit())
+ .output()
+ .unwrap_or_else(|e| {
+ eprintln!(
+ "Failed to run cargo build in {}: {e}",
+ workspace_root.display()
+ );
+ std::process::exit(1);
+ });
+ if !output.status.success() {
+ eprintln!("`cargo build --bin wt` failed; timeline needs a current wt binary.");
+ std::process::exit(output.status.code().unwrap_or(1));
}
- candidate
+ // Cargo reports every requested artifact, fresh or rebuilt, so the `wt`
+ // executable message is always present on success.
+ String::from_utf8_lossy(&output.stdout)
+ .lines()
+ .filter_map(|line| serde_json::from_str::<serde_json::Value>(line).ok())
+ .find_map(|msg| {
+ (msg["reason"] == "compiler-artifact" && msg["target"]["name"] == "wt")
+ .then(|| msg["executable"].as_str().map(PathBuf::from))
+ .flatten()
+ })
+ .unwrap_or_else(|| {
+ eprintln!("cargo build succeeded but reported no `wt` executable artifact");
+ std::process::exit(1);
+ })
}
/// Run a `wt -vv` command and render the `trace.jsonl` it writes.
diff --git a/tests/integration_tests/ci_status.rs b/tests/integration_tests/ci_status.rs
index 9a5f2a82a..7c2900e40 100644
--- a/tests/integration_tests/ci_status.rs
+++ b/tests/integration_tests/ci_status.rs
@@ -2,12 +2,6 @@
//!
//! These tests verify that the CI status parsing code correctly handles
//! JSON responses from GitHub (gh) and GitLab (glab) CLI tools.
-//!
-//! ## Windows support
-//!
-//! On Windows, mock-stub.exe sets MOCK_SCRIPT_DIR so the mock gh script can
-//! reliably locate its JSON data files. Use MOCK_DEBUG=1 to troubleshoot
-//! path issues.
use crate::common::{
TestRepo, make_snapshot_cmd,
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index fdd35fead..c7586fbac 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -2178,9 +2178,9 @@ fn test_complete_custom_subcommand_forwards(repo: TestRepo) {
repo.commit("initial");
- // Create a real shell script that outputs completions (not mock-stub, which
- // needs WORKTRUNK_TEST_MOCK_CONFIG_DIR and doesn't know about COMPLETE env
- // var).
+ // Create a real shell script that outputs completions (not a mock_commands
+ // mock, which needs WORKTRUNK_TEST_MOCK_CONFIG_DIR and plays back its config
+ // instead of answering the COMPLETE env var).
let ext_dir = tempfile::tempdir().unwrap();
let retired_file = ext_dir.path().join("retired");
std::fs::write(&retired_file, "").unwrap();
diff --git a/tests/integration_tests/custom.rs b/tests/integration_tests/custom.rs
index 4aec835db..bbf3e8226 100644
--- a/tests/integration_tests/custom.rs
+++ b/tests/integration_tests/custom.rs
@@ -276,7 +276,7 @@ fn custom_subcommand_respects_global_dash_c_flag() {
#[test]
fn custom_subcommand_passes_help_flag_through() {
// `wt foo --help` should hand `--help` to `wt-foo`, not to wt itself.
- // The mock-stub has no built-in `--help` handler, so if `--help` reaches
+ // The mock playback has no built-in `--help` handler, so if `--help` reaches
// it the mock falls through to `_default` (which we set to exit 0).
let dir = mock_bin_dir(
"wt-wt-test-extcmd-help",
diff --git a/tests/integration_tests/init.rs b/tests/integration_tests/init.rs
index c31157ed9..c88c82dda 100644
--- a/tests/integration_tests/init.rs
+++ b/tests/integration_tests/init.rs
@@ -103,6 +103,54 @@ fn test_init_rejects_unsafe_cmd(#[case] shell: &str, repo: TestRepo) {
);
}
+/// A degenerate argv\[0\] — empty here, so it has no file name — never selects
+/// mock playback: `command_name()` yields `None` and the process runs as wt,
+/// rather than panicking inside `main()` or probing the config dir.
+#[test]
+fn test_mock_dispatch_ignores_degenerate_argv0() {
+ use std::os::unix::process::CommandExt;
+
+ let config_dir = tempfile::tempdir().unwrap();
+ let output = Command::new(wt_bin())
+ .arg0("")
+ .arg("--version")
+ .env("WORKTRUNK_TEST_MOCK_CONFIG_DIR", config_dir.path())
+ .output()
+ .unwrap();
+
+ assert!(output.status.success(), "wt --version should succeed");
+ assert!(
+ String::from_utf8_lossy(&output.stdout).starts_with("wt "),
+ "expected wt's own version output, got:\n{}",
+ String::from_utf8_lossy(&output.stdout)
+ );
+}
+
+/// A non-UTF8 argv\[0\] must not panic the dispatch (`env::args()` panics on
+/// non-Unicode arguments; the dispatch reads `args_os`): it lossily converts,
+/// matches no config, and wt runs as itself.
+#[test]
+fn test_mock_dispatch_survives_non_utf8_argv0() {
+ use std::ffi::OsStr;
+ use std::os::unix::ffi::OsStrExt;
+ use std::os::unix::process::CommandExt;
+
+ let config_dir = tempfile::tempdir().unwrap();
+ let output = Command::new(wt_bin())
+ .arg0(OsStr::from_bytes(b"\xff\xfe"))
+ .arg("--version")
+ .env("WORKTRUNK_TEST_MOCK_CONFIG_DIR", config_dir.path())
+ .output()
+ .unwrap();
+
+ assert!(output.status.success(), "wt --version should succeed");
+ assert!(
+ String::from_utf8_lossy(&output.stdout).starts_with("wt "),
+ "expected wt's own version output, got:\n{}",
+ String::from_utf8_lossy(&output.stdout)
+ );
+}
+
#[rstest]
fn test_init_rejects_unsafe_argv0_command_name(repo: TestRepo) {
let temp_dir = tempfile::tempdir().unwrap();
diff --git a/tests/integration_tests/step_prune.rs b/tests/integration_tests/step_prune.rs
index 16d7808ed..ae4ef73a7 100644
--- a/tests/integration_tests/step_prune.rs
+++ b/tests/integration_tests/step_prune.rs
@@ -1457,7 +1457,7 @@ fn test_prune_summary_counts_declined_deletion_as_worktree_only(mut repo: TestRe
/// for it rather than racing ahead. The shim is Unix-only because Rust's
/// `Command` resolves a bare program name through `CreateProcess`, which
/// appends only `.exe` and never finds a `git.cmd`/`git.bat` — the same
-/// reason `mock_commands` ships a real `mock-stub.exe` on Windows. Windows
+/// reason `mock_commands` links a real `.exe` mock on Windows. Windows
/// still exercises the fallback (the pre-blocked staged path) and the
/// synchronous-completion assertion.
#[rstest]
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index cbb6fbf51..007837f7d 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -2350,9 +2350,7 @@ worktree-path = "{{ repo_path }}/../{{ branch | sanitize }}"
// PR Syntax Tests (pr:<number>)
// ============================================================================
-use crate::common::mock_commands::{
- MockConfig, MockResponse, copy_mock_binary, tea_api_include_stderr,
-};
+use crate::common::mock_commands::{MockConfig, MockResponse, tea_api_include_stderr};
/// Set origin to a GitHub URL so `fetch_pr_info` can parse owner/repo.
///
@@ -2826,30 +2824,24 @@ fn test_switch_prs_dry_run_empty_gitlab(repo: TestRepo) {
/// - `head.ref`, `head.repo.owner.login`, `head.repo.name`
/// - `base.repo.owner.login`, `base.repo.name`
/// - `html_url`
-fn setup_mock_gh_for_pr(repo: &TestRepo, gh_response: Option<&str>) -> std::path::PathBuf {
+fn setup_mock_gh_for_pr(repo: &TestRepo, gh_response: &str) -> std::path::PathBuf {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- // Copy mock-stub binary as "gh"
- copy_mock_binary(&mock_bin, "gh");
-
- // Write PR response file if provided
- if let Some(response) = gh_response {
- fs::write(mock_bin.join("pr_response.json"), response).unwrap();
+ fs::write(mock_bin.join("pr_response.json"), gh_response).unwrap();
- MockConfig::new("gh")
- .version("gh version 2.0.0 (mock)")
- .command("api", MockResponse::file("pr_response.json"))
- .command("_default", MockResponse::exit(1))
- .write(&mock_bin);
- }
+ MockConfig::new("gh")
+ .version("gh version 2.0.0 (mock)")
+ .command("api", MockResponse::file("pr_response.json"))
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
mock_bin
}
/// Configure command environment for any mock CLI installed in `mock_bin`.
///
-/// Sets `WORKTRUNK_TEST_MOCK_CONFIG_DIR` (so mock-stub finds its config) and
+/// Sets `WORKTRUNK_TEST_MOCK_CONFIG_DIR` (so the mock playback finds its config) and
/// prepends `mock_bin` to `PATH` (so the mock binary is found before any real
/// CLI).
fn configure_mock_cli_env(cmd: &mut std::process::Command, mock_bin: &Path) {
@@ -2903,7 +2895,7 @@ fn test_switch_pr_create_conflict(#[from(repo_with_remote)] repo: TestRepo) {
"html_url": "https://github.com/owner/test-repo/pull/101"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -2959,7 +2951,7 @@ fn test_switch_pr_same_repo_custom_ssh_user(#[from(repo_with_remote)] mut repo:
"html_url": "https://github.com/owner/test-repo/pull/101"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -3029,7 +3021,7 @@ fn test_switch_pr_same_repo_limited_refspec(#[from(repo_with_remote)] mut repo:
"html_url": "https://github.com/owner/test-repo/pull/101"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -3074,7 +3066,7 @@ fn test_switch_pr_same_repo_no_remote(#[from(repo_with_remote)] repo: TestRepo)
"html_url": "https://github.com/owner/test-repo/pull/101"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -3159,7 +3151,7 @@ fn test_switch_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -3246,7 +3238,7 @@ post-switch = "echo 'pr_number={{ pr_number }} pr_url={{ pr_url }}' > {{ repo_pa
},
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let mut cmd = repo.wt_command();
cmd.args(["switch", "pr:42", "--yes"]);
@@ -3354,7 +3346,7 @@ fn test_switch_pr_reads_invoking_worktree_config(#[from(repo_with_remote)] repo:
},
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
// (a) Without `--yes`: the approval prompt lists the *invoking* worktree's
// hook (never the PR's), then bails (stdin is not a TTY in tests).
@@ -3442,7 +3434,7 @@ fn test_switch_pr_fork_no_upstream_remote(#[from(repo_with_remote)] repo: TestRe
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -3568,9 +3560,6 @@ fn test_switch_pr_not_found(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- // Copy mock-stub binary as "gh"
- copy_mock_binary(&mock_bin, "gh");
-
// Configure gh api to return error for PR not found (JSON on stdout, human-readable on stderr)
MockConfig::new("gh")
.version("gh version 2.0.0 (mock)")
@@ -3601,8 +3590,6 @@ fn test_switch_pr_not_found_gh_default(#[from(repo_with_remote)] repo: TestRepo)
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "gh");
-
MockConfig::new("gh")
.version("gh version 2.0.0 (mock)")
.command(
@@ -3669,7 +3656,6 @@ fn test_switch_pr_uses_nonprimary_github_remote(#[from(repo_with_remote)] mut re
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "gh");
fs::write(
mock_bin.join("pr_response.json"),
r#"{
@@ -3729,7 +3715,7 @@ fn test_switch_pr_deleted_fork(#[from(repo_with_remote)] repo: TestRepo) {
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -3797,7 +3783,7 @@ fn test_switch_base_pr_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {
"html_url": "https://github.com/owner/test-repo/pull/101"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -3869,7 +3855,7 @@ fn test_switch_base_pr_sets_upstream(#[from(repo_with_remote)] mut repo: TestRep
}}"#
);
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(&gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, &gh_response);
let mut cmd = repo.wt_command();
cmd.args([
@@ -3970,7 +3956,7 @@ fn test_switch_base_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let mut settings = setup_snapshot_settings(&repo);
// Fork base resolves to a commit SHA (no tracking branch created). Mask it
@@ -4049,7 +4035,7 @@ fn test_switch_base_mr_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {
"web_url": "https://gitlab.com/owner/test-repo/-/merge_requests/101"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -4120,7 +4106,7 @@ fn test_switch_pr_fork_existing_same_pr(#[from(repo_with_remote)] repo: TestRepo
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -4205,7 +4191,7 @@ fn test_switch_pr_fork_existing_different_pr(#[from(repo_with_remote)] repo: Tes
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -4291,7 +4277,7 @@ fn test_switch_pr_fork_existing_same_pr_wrong_remote(#[from(repo_with_remote)] m
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
configure_mock_cli_env(&mut cmd, &mock_bin);
let output = cmd.output().unwrap();
@@ -4372,7 +4358,7 @@ fn test_switch_pr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: Test
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -4457,7 +4443,7 @@ fn test_switch_pr_fork_prefixed_exists_same_pr(#[from(repo_with_remote)] repo: T
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -4527,7 +4513,7 @@ fn test_switch_pr_fork_prefixed_exists_different_pr(#[from(repo_with_remote)] re
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -4544,8 +4530,6 @@ fn test_switch_pr_not_authenticated(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "gh");
-
// Configure gh api to return auth error (JSON on stdout, human-readable on stderr)
MockConfig::new("gh")
.version("gh version 2.0.0 (mock)")
@@ -4573,8 +4557,6 @@ fn test_switch_pr_rate_limit(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "gh");
-
// Configure gh api to return rate limit error (JSON on stdout, human-readable on stderr)
MockConfig::new("gh")
.version("gh version 2.0.0 (mock)")
@@ -4604,8 +4586,6 @@ fn test_switch_pr_invalid_json(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "gh");
-
// Configure gh api to return invalid JSON
MockConfig::new("gh")
.version("gh version 2.0.0 (mock)")
@@ -4628,8 +4608,6 @@ fn test_switch_pr_network_error(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "gh");
-
// Configure gh api to return network error (no JSON, just stderr for network failures)
MockConfig::new("gh")
.version("gh version 2.0.0 (mock)")
@@ -4655,8 +4633,6 @@ fn test_switch_pr_unknown_error(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "gh");
-
// Configure gh api to return an unrecognized multi-line error
// (realistic errors from gh often include context on multiple lines)
let error_message = "error: unexpected API response\n\
@@ -4683,8 +4659,6 @@ fn test_switch_pr_empty_branch(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "gh");
-
// Configure gh to return valid JSON but with empty branch name (head.ref is "")
let gh_response = r#"{
"title": "PR with empty branch",
@@ -4736,7 +4710,6 @@ fn test_switch_pr_empty_branch(#[from(repo_with_remote)] repo: TestRepo) {
fn setup_mock_tea(repo: &TestRepo, status: &str, body: &str) -> std::path::PathBuf {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "tea");
fs::write(mock_bin.join("tea_pr_response.json"), body).unwrap();
MockConfig::new("tea")
@@ -5257,7 +5230,7 @@ fn test_switch_pr_self_hosted_defaults_to_github(#[from(repo_with_remote)] mut r
},
"html_url": "https://forge.example.com/owner/test-repo/pull/101"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+ let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -5301,7 +5274,6 @@ fn test_switch_pr_gitea_request_failed(#[from(repo_with_remote)] repo: TestRepo)
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "tea");
MockConfig::new("tea")
.version("tea version development (mock)")
@@ -5497,7 +5469,6 @@ fn test_switch_pr_gitea_no_status_line(#[from(repo_with_remote)] repo: TestRepo)
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "tea");
// A complete PR body, so nothing but the absent status line can reject it.
MockConfig::new("tea")
@@ -5579,21 +5550,17 @@ const AZ_EXTENSION_INSTALLED: &str = r#"[{"name": "azure-devops", "version": "1.
///
/// Returns the path to the mock bin directory; pass it to
/// `configure_mock_cli_env`.
-fn setup_mock_az(repo: &TestRepo, az_pr_response: Option<&str>) -> std::path::PathBuf {
+fn setup_mock_az(repo: &TestRepo, az_pr_response: &str) -> std::path::PathBuf {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "az");
+ fs::write(mock_bin.join("az_pr_response.json"), az_pr_response).unwrap();
- if let Some(response) = az_pr_response {
- fs::write(mock_bin.join("az_pr_response.json"), response).unwrap();
-
- MockConfig::new("az")
- .version("azure-cli 2.60.0 (mock)")
- .command("repos pr show", MockResponse::file("az_pr_response.json"))
- .command("_default", MockResponse::exit(1))
- .write(&mock_bin);
- }
+ MockConfig::new("az")
+ .version("azure-cli 2.60.0 (mock)")
+ .command("repos pr show", MockResponse::file("az_pr_response.json"))
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
mock_bin
}
@@ -5639,7 +5606,7 @@ fn test_switch_pr_azure_create_conflict(#[from(repo_with_remote)] repo: TestRepo
"forkSource": null
}"#;
- let mock_bin = setup_mock_az(&repo, Some(az_response));
+ let mock_bin = setup_mock_az(&repo, az_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -5689,7 +5656,7 @@ fn test_switch_pr_azure_same_repo(#[from(repo_with_remote)] mut repo: TestRepo)
"forkSource": null
}"#;
- let mock_bin = setup_mock_az(&repo, Some(az_response));
+ let mock_bin = setup_mock_az(&repo, az_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -5723,7 +5690,7 @@ fn test_switch_pr_azure_project_name_with_spaces(#[from(repo_with_remote)] mut r
"forkSource": null
}"#;
- let mock_bin = setup_mock_az(&repo, Some(az_response));
+ let mock_bin = setup_mock_az(&repo, az_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -5762,7 +5729,7 @@ fn test_switch_pr_azure_web_url(#[from(repo_with_remote)] mut repo: TestRepo) {
"forkSource": null
}"#;
- let mock_bin = setup_mock_az(&repo, Some(az_response));
+ let mock_bin = setup_mock_az(&repo, az_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -5802,7 +5769,7 @@ fn test_switch_pr_azure_empty_source_branch(#[from(repo_with_remote)] repo: Test
"forkSource": null
}"#;
- let mock_bin = setup_mock_az(&repo, Some(az_response));
+ let mock_bin = setup_mock_az(&repo, az_response);
let output = {
let mut cmd = repo.wt_command();
@@ -5847,7 +5814,7 @@ fn test_switch_pr_azure_visualstudio_host(#[from(repo_with_remote)] mut repo: Te
"forkSource": null
}"#;
- let mock_bin = setup_mock_az(&repo, Some(az_response));
+ let mock_bin = setup_mock_az(&repo, az_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -5904,7 +5871,7 @@ fn test_switch_pr_azure_fork(#[from(repo_with_remote)] repo: TestRepo) {
}
}"#;
- let mock_bin = setup_mock_az(&repo, Some(az_response));
+ let mock_bin = setup_mock_az(&repo, az_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -5931,7 +5898,6 @@ fn test_switch_pr_azure_not_found(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "az");
MockConfig::new("az")
.version("azure-cli 2.60.0 (mock)")
@@ -6011,7 +5977,7 @@ fn test_switch_pr_azure_forge_platform(#[from(repo_with_remote)] repo: TestRepo)
"forkSource": null
}"#;
- let mock_bin = setup_mock_az(&repo, Some(az_response));
+ let mock_bin = setup_mock_az(&repo, az_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6032,7 +5998,7 @@ fn test_switch_pr_azure_invalid_json(#[from(repo_with_remote)] repo: TestRepo) {
"https://dev.azure.com/myorg/myproject/_git/test-repo",
]);
- let mock_bin = setup_mock_az(&repo, Some("not json {"));
+ let mock_bin = setup_mock_az(&repo, "not json {");
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6059,7 +6025,6 @@ fn test_switch_pr_azure_server_error(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "az");
MockConfig::new("az")
.version("azure-cli 2.60.0 (mock)")
@@ -6092,7 +6057,6 @@ fn test_switch_pr_azure_auth_error(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "az");
MockConfig::new("az")
.version("azure-cli 2.60.0 (mock)")
@@ -6132,7 +6096,6 @@ fn test_switch_pr_azure_extension_not_installed(#[from(repo_with_remote)] repo:
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "az");
MockConfig::new("az")
.version("azure-cli 2.60.0 (mock)")
@@ -6187,7 +6150,7 @@ fn test_switch_pr_azure_org_undeterminable(#[from(repo_with_remote)] repo: TestR
"forkSource": null
}"#;
- let mock_bin = setup_mock_az(&repo, Some(az_response));
+ let mock_bin = setup_mock_az(&repo, az_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6206,23 +6169,17 @@ fn test_switch_pr_azure_org_undeterminable(#[from(repo_with_remote)] repo: TestR
/// The response should be in `glab api projects/:id/merge_requests/<number>` format:
/// - `source_branch`, `source_project_id`, `target_project_id`
/// - `web_url`
-fn setup_mock_glab_for_mr(repo: &TestRepo, glab_response: Option<&str>) -> std::path::PathBuf {
+fn setup_mock_glab_for_mr(repo: &TestRepo, glab_response: &str) -> std::path::PathBuf {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- // Copy mock-stub binary as "glab"
- copy_mock_binary(&mock_bin, "glab");
-
- // Write MR response file if provided
- if let Some(response) = glab_response {
- fs::write(mock_bin.join("mr_response.json"), response).unwrap();
+ fs::write(mock_bin.join("mr_response.json"), glab_response).unwrap();
- MockConfig::new("glab")
- .version("glab version 1.40.0 (mock)")
- .command("api", MockResponse::file("mr_response.json"))
- .command("_default", MockResponse::exit(1))
- .write(&mock_bin);
- }
+ MockConfig::new("glab")
+ .version("glab version 1.40.0 (mock)")
+ .command("api", MockResponse::file("mr_response.json"))
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
mock_bin
}
@@ -6242,7 +6199,7 @@ fn test_switch_mr_create_conflict(#[from(repo_with_remote)] repo: TestRepo) {
"web_url": "https://gitlab.com/owner/test-repo/-/merge_requests/101"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6307,7 +6264,7 @@ fn test_switch_mr_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {
"web_url": "https://gitlab.com/owner/test-repo/-/merge_requests/101"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6372,7 +6329,7 @@ fn test_switch_mr_same_repo_limited_refspec(#[from(repo_with_remote)] mut repo:
"web_url": "https://gitlab.com/owner/test-repo/-/merge_requests/101"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6409,7 +6366,7 @@ fn test_switch_mr_same_repo_no_remote(#[from(repo_with_remote)] repo: TestRepo)
"web_url": "https://gitlab.com/owner/test-repo/-/merge_requests/101"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6433,7 +6390,7 @@ fn test_switch_mr_malformed_web_url_no_separator(#[from(repo_with_remote)] repo:
"web_url": "https://gitlab.com/owner/test-repo/merge_requests/101"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6457,7 +6414,7 @@ fn test_switch_mr_malformed_web_url_no_project(#[from(repo_with_remote)] repo: T
"web_url": "https://gitlab.com/-/merge_requests/101"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6473,9 +6430,6 @@ fn test_switch_mr_not_found(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- // Copy mock-stub binary as "glab"
- copy_mock_binary(&mock_bin, "glab");
-
// Configure glab api to return 404 error (JSON on stdout, human-readable on
// stderr — glab formats the API's own message as `glab: <message> (HTTP N)`)
MockConfig::new("glab")
@@ -6503,8 +6457,6 @@ fn test_switch_mr_not_authenticated(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "glab");
-
// Configure glab api to return 401 error (JSON on stdout, human-readable on
// stderr — the shape a real `glab api` produces for a rejected token)
MockConfig::new("glab")
@@ -6532,8 +6484,6 @@ fn test_switch_mr_invalid_json(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "glab");
-
// Configure glab api to return invalid JSON
MockConfig::new("glab")
.version("glab version 1.40.0 (mock)")
@@ -6555,8 +6505,6 @@ fn test_switch_mr_empty_branch(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "glab");
-
// Configure glab api to return valid JSON but with empty branch name
let glab_response = r#"{
"title": "MR with empty branch",
@@ -6645,11 +6593,10 @@ fn test_switch_mr_fork(#[from(repo_with_remote)] repo: TestRepo) {
]);
// Set up mock glab with separate responses for MR API and project APIs.
- // The mock-stub supports compound keys like "api projects/456" to match
+ // Mock playback supports compound keys like "api projects/456" to match
// different API paths.
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "glab");
// MR API response (no nested project data - that comes from separate calls)
let mr_response = r#"{
@@ -6775,7 +6722,7 @@ fn test_switch_mr_fork_existing_branch_tracks_mr(#[from(repo_with_remote)] repo:
"web_url": "https://gitlab.com/owner/test-repo/-/merge_requests/42"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6825,7 +6772,7 @@ fn test_switch_mr_fork_existing_branch_tracks_different(#[from(repo_with_remote)
"web_url": "https://gitlab.com/owner/test-repo/-/merge_requests/42"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6862,7 +6809,7 @@ fn test_switch_mr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: Test
"web_url": "https://gitlab.com/owner/test-repo/-/merge_requests/42"
}"#;
- let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));
+ let mock_bin = setup_mock_glab_for_mr(&repo, glab_response);
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6878,8 +6825,6 @@ fn test_switch_mr_unknown_error(#[from(repo_with_remote)] repo: TestRepo) {
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
- copy_mock_binary(&mock_bin, "glab");
-
// Configure glab api to return an unknown error (non-JSON stderr, like network errors)
MockConfig::new("glab")
.version("glab version 1.40.0 (mock)")