Skip to content

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

fix(list): scope the Azure DevOps PR lookup to this repository (#4326)

Worktrunk Bot37b537be9e0b
diff --git a/src/commands/list/ci_status/azure.rs b/src/commands/list/ci_status/azure.rs
index d5ae49f01..62f1ddf53 100644
--- a/src/commands/list/ci_status/azure.rs
+++ b/src/commands/list/ci_status/azure.rs
@@ -12,8 +12,8 @@ use super::{
parse_json, retriable_pr_error,
};
-/// Resolve the Azure DevOps context (host, org, project, `--org` URL) for this
-/// branch's `az` invocations.
+/// Resolve the Azure DevOps context (host, org, project, repository, `--org`
+/// URL) for this branch's `az` invocations.
///
/// Walks the shared [`branch_remote_url`] chain first — so a remote-branch
/// row from `wt list --remotes --full` queries the right tenant in
@@ -30,11 +30,17 @@ fn azure_context(repo: &Repository, branch: &CiBranchName) -> Option<AzureContex
let host = parsed.host().to_string();
let organization = parsed.azure_organization()?.to_string();
let project = parsed.azure_project()?.to_string();
+ // Clone URLs percent-encode the name (`My%20Repo`), and `az` encodes
+ // `--repository` again when building the REST path.
+ let repository =
+ String::from_utf8_lossy(&urlencoding::decode_binary(parsed.repo().as_bytes()))
+ .into_owned();
let org_url = az_url::az_org_url(&host, &organization);
Some(AzureContext {
host,
organization,
project,
+ repository,
org_url,
})
};
@@ -56,12 +62,18 @@ struct AzureContext {
host: String,
organization: String,
project: String,
+ /// Repository name. `az` infers it from the git remote only when `--org`
+ /// is absent, and we always pass `--org`, so a command scoped to this
+ /// repository has to name it.
+ repository: String,
org_url: String,
}
/// Detect Azure DevOps PR CI status for a branch.
///
-/// Uses `az repos pr list` to find an open PR for the branch.
+/// Uses `az repos pr list` to find an open PR for the branch in this
+/// repository. Without `--repository` the list spans every repository in the
+/// project, so a same-named branch in a sibling repository would match.
pub(super) fn detect_azure_pr(
repo: &Repository,
branch: &CiBranchName,
@@ -83,6 +95,8 @@ pub(super) fn detect_azure_pr(
"active",
"--project",
&ctx.project,
+ "--repository",
+ &ctx.repository,
"--org",
&ctx.org_url,
"--output",
@@ -364,6 +378,28 @@ mod tests {
let ctx = azure_context(&repo, &branch).expect("scan should find the azure remote");
assert_eq!(ctx.organization, "myorg");
assert_eq!(ctx.project, "myproject");
+ assert_eq!(ctx.repository, "myrepo");
+ }
+
+ /// The repository name is decoded, since `az` percent-encodes it again.
+ #[test]
+ fn test_azure_context_decodes_repository_name() {
+ let test = TestRepo::with_initial_commit();
+ test.run_git(&[
+ "remote",
+ "add",
+ "origin",
+ "https://dev.azure.com/myorg/myproject/_git/My%20Repo",
+ ]);
+ let repo = Repository::at(test.root_path()).unwrap();
+ let branch = CiBranchName {
+ full_name: "feature".to_string(),
+ remote: None,
+ name: "feature".to_string(),
+ };
+
+ let ctx = azure_context(&repo, &branch).expect("origin is an azure remote");
+ assert_eq!(ctx.repository, "My Repo");
}
/// No Azure remote anywhere → `None`.
diff --git a/tests/integration_tests/ci_status.rs b/tests/integration_tests/ci_status.rs
index da97bfb69..70caa295d 100644
--- a/tests/integration_tests/ci_status.rs
+++ b/tests/integration_tests/ci_status.rs
@@ -1203,6 +1203,47 @@ fn test_list_full_with_azure_stale_pipeline(mut repo: TestRepo) {
run_azure_ci_status_test(&mut repo, "azure_stale_pipeline", "[]", runs_json);
}
+/// `az repos pr list` searches every repository in the project unless it is
+/// told which one, and `az` infers the repository from the git remote only when
+/// `--org` is absent. Since the lookup passes `--org`, it must pass
+/// `--repository` too, or a same-named branch's PR in a sibling repository
+/// shows up on this repository's row.
+#[rstest]
+fn test_list_full_azure_pr_lookup_names_the_repository(mut repo: TestRepo) {
+ setup_azure_repo_with_feature(&mut repo);
+ repo.setup_mock_az_with_ci_data("[]", "[]");
+
+ // Outside the repo under test, so the log can't dirty the working tree the
+ // command is inspecting.
+ let call_log = tempfile::tempdir().unwrap();
+ let mut cmd = repo.wt_command();
+ cmd.args(["list", "--full"]);
+ repo.configure_mock_commands(&mut cmd);
+ cmd.env("WORKTRUNK_TEST_MOCK_CALL_LOG_DIR", call_log.path());
+ let output = cmd.output().unwrap();
+ assert!(
+ output.status.success(),
+ "wt list --full should succeed: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+
+ let calls = mock_calls(call_log.path(), "az");
+ let pr_lists: Vec<_> = calls
+ .iter()
+ .filter(|call| call.starts_with("repos pr list"))
+ .collect();
+ assert!(
+ !pr_lists.is_empty(),
+ "the fixture must reach PR detection. calls: {calls:#?}"
+ );
+ for call in pr_lists {
+ assert!(
+ call.contains("--repository test-repo"),
+ "PR lookup must be scoped to this repository: {call}"
+ );
+ }
+}
+
/// No PR and no pipeline runs → no CI indicator.
#[rstest]
fn test_list_full_with_azure_no_ci(mut repo: TestRepo) {