Skip to content

Commit 44170a7

Browse files
jawwad-aliclaude
andcommitted
test(auth): build the mocked az path with the host's path rules
Fixes the macOS CI failure. The test hardcoded a Windows absolute path, but the production code calls os.path.isabs() -- on POSIX runners "C:\Program Files\..." reads as RELATIVE, so the fallback branch ran and argv[0] was "az" instead of the resolved path. Construct the path with os.path.join(os.path.abspath(os.sep), ...) so it is absolute under the host's rules, and assert against that value. The fallback test's inputs (".\az.CMD", "az.cmd", "./az") are relative under both ntpath and posixpath, so they were already portable. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 6621b18 commit 44170a7

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎tests/test_authentication.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,19 +542,25 @@ def test_resolve_token_azure_cli_resolves_executable(self):
542542
entry = AuthConfigEntry(
543543
hosts=("dev.azure.com",), provider="azure-devops", auth="azure-cli",
544544
)
545+
# Build the absolute path with the HOST's rules: the production code
546+
# calls os.path.isabs(), so a hardcoded Windows path would read as
547+
# RELATIVE on POSIX runners and silently exercise the fallback branch
548+
# instead of the one under test.
549+
resolved_path = os.path.join(os.path.abspath(os.sep), "opt", "az", "az.CMD")
550+
assert os.path.isabs(resolved_path)
545551
result = MagicMock()
546552
result.returncode = 0
547553
result.stdout = '{"accessToken": "tok"}'
548554
with patch(
549555
"specify_cli.authentication.azure_devops.shutil.which",
550-
return_value=r"C:\Program Files\az\wbin\az.CMD",
556+
return_value=resolved_path,
551557
), patch(
552558
"specify_cli.authentication.azure_devops.subprocess.run",
553559
return_value=result,
554560
) as run:
555561
assert AzureDevOpsAuth().resolve_token(entry) == "tok"
556562
argv = run.call_args.args[0]
557-
assert argv[0] == r"C:\Program Files\az\wbin\az.CMD"
563+
assert argv[0] == resolved_path
558564
assert argv[1:4] == ["account", "get-access-token", "--resource"]
559565

560566
@pytest.mark.parametrize("which_result", [None, r".\az.CMD", "az.cmd", "./az"])

0 commit comments

Comments
 (0)