Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(forge): classify a forge by the brand in the hostname, not by DNS label (#3673)
Maximilian Roos0f2d562541cb
diff --git a/dev/wt.example.toml b/dev/wt.example.tomlindex af1e8541b..246f82db0 100644--- a/dev/wt.example.toml+++ b/dev/wt.example.toml@@ -21,7 +21,7 @@## ## Forge platform#-# Name the forge explicitly for SSH aliases or self-hosted instances, where it can't be detected from the remote URL:+# The forge is read from the remote's hostname: any host carrying `github`, `gitlab`, or `gitea` anywhere in it, plus the Azure DevOps service domains. Name the forge explicitly for a host carrying none of those, such as a Forgejo instance at `forge.example.com`:## [forge]# platform = "github" # or "gitlab", "gitea" (experimental), "azure-devops" (experimental)diff --git a/docs/content/config.md b/docs/content/config.mdindex 3184b2175..db71335d3 100644--- a/docs/content/config.md+++ b/docs/content/config.md@@ -536,7 +536,7 @@ url = "http://localhost:{{ branch | hash_port }}"## Forge platform-Name the forge explicitly for SSH aliases or self-hosted instances, where it can't be detected from the remote URL:+The forge is read from the remote's hostname: any host carrying `github`, `gitlab`, or `gitea` anywhere in it, plus the Azure DevOps service domains. Name the forge explicitly for a host carrying none of those, such as a Forgejo instance at `forge.example.com`:```toml[forge]diff --git a/plugins/worktrunk/skills/worktrunk/reference/config.md b/plugins/worktrunk/skills/worktrunk/reference/config.mdindex aa83b13a8..273b87172 100644--- a/plugins/worktrunk/skills/worktrunk/reference/config.md+++ b/plugins/worktrunk/skills/worktrunk/reference/config.md@@ -531,7 +531,7 @@ url = "http://localhost:{{ branch | hash_port }}"## Forge platform-Name the forge explicitly for SSH aliases or self-hosted instances, where it can't be detected from the remote URL:+The forge is read from the remote's hostname: any host carrying `github`, `gitlab`, or `gitea` anywhere in it, plus the Azure DevOps service domains. Name the forge explicitly for a host carrying none of those, such as a Forgejo instance at `forge.example.com`:```toml[forge]diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.mdindex aa83b13a8..273b87172 100644--- a/skills/worktrunk/reference/config.md+++ b/skills/worktrunk/reference/config.md@@ -531,7 +531,7 @@ url = "http://localhost:{{ branch | hash_port }}"## Forge platform-Name the forge explicitly for SSH aliases or self-hosted instances, where it can't be detected from the remote URL:+The forge is read from the remote's hostname: any host carrying `github`, `gitlab`, or `gitea` anywhere in it, plus the Azure DevOps service domains. Name the forge explicitly for a host carrying none of those, such as a Forgejo instance at `forge.example.com`:```toml[forge]diff --git a/src/cli/mod.rs b/src/cli/mod.rsindex 4721d6f0f..d6b3ee491 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -2401,7 +2401,7 @@ url = "http://localhost:{{ branch | hash_port }}"## Forge platform-Name the forge explicitly for SSH aliases or self-hosted instances, where it can't be detected from the remote URL:+The forge is read from the remote's hostname: any host carrying `github`, `gitlab`, or `gitea` anywhere in it, plus the Azure DevOps service domains. Name the forge explicitly for a host carrying none of those, such as a Forgejo instance at `forge.example.com`:```toml[forge]diff --git a/src/commands/config/show.rs b/src/commands/config/show.rsindex a35f7911e..c0110741d 100644--- a/src/commands/config/show.rs+++ b/src/commands/config/show.rs@@ -26,7 +26,6 @@ use worktrunk::styling::{use crate::cli::{SwitchFormat, version_str};use crate::commands::configure_shell::{ConfigAction, ConfigureResult, scan_shell_configs};-use crate::commands::legacy_forge_alias_diagnostic;use crate::commands::list::ci_status::CiToolsStatus;use crate::help_pager::show_help_in_pager;use crate::llm::test_commit_generation;@@ -506,21 +505,11 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {}}None => {- if let Some(alias) = repo.legacy_forge_alias() {- writeln!(- out,- "{}",- warning_message(legacy_forge_alias_diagnostic(&alias))- )?;- } else {- writeln!(- out,- "{}",- hint_message(- "CI status requires GitHub, GitLab, Gitea, or Azure DevOps remote"- )- )?;- }+ writeln!(+ out,+ "{}",+ hint_message("CI status requires GitHub, GitLab, Gitea, or Azure DevOps remote")+ )?;}}diff --git a/src/commands/list/collect/mod.rs b/src/commands/list/collect/mod.rsindex 0a3b0bc22..d99d73630 100644--- a/src/commands/list/collect/mod.rs+++ b/src/commands/list/collect/mod.rs@@ -2017,21 +2017,6 @@ pub fn collect(return Ok(None);}- // The old substring classifier treated branded SSH aliases such as- // `github-personal` as forges. Keep provider dispatch on the safer exact- // boundary, but explain the migration once when this collection actually- // requested CI. Do this after final table rendering so resolving the- // effective URL cannot add a git subprocess to the skeleton's critical- // path. Picker collections route through the warning stash; the statusline- // uses `populate_item`, not this path, and remains silent.- if collected.ci- && let Some(alias) = repo.legacy_forge_alias()- {- emit_warning(- warning_message(crate::commands::legacy_forge_alias_diagnostic(&alias)).to_string(),- );- }-// Status symbols are now computed during data collection (both modes), no fallback needed// Display collection errors/warnings (after table rendering)diff --git a/src/commands/mod.rs b/src/commands/mod.rsindex 4d065b280..e369e55e3 100644--- a/src/commands/mod.rs+++ b/src/commands/mod.rs@@ -71,7 +71,6 @@ pub(crate) use worktree::{pub(crate) use worktrunk::shell::Shell;use color_print::cformat;-use worktrunk::git::LegacyForgeAlias;use worktrunk::styling::{eprintln, format_with_gutter};pub(crate) fn flag_pair(positive: bool, negative: bool) -> Option<bool> {@@ -82,16 +81,6 @@ pub(crate) fn flag_pair(positive: bool, negative: bool) -> Option<bool> {}}-/// Actionable compatibility diagnostic for branded SSH aliases that no longer-/// cross the exact-label forge-classification boundary.-pub(crate) fn legacy_forge_alias_diagnostic(alias: &LegacyForgeAlias) -> String {- let platform = alias.platform().to_string();- let host = alias.host();- cformat!(- "SSH host alias <bold>{host}</> is not auto-detected as a forge; enable CI status and <bold>wt switch --prs</> with <bold>forge.platform = \"{platform}\"</> @ <bold>.config/wt.toml</>"- )-}-/// Format command execution label with optional command name.////// Examples:diff --git a/src/commands/picker/prs.rs b/src/commands/picker/prs.rsindex b0ed48aea..4f48fa862 100644--- a/src/commands/picker/prs.rs+++ b/src/commands/picker/prs.rs@@ -50,7 +50,6 @@ use unicode_width::UnicodeWidthStr;use worktrunk::git::{ForgeKind, RefType, Repository};use worktrunk::styling::{HINT_SYMBOL, INFO_SYMBOL, StyledLine, WARNING_SYMBOL, warning_message};-use super::super::legacy_forge_alias_diagnostic;use super::super::list::ci_status::{CiSource, CiStatus, GitHubComment, GitHubPrInfo, PrRef, PrStatus, ReviewState,non_interactive_cmd, tool_available,@@ -641,9 +640,6 @@ fn fetch_open_prs(repo: &Repository) -> anyhow::Result<Vec<PrEntry>> {anyhow::bail!("--prs supports GitHub and GitLab; this repository's forge is {other}")}None => {- if let Some(alias) = repo.legacy_forge_alias() {- anyhow::bail!("{}", legacy_forge_alias_diagnostic(&alias));- }anyhow::bail!("--prs could not determine the forge from the remote URL")}}@@ -1841,24 +1837,6 @@ mod tests {);}- #[test]- fn fetch_open_prs_explains_legacy_forge_alias_configuration() {- let test = worktrunk::testing::TestRepo::with_initial_commit();- test.run_git(&[- "remote",- "add",- "origin",- "git@github-personal:owner/repo.git",- ]);- let err = fetch_open_prs(&test.repo)- .expect_err("expected --prs to require explicit forge config");- let message = err.to_string();- assert!(- message.contains("github-personal") && message.contains("forge.platform = \"github\""),- "unexpected error: {err:#}"- );- }-#[test]fn fetch_open_prs_bails_on_an_unsupported_forge() {// A recognized-but-unsupported forge (here Gitea, by its host) reportsdiff --git a/src/config/project.rs b/src/config/project.rsindex be3f11c41..4c4f9209a 100644--- a/src/config/project.rs+++ b/src/config/project.rs@@ -94,9 +94,9 @@ pub struct ProjectCommitGenerationConfig {/// Project-level forge configuration.///-/// Names the forge explicitly, for repos where URL-based detection can't-/// determine it (e.g., SSH host aliases, GitHub Enterprise, or self-hosted-/// GitLab with custom domains).+/// Names the forge explicitly, for a remote whose hostname carries no forge+/// name for [`ForgeKind::from_host`](crate::git::ForgeKind::from_host) to read+/// (a Forgejo instance at `forge.example.com`, a company git server).////// # Example///diff --git a/src/git/ci_platform.rs b/src/git/ci_platform.rsindex 28c444510..23363fcdf 100644--- a/src/git/ci_platform.rs+++ b/src/git/ci_platform.rs@@ -24,83 +24,38 @@ pub enum ForgeKind {AzureDevOps,}-/// A branded SSH host alias that the former substring classifier recognized.-///-/// This is diagnostic-only: callers can explain the compatibility change and-/// suggest `forge.platform`, but must not use it to select a forge provider.-/// Dispatch remains on [`ForgeKind::from_host`]'s exact-label boundary.-#[derive(Debug, Clone, PartialEq, Eq)]-pub struct LegacyForgeAlias {- host: String,- platform: ForgeKind,-}--impl LegacyForgeAlias {- pub fn host(&self) -> &str {- &self.host- }-- pub fn platform(&self) -> ForgeKind {- self.platform- }-- /// Recognize the common multi-account SSH alias form (`github-personal`).- ///- /// Only SSH URLs with a single-label, forge-prefixed host qualify. Dotted- /// hosts stay out even when they contain a forge name: those are exactly- /// the security-sensitive lookalikes the exact-label classifier rejects.- fn from_url(url: &str) -> Option<Self> {- let url = url.trim();- let is_ssh = url.starts_with("ssh://")- || url- .split_once(':')- .is_some_and(|(authority, _)| !authority.contains('/') && authority.contains('@'));- if !is_ssh {- return None;- }-- let parsed = GitRemoteUrl::parse(url)?;- let host = normalized_hostname(parsed.host());- if host.contains('.') || ForgeKind::from_host(&host).is_some() {- return None;- }-- let platform = [- ("github-", ForgeKind::GitHub),- ("gitlab-", ForgeKind::GitLab),- ("gitea-", ForgeKind::Gitea),- ]- .into_iter()- .find_map(|(prefix, platform)| {- host.strip_prefix(prefix)- .filter(|suffix| !suffix.is_empty())- .map(|_| platform)- })?;-- Some(Self { host, platform })- }-}-impl ForgeKind {/// Classify a forge from a remote hostname.///- /// GitHub, GitLab, and Gitea self-hosted instances commonly put the forge- /// name in its own DNS label. Azure DevOps has fixed service domains, so it- /// uses domain-suffix matching and takes precedence over branded labels- /// inside those domains. Both rules respect label boundaries:- /// `github-mirror.example` and `dev.azure.com.attacker.example` are not- /// recognized. A branded hostname can opt in through `[forge].platform`.+ /// GitHub, GitLab, and Gitea are brand names, and a self-hosted instance+ /// puts its brand in the hostname however it likes: `github.mycompany.com`,+ /// `github-enterprise.acme.com`, `mygithub.com`, the `github-personal` SSH+ /// alias. So any host carrying the name matches, first match winning. Azure+ /// DevOps is not a brand in the hostname but two fixed service domains, so+ /// it matches by domain suffix and takes precedence inside those domains —+ /// `evil-visualstudio.com` and `dev.azure.com.attacker.example` are outside+ /// them and do not match.+ ///+ /// Recall is what this optimizes, not resistance to a lookalike name. The+ /// hostname comes out of the user's own `.git/config`, and whoever can put+ /// a host there can put code there too, so the trust decision was made at+ /// clone time; all this picks is which forge CLI runs against a remote the+ /// user already builds from. A stricter name test would not hold anyway —+ /// an attacker controls their own DNS, so `github.attacker.example`+ /// satisfies one — while it does shut out the self-hoster who named a box+ /// `github-enterprise.acme.com` years ago. `[forge].platform` overrides the+ /// guess, and names the forge for a host that carries no brand at all.pub fn from_host(host: &str) -> Option<Self> {let host = normalized_hostname(host);if normalized_host_is_within(&host, "dev.azure.com")|| normalized_host_is_within(&host, "visualstudio.com"){Some(Self::AzureDevOps)- } else if host_has_label(&host, "github") {+ } else if host.contains("github") {Some(Self::GitHub)- } else if host_has_label(&host, "gitlab") {+ } else if host.contains("gitlab") {Some(Self::GitLab)- } else if host_has_label(&host, "gitea") {+ } else if host.contains("gitea") {Some(Self::Gitea)} else {None@@ -130,10 +85,6 @@ pub(super) fn normalized_hostname(host: &str) -> String {host.trim_end_matches('.').to_ascii_lowercase()}-fn host_has_label(host: &str, label: &str) -> bool {- host.split('.').any(|candidate| candidate == label)-}-fn normalized_host_is_within(host: &str, domain: &str) -> bool {host == domain || host.strip_suffix(domain).is_some_and(|p| p.ends_with('.'))}@@ -183,20 +134,6 @@ impl Repository {None}- /// Return a diagnostic for a legacy branded SSH alias on the primary remote.- ///- /// A configured platform resolves the ambiguity and suppresses the- /// diagnostic. The returned value never participates in provider dispatch.- pub fn legacy_forge_alias(&self) -> Option<LegacyForgeAlias> {- if self.configured_ci_platform().is_some() {- return None;- }-- let remote = self.primary_remote().ok()?;- let url = self.effective_remote_url(&remote)?;- LegacyForgeAlias::from_url(&url)- }-/// The CI platform set in project config (`forge.platform` / `ci.platform`).////// `None` when unset or unrecognized. Resolved once per repository handle,@@ -326,7 +263,7 @@ mod tests {}#[test]- fn test_fixed_azure_domains_take_precedence_over_forge_labels() {+ fn test_fixed_azure_domains_take_precedence_over_brand_names() {for host in ["github.dev.azure.com","gitlab.visualstudio.com",@@ -342,42 +279,59 @@ mod tests {}#[test]- fn test_legacy_forge_alias_is_diagnostic_only_for_branded_ssh_aliases() {+ fn test_branded_hosts_classify_however_the_instance_is_named() {+ // A self-hosted instance carries its brand wherever it likes: its own+ // label, a hyphenated label, inside a word, or a single-label SSH+ // alias. All of them resolve without config.for (url, platform) in [+ (+ "https://github-enterprise.acme.com/owner/repo.git",+ ForgeKind::GitHub,+ ),+ ("https://mygithub.com/owner/repo.git", ForgeKind::GitHub),("git@github-personal:owner/repo.git", ForgeKind::GitHub),+ (+ "https://gitlab-internal.company.com/owner/repo.git",+ ForgeKind::GitLab,+ ),("ssh://git@gitlab-work/owner/repo.git", ForgeKind::GitLab),- ("git@gitea-local:owner/repo.git", ForgeKind::Gitea),+ (+ "[email protected]:owner/repo.git",+ ForgeKind::Gitea,+ ),+ // Case and port are normalized away before the name is read.+ (+ "https://GitHub-Enterprise.ACME.com:8443/owner/repo.git",+ ForgeKind::GitHub,+ ),] {- let alias = LegacyForgeAlias::from_url(url).expect(url);- assert_eq!(alias.platform(), platform, "{url}");- assert_eq!(ForgeKind::from_host(alias.host()), None, "{url}");+ assert_eq!(platform_from_url(url), Some(platform), "{url}");}+ // A host carrying no brand still needs `forge.platform`.for url in [- "[email protected]:owner/repo.git",+ "https://bitbucket.org/owner/repo.git",+ "https://codeberg.org/owner/repo.git",+ "https://git.example.com/owner/repo.git","git@work:owner/repo.git",- "git@notgithub-personal:owner/repo.git",- "[email protected]:owner/repo.git",- "[email protected]:owner/repo.git",- "https://github-personal/owner/repo.git",] {- assert_eq!(LegacyForgeAlias::from_url(url), None, "{url}");+ assert_eq!(platform_from_url(url), None, "{url}");}}#[test]- fn test_configured_platform_suppresses_legacy_alias_diagnostic() {+ fn test_configured_platform_overrides_host_inference() {+ // The remote's own name says GitLab; config says GitHub and wins.let test = crate::testing::TestRepo::new();test.run_git(&["remote","add","origin",- "git@github-personal:owner/repo.git",+ "https://gitlab-internal.company.com/owner/repo.git",]);test.write_project_config("[forge]\nplatform = \"github\"\n");let repo = Repository::at(test.root_path().to_path_buf()).unwrap();assert_eq!(repo.ci_platform(None), Some(ForgeKind::GitHub));- assert_eq!(repo.legacy_forge_alias(), None);}}diff --git a/src/git/mod.rs b/src/git/mod.rsindex d57d59b48..fed17e2ec 100644--- a/src/git/mod.rs+++ b/src/git/mod.rs@@ -39,7 +39,7 @@ static HEAVY_OPS_SEMAPHORE: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::nepub const NULL_OID: &str = "0000000000000000000000000000000000000000";// Re-exports from submodules-pub use ci_platform::{ForgeKind, LegacyForgeAlias};+pub use ci_platform::ForgeKind;pub(crate) use diff::DiffStats;pub use diff::{LineDiff, parse_numstat_line};pub use error::{diff --git a/src/git/remote_ref/mod.rs b/src/git/remote_ref/mod.rsindex c307b5b76..3a565c7fa 100644--- a/src/git/remote_ref/mod.rs+++ b/src/git/remote_ref/mod.rs@@ -867,8 +867,14 @@ mod tests {assert_eq!(hostile_userinfo.host, "attacker.example");assert_eq!(hostile_userinfo.url, "https://attacker.example/owner/repo");+ // A brand anywhere in the host classifies here too.+ let branded = repo_info_from_ref_url("https://github-mirror.example/owner/repo/pull/1")+ .expect("ref URL is structurally valid");+ assert_eq!(branded.provider, GitRepoProvider::GitHub);++ // The Azure service domains stay bounded by suffix, and a host outside+ // them carries no brand to fall back on.for input in [- "https://github-mirror.example/owner/repo/pull/1","https://dev.azure.com.attacker.example/org/project/_git/repo/pullrequest/9","https://evil-visualstudio.com/org/project/_git/repo/pullrequest/9",] {diff --git a/src/git/url.rs b/src/git/url.rsindex e6b5746f4..009d3fa2a 100644--- a/src/git/url.rs+++ b/src/git/url.rs@@ -805,7 +805,8 @@ mod tests {}#[test]- fn forge_detection_respects_host_boundaries_and_ports() {+ fn forge_detection_reads_the_brand_and_bounds_the_azure_domains() {+ // A brand anywhere in the host classifies, ports included.let supported = [("https://github.com:8443/owner/repo.git", ForgeKind::GitHub),(@@ -816,6 +817,18 @@ mod tests {"https://gitea.example.com:8443/owner/repo.git",ForgeKind::Gitea,),+ (+ "https://github-mirror.example/owner/repo.git",+ ForgeKind::GitHub,+ ),+ (+ "https://notgitlab.example/owner/repo.git",+ ForgeKind::GitLab,+ ),+ (+ "https://gitea-mirror.example/owner/repo.git",+ ForgeKind::Gitea,+ ),("https://dev.azure.com:8443/org/project/_git/repo",ForgeKind::AzureDevOps,@@ -826,15 +839,14 @@ mod tests {assert_eq!(parsed.forge_kind(), Some(expected), "{input}");}- let lookalikes = [- "https://github-mirror.example/owner/repo.git",- "https://notgitlab.example/owner/repo.git",- "https://gitea-mirror.example/owner/repo.git",+ // The Azure service domains are matched by suffix, so a host merely+ // containing one is outside them and carries no brand to fall back on.+ let outside_the_azure_domains = ["https://dev.azure.com.attacker.example/org/project/_git/repo","https://evil-visualstudio.com/org/project/_git/repo",];- for input in lookalikes {- let parsed = GitRemoteUrl::parse(input).expect("lookalike URL is structurally valid");+ for input in outside_the_azure_domains {+ let parsed = GitRemoteUrl::parse(input).expect("URL is structurally valid");assert_eq!(parsed.forge_kind(), None, "{input}");assert_eq!(parseddiff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rsindex 9de60b266..c4a748ed3 100644--- a/tests/integration_tests/config_show.rs+++ b/tests/integration_tests/config_show.rs@@ -3,7 +3,6 @@ use crate::common::{setup_home_snapshot_settings, setup_snapshot_settings, setup_snapshot_settings_with_home,temp_home, wt_command,};-use insta::assert_snapshot;use insta_cmd::assert_cmd_snapshot;use rstest::rstest;use std::fs;@@ -1343,48 +1342,6 @@ fn test_config_show_full_not_configured(mut repo: TestRepo, temp_home: TempDir)});}-#[rstest]-fn test_config_show_full_legacy_forge_alias(mut repo: TestRepo, temp_home: TempDir) {- repo.setup_mock_ci_tools_unauthenticated();- repo.run_git(&[- "remote",- "set-url",- "origin",- "git@github-personal:owner/repo.git",- ]);-- let global_config_dir = temp_home.path().join(".config").join("worktrunk");- fs::create_dir_all(&global_config_dir).unwrap();- fs::write(- global_config_dir.join("config.toml"),- "worktree-path = \"../{{ repo }}.{{ branch }}\"",- )- .unwrap();-- let mut cmd = repo.wt_command();- cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"));- cmd.arg("config")- .arg("show")- .arg("--full")- .current_dir(repo.root_path());- set_temp_home_env(&mut cmd, temp_home.path());- set_xdg_config_path(&mut cmd, temp_home.path());-- let output = cmd.output().unwrap();- assert!(- output.status.success(),- "config show should succeed:\n{}",- String::from_utf8_lossy(&output.stderr)- );- let stdout = String::from_utf8_lossy(&output.stdout);- let alias_lines = stdout- .lines()- .filter(|line| line.contains("SSH host alias"))- .collect::<Vec<_>>()- .join("\n");- assert_snapshot!(alias_lines, @r#"[33m▲[39m [33mSSH host alias [1mgithub-personal[22m is not auto-detected as a forge; enable CI status and [1mwt switch --prs[22m with [1mforge.platform = "github"[22m @ [1m.config/wt.toml[22m[39m"#);-}-#[rstest]fn test_config_show_full_command_not_found(mut repo: TestRepo, temp_home: TempDir) {// Setup mock gh/glab for deterministic BINARIES outputdiff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rsindex 7c53897f8..ecaf3416c 100644--- a/tests/integration_tests/list.rs+++ b/tests/integration_tests/list.rs@@ -2,7 +2,6 @@ use crate::common::{DAY, HOUR, MINUTE, TestRepo, list_snapshots, make_snapshot_cmd, repo, repo_with_remote,setup_snapshot_settings_for_paths, wt_command,};-use insta::assert_snapshot;use insta_cmd::assert_cmd_snapshot;use rstest::rstest;@@ -443,49 +442,49 @@ fn test_list_json_repo_url_from_ssh_remote(repo: TestRepo) {);}-/// CI collection reports the intentional exact-label compatibility break once,-/// while an explicit forge platform resolves and suppresses the diagnostic.-/// The statusline takes its separate silent collection path.-#[rstest]-fn test_list_ci_legacy_forge_alias_diagnostic(mut repo: TestRepo) {- repo.setup_mock_gh();- repo.run_git(&[- "remote",- "set-url",- "origin",- "git@github-personal:owner/repo.git",- ]);-- let output = repo.wt_command().args(["list", "--full"]).output().unwrap();- assert!(output.status.success());- let stderr = String::from_utf8_lossy(&output.stderr);- let alias_lines = stderr- .lines()- .filter(|line| line.contains("SSH host alias"))- .collect::<Vec<_>>()- .join("\n");- assert_snapshot!(alias_lines, @r#"[33m▲[39m [33mSSH host alias [1mgithub-personal[22m is not auto-detected as a forge; enable CI status and [1mwt switch --prs[22m with [1mforge.platform = "github"[22m @ [1m.config/wt.toml[22m[39m"#);-- let statusline = repo- .wt_command()- .args(["list", "statusline", "--format=json"])- .output()- .unwrap();- assert!(statusline.status.success());- let statusline_stderr = String::from_utf8_lossy(&statusline.stderr);- assert!(- statusline_stderr.is_empty(),- "statusline must remain silent:\n{statusline_stderr}"- );+/// A self-hosted instance names its forge however it likes — its own label, a+/// hyphenated one, inside a word, or a single-label SSH alias — and the+/// provider follows the name with no config. The statusline stays silent.+#[rstest]+fn test_list_json_provider_reads_branded_self_hosted_hosts(repo: TestRepo) {+ for (remote, host, provider) in [+ (+ "https://github-enterprise.acme.com/owner/repo.git",+ "github-enterprise.acme.com",+ "github",+ ),+ (+ "https://gitlab-internal.company.com/owner/repo.git",+ "gitlab-internal.company.com",+ "gitlab",+ ),+ (+ "https://mygithub.com/owner/repo.git",+ "mygithub.com",+ "github",+ ),+ (+ "git@github-personal:owner/repo.git",+ "github-personal",+ "github",+ ),+ ] {+ repo.run_git(&["remote", "set-url", "origin", remote]);+ let output = repo+ .wt_command()+ .args(["list", "--format=json"])+ .output()+ .unwrap();+ assert!(+ output.status.success(),+ "wt list should succeed for {remote}"+ );- repo.write_project_config("[forge]\nplatform = \"github\"\n");- let configured = repo.wt_command().args(["list", "--full"]).output().unwrap();- assert!(configured.status.success());- let configured_stderr = String::from_utf8_lossy(&configured.stderr);- assert!(- !configured_stderr.contains("SSH host alias"),- "explicit forge config should suppress the diagnostic:\n{configured_stderr}"- );+ let json: Vec<serde_json::Value> = serde_json::from_slice(&output.stdout).unwrap();+ let row = json.first().expect("at least one row");+ assert_eq!(row["repo"]["provider"].as_str(), Some(provider), "{remote}");+ assert_eq!(row["repo"]["host"].as_str(), Some(host), "{remote}");+ }}#[rstest]diff --git a/tests/integration_tests/switch_picker_dry_run.rs b/tests/integration_tests/switch_picker_dry_run.rsindex 9bd8a3ac9..eff6e1803 100644--- a/tests/integration_tests/switch_picker_dry_run.rs+++ b/tests/integration_tests/switch_picker_dry_run.rs@@ -11,7 +11,6 @@use crate::common::mock_commands::{MockConfig, MockResponse, mock_calls};use crate::common::{TEST_EPOCH, TestRepo, repo};-use insta::assert_snapshot;use rstest::rstest;#[rstest::fixture]@@ -337,34 +336,6 @@ fn test_picker_dry_run_drains_stashed_warnings(mut repo: TestRepo) {);}-/// The collect and `--prs` threads discover the same legacy alias-/// independently. Their shared stash emits the actionable migration warning-/// once after the picker releases the terminal.-#[rstest]-fn test_picker_dry_run_deduplicates_legacy_forge_alias_warning(repo: TestRepo) {- repo.run_git(&[- "remote",- "set-url",- "origin",- "git@github-personal:owner/repo.git",- ]);-- let output = repo- .wt_command()- .args(["switch", "--prs"])- .env("WORKTRUNK_PICKER_DRY_RUN", "1")- .output()- .unwrap();- assert!(- output.status.success(),- "dry-run should exit 0; stderr:\n{}",- String::from_utf8_lossy(&output.stderr)- );-- let stderr = String::from_utf8_lossy(&output.stderr);- assert_snapshot!(stderr.as_ref(), @r#"[33m▲[39m [33mSSH host alias [1mgithub-personal[22m is not auto-detected as a forge; enable CI status and [1mwt switch --prs[22m with [1mforge.platform = "github"[22m @ [1m.config/wt.toml[22m[39m"#);-}-/// Same as above but with `list.summary=true` and a strict fake LLM command,/// proving the configured generator runs before its result reaches mode 5.#[rstest]diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snapindex f2d749fb9..81cc452bd 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap@@ -10,6 +10,13 @@ info:CLICOLOR_FORCE: "1"COLUMNS: "500"GIT_ALLOW_PROTOCOL: file+ GIT_CONFIG_COUNT: "2"+ GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig+ GIT_CONFIG_KEY_0: user.useConfigOnly+ GIT_CONFIG_KEY_1: rerere.enabled+ GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig+ GIT_CONFIG_VALUE_0: "true"+ GIT_CONFIG_VALUE_1: "false"LANG: CLC_ALL: CLLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"@@ -485,7 +492,7 @@ With [2m--project[0m, creates [2m.config/wt.toml[0m in the current repositor[107m [0m [2m#[0m[107m [0m [2m# ## Forge platform[0m[107m [0m [2m#[0m-[107m [0m [2m# Name the forge explicitly for SSH aliases or self-hosted instances, where it can't be detected from the remote URL:[0m+[107m [0m [2m# The forge is read from the remote's hostname: any host carrying `github`, `gitlab`, or `gitea` anywhere in it, plus the Azure DevOps service domains. Name the forge explicitly for a host carrying none of those, such as a Forgejo instance at `forge.example.com`:[0m[107m [0m [2m#[0m[107m [0m [2m# [forge][0m[107m [0m [2m# platform = "github" # or "gitlab", "gitea" (experimental), "azure-devops" (experimental)[0mdiff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snapindex 6ac5b87ee..c0253b9b4 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap@@ -9,6 +9,13 @@ info:CLICOLOR_FORCE: "1"COLUMNS: "500"GIT_ALLOW_PROTOCOL: file+ GIT_CONFIG_COUNT: "2"+ GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig+ GIT_CONFIG_KEY_0: user.useConfigOnly+ GIT_CONFIG_KEY_1: rerere.enabled+ GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig+ GIT_CONFIG_VALUE_0: "true"+ GIT_CONFIG_VALUE_1: "false"LANG: CLC_ALL: CLLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"@@ -524,7 +531,7 @@ URL column in [2mwt list[0m (dimmed when port not listening):[1m[32mForge platform[0m-Name the forge explicitly for SSH aliases or self-hosted instances, where it can't be detected from the remote URL:+The forge is read from the remote's hostname: any host carrying [2mgithub[0m, [2mgitlab[0m, or [2mgitea[0m anywhere in it, plus the Azure DevOps service domains. Name the forge explicitly for a host carrying none of those, such as a Forgejo instance at [2mforge.example.com[0m:[107m [0m [2m[36m[forge][0m[107m [0m [2mplatform = [0m[2m[32m"github"[0m[2m [0m[2m# or "gitlab", "gitea" (experimental), "azure-devops" (experimental)[0m