claude-agent-sdk 0.2.184
Filename quote introduces shell commandBasename is uppercase README.md
SHA-256f76d069f835f1b101e4134f7a5e3c23a081e7e626fc072187ea1ec03dfb673a3
Evidence
1"""Tests for scripts/update_cli_version.py version validation and file writing."""
2
3import importlib.util
4import re
5import subprocess
6import sys
7from pathlib import Path
8
9import pytest
10
11REPO_ROOT = Path(__file__).parent.parent
12SCRIPT_PATH = REPO_ROOT / "scripts" / "update_cli_version.py"
13
14# scripts/ is not a package, so load update_cli_version.py by path
15_spec = importlib.util.spec_from_file_location("update_cli_version", SCRIPT_PATH)
16assert _spec is not None and _spec.loader is not None
17update_cli_version = importlib.util.module_from_spec(_spec)
18sys.modules["update_cli_version"] = update_cli_version
19_spec.loader.exec_module(update_cli_version)
20
21DEV_VERSION = "2.1.146-dev.20260519.t105443.shaece3dab"
22
23ORIGINAL = '"""Bundled Claude Code CLI version."""\n\n__cli_version__ = "2.1.195"\n'
24
25
26@pytest.fixture
27def version_file(tmp_path: Path) -> Path:
28 """A stand-in for src/claude_agent_sdk/_cli_version.py."""
29 path = tmp_path / "_cli_version.py"
30 path.write_text(ORIGINAL)
31 return path
32
33
34def import_version(path: Path) -> str:
35 """Import the written file as Python and return its __cli_version__.
36
37 Fails on a file that is not valid Python, which is the whole point: the
38 value goes into a real source file that later gets imported.
39 """
40 spec = importlib.util.spec_from_file_location(f"_written_{path.stem}", path)
41 assert spec is not None and spec.loader is not None
42 module = importlib.util.module_from_spec(spec)
43 spec.loader.exec_module(module)
44 version: str = module.__cli_version__
45 return version
46
47
48class TestAcceptedVersions:
59:8… "1.2.3-rc.1+build.4",
60 ],
61 )
62 def test_round_trip(self, version_file: Path, version: str) -> None:
63 update_cli_version.update_cli_version(version, version_file)
64 assert import_version(version_file) == version
65
66 @pytest.mark.parametrize(
67 ("argument", "written"),
68 [
69 ("1.2.3\n …
80:31… ate_cli_version(argument, version_file)
81 assert import_version(version_file) == written
82
83 def test_docstring_and_shape_preserved(self, version_file: Path) -> None:
84 update_cli_version.update_cli_version(DEV_VERSION, version_file)
85 assert version_file.read_text() == ORIGINAL.replace("2.1.195", DEV_VERSION)
86
87 def test_only_first_assignment_replaced(self, tmp_path: Path) -> None:
88 path = tmp_path / "_cli_version.py"
89 path.write_text('__cli_version__ = "1.0.0"\n_other = "1.0.0"\n')
90 update_cli_version.update_cli_version("2.0.0", path)
⋯7 lines
100:51… teral in a real source file.
101 '1.0.0"',
102 '1.0.0" + __import__("os").system("id") + "',
103 '"',
104 # Backslashes: re.sub() replacement-escape processing, and invalid
105 # Python escapes in the emitted literal …
184:7… with pytest.raises(ValueError) as excinfo:
185 update_cli_version.update_cli_version('1.0.0"; id', version_file)
186 assert '1.0.0"; id' in str(excinfo.value)
187
188 def test_missing_assignment_leaves_file_untouched(self, tmp_path: Path) -> None:
189 path = tmp_path / "_cli_version …
Showing the top 5 files — 7 more files (147 regions) not shown.
No evidence locations were recorded for this file. Raw result