The OS lanes are marker-driven: list_os_marked_tests.py picks the files
a lane imports from their platforms() specs and the lane selects with
-m platforms. A test gated with skipif(sys.platform != "win32") is
therefore never imported on the Windows lane and skipped everywhere else
— it runs on no host. skipif(sys.platform == "win32") tests were merely
invisible to the lane bookkeeping, but the rule the tree now follows is
one host marker, never a bare skipif.
Mechanical mapping, semantics preserved: skip-on-Windows → "posix",
skip-off-Windows → "windows", skip-off-Linux → "linux", skip-on-macOS →
"not macos". The former skip reasons stay as trailing comments. A
non-host condition (os.geteuid() == 0) stays a separate skipif beside
the marker, spelled getattr(os, "geteuid", ...) so the decorator still
imports on Windows.
Where the conversion would stack two platforms() marks on one test (the
conftest rejects that at collection) the narrower mark wins:
- test_update_wedged_gateway: the class is already platforms("linux");
its per-test "needs UNIX sockets" marks were redundant and are gone.
- test_process_registry.TestSystemdCgroupIsolation: the class-level
skip-on-Windows moves onto the 11 methods that had no host mark; the
11 platforms("linux") methods keep theirs.
- test_file_ops_single_roundtrip: the two fifo tests drop their
platforms("linux") in favour of the module's "posix" (mkfifo exists on
macOS; both tests already skip when it does not).
- test_linux_desktop_entry / test_gateway_job_teardown_live: duplicate
or wider marks removed.
60 lines
2.4 KiB
Python
60 lines
2.4 KiB
Python
"""Claude Code version detection must see the CLI from a GUI-launched process.
|
|
|
|
Anthropic gates OAuth model access on the Claude Code version in the user-agent;
|
|
reporting one below the gate returns HTTP 400. GUI launches (the desktop app,
|
|
macOS LaunchAgents) inherit a bare ``/usr/bin:/bin:/usr/sbin:/sbin`` PATH, so a
|
|
bare-name lookup found nothing and detection fell back to the stale constant.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
import agent.anthropic_adapter as adapter
|
|
from agent.anthropic_adapter import _CLAUDE_CODE_VERSION_FALLBACK, _detect_claude_code_version
|
|
|
|
|
|
def _install(directory, name: str) -> str:
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
path = directory / name
|
|
path.write_text("#!/bin/sh\n")
|
|
path.chmod(0o755)
|
|
return str(path)
|
|
|
|
|
|
def _cli_versions(monkeypatch, versions: dict[str, str]):
|
|
"""Only the given executable paths answer ``--version``; anything else is a bug."""
|
|
|
|
def runner(cmd, *args, **kwargs):
|
|
assert cmd[0] in versions, f"probed unexpected path: {cmd[0]}"
|
|
return subprocess.CompletedProcess(
|
|
args=cmd, returncode=0, stdout=f"{versions[cmd[0]]} (Claude Code)", stderr=""
|
|
)
|
|
|
|
monkeypatch.setattr(adapter.subprocess, "run", runner)
|
|
|
|
|
|
def test_gui_launch_reports_installed_version_not_fallback(monkeypatch, tmp_path):
|
|
"""Bare GUI PATH, CLI only under an install prefix → real version, not the fallback."""
|
|
monkeypatch.setenv("PATH", str(tmp_path / "empty-path"))
|
|
monkeypatch.setattr(adapter, "_CLAUDE_CODE_PREFIXES", (str(tmp_path / "prefix"),))
|
|
installed = _install(tmp_path / "prefix", "claude")
|
|
_cli_versions(monkeypatch, {installed: "2.1.276"})
|
|
|
|
assert _detect_claude_code_version() == "2.1.276" != _CLAUDE_CODE_VERSION_FALLBACK
|
|
|
|
|
|
@pytest.mark.platforms("posix") # PATH lookup of an extensionless shim is POSIX-only
|
|
def test_path_hit_is_probed_first(monkeypatch, tmp_path):
|
|
"""A PATH ``claude-code`` beats a stale prefix ``claude``: every PATH hit precedes every prefix."""
|
|
on_path = _install(tmp_path / "path", "claude-code")
|
|
stale = _install(tmp_path / "prefix", "claude")
|
|
monkeypatch.setenv("PATH", str(tmp_path / "path"))
|
|
monkeypatch.setattr(adapter, "_CLAUDE_CODE_PREFIXES", (str(tmp_path / "prefix"),))
|
|
_cli_versions(monkeypatch, {on_path: "2.1.400", stale: "2.1.100"})
|
|
|
|
assert _detect_claude_code_version() == "2.1.400"
|