Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(opencode): read an empty OPENCODE_CONFIG_DIR as unset, not as a relative path (#4084)
Worktrunk Bot4ef5644b6964
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 35574c246..f656a797d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,8 @@### Fixed+- **`wt config plugins opencode install` no longer writes the plugin into the directory it was run from**: an exported-but-empty `OPENCODE_CONFIG_DIR` was taken at face value, so the install target collapsed to the relative path `plugins/worktrunk.ts` — typically somewhere inside the user's repository. `is_plugin_installed()` then read the plugin back from that same relative path, so the install reported success while OpenCode never saw it. An empty value now reads as unset, as it already did for `$CLAUDE_CONFIG_DIR` and `$PI_CONFIG_DIR`; the documented precedence `$OPENCODE_CONFIG_DIR` > `$XDG_CONFIG_HOME/opencode` > `~/.config/opencode` is unchanged. ([#4084](https://github.com/max-sixty/worktrunk/pull/4084))+- **`wt step prune` no longer deletes a branch created minutes ago from an older commit**: the min-age guard aged a branch with no worktree by the committer date of the commit it points at, so `git branch <name> main` on a default branch whose last commit was over a day old was pruned on the next run — the case `--min-age` exists to prevent. The branch's age now comes from its oldest reflog entry, written when the branch was created.- **`wt merge` no longer deletes a worktree locked with `git worktree lock`**: its cleanup step removed the worktree anyway and reported success. The merge now completes and prints `Worktree preserved (locked)`, and every Worktrunk removal path refuses a lock even under `--force` — what `git worktree remove` does, minus git's `-f -f` override. Unlock with `git worktree unlock <path>` first. ([#4073](https://github.com/max-sixty/worktrunk/pull/4073), thanks @Duang777)diff --git a/src/commands/config/opencode.rs b/src/commands/config/opencode.rsindex 9ca084881..b64c153f1 100644--- a/src/commands/config/opencode.rs+++ b/src/commands/config/opencode.rs@@ -21,8 +21,16 @@ const PLUGIN_SOURCE: &str = include_str!("../../../dev/opencode-plugin.ts");/// `~/Library/Application Support/opencode/` path is reserved for *managed* settings and is/// not where OpenCode looks for user plugins, so we deliberately avoid `dirs::config_dir()`/// here — it would put the plugin in the wrong place on macOS.+///+/// Both overrides read an exported-but-empty value as unset, matching+/// `CLAUDE_CONFIG_DIR` in `config::show` and `PI_CONFIG_DIR` in `config::pi`.+/// An empty value taken at face value yields the relative path `plugins/`, so+/// the install writes the plugin into whatever directory `wt` was run from.fn opencode_plugins_dir() -> Result<PathBuf> {- let config_dir = if let Ok(dir) = std::env::var("OPENCODE_CONFIG_DIR") {+ let config_dir = if let Some(dir) = std::env::var("OPENCODE_CONFIG_DIR")+ .ok()+ .filter(|s| !s.is_empty())+ {PathBuf::from(dir)} else if let Some(xdg) = std::env::var("XDG_CONFIG_HOME").ok()diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rsindex 1b32110e8..b1c4f7790 100644--- a/tests/integration_tests/config_show.rs+++ b/tests/integration_tests/config_show.rs@@ -2711,6 +2711,49 @@ fn test_opencode_install_defaults_to_home_dot_config(temp_home: TempDir) {);}+/// An exported-but-empty `OPENCODE_CONFIG_DIR` reads as unset, not as a+/// directory named `""`.+///+/// Regression guard: the empty value used to be taken at face value, so the+/// install target collapsed to the relative path `plugins/worktrunk.ts` and+/// the plugin was written into whatever directory `wt` was run from — with+/// `is_plugin_installed()` then reading it back from there, so the install+/// reported success while OpenCode never saw the plugin.+#[rstest]+fn test_opencode_install_treats_empty_config_dir_as_unset(temp_home: TempDir) {+ let run_dir = temp_home.path().join("run-from-here");+ fs::create_dir_all(&run_dir).unwrap();++ let mut cmd = wt_command();+ set_temp_home_env(&mut cmd, temp_home.path());+ cmd.env("OPENCODE_CONFIG_DIR", "");+ cmd.current_dir(&run_dir);+ cmd.args(["config", "plugins", "opencode", "install", "--yes"]);++ let output = cmd.output().expect("install command should run");+ assert!(+ output.status.success(),+ "install failed: stdout={}, stderr={}",+ String::from_utf8_lossy(&output.stdout),+ String::from_utf8_lossy(&output.stderr),+ );++ let canonical_home =+ crate::common::canonicalize(temp_home.path()).unwrap_or_else(|_| temp_home.path().into());+ // set_temp_home_env sets XDG_CONFIG_HOME = $HOME/.config, which is the next+ // rung down the precedence once the empty override is discarded.+ let plugin_path = canonical_home.join(".config/opencode/plugins/worktrunk.ts");+ assert!(+ plugin_path.exists(),+ "Plugin should fall through to the XDG path, but not found at: {}",+ plugin_path.display(),+ );+ assert!(+ !run_dir.join("plugins").exists(),+ "Plugin must not be written relative to the invocation directory"+ );+}+/// Install prompt declined (no `--yes`, piped stdin → empty → declined)./// Exercises the `return Ok(())` branch at lines 83-84 of opencode.rs.#[rstest]