Skip to content

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

feat(switch): experimental Gitea PR support via pr: shortcut (#1320)

Steve Beaulac7fca05441ea4
diff --git a/dev/wt.example.toml b/dev/wt.example.toml
index 64a0a7416..96632f131 100644
--- a/dev/wt.example.toml
+++ b/dev/wt.example.toml
@@ -24,7 +24,7 @@
# Override platform detection for SSH aliases or self-hosted instances:
#
# [forge]
-# platform = "github" # or "gitlab"
+# platform = "github" # or "gitea" (experimental), "gitlab"
# hostname = "github.example.com" # Example: API host (GHE / self-hosted GitLab)
#
# ## Copy-ignored excludes
diff --git a/docs/content/config.md b/docs/content/config.md
index 4ffe0e236..29631899a 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -402,7 +402,7 @@ Override platform detection for SSH aliases or self-hosted instances:
```toml
[forge]
-platform = "github" # or "gitlab"
+platform = "github" # or "gitea" (experimental), "gitlab"
hostname = "github.example.com" # Example: API host (GHE / self-hosted GitLab)
```
@@ -924,7 +924,7 @@ CI status cache.
Caches GitHub/GitLab CI status for display in [`wt list`](@/list.md#ci-status).
-Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `forge.platform = "github"` in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
+Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `forge.platform = "github"` (or `"gitlab"`) in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
Checks open PRs/MRs first, then branch pipelines for branches with upstream. Local-only branches (no remote tracking) show blank.
diff --git a/docs/content/switch.md b/docs/content/switch.md
index 33693b6b6..6d6c3a031 100644
--- a/docs/content/switch.md
+++ b/docs/content/switch.md
@@ -106,6 +106,8 @@ Requires `gh` (GitHub) or `glab` (GitLab) CLI to be installed and authenticated.
**Forks:** The local branch uses the PR/MR's branch name directly (e.g., `feature-fix`), so `git push` works normally. If a local branch with that name already exists tracking something else, rename it first.
+**Gitea (experimental):** `pr:` is also compatible with Gitea via the `tea` CLI. Set `[forge] platform = "gitea"` in `.config/wt.toml` to opt in; worktrunk also auto-detects Gitea when the remote host contains `gitea` or when `tea login add` has been run for the host.
+
## When wt switch fails
- **Branch doesn't exist** — Use `--create`, or check `wt list --branches`
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index 93ae2676f..c7c735d63 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -401,7 +401,7 @@ Override platform detection for SSH aliases or self-hosted instances:
```toml
[forge]
-platform = "github" # or "gitlab"
+platform = "github" # or "gitea" (experimental), "gitlab"
hostname = "github.example.com" # Example: API host (GHE / self-hosted GitLab)
```
@@ -966,7 +966,7 @@ CI status cache.
Caches GitHub/GitLab CI status for display in [`wt list`](https://worktrunk.dev/list/#ci-status).
-Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `forge.platform = "github"` in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
+Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `forge.platform = "github"` (or `"gitlab"`) in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
Checks open PRs/MRs first, then branch pipelines for branches with upstream. Local-only branches (no remote tracking) show blank.
diff --git a/skills/worktrunk/reference/switch.md b/skills/worktrunk/reference/switch.md
index 00b31a899..1d377679e 100644
--- a/skills/worktrunk/reference/switch.md
+++ b/skills/worktrunk/reference/switch.md
@@ -104,6 +104,8 @@ Requires `gh` (GitHub) or `glab` (GitLab) CLI to be installed and authenticated.
**Forks:** The local branch uses the PR/MR's branch name directly (e.g., `feature-fix`), so `git push` works normally. If a local branch with that name already exists tracking something else, rename it first.
+**Gitea (experimental):** `pr:` is also compatible with Gitea via the `tea` CLI. Set `[forge] platform = "gitea"` in `.config/wt.toml` to opt in; worktrunk also auto-detects Gitea when the remote host contains `gitea` or when `tea login add` has been run for the host.
+
## When wt switch fails
- **Branch doesn't exist** — Use `--create`, or check `wt list --branches`
diff --git a/src/cli/config.rs b/src/cli/config.rs
index 363ff8015..f7a7207e2 100644
--- a/src/cli/config.rs
+++ b/src/cli/config.rs
@@ -822,7 +822,7 @@ $ wt config state hints clear NAME # re-show specific hint
name = "ci-status",
after_long_help = r#"Caches GitHub/GitLab CI status for display in [`wt list`](@/list.md#ci-status).
-Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `forge.platform = "github"` in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
+Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `forge.platform = "github"` (or `"gitlab"`) in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
Checks open PRs/MRs first, then branch pipelines for branches with upstream. Local-only branches (no remote tracking) show blank.
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index ad8de4b61..7ed9ee708 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -632,6 +632,8 @@ Requires `gh` (GitHub) or `glab` (GitLab) CLI to be installed and authenticated.
**Forks:** The local branch uses the PR/MR's branch name directly (e.g., `feature-fix`), so `git push` works normally. If a local branch with that name already exists tracking something else, rename it first.
+**Gitea (experimental):** `pr:` is also compatible with Gitea via the `tea` CLI. Set `[forge] platform = "gitea"` in `.config/wt.toml` to opt in; worktrunk also auto-detects Gitea when the remote host contains `gitea` or when `tea login add` has been run for the host.
+
## When wt switch fails
- **Branch doesn't exist** — Use `--create`, or check `wt list --branches`
@@ -1934,7 +1936,7 @@ Override platform detection for SSH aliases or self-hosted instances:
```toml
[forge]
-platform = "github" # or "gitlab"
+platform = "github" # or "gitea" (experimental), "gitlab"
hostname = "github.example.com" # Example: API host (GHE / self-hosted GitLab)
```
diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rs
index e9ad3c72c..4cd0a684d 100644
--- a/src/commands/worktree/switch.rs
+++ b/src/commands/worktree/switch.rs
@@ -7,7 +7,7 @@ use std::collections::HashMap;
use std::path::{Path, PathBuf};
use crate::display::format_relative_time_short;
-use anyhow::Context;
+use anyhow::{Context, bail};
use color_print::cformat;
use dunce::canonicalize;
use serde::Serialize;
@@ -16,7 +16,7 @@ use worktrunk::config::{
UserConfig, ValidationScope, expand_template, template_references_var, validate_template,
};
use worktrunk::git::remote_ref::{
- self, GitHubProvider, GitLabProvider, RemoteRefInfo, RemoteRefProvider,
+ self, GitHubProvider, GitLabProvider, GiteaProvider, RemoteRefInfo, RemoteRefProvider,
};
use worktrunk::git::{
GitError, RefContext, RefType, Repository, SwitchSuggestionCtx, current_or_recover,
@@ -73,6 +73,111 @@ fn format_ref_context(ctx: &impl RefContext) -> String {
)
}
+#[derive(Debug, Clone, Copy)]
+enum PrProviderChoice {
+ GitHub,
+ Gitea,
+}
+
+/// Choose which provider should handle `pr:<number>` resolution.
+///
+/// Priority:
+/// 1. `forge.platform` config override
+/// 2. Primary remote URL detection (host contains `github`/`gitea`)
+/// 3. CLI auth lookup — if `tea` has a login for this host but `gh` does
+/// not, pick Gitea; otherwise default to GitHub
+///
+/// The default-to-GitHub fall-through means a self-hosted Gitea on a branded
+/// host (e.g. `git.example.com`) without `tea login add` will see a single
+/// GitHub error (with hint to set `forge.platform = "gitea"`), instead of a
+/// wrapped two-provider error.
+fn choose_pr_provider(repo: &Repository) -> anyhow::Result<PrProviderChoice> {
+ if let Some(platform_raw) = repo
+ .load_project_config()
+ .ok()
+ .flatten()
+ .and_then(|c| c.forge_platform().map(str::to_string))
+ {
+ let platform = platform_raw.to_ascii_lowercase();
+ match platform.as_str() {
+ "github" => return Ok(PrProviderChoice::GitHub),
+ "gitea" => return Ok(PrProviderChoice::Gitea),
+ "gitlab" => {
+ bail!("forge.platform is set to gitlab; use mr:<number> instead of pr:<number>")
+ }
+ _ => bail!(
+ "Invalid forge.platform value `{platform_raw}` in .config/wt.toml; \
+ expected one of: github, gitea, gitlab"
+ ),
+ }
+ }
+
+ // Use the raw remote URL (not effective) — `insteadOf` rewrites are for
+ // git transport (e.g., redirecting fetches through a local mirror) and
+ // can produce a path that doesn't reflect the real forge host.
+ let detected = repo
+ .primary_remote()
+ .ok()
+ .and_then(|remote| repo.remote_url(&remote))
+ .and_then(|url| worktrunk::git::GitRemoteUrl::parse(&url));
+
+ let Some(parsed) = detected else {
+ return Ok(PrProviderChoice::GitHub);
+ };
+
+ if parsed.is_github() {
+ return Ok(PrProviderChoice::GitHub);
+ }
+ if parsed.is_gitlab() {
+ bail!("Detected GitLab remote; use mr:<number> instead of pr:<number>")
+ }
+ if parsed.is_gitea() {
+ return Ok(PrProviderChoice::Gitea);
+ }
+
+ // Self-hosted forge with a non-distinctive hostname. Ask the CLIs which
+ // one is configured for this host. If only `tea` has a login, pick Gitea;
+ // otherwise default to GitHub (the common case, and the one users get
+ // useful errors from when nothing is set up).
+ if remote_ref::gitea::is_authed_for(parsed.host())
+ && !remote_ref::github::is_authed_for(parsed.host())
+ {
+ Ok(PrProviderChoice::Gitea)
+ } else {
+ Ok(PrProviderChoice::GitHub)
+ }
+}
+
+fn resolve_pr_target(
+ repo: &Repository,
+ number: u32,
+ create: bool,
+ base: Option<&str>,
+) -> anyhow::Result<ResolvedTarget> {
+ if base.is_some() {
+ return Err(GitError::RefBaseConflict {
+ ref_type: RefType::Pr,
+ number,
+ }
+ .into());
+ }
+
+ match choose_pr_provider(repo)? {
+ PrProviderChoice::GitHub => resolve_remote_ref(repo, &GitHubProvider, number, create, base),
+ PrProviderChoice::Gitea => resolve_remote_ref(repo, &GiteaProvider, number, create, base),
+ }
+}
+
+fn resolve_pr_base(
+ repo: &Repository,
+ number: u32,
+) -> anyhow::Result<(String, Option<(String, String)>)> {
+ match choose_pr_provider(repo)? {
+ PrProviderChoice::GitHub => resolve_remote_ref_as_base(repo, &GitHubProvider, number),
+ PrProviderChoice::Gitea => resolve_remote_ref_as_base(repo, &GiteaProvider, number),
+ }
+}
+
/// Resolve a remote ref (PR or MR) using the unified provider interface.
fn resolve_remote_ref(
repo: &Repository,
@@ -162,7 +267,7 @@ fn resolve_fork_ref(
});
}
- // Branch exists but doesn't track this ref - try prefixed name (GitHub only)
+ // Branch exists but doesn't track this ref - try prefixed name (GitHub/Gitea)
if let Some(prefixed) = info.prefixed_local_branch_name() {
if let Some(prefixed_tracks) = remote_ref::branch_tracks_ref(
repo_root,
@@ -329,7 +434,7 @@ fn resolve_base_ref(
if let Some(suffix) = base.strip_prefix("pr:")
&& let Ok(number) = suffix.parse::<u32>()
{
- return resolve_remote_ref_as_base(repo, &GitHubProvider, number);
+ return resolve_pr_base(repo, number);
}
if let Some(suffix) = base.strip_prefix("mr:")
@@ -408,7 +513,7 @@ fn resolve_switch_target(
if let Some(suffix) = branch.strip_prefix("pr:")
&& let Ok(number) = suffix.parse::<u32>()
{
- return resolve_remote_ref(repo, &GitHubProvider, number, create, base);
+ return resolve_pr_target(repo, number, create, base);
}
// Handle mr:<number> syntax (GitLab MRs)
diff --git a/src/config/project.rs b/src/config/project.rs
index ad26a59cb..60aaa7fcc 100644
--- a/src/config/project.rs
+++ b/src/config/project.rs
@@ -66,14 +66,16 @@ pub struct ProjectCiConfig {
///
/// ```toml
/// [forge]
-/// platform = "github" # or "gitlab"
+/// platform = "github" # or "gitea" (experimental), "gitlab"
/// hostname = "github.example.com" # API hostname for GHE / self-hosted GitLab
/// ```
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, JsonSchema)]
pub struct ProjectForgeConfig {
/// Forge platform override. When set, skips URL-based platform detection.
///
- /// Values: "github" or "gitlab"
+ /// Values: "github", "gitea" (experimental), or "gitlab". The `wt switch
+ /// pr:` shortcut uses `forge.platform` to decide which CLI to invoke
+ /// (`gh`, `tea`, or `glab`).
#[serde(default)]
pub platform: Option<String>,
diff --git a/src/git/remote_ref/gitea.rs b/src/git/remote_ref/gitea.rs
new file mode 100644
index 000000000..5ccc86082
--- /dev/null
+++ b/src/git/remote_ref/gitea.rs
@@ -0,0 +1,512 @@
+//! Gitea PR provider.
+//!
+//! Implements `RemoteRefProvider` for Gitea Pull Requests using the `tea` CLI.
+//!
+//! ## API path resolution
+//!
+//! `tea api <path>` does support `{owner}` and `{repo}` placeholders, but their
+//! values come from `tea`'s own repo-context resolver, which depends on the
+//! local git remote being a Gitea-accessible URL and on the user having set up
+//! `tea login add` first. We resolve owner/repo from the primary remote URL
+//! ourselves and pass an already-expanded path so the call works regardless of
+//! how `tea` resolves its own context.
+
+use anyhow::{Context, bail};
+use serde::Deserialize;
+
+use super::{
+ CliApiRequest, PlatformData, RemoteRefInfo, RemoteRefProvider, cli_api_error,
+ extract_host_from_html_url, run_cli_api,
+};
+use crate::git::{self, RefType, Repository};
+
+/// Gitea Pull Request provider.
+#[derive(Debug, Clone, Copy)]
+pub struct GiteaProvider;
+
+impl RemoteRefProvider for GiteaProvider {
+ fn ref_type(&self) -> RefType {
+ RefType::Pr
+ }
+
+ fn fetch_info(&self, number: u32, repo: &Repository) -> anyhow::Result<RemoteRefInfo> {
+ fetch_pr_info(number, repo)
+ }
+
+ fn ref_path(&self, number: u32) -> String {
+ format!("pull/{}/head", number)
+ }
+}
+
+/// Raw JSON response from `tea api repos/{owner}/{repo}/pulls/{number}`.
+#[derive(Debug, Deserialize)]
+struct TeaApiPrResponse {
+ title: String,
+ user: TeaUser,
+ state: String,
+ #[serde(default)]
+ draft: bool,
+ head: TeaPrRef,
+ base: TeaPrRef,
+ html_url: String,
+}
+
+/// Error response from Gitea API.
+#[derive(Debug, Deserialize)]
+struct TeaApiErrorResponse {
+ #[serde(default)]
+ message: String,
+}
+
+#[derive(Debug, Deserialize)]
+struct TeaUser {
+ login: String,
+}
+
+#[derive(Debug, Deserialize)]
+struct TeaPrRef {
+ #[serde(default)]
+ label: String,
+ #[serde(rename = "ref")]
+ #[serde(default)]
+ ref_name: String,
+ repo: Option<TeaPrRepo>,
+}
+
+#[derive(Debug, Deserialize)]
+struct TeaPrRepo {
+ name: String,
+ owner: TeaOwner,
+}
+
+#[derive(Debug, Deserialize)]
+struct TeaOwner {
+ login: String,
+}
+
+/// Fetch PR information from Gitea using the `tea` CLI.
+fn fetch_pr_info(pr_number: u32, repo: &Repository) -> anyhow::Result<RemoteRefInfo> {
+ let repo_root = repo.repo_path()?;
+
+ // Resolve owner/repo from the primary remote URL so we pass a fully
+ // expanded path to `tea api`. See module docstring for rationale.
+ let remote = repo.primary_remote()?;
+ let url = repo
+ .remote_url(&remote)
+ .ok_or_else(|| anyhow::anyhow!("Remote '{}' has no URL", remote))?;
+ let parsed = git::GitRemoteUrl::parse(&url)
+ .ok_or_else(|| anyhow::anyhow!("Cannot parse remote URL: {}", url))?;
+
+ let api_path = format!(
+ "repos/{}/{}/pulls/{}",
+ parsed.owner(),
+ parsed.repo(),
+ pr_number,
+ );
+
+ let output = run_cli_api(CliApiRequest {
+ tool: "tea",
+ args: &["api", &api_path],
+ repo_root,
+ // tea reads no prompt-disable env var; pass a no-op key/value so the
+ // shared helper has something to set without inventing a fake var.
+ prompt_env: ("TEA_NO_PROMPT", "1"),
+ install_hint: "Gitea CLI (tea) not installed; install from https://gitea.com/gitea/tea",
+ run_context: "Failed to run tea api",
+ })?;
+
+ if !output.status.success() {
+ if let Ok(error_response) = serde_json::from_slice::<TeaApiErrorResponse>(&output.stdout) {
+ let message_lower = error_response.message.to_ascii_lowercase();
+ if message_lower.contains("404") || message_lower.contains("not found") {
+ bail!(
+ "Gitea PR #{} not found on {}/{}",
+ pr_number,
+ parsed.owner(),
+ parsed.repo()
+ );
+ }
+ if message_lower.contains("401") || message_lower.contains("unauthorized") {
+ bail!("Gitea CLI not authenticated; run tea login add");
+ }
+ if message_lower.contains("403") || message_lower.contains("forbidden") {
+ bail!("Gitea API access forbidden for PR #{}", pr_number);
+ }
+ }
+
+ return Err(cli_api_error(
+ RefType::Pr,
+ format!("tea api failed for PR #{}", pr_number),
+ &output,
+ ));
+ }
+
+ let response: TeaApiPrResponse = serde_json::from_slice(&output.stdout).with_context(|| {
+ format!(
+ "Failed to parse Gitea API response for PR #{}. \
+ This may indicate a Gitea API change.",
+ pr_number
+ )
+ })?;
+
+ // Check head.repo before extract_source_branch so deleted-source PRs hit
+ // the specific "source repository was deleted" message instead of falling
+ // back to the generic "no source branch" path.
+ let base_repo = response.base.repo.context(
+ "Gitea PR base repository is null; this is unexpected and may indicate a Gitea API issue",
+ )?;
+
+ let TeaPrRef {
+ label: head_label,
+ ref_name: head_ref_name,
+ repo: head_repo_opt,
+ } = response.head;
+
+ let head_repo = head_repo_opt.ok_or_else(|| {
+ anyhow::anyhow!(
+ "Gitea PR #{} source repository was deleted. \
+ The fork that this PR was opened from no longer exists, \
+ so the branch cannot be checked out.",
+ pr_number
+ )
+ })?;
+
+ let source_branch =
+ extract_source_branch_from_parts(&head_label, &head_ref_name).ok_or_else(|| {
+ anyhow::anyhow!(
+ "Gitea PR #{} has no usable source branch — head.label/head.ref \
+ carry placeholders, so the PR may be in an invalid state",
+ pr_number
+ )
+ })?;
+
+ let is_cross_repo = !base_repo
+ .owner
+ .login
+ .eq_ignore_ascii_case(&head_repo.owner.login)
+ || !base_repo.name.eq_ignore_ascii_case(&head_repo.name);
+
+ let host = extract_host_from_html_url(&response.html_url)?;
+
+ let fork_push_url =
+ is_cross_repo.then(|| fork_remote_url(&host, &head_repo.owner.login, &head_repo.name));
+
+ Ok(RemoteRefInfo {
+ ref_type: RefType::Pr,
+ number: pr_number,
+ title: response.title,
+ author: response.user.login,
+ state: response.state,
+ draft: response.draft,
+ source_branch,
+ is_cross_repo,
+ url: response.html_url,
+ fork_push_url,
+ platform_data: PlatformData::Gitea {
+ host,
+ head_owner: head_repo.owner.login,
+ head_repo: head_repo.name,
+ base_owner: base_repo.owner.login,
+ base_repo: base_repo.name,
+ },
+ })
+}
+
+/// Extract the source branch name from a PR's head ref/label.
+///
+/// Prefers `label` (Gitea returns `owner:branch` for forks, `branch` otherwise).
+/// Falls back to `ref`, which Gitea returns as the bare branch name (e.g.
+/// `feature-auth`); the `refs/heads/` strip handles Gitea instances that
+/// happen to return a fully-qualified ref.
+///
+/// When `head.repo` is null Gitea may still emit placeholder strings here
+/// (`label = "unknown repository"`, `ref = "refs/pull/<n>/head"`). `fetch_pr_info`
+/// checks `head.repo` before calling us, so by the time this runs we expect a
+/// real branch name; placeholders that slip through return None and bail.
+fn extract_source_branch_from_parts(label: &str, ref_name: &str) -> Option<String> {
+ if !label.is_empty() {
+ let candidate = label
+ .split_once(':')
+ .map(|(_, b)| b)
+ .unwrap_or(label)
+ .trim();
+ if is_real_branch_name(candidate) {
+ return Some(candidate.to_string());
+ }
+ }
+
+ let candidate = ref_name
+ .strip_prefix("refs/heads/")
+ .unwrap_or(ref_name)
+ .trim();
+ is_real_branch_name(candidate).then(|| candidate.to_string())
+}
+
+/// A branch name candidate is real when it's non-empty, has no whitespace
+/// (placeholders like `"unknown repository"` carry a space), and isn't a
+/// PR-tracking ref like `refs/pull/<n>/head` or `pulls/<n>/head`.
+fn is_real_branch_name(s: &str) -> bool {
+ !s.is_empty()
+ && !s.contains(char::is_whitespace)
+ && !s.starts_with("refs/")
+ && !s.starts_with("pulls/")
+ && !s.starts_with("pull/")
+}
+
+/// Construct the remote URL for a Gitea repository.
+pub fn fork_remote_url(host: &str, owner: &str, repo: &str) -> String {
+ format!("https://{}/{}/{}.git", host, owner, repo)
+}
+
+/// Whether `tea` has a login configured for `host`.
+///
+/// Used by the switch dispatcher to decide which provider to try when the
+/// remote URL doesn't unambiguously identify the forge. Reads tea's config
+/// file directly — `$XDG_CONFIG_HOME/tea/config.yml` (default
+/// `~/.config/tea/config.yml`) with legacy fallback `~/.tea/tea.yml` — and
+/// returns true if any `logins[].url` parses to the same host. Pure local
+/// I/O; never invokes `tea` (which can trigger an OAuth refresh on lookup).
+pub fn is_authed_for(host: &str) -> bool {
+ read_tea_config().is_some_and(|content| config_has_login_for(&content, host))
+}
+
+/// Pure parser: scan tea's `config.yml` content for a `logins[].url` whose
+/// host matches `target`. Extracted from `is_authed_for` so the YAML-shaped
+/// matching can be unit-tested without touching the filesystem or env vars.
+fn config_has_login_for(content: &str, target: &str) -> bool {
+ content.lines().any(|line| {
+ let trimmed = line.trim_start();
+ let Some(rest) = trimmed.strip_prefix("url:") else {
+ return false;
+ };
+ let value = rest.trim().trim_matches(|c: char| c == '"' || c == '\'');
+ let Some(without_scheme) = value
+ .strip_prefix("https://")
+ .or_else(|| value.strip_prefix("http://"))
+ else {
+ return false;
+ };
+ let host = without_scheme.split(['/', '?', '#']).next().unwrap_or("");
+ host.eq_ignore_ascii_case(target)
+ })
+}
+
+/// Read tea's config.yml, honoring `$XDG_CONFIG_HOME` and the legacy
+/// `~/.tea/tea.yml` fallback. Returns None if neither file is readable.
+fn read_tea_config() -> Option<String> {
+ let xdg = std::env::var_os("XDG_CONFIG_HOME").map(std::path::PathBuf::from);
+ let home = dirs::home_dir();
+
+ let primary = xdg
+ .clone()
+ .or_else(|| home.as_ref().map(|h| h.join(".config")))
+ .map(|base| base.join("tea").join("config.yml"));
+ if let Some(path) = primary
+ && let Ok(content) = std::fs::read_to_string(&path)
+ {
+ return Some(content);
+ }
+
+ let legacy = home.map(|h| h.join(".tea").join("tea.yml"));
+ if let Some(path) = legacy
+ && let Ok(content) = std::fs::read_to_string(&path)
+ {
+ return Some(content);
+ }
+ None
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_ref_path() {
+ let provider = GiteaProvider;
+ assert_eq!(provider.ref_path(7), "pull/7/head");
+ assert_eq!(provider.tracking_ref(7), "refs/pull/7/head");
+ }
+
+ #[test]
+ fn test_ref_type() {
+ let provider = GiteaProvider;
+ assert_eq!(provider.ref_type(), RefType::Pr);
+ }
+
+ #[test]
+ fn test_extract_source_branch_prefers_label() {
+ let head = TeaPrRef {
+ label: "alice:feature-auth".to_string(),
+ ref_name: "refs/pull/42/head".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ Some("feature-auth".to_string())
+ );
+ }
+
+ #[test]
+ fn test_extract_source_branch_from_plain_label() {
+ let head = TeaPrRef {
+ label: "feature-auth".to_string(),
+ ref_name: "refs/pull/42/head".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ Some("feature-auth".to_string())
+ );
+ }
+
+ #[test]
+ fn test_extract_source_branch_fallback_to_bare_ref() {
+ // Gitea returns just the branch name in head.ref
+ let head = TeaPrRef {
+ label: "".to_string(),
+ ref_name: "feature-auth".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ Some("feature-auth".to_string())
+ );
+ }
+
+ #[test]
+ fn test_extract_source_branch_fallback_strips_refs_heads() {
+ let head = TeaPrRef {
+ label: "".to_string(),
+ ref_name: "refs/heads/feature-auth".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ Some("feature-auth".to_string())
+ );
+ }
+
+ #[test]
+ fn test_extract_source_branch_label_with_empty_branch_falls_through() {
+ // Label "owner:" → split_once gives ("", ""); after trim it's empty,
+ // so the function falls through to the ref-name branch.
+ let head = TeaPrRef {
+ label: "owner:".to_string(),
+ ref_name: "feature-auth".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ Some("feature-auth".to_string())
+ );
+ }
+
+ #[test]
+ fn test_extract_source_branch_empty_after_strip_returns_none() {
+ // Bare "refs/heads/" strips to empty — no branch name available.
+ let head = TeaPrRef {
+ label: "".to_string(),
+ ref_name: "refs/heads/".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ None
+ );
+ }
+
+ #[test]
+ fn test_extract_source_branch_empty_ref_returns_none() {
+ let head = TeaPrRef {
+ label: "".to_string(),
+ ref_name: "".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ None
+ );
+ }
+
+ #[test]
+ fn test_extract_source_branch_skips_deleted_branch_ref() {
+ // Gitea uses "pulls/<idx>/head" when the source branch is deleted —
+ // not a usable branch name.
+ let head = TeaPrRef {
+ label: "".to_string(),
+ ref_name: "pulls/42/head".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ None
+ );
+ }
+
+ #[test]
+ fn test_extract_source_branch_rejects_placeholders() {
+ // Deleted-source PRs: Gitea returns "unknown repository" as the label
+ // (contains a space, not a real branch name) and "refs/pull/<n>/head"
+ // as the ref (a tracking ref, not a branch). Both must be rejected so
+ // fetch_pr_info bails with the deleted-source error rather than
+ // proceeding to fetch an invalid branch.
+ let head = TeaPrRef {
+ label: "unknown repository".to_string(),
+ ref_name: "refs/pull/42/head".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ None
+ );
+
+ // Same but with the bare `pull/<n>/head` form some Gitea versions emit.
+ let head = TeaPrRef {
+ label: "".to_string(),
+ ref_name: "pull/42/head".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ None
+ );
+
+ // A bare `refs/pull/...` in the label (no `:` separator) must also fail.
+ let head = TeaPrRef {
+ label: "refs/pull/42/head".to_string(),
+ ref_name: "".to_string(),
+ repo: None,
+ };
+ assert_eq!(
+ extract_source_branch_from_parts(&head.label, &head.ref_name),
+ None
+ );
+ }
+
+ #[test]
+ fn test_config_has_login_for_matches_known_hosts() {
+ // tea writes one entry per `tea login add`. Match by host extracted
+ // from the URL — case-insensitive, scheme-agnostic, ignores trailing
+ // path/query.
+ let yaml = r#"logins:
+ - name: gitea-com
+ url: https://gitea.com
+ default: true
+ - name: selfhosted
+ url: "https://forge.example.com/"
+ - name: with-path
+ url: http://other.test/api/v1
+"#;
+ assert!(config_has_login_for(yaml, "gitea.com"));
+ assert!(config_has_login_for(yaml, "GITEA.COM"));
+ assert!(config_has_login_for(yaml, "forge.example.com"));
+ assert!(config_has_login_for(yaml, "other.test"));
+ assert!(!config_has_login_for(yaml, "not-configured.test"));
+ // Empty config has no logins.
+ assert!(!config_has_login_for("", "gitea.com"));
+ // Stray `url:` outside a logins entry must not match — but the parser
+ // is line-based and intentionally permissive; document the trade-off
+ // by asserting the tea-shaped scheme-prefixed form is required.
+ assert!(!config_has_login_for("url: gitea.com\n", "gitea.com"));
+ }
+}
diff --git a/src/git/remote_ref/github.rs b/src/git/remote_ref/github.rs
index 2f176d4f4..87d7a4a51 100644
--- a/src/git/remote_ref/github.rs
+++ b/src/git/remote_ref/github.rs
@@ -9,7 +9,7 @@ use serde::Deserialize;
use super::{
CliApiRequest, PlatformData, RemoteRefInfo, RemoteRefProvider, cli_api_error, cli_config_value,
- run_cli_api,
+ extract_host_from_html_url, run_cli_api,
};
use crate::git::{self, RefType, Repository};
use crate::shell_exec::Cmd;
@@ -212,25 +212,10 @@ fn fetch_pr_info(pr_number: u32, repo: &Repository) -> anyhow::Result<RemoteRefI
.eq_ignore_ascii_case(&head_repo.owner.login)
|| !base_repo.name.eq_ignore_ascii_case(&head_repo.name);
- let host = response
- .html_url
- .strip_prefix("https://")
- .or_else(|| response.html_url.strip_prefix("http://"))
- .and_then(|s| s.split('/').next())
- .filter(|h| !h.is_empty())
- .with_context(|| format!("Failed to parse host from PR URL: {}", response.html_url))?
- .to_string();
-
- // Compute fork push URL only for cross-repo PRs
- let fork_push_url = if is_cross_repo {
- Some(fork_remote_url(
- &host,
- &head_repo.owner.login,
- &head_repo.name,
- ))
- } else {
- None
- };
+ let host = extract_host_from_html_url(&response.html_url)?;
+
+ let fork_push_url =
+ is_cross_repo.then(|| fork_remote_url(&host, &head_repo.owner.login, &head_repo.name));
Ok(RemoteRefInfo {
ref_type: RefType::Pr,
@@ -258,6 +243,22 @@ fn use_ssh_protocol() -> bool {
cli_config_value("gh", "git_protocol").as_deref() == Some("ssh")
}
+/// Whether `gh` has an authentication token configured for `host`.
+///
+/// Used by the switch dispatcher to decide which provider to try when the
+/// remote URL doesn't unambiguously identify the forge (e.g. self-hosted on
+/// `git.example.com`). `gh auth token --hostname <host>` reads from
+/// `~/.config/gh/hosts.yml` and the OS keyring — no network. Returns `false`
+/// if `gh` is not installed.
+pub fn is_authed_for(host: &str) -> bool {
+ Cmd::new("gh")
+ .args(["auth", "token", "--hostname", host])
+ .env("GH_PROMPT_DISABLED", "1")
+ .run()
+ .map(|o| o.status.success())
+ .unwrap_or(false)
+}
+
/// Construct the remote URL for a fork repository.
pub fn fork_remote_url(host: &str, owner: &str, repo: &str) -> String {
if use_ssh_protocol() {
diff --git a/src/git/remote_ref/info.rs b/src/git/remote_ref/info.rs
index 413357621..9411541c8 100644
--- a/src/git/remote_ref/info.rs
+++ b/src/git/remote_ref/info.rs
@@ -22,6 +22,19 @@ pub enum PlatformData {
/// Name of the base (target) repository.
base_repo: String,
},
+ /// Gitea-specific data.
+ Gitea {
+ /// Gitea host (e.g., "gitea.com", "git.example.com").
+ host: String,
+ /// Owner of the head (source) repository.
+ head_owner: String,
+ /// Name of the head (source) repository.
+ head_repo: String,
+ /// Owner of the base (target) repository.
+ base_owner: String,
+ /// Name of the base (target) repository.
+ base_repo: String,
+ },
/// GitLab-specific data.
GitLab {
/// GitLab host (e.g., "gitlab.com", "gitlab.example.com").
@@ -103,6 +116,9 @@ impl RefContext for RemoteRefInfo {
PlatformData::GitHub { head_owner, .. } => {
format!("{}:{}", head_owner, self.source_branch)
}
+ PlatformData::Gitea { head_owner, .. } => {
+ format!("{}:{}", head_owner, self.source_branch)
+ }
PlatformData::GitLab { .. } => {
// For GitLab, try to extract namespace from fork_push_url
if let Some(url) = &self.fork_push_url
@@ -123,10 +139,10 @@ impl RemoteRefInfo {
/// Generate a prefixed local branch name for when the unprefixed name conflicts.
///
/// Returns `<owner>/<branch>` (e.g., `contributor/main`).
- /// Only meaningful for GitHub fork PRs; GitLab doesn't support this pattern.
+ /// Used for GitHub/Gitea fork PRs; GitLab doesn't support this pattern.
pub fn prefixed_local_branch_name(&self) -> Option<String> {
match &self.platform_data {
- PlatformData::GitHub { head_owner, .. } => {
+ PlatformData::GitHub { head_owner, .. } | PlatformData::Gitea { head_owner, .. } => {
Some(format!("{}/{}", head_owner, self.source_branch))
}
PlatformData::GitLab { .. } => None,
@@ -197,6 +213,30 @@ mod tests {
assert_eq!(info.source_ref(), "feature-auth");
}
+ #[test]
+ fn test_source_ref_fork_gitea() {
+ let info = RemoteRefInfo {
+ ref_type: RefType::Pr,
+ number: 42,
+ title: "Add feature".to_string(),
+ author: "contributor".to_string(),
+ state: "open".to_string(),
+ draft: false,
+ source_branch: "feature-fix".to_string(),
+ is_cross_repo: true,
+ url: "https://git.example.com/owner/repo/pulls/42".to_string(),
+ fork_push_url: Some("https://git.example.com/contributor/repo.git".to_string()),
+ platform_data: PlatformData::Gitea {
+ host: "git.example.com".to_string(),
+ head_owner: "contributor".to_string(),
+ head_repo: "repo".to_string(),
+ base_owner: "owner".to_string(),
+ base_repo: "repo".to_string(),
+ },
+ };
+ assert_eq!(info.source_ref(), "contributor:feature-fix");
+ }
+
#[test]
fn test_source_ref_fork_github() {
let info = RemoteRefInfo {
@@ -272,6 +312,33 @@ mod tests {
);
}
+ #[test]
+ fn test_prefixed_local_branch_name_gitea() {
+ let info = RemoteRefInfo {
+ ref_type: RefType::Pr,
+ number: 101,
+ title: "Test".to_string(),
+ author: "contributor".to_string(),
+ state: "open".to_string(),
+ draft: false,
+ source_branch: "main".to_string(),
+ is_cross_repo: true,
+ url: "https://git.example.com/owner/repo/pulls/101".to_string(),
+ fork_push_url: Some("https://git.example.com/contributor/repo.git".to_string()),
+ platform_data: PlatformData::Gitea {
+ host: "git.example.com".to_string(),
+ head_owner: "contributor".to_string(),
+ head_repo: "repo".to_string(),
+ base_owner: "owner".to_string(),
+ base_repo: "repo".to_string(),
+ },
+ };
+ assert_eq!(
+ info.prefixed_local_branch_name(),
+ Some("contributor/main".to_string())
+ );
+ }
+
#[test]
fn test_prefixed_local_branch_name_gitlab() {
let info = RemoteRefInfo {
diff --git a/src/git/remote_ref/mod.rs b/src/git/remote_ref/mod.rs
index f18f86db7..8417f6c5e 100644
--- a/src/git/remote_ref/mod.rs
+++ b/src/git/remote_ref/mod.rs
@@ -1,6 +1,6 @@
//! Unified PR/MR reference resolution.
//!
-//! This module provides a trait-based architecture for resolving GitHub PRs and GitLab MRs
+//! This module provides a trait-based architecture for resolving GitHub/Gitea PRs and GitLab MRs
//! to local branches. Both platforms follow the same workflow:
//!
//! 1. Parse `pr:<number>` or `mr:<number>` syntax
@@ -29,11 +29,20 @@
//!
//! Uses `glab api projects/:id/merge_requests/<number>`. Fork MRs require additional
//! API calls to fetch source/target project URLs.
+//!
+//! ## Gitea (experimental)
+//!
+//! Uses `tea api repos/{owner}/{repo}/pulls/<number>`. Unlike `gh`, `tea`'s
+//! `{owner}`/`{repo}` template expansion depends on local repo context, so the
+//! provider resolves owner/repo from the primary remote URL and passes a
+//! pre-expanded path.
+pub mod gitea;
pub mod github;
pub mod gitlab;
mod info;
+pub use gitea::GiteaProvider;
pub use github::GitHubProvider;
pub use gitlab::GitLabProvider;
pub use info::{PlatformData, RemoteRefInfo};
@@ -42,7 +51,7 @@ use std::io::ErrorKind;
use std::path::Path;
use std::process::Output;
-use anyhow::bail;
+use anyhow::{Context, bail};
use crate::git::error::GitError;
use crate::git::{RefType, Repository};
@@ -119,6 +128,19 @@ pub(super) fn cli_api_error(ref_type: RefType, message: String, output: &Output)
.into()
}
+/// Extract the host (e.g. `github.com`) from a PR/MR `html_url` returned by
+/// the forge API. Both GitHub and Gitea responses use the same `https://host/...`
+/// shape, so we share the parser.
+pub(super) fn extract_host_from_html_url(html_url: &str) -> anyhow::Result<String> {
+ html_url
+ .strip_prefix("https://")
+ .or_else(|| html_url.strip_prefix("http://"))
+ .and_then(|s| s.split('/').next())
+ .filter(|h| !h.is_empty())
+ .map(String::from)
+ .with_context(|| format!("Failed to parse host from PR URL: {html_url}"))
+}
+
pub(super) fn cli_config_value(tool: &str, key: &str) -> Option<String> {
Cmd::new(tool)
.args(["config", "get", key])
@@ -141,6 +163,11 @@ pub fn find_remote(repo: &Repository, info: &RemoteRefInfo) -> Result<String, Gi
base_repo,
..
}
+ | PlatformData::Gitea {
+ base_owner,
+ base_repo,
+ ..
+ }
| PlatformData::GitLab {
base_owner,
base_repo,
@@ -157,6 +184,12 @@ pub fn find_remote(repo: &Repository, info: &RemoteRefInfo) -> Result<String, Gi
base_repo,
..
} => github::fork_remote_url(host, base_owner, base_repo),
+ PlatformData::Gitea {
+ host,
+ base_owner,
+ base_repo,
+ ..
+ } => gitea::fork_remote_url(host, base_owner, base_repo),
PlatformData::GitLab {
host,
base_owner,
@@ -207,6 +240,10 @@ mod tests {
assert_eq!(gh.ref_path(123), "pull/123/head");
assert_eq!(gh.tracking_ref(123), "refs/pull/123/head");
+ let ge = GiteaProvider;
+ assert_eq!(ge.ref_path(7), "pull/7/head");
+ assert_eq!(ge.tracking_ref(7), "refs/pull/7/head");
+
let gl = GitLabProvider;
assert_eq!(gl.ref_path(42), "merge-requests/42/head");
assert_eq!(gl.tracking_ref(42), "refs/merge-requests/42/head");
diff --git a/src/git/url.rs b/src/git/url.rs
index e4bac7113..fbaa103df 100644
--- a/src/git/url.rs
+++ b/src/git/url.rs
@@ -158,6 +158,13 @@ impl GitRemoteUrl {
pub fn is_gitlab(&self) -> bool {
self.host.to_ascii_lowercase().contains("gitlab")
}
+
+ /// Check if this URL points to a Gitea host.
+ ///
+ /// Matches gitea.com and self-hosted Gitea instances (e.g., gitea.example.com).
+ pub fn is_gitea(&self) -> bool {
+ self.host.to_ascii_lowercase().contains("gitea")
+ }
}
/// Extract owner and repository name from a git remote URL.
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 8743e8de1..a34e2352c 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -1818,12 +1818,15 @@ fn setup_mock_gh_for_pr(repo: &TestRepo, gh_response: Option<&str>) -> std::path
mock_bin
}
-/// Configure command environment for mock gh.
-fn configure_mock_gh_env(cmd: &mut std::process::Command, mock_bin: &Path) {
- // Tell mock-stub where to find config files
+/// Configure command environment for any mock CLI installed in `mock_bin`.
+///
+/// Sets `MOCK_CONFIG_DIR` (so mock-stub 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) {
cmd.env("MOCK_CONFIG_DIR", mock_bin);
- // Build PATH with mock binary first
+ // Find the actual PATH var name (case-insensitive on Windows) to avoid
+ // creating a duplicate entry with different case.
let (path_var_name, current_path) = std::env::vars_os()
.find(|(k, _)| k.eq_ignore_ascii_case("PATH"))
.map(|(k, v)| (k.to_string_lossy().into_owned(), Some(v)))
@@ -1875,7 +1878,7 @@ fn test_switch_pr_create_conflict(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["--create", "pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_create_conflict", cmd);
});
}
@@ -1939,7 +1942,7 @@ fn test_switch_pr_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_same_repo", cmd);
});
}
@@ -2009,7 +2012,7 @@ fn test_switch_pr_same_repo_limited_refspec(#[from(repo_with_remote)] mut repo:
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_same_repo_limited_refspec", cmd);
});
}
@@ -2054,7 +2057,7 @@ fn test_switch_pr_same_repo_no_remote(#[from(repo_with_remote)] repo: TestRepo)
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_same_repo_no_remote", cmd);
});
}
@@ -2139,7 +2142,7 @@ fn test_switch_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_fork", cmd);
});
}
@@ -2220,7 +2223,7 @@ post-switch = "echo 'pr_number={{ pr_number }} pr_url={{ pr_url }}' > {{ repo_pa
let mut cmd = repo.wt_command();
cmd.args(["switch", "pr:42", "--yes"]);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
let output = cmd.output().expect("wt switch pr:42 should run");
assert!(
output.status.success(),
@@ -2285,7 +2288,7 @@ fn test_switch_pr_fork_no_upstream_remote(#[from(repo_with_remote)] repo: TestRe
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_fork_no_upstream", cmd);
});
}
@@ -2394,7 +2397,7 @@ fn test_switch_pr_fork_gh_default_repo(#[from(repo_with_remote)] repo: TestRepo)
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_fork_gh_default", cmd);
});
}
@@ -2424,7 +2427,7 @@ fn test_switch_pr_not_found(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:9999"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_not_found", cmd);
});
}
@@ -2456,7 +2459,7 @@ fn test_switch_pr_deleted_fork(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_deleted_fork", cmd);
});
}
@@ -2535,7 +2538,7 @@ fn test_switch_base_pr_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {
],
None,
);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_base_pr_same_repo", cmd);
});
}
@@ -2597,7 +2600,7 @@ fn test_switch_base_pr_sets_upstream(#[from(repo_with_remote)] mut repo: TestRep
cmd.args([
"switch", "--create", "swa-65", "--base", "pr:2648", "--no-cd",
]);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
let status = cmd.status().expect("wt switch should run");
assert!(status.success(), "wt switch failed: {:?}", status);
@@ -2706,7 +2709,7 @@ fn test_switch_base_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {
&["--create", "my-work", "--base", "pr:42", "--no-cd"],
None,
);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_base_pr_fork", cmd);
});
@@ -2847,7 +2850,7 @@ fn test_switch_pr_fork_existing_same_pr(#[from(repo_with_remote)] repo: TestRepo
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_fork_existing_same_pr", cmd);
});
}
@@ -2932,7 +2935,7 @@ fn test_switch_pr_fork_existing_different_pr(#[from(repo_with_remote)] repo: Tes
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_fork_existing_different_pr", cmd);
});
}
@@ -3015,7 +3018,7 @@ fn test_switch_pr_fork_existing_same_pr_wrong_remote(#[from(repo_with_remote)] m
let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
let output = cmd.output().unwrap();
assert!(output.status.success(), "switch should succeed");
@@ -3099,7 +3102,7 @@ fn test_switch_pr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: Test
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_fork_existing_no_tracking", cmd);
});
}
@@ -3184,7 +3187,7 @@ fn test_switch_pr_fork_prefixed_exists_same_pr(#[from(repo_with_remote)] repo: T
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_fork_prefixed_exists_same_pr", cmd);
});
}
@@ -3254,7 +3257,7 @@ fn test_switch_pr_fork_prefixed_exists_different_pr(#[from(repo_with_remote)] re
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_fork_prefixed_exists_different_pr", cmd);
});
}
@@ -3283,7 +3286,7 @@ fn test_switch_pr_not_authenticated(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_not_authenticated", cmd);
});
}
@@ -3314,7 +3317,7 @@ fn test_switch_pr_rate_limit(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_rate_limit", cmd);
});
}
@@ -3338,7 +3341,7 @@ fn test_switch_pr_invalid_json(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_invalid_json", cmd);
});
}
@@ -3365,7 +3368,7 @@ fn test_switch_pr_network_error(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_network_error", cmd);
});
}
@@ -3393,7 +3396,7 @@ fn test_switch_pr_unknown_error(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_unknown_error", cmd);
});
}
@@ -3433,11 +3436,700 @@ fn test_switch_pr_empty_branch(#[from(repo_with_remote)] repo: TestRepo) {
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
- configure_mock_gh_env(&mut cmd, &mock_bin);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_empty_branch", cmd);
});
}
+// ============================================================================
+// PR Syntax Tests on Gitea remotes
+//
+// These exercise `pr:<N>` against a Gitea remote (host detection picks the
+// `tea` provider; provider selection is in choose_pr_provider). The remote
+// URLs use `gitea.example.com` so `GitRemoteUrl::is_gitea()` matches and the
+// ambiguous fallback is skipped — the runtime calls only the mock `tea`,
+// not real `gh`.
+// ============================================================================
+
+/// Helper to set up mock tea for Gitea PR tests with custom response.
+///
+/// Returns the path to the mock bin directory; pass it to
+/// `configure_mock_cli_env`.
+fn setup_mock_tea(repo: &TestRepo, tea_response: Option<&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");
+
+ if let Some(response) = tea_response {
+ fs::write(mock_bin.join("tea_pr_response.json"), response).unwrap();
+
+ MockConfig::new("tea")
+ .version("tea version development (mock)")
+ .command("api", MockResponse::file("tea_pr_response.json"))
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
+ }
+
+ mock_bin
+}
+
+#[rstest]
+fn test_switch_pr_gitea_create_conflict(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ let tea_response = r#"{
+ "title": "Fix authentication bug in login flow",
+ "user": {"login": "alice"},
+ "state": "open",
+ "draft": false,
+ "head": {
+ "label": "feature-auth",
+ "ref": "feature-auth",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "base": {
+ "label": "main",
+ "ref": "main",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "html_url": "https://gitea.example.com/owner/test-repo/pulls/101"
+ }"#;
+
+ let mock_bin = setup_mock_tea(&repo, Some(tea_response));
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["--create", "pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_create_conflict", cmd);
+ });
+}
+
+#[rstest]
+fn test_switch_pr_gitea_base_conflict(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["--base", "main", "pr:101"], None);
+ assert_cmd_snapshot!("switch_pr_gitea_base_conflict", cmd);
+ });
+}
+
+#[rstest]
+fn test_switch_pr_gitea_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {
+ repo.add_worktree("feature-auth");
+ repo.run_git(&["push", "origin", "feature-auth"]);
+
+ let bare_url = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["config", "remote.origin.url"])
+ .run()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
+
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ repo.run_git(&[
+ "config",
+ &format!("url.{}.insteadOf", bare_url),
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ let tea_response = r#"{
+ "title": "Fix authentication bug in login flow",
+ "user": {"login": "alice"},
+ "state": "open",
+ "draft": false,
+ "head": {
+ "label": "feature-auth",
+ "ref": "feature-auth",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "base": {
+ "label": "main",
+ "ref": "main",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "html_url": "https://gitea.example.com/owner/test-repo/pulls/101"
+ }"#;
+
+ let mock_bin = setup_mock_tea(&repo, Some(tea_response));
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_same_repo", cmd);
+ });
+}
+
+#[rstest]
+fn test_switch_pr_gitea_fork(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&["checkout", "-b", "gitea-pr-source"]);
+ fs::write(
+ repo.root_path().join("gitea-pr-file.txt"),
+ "Gitea PR content",
+ )
+ .unwrap();
+ repo.run_git(&["add", "gitea-pr-file.txt"]);
+ repo.run_git(&["commit", "-m", "Gitea PR commit"]);
+
+ let commit_sha = repo
+ .git_command()
+ .args(["rev-parse", "HEAD"])
+ .run()
+ .unwrap();
+ let sha = String::from_utf8_lossy(&commit_sha.stdout)
+ .trim()
+ .to_string();
+
+ repo.run_git(&["push", "origin", &format!("{}:refs/pull/42/head", sha)]);
+ repo.run_git(&["checkout", "main"]);
+
+ let bare_url = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["config", "remote.origin.url"])
+ .run()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
+
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+ repo.run_git(&[
+ "config",
+ &format!("url.{}.insteadOf", bare_url),
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ let tea_response = r#"{
+ "title": "Add feature fix for edge case",
+ "user": {"login": "contributor"},
+ "state": "open",
+ "draft": false,
+ "head": {
+ "label": "contributor:feature-fix",
+ "ref": "feature-fix",
+ "repo": {"name": "test-repo", "owner": {"login": "contributor"}}
+ },
+ "base": {
+ "label": "main",
+ "ref": "main",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "html_url": "https://gitea.example.com/owner/test-repo/pulls/42"
+ }"#;
+
+ let mock_bin = setup_mock_tea(&repo, Some(tea_response));
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_fork", cmd);
+ });
+}
+
+#[rstest]
+fn test_switch_pr_gitea_not_found(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ 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)")
+ .command(
+ "api",
+ MockResponse::output(r#"{"message":"404 Not found"}"#).with_exit_code(1),
+ )
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:9999"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_not_found", cmd);
+ });
+}
+
+#[rstest]
+fn test_switch_pr_gitea_tea_not_installed(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ let Some(minimal_bin) = setup_minimal_bin_without_cli(&repo) else {
+ eprintln!("Skipping test: symlinks not available on this system");
+ return;
+ };
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_cli_not_installed_env(&mut cmd, &minimal_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_tea_not_installed", cmd);
+ });
+}
+
+/// `forge.platform = "gitea"` overrides remote-URL detection. With a non-Gitea
+/// URL, the override picks the Gitea provider directly (no ambiguous fallback).
+#[rstest]
+fn test_switch_pr_gitea_forge_platform_override(#[from(repo_with_remote)] repo: TestRepo) {
+ // Non-Gitea-looking URL — without the override we'd hit the ambiguous path.
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://git.internal.example.com/owner/test-repo.git",
+ ]);
+
+ let project_config = repo.root_path().join(".config/wt.toml");
+ fs::create_dir_all(project_config.parent().unwrap()).unwrap();
+ fs::write(&project_config, "[forge]\nplatform = \"gitea\"\n").unwrap();
+
+ let tea_response = r#"{
+ "title": "Override test",
+ "user": {"login": "alice"},
+ "state": "open",
+ "draft": false,
+ "head": {
+ "label": "feature-auth",
+ "ref": "feature-auth",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "base": {
+ "label": "main",
+ "ref": "main",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "html_url": "https://git.internal.example.com/owner/test-repo/pulls/101"
+ }"#;
+
+ let mock_bin = setup_mock_tea(&repo, Some(tea_response));
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["--create", "pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_forge_platform_override", cmd);
+ });
+}
+
+/// `forge.platform = "gitlab"` with `pr:` should bail and tell the user to use
+/// `mr:` instead — the platform is incompatible with the syntax.
+#[rstest]
+fn test_switch_pr_forge_platform_gitlab_rejects_pr(#[from(repo_with_remote)] repo: TestRepo) {
+ let project_config = repo.root_path().join(".config/wt.toml");
+ fs::create_dir_all(project_config.parent().unwrap()).unwrap();
+ fs::write(&project_config, "[forge]\nplatform = \"gitlab\"\n").unwrap();
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ assert_cmd_snapshot!("switch_pr_forge_platform_gitlab", cmd);
+ });
+}
+
+/// An invalid `forge.platform` value bails with a clear error listing the
+/// accepted values, rather than silently routing somewhere via fall-through.
+#[rstest]
+fn test_switch_pr_forge_platform_invalid_bails(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://github.com/owner/test-repo.git",
+ ]);
+
+ let project_config = repo.root_path().join(".config/wt.toml");
+ fs::create_dir_all(project_config.parent().unwrap()).unwrap();
+ fs::write(&project_config, "[forge]\nplatform = \"bitbucket\"\n").unwrap();
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ assert_cmd_snapshot!("switch_pr_forge_platform_invalid_bails", cmd);
+ });
+}
+
+/// With no parseable remote URL, dispatch defaults to GitHub. Without `gh`
+/// installed the GitHub provider bails with the install hint — a single,
+/// readable error rather than a wrapped two-provider message.
+#[rstest]
+fn test_switch_pr_no_remote_defaults_to_github(repo: TestRepo) {
+ let Some(minimal_bin) = setup_minimal_bin_without_cli(&repo) else {
+ eprintln!("Skipping test: symlinks not available on this system");
+ return;
+ };
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_cli_not_installed_env(&mut cmd, &minimal_bin);
+ assert_cmd_snapshot!("switch_pr_no_remote_defaults_to_github", cmd);
+ });
+}
+
+/// Detected GitLab remote with `pr:` should bail and tell the user to use `mr:`.
+#[rstest]
+fn test_switch_pr_gitlab_remote_rejects_pr(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitlab.com/owner/test-repo.git",
+ ]);
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ assert_cmd_snapshot!("switch_pr_gitlab_remote", cmd);
+ });
+}
+
+/// Self-hosted forge whose hostname doesn't match any URL detection rule, but
+/// `tea` has a login configured for it (via `tea login add`) — dispatch
+/// inspects tea's config file and routes to Gitea.
+#[rstest]
+fn test_switch_pr_self_hosted_tea_authed_dispatches_to_gitea(
+ #[from(repo_with_remote)] repo: TestRepo,
+) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://forge.selfhosted.test/owner/test-repo.git",
+ ]);
+
+ let tea_config_dir = repo.home_path().join(".config").join("tea");
+ fs::create_dir_all(&tea_config_dir).unwrap();
+ fs::write(
+ tea_config_dir.join("config.yml"),
+ "logins:\n - name: selfhosted\n url: https://forge.selfhosted.test\n default: true\n",
+ )
+ .unwrap();
+
+ let tea_response = r#"{
+ "title": "Routed via tea config",
+ "user": {"login": "alice"},
+ "state": "open",
+ "draft": false,
+ "head": {
+ "label": "feature-auth",
+ "ref": "feature-auth",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "base": {
+ "label": "main",
+ "ref": "main",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "html_url": "https://forge.selfhosted.test/owner/test-repo/pulls/101"
+ }"#;
+ let mock_bin = setup_mock_tea(&repo, Some(tea_response));
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_self_hosted_tea_authed", cmd);
+ });
+}
+
+/// Self-hosted forge with a non-distinctive hostname (`forge.example.com`)
+/// and neither `gh` nor `tea` configured for it — dispatch defaults to
+/// GitHub. The mock `gh api` succeeds, so the PR is checked out and the
+/// user never sees a wrapped error.
+#[rstest]
+fn test_switch_pr_self_hosted_defaults_to_github(#[from(repo_with_remote)] mut repo: TestRepo) {
+ repo.add_worktree("feature-auth");
+ repo.run_git(&["push", "origin", "feature-auth"]);
+
+ let bare_url = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["config", "remote.origin.url"])
+ .run()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
+
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://forge.example.com/owner/test-repo.git",
+ ]);
+ repo.run_git(&[
+ "config",
+ &format!("url.{}.insteadOf", bare_url),
+ "https://forge.example.com/owner/test-repo.git",
+ ]);
+
+ let gh_response = r#"{
+ "title": "Self-hosted defaults to gh",
+ "user": {"login": "alice"},
+ "state": "open",
+ "draft": false,
+ "head": {
+ "ref": "feature-auth",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "base": {
+ "ref": "main",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "html_url": "https://forge.example.com/owner/test-repo/pull/101"
+ }"#;
+ let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_self_hosted_defaults_to_github", cmd);
+ });
+}
+
+/// Gitea API returns malformed JSON — covers the JSON parse error path
+/// in `gitea::fetch_pr_info`.
+#[rstest]
+fn test_switch_pr_gitea_invalid_json(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ let mock_bin = setup_mock_tea(&repo, Some("not json {"));
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_invalid_json", cmd);
+ });
+}
+
+/// Gitea API returns a 5xx-style generic error (non-404/401/403) — exercises
+/// the generic `cli_api_error` fallback in `gitea::fetch_pr_info`.
+#[rstest]
+fn test_switch_pr_gitea_server_error(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ 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)")
+ .command(
+ "api",
+ MockResponse::output(r#"{"message":"500 Internal Server Error"}"#)
+ .with_stderr("tea: server error\n")
+ .with_exit_code(1),
+ )
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_server_error", cmd);
+ });
+}
+
+/// Gitea API returns a PR with no source branch (label and ref both empty)
+/// — exercises the `extract_source_branch` failure path in `fetch_pr_info`.
+#[rstest]
+fn test_switch_pr_gitea_no_source_branch(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ let tea_response = r#"{
+ "title": "Stuck PR",
+ "user": {"login": "alice"},
+ "state": "open",
+ "draft": false,
+ "head": {
+ "label": "",
+ "ref": "",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "base": {
+ "label": "main",
+ "ref": "main",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "html_url": "https://gitea.example.com/owner/test-repo/pulls/101"
+ }"#;
+
+ let mock_bin = setup_mock_tea(&repo, Some(tea_response));
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_no_source_branch", cmd);
+ });
+}
+
+/// Gitea API returns a PR whose head repo is null (the fork has been deleted).
+/// Covers the `head_repo` `ok_or_else` path in `gitea::fetch_pr_info`.
+#[rstest]
+fn test_switch_pr_gitea_deleted_fork(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ let tea_response = r#"{
+ "title": "Deleted fork PR",
+ "user": {"login": "alice"},
+ "state": "open",
+ "draft": false,
+ "head": {
+ "label": "alice:gone",
+ "ref": "gone",
+ "repo": null
+ },
+ "base": {
+ "label": "main",
+ "ref": "main",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ },
+ "html_url": "https://gitea.example.com/owner/test-repo/pulls/101"
+ }"#;
+
+ let mock_bin = setup_mock_tea(&repo, Some(tea_response));
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_deleted_fork", cmd);
+ });
+}
+
+/// Gitea CLI returning 401/Unauthorized hits the dedicated bail message
+/// (covers the auth-error branch in `gitea::fetch_pr_info`).
+#[rstest]
+fn test_switch_pr_gitea_unauthorized(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ 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)")
+ .command(
+ "api",
+ MockResponse::output(r#"{"message":"401 Unauthorized"}"#).with_exit_code(1),
+ )
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_unauthorized", cmd);
+ });
+}
+
+/// Gitea CLI returning 403/Forbidden hits the dedicated bail message
+/// (covers the forbidden branch in `gitea::fetch_pr_info`).
+#[rstest]
+fn test_switch_pr_gitea_forbidden(#[from(repo_with_remote)] repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/owner/test-repo.git",
+ ]);
+
+ 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)")
+ .command(
+ "api",
+ MockResponse::output(r#"{"message":"403 Forbidden"}"#).with_exit_code(1),
+ )
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:101"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_forbidden", cmd);
+ });
+}
+
// ============================================================================
// MR Syntax Tests (mr:<number>) - GitLab
// ============================================================================
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
index 601d4b575..344926815 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
@@ -359,7 +359,7 @@ With --project, creates .config/wt.toml in the current repositor
  # Override platform detection for SSH aliases or self-hosted instances:
  #
  # [forge]
-  # platform = "github" # or "gitlab"
+  # platform = "github" # or "gitea" (experimental), "gitlab"
  # hostname = "github.example.com" # Example: API host (GHE / self-hosted GitLab)
  #
  # ## Copy-ignored excludes
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
index b33d54106..b38d6c1ab 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
@@ -398,7 +398,7 @@ URL column in wt list (dimmed when port not listening):
Override platform detection for SSH aliases or self-hosted instances:
  [forge]
-  platform = "github" # or "gitlab"
+  platform = "github" # or "gitea" (experimental), "gitlab"
  hostname = "github.example.com" # Example: API host (GHE / self-hosted GitLab)
Copy-ignored excludes
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
index 59aa889c8..5a0165f2f 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
@@ -21,13 +21,17 @@ info:
WORKTRUNK_APPROVALS_PATH: /nonexistent/wt/approvals.toml
WORKTRUNK_CONFIG_PATH: /nonexistent/wt/config.toml
WORKTRUNK_SYSTEM_CONFIG_PATH: /etc/xdg/worktrunk/config.toml
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
---
success: true
exit_code: 0
@@ -63,7 +67,7 @@ Usage: wt config state ci-status [OPTIONS] [COMMAND]
Caches GitHub/GitLab CI status for display in wt list.
-Requires gh (GitHub) or glab (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with forge.platform = "github" in .config/wt.toml for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set forge.hostname.
+Requires gh (GitHub) or glab (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with forge.platform = "github" (or "gitlab") in .config/wt.toml for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set forge.hostname.
Checks open PRs/MRs first, then branch pipelines for branches with upstream. Local-only branches (no remote tracking) show blank.
diff --git a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
index 4dca8ae4d..eb5c33df3 100644
--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
@@ -19,13 +19,17 @@ info:
WORKTRUNK_APPROVALS_PATH: /nonexistent/wt/approvals.toml
WORKTRUNK_CONFIG_PATH: /nonexistent/wt/config.toml
WORKTRUNK_SYSTEM_CONFIG_PATH: /etc/xdg/worktrunk/config.toml
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
---
success: true
exit_code: 0
@@ -209,6 +213,8 @@ Requires gh (GitHub) or glab (GitLab) CLI to be installed and au
Forks: The local branch uses the PR/MR's branch name directly (e.g., feature-fix), so git push works normally. If a local branch with that name already exists tracking something else, rename it first.
+Gitea (experimental): pr: is also compatible with Gitea via the tea CLI. Set [forge] platform = "gitea" in .config/wt.toml to opt in; worktrunk also auto-detects Gitea when the remote host contains gitea or when tea login add has been run for the host.
+
When wt switch fails
- Branch doesn't exist — Use --create, or check wt list --branches
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_forge_platform_gitlab.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_forge_platform_gitlab.snap
new file mode 100644
index 000000000..f515589df
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_forge_platform_gitlab.snap
@@ -0,0 +1,56 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ forge.platform is set to gitlab; use mr:<number> instead of pr:<number>
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_forge_platform_invalid_bails.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_forge_platform_invalid_bails.snap
new file mode 100644
index 000000000..2aec7e705
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_forge_platform_invalid_bails.snap
@@ -0,0 +1,56 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ Invalid forge.platform value `bitbucket` in .config/wt.toml; expected one of: github, gitea, gitlab
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_base_conflict.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_base_conflict.snap
new file mode 100644
index 000000000..8ea590bec
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_base_conflict.snap
@@ -0,0 +1,50 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--base"
+ - main
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ Cannot use --base with pr:101
+↳ PRs already have a base; remove --base
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_create_conflict.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_create_conflict.snap
new file mode 100644
index 000000000..729929605
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_create_conflict.snap
@@ -0,0 +1,52 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+  Fix authentication bug in login flow (#101)
+  by @alice · open · feature-auth · https://gitea.example.com/owner/test-repo/pulls/101
+✗ Cannot create branch for pr:101 — PR already has branch feature-auth
+↳ To switch to it: wt switch pr:101
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_deleted_fork.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_deleted_fork.snap
new file mode 100644
index 000000000..f2357079d
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_deleted_fork.snap
@@ -0,0 +1,57 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+✗ Gitea PR #101 source repository was deleted. The fork that this PR was opened from no longer exists, so the branch cannot be checked out.
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forbidden.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forbidden.snap
new file mode 100644
index 000000000..5886a7946
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forbidden.snap
@@ -0,0 +1,57 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+✗ Gitea API access forbidden for PR #101
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forge_platform_override.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forge_platform_override.snap
new file mode 100644
index 000000000..e6617bfd2
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_forge_platform_override.snap
@@ -0,0 +1,52 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+  Override test (#101)
+  by @alice · open · feature-auth · https://git.internal.example.com/owner/test-repo/pulls/101
+✗ Cannot create branch for pr:101 — PR already has branch feature-auth
+↳ To switch to it: wt switch pr:101
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_fork.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_fork.snap
new file mode 100644
index 000000000..0bb147725
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_fork.snap
@@ -0,0 +1,53 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:42"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #42...
+  Add feature fix for edge case (#42)
+  by @contributor · open · contributor:feature-fix · https://gitea.example.com/owner/test-repo/pulls/42
+○ Push configured to fork: https://gitea.example.com/contributor/test-repo.git
+✓ Created branch feature-fix (tracking PR #42) and worktree @ _REPO_.feature-fix
+▲ Cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_invalid_json.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_invalid_json.snap
new file mode 100644
index 000000000..f41a9fe22
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_invalid_json.snap
@@ -0,0 +1,58 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+✗ Failed to parse Gitea API response for PR #101. This may indicate a Gitea API change.
+  expected ident at line 1 column 2
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_no_source_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_no_source_branch.snap
new file mode 100644
index 000000000..8ef2e2be3
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_no_source_branch.snap
@@ -0,0 +1,57 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+✗ Gitea PR #101 has no usable source branch — head.label/head.ref carry placeholders, so the PR may be in an invalid state
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_not_found.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_not_found.snap
new file mode 100644
index 000000000..ac399790f
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_not_found.snap
@@ -0,0 +1,48 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:9999"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #9999...
+✗ Gitea PR #9999 not found on owner/test-repo
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_same_repo.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_same_repo.snap
new file mode 100644
index 000000000..3f709f4dc
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_same_repo.snap
@@ -0,0 +1,52 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+  Fix authentication bug in login flow (#101)
+  by @alice · open · feature-auth · https://gitea.example.com/owner/test-repo/pulls/101
+◎ Fetching feature-auth from origin...
+▲ Worktree for feature-auth @ _REPO_.feature-auth, but cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_server_error.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_server_error.snap
new file mode 100644
index 000000000..c10e4b9f8
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_server_error.snap
@@ -0,0 +1,58 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+✗ tea api failed for PR #101
+  tea: server error
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_tea_not_installed.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_tea_not_installed.snap
new file mode 100644
index 000000000..0cfb14c4d
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_tea_not_installed.snap
@@ -0,0 +1,48 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+✗ Gitea CLI (tea) not installed; install from https://gitea.com/gitea/tea
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_unauthorized.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_unauthorized.snap
new file mode 100644
index 000000000..0414711dc
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_unauthorized.snap
@@ -0,0 +1,57 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+✗ Gitea CLI not authenticated; run tea login add
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitlab_remote.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitlab_remote.snap
new file mode 100644
index 000000000..83051a501
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitlab_remote.snap
@@ -0,0 +1,56 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ Detected GitLab remote; use mr:<number> instead of pr:<number>
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_no_remote_defaults_to_github.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_no_remote_defaults_to_github.snap
new file mode 100644
index 000000000..8a27989a6
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_no_remote_defaults_to_github.snap
@@ -0,0 +1,57 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+✗ Cannot parse remote URL: ../origin.git
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_self_hosted_defaults_to_github.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_self_hosted_defaults_to_github.snap
new file mode 100644
index 000000000..fe225eef1
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_self_hosted_defaults_to_github.snap
@@ -0,0 +1,61 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+  Self-hosted defaults to gh (#101)
+  by @alice · open · feature-auth · https://forge.example.com/owner/test-repo/pull/101
+◎ Fetching feature-auth from origin...
+▲ Worktree for feature-auth @ _REPO_.feature-auth, but cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_self_hosted_tea_authed.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_self_hosted_tea_authed.snap
new file mode 100644
index 000000000..d3d99f5d1
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_self_hosted_tea_authed.snap
@@ -0,0 +1,61 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:101"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #101...
+  Routed via tea config (#101)
+  by @alice · open · feature-auth · https://forge.selfhosted.test/owner/test-repo/pulls/101
+◎ Fetching feature-auth from origin...
+✗ Failed to fetch branch feature-auth from origin
+  fatal: unable to access 'https://forge.selfhosted.test/owner/test-repo.git/': Could not resolve host: forge.selfhosted.test