code-aide 1.20.0__tar.gz → 1.21.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. {code_aide-1.20.0 → code_aide-1.21.0}/PKG-INFO +23 -1
  2. {code_aide-1.20.0 → code_aide-1.21.0}/README.md +22 -0
  3. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/__init__.py +1 -1
  4. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/app_bundle.py +6 -2
  5. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/commands_tools.py +16 -0
  6. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/data/tools.json +10 -0
  7. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/install.py +8 -0
  8. code_aide-1.21.0/src/code_aide/macos_quarantine.py +95 -0
  9. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/operation_handlers.py +8 -5
  10. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/status.py +19 -6
  11. code_aide-1.21.0/tests/conftest.py +23 -0
  12. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_commands_tools.py +45 -0
  13. code_aide-1.21.0/tests/test_macos_quarantine.py +218 -0
  14. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_npm_cache.py +5 -2
  15. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_operations.py +7 -0
  16. code_aide-1.21.0/tests/test_quarantine_integration.py +133 -0
  17. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_status.py +28 -0
  18. {code_aide-1.20.0 → code_aide-1.21.0}/.github/workflows/ci.yml +0 -0
  19. {code_aide-1.20.0 → code_aide-1.21.0}/.github/workflows/publish.yml +0 -0
  20. {code_aide-1.20.0 → code_aide-1.21.0}/.gitignore +0 -0
  21. {code_aide-1.20.0 → code_aide-1.21.0}/.gitlab-ci.yml +0 -0
  22. {code_aide-1.20.0 → code_aide-1.21.0}/.pre-commit-config.yaml +0 -0
  23. {code_aide-1.20.0 → code_aide-1.21.0}/AGENTS.md +0 -0
  24. {code_aide-1.20.0 → code_aide-1.21.0}/CLAUDE.md +0 -0
  25. {code_aide-1.20.0 → code_aide-1.21.0}/LICENSE +0 -0
  26. {code_aide-1.20.0 → code_aide-1.21.0}/Makefile +0 -0
  27. {code_aide-1.20.0 → code_aide-1.21.0}/TODO.md +0 -0
  28. {code_aide-1.20.0 → code_aide-1.21.0}/pyproject.toml +0 -0
  29. {code_aide-1.20.0 → code_aide-1.21.0}/script-archive/README.md +0 -0
  30. {code_aide-1.20.0 → code_aide-1.21.0}/script-archive/amp-install.sh +0 -0
  31. {code_aide-1.20.0 → code_aide-1.21.0}/script-archive/antigravity-install.sh +0 -0
  32. {code_aide-1.20.0 → code_aide-1.21.0}/script-archive/claude-install.sh +0 -0
  33. {code_aide-1.20.0 → code_aide-1.21.0}/script-archive/cursor-install.sh +0 -0
  34. {code_aide-1.20.0 → code_aide-1.21.0}/specs/2026-05-03-qwen3.6-code-quality-analysis-original.md +0 -0
  35. {code_aide-1.20.0 → code_aide-1.21.0}/specs/2026-05-03-qwen3.6-code-quality-analysis.md +0 -0
  36. {code_aide-1.20.0 → code_aide-1.21.0}/specs/antigravity-cli-integration.md +0 -0
  37. {code_aide-1.20.0 → code_aide-1.21.0}/specs/auto-migrate-deprecated-installs.md +0 -0
  38. {code_aide-1.20.0 → code_aide-1.21.0}/specs/claude-native-installer-migration.md +0 -0
  39. {code_aide-1.20.0 → code_aide-1.21.0}/specs/missing-coding-llm-cli-tools.md +0 -0
  40. {code_aide-1.20.0 → code_aide-1.21.0}/specs/pre-commit-uv-setup.md +0 -0
  41. {code_aide-1.20.0 → code_aide-1.21.0}/specs/remove-bundled-version-baseline.md +0 -0
  42. {code_aide-1.20.0 → code_aide-1.21.0}/specs/unify-upgrade-eligibility-with-shared-evaluator.md +0 -0
  43. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/__main__.py +0 -0
  44. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/commands_actions.py +0 -0
  45. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/config.py +0 -0
  46. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/console.py +0 -0
  47. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/constants.py +0 -0
  48. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/detection.py +0 -0
  49. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/detection_types.py +0 -0
  50. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/entry.py +0 -0
  51. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/install_types.py +0 -0
  52. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/npm_cache.py +0 -0
  53. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/operations.py +0 -0
  54. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/package_info.py +0 -0
  55. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/package_managers.py +0 -0
  56. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/path_copies.py +0 -0
  57. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/prereqs.py +0 -0
  58. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/release_assets.py +0 -0
  59. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/status_print.py +0 -0
  60. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/tool_groups.py +0 -0
  61. {code_aide-1.20.0 → code_aide-1.21.0}/src/code_aide/versions.py +0 -0
  62. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_app_bundle.py +0 -0
  63. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_commands_actions.py +0 -0
  64. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_config.py +0 -0
  65. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_console.py +0 -0
  66. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_constants.py +0 -0
  67. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_detection.py +0 -0
  68. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_entry.py +0 -0
  69. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_error_paths.py +0 -0
  70. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_install.py +0 -0
  71. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_install_types.py +0 -0
  72. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_package_info.py +0 -0
  73. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_package_managers.py +0 -0
  74. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_path_copies.py +0 -0
  75. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_prereqs.py +0 -0
  76. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_release_assets.py +0 -0
  77. {code_aide-1.20.0 → code_aide-1.21.0}/tests/test_versions.py +0 -0
  78. {code_aide-1.20.0 → code_aide-1.21.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: code-aide
3
- Version: 1.20.0
3
+ Version: 1.21.0
4
4
  Summary: Manage AI coding CLI tools (Claude, Antigravity, Copilot, Cursor, Gemini, Amp, Codex)
5
5
  Project-URL: Homepage, https://github.com/dajobe/code-aide
6
6
  Project-URL: Repository, https://github.com/dajobe/code-aide
@@ -172,6 +172,7 @@ consulted when the relevant install method or platform applies.
172
172
  | `install_sha256` | script | SHA-256 of the install script body — required for verified installs |
173
173
  | `download_sha256` | Cache | SHA-256 of the downloaded tarball for direct_download tools; recorded by `update-versions`, verified on install |
174
174
  | `install_script_path_prepend` | script | Extra directories prepended to `PATH` when the install script runs (e.g. `["~/.local/bin"]`) |
175
+ | `macos_quarantine_paths` | script | Tool-owned paths for macOS quarantine cleanup; expands `~` and resolves executable symlinks |
175
176
  | `download_url_template` | direct | URL template with `{version}`, `{os}`, `{arch}` placeholders |
176
177
  | `install_dir` | direct | Directory to extract into; supports `{version}` |
177
178
  | `bin_dir` | direct | Directory where symlinks for `command` are created (e.g. `~/.local/bin`) |
@@ -272,6 +273,27 @@ uv run pytest tests/test_install.py::TestDetectOsArch -v
272
273
 
273
274
  Apache-2.0
274
275
 
276
+ ## macOS quarantine during installation
277
+
278
+ After successful installs and upgrades, code-aide removes the
279
+ `com.apple.quarantine` attribute from the installed npm package (including
280
+ nested native helpers), direct-download directory, or verified app bundle.
281
+ Script installs clear their configured artifact paths and resolved command.
282
+ Homebrew upgrades clear the selected formula or cask directory. Symlinks inside
283
+ these directories are not followed into other installations.
284
+
285
+ This addresses Gatekeeper prompts that can block unattended use, including
286
+ Codex's `codex-code-mode-host` helper and the resulting "timed out negotiating
287
+ with the code-mode host" error when quarantine is the cause. Helpers do not need
288
+ to be on `PATH`. Other causes of that timeout are unaffected.
289
+
290
+ Cleanup preserves other extended attributes and does not change system-wide
291
+ Gatekeeper settings. It runs without `sudo`; permission failures are reported as
292
+ install or upgrade failures, leaving the installed files in place. Dry runs and
293
+ non-macOS hosts do not change extended attributes. Existing installs can be
294
+ processed with `code-aide install --force TOOL` or `code-aide upgrade TOOL`.
295
+ Updates performed independently by a tool's own updater are outside this step.
296
+
275
297
  ## npm download cache lifetime
276
298
 
277
299
  Standalone install, upgrade, removal (including migration), and installation
@@ -145,6 +145,7 @@ consulted when the relevant install method or platform applies.
145
145
  | `install_sha256` | script | SHA-256 of the install script body — required for verified installs |
146
146
  | `download_sha256` | Cache | SHA-256 of the downloaded tarball for direct_download tools; recorded by `update-versions`, verified on install |
147
147
  | `install_script_path_prepend` | script | Extra directories prepended to `PATH` when the install script runs (e.g. `["~/.local/bin"]`) |
148
+ | `macos_quarantine_paths` | script | Tool-owned paths for macOS quarantine cleanup; expands `~` and resolves executable symlinks |
148
149
  | `download_url_template` | direct | URL template with `{version}`, `{os}`, `{arch}` placeholders |
149
150
  | `install_dir` | direct | Directory to extract into; supports `{version}` |
150
151
  | `bin_dir` | direct | Directory where symlinks for `command` are created (e.g. `~/.local/bin`) |
@@ -245,6 +246,27 @@ uv run pytest tests/test_install.py::TestDetectOsArch -v
245
246
 
246
247
  Apache-2.0
247
248
 
249
+ ## macOS quarantine during installation
250
+
251
+ After successful installs and upgrades, code-aide removes the
252
+ `com.apple.quarantine` attribute from the installed npm package (including
253
+ nested native helpers), direct-download directory, or verified app bundle.
254
+ Script installs clear their configured artifact paths and resolved command.
255
+ Homebrew upgrades clear the selected formula or cask directory. Symlinks inside
256
+ these directories are not followed into other installations.
257
+
258
+ This addresses Gatekeeper prompts that can block unattended use, including
259
+ Codex's `codex-code-mode-host` helper and the resulting "timed out negotiating
260
+ with the code-mode host" error when quarantine is the cause. Helpers do not need
261
+ to be on `PATH`. Other causes of that timeout are unaffected.
262
+
263
+ Cleanup preserves other extended attributes and does not change system-wide
264
+ Gatekeeper settings. It runs without `sudo`; permission failures are reported as
265
+ install or upgrade failures, leaving the installed files in place. Dry runs and
266
+ non-macOS hosts do not change extended attributes. Existing installs can be
267
+ processed with `code-aide install --force TOOL` or `code-aide upgrade TOOL`.
268
+ Updates performed independently by a tool's own updater are outside this step.
269
+
248
270
  ## npm download cache lifetime
249
271
 
250
272
  Standalone install, upgrade, removal (including migration), and installation
@@ -1,3 +1,3 @@
1
1
  """code-aide - Manage AI coding CLI tools."""
2
2
 
3
- __version__ = "1.20.0"
3
+ __version__ = "1.21.0"
@@ -25,7 +25,7 @@ import time
25
25
  import urllib.request
26
26
  from typing import Any, Dict, List, Optional
27
27
 
28
- from code_aide import __version__
28
+ from code_aide import __version__, macos_quarantine
29
29
  from code_aide.console import error, info, success, warning
30
30
  from code_aide.detection_types import DetectedInstallInfo
31
31
  from code_aide.install_types import InstallMethod, InstallType, parse_install_type
@@ -410,7 +410,7 @@ def install_app_bundle(
410
410
  and (dryrun or signature_ok(bundle))
411
411
  ):
412
412
  info(f"{name} {version} is already active at {link}")
413
- return True
413
+ return dryrun or macos_quarantine.clear_quarantine(bundle)
414
414
 
415
415
  if dryrun:
416
416
  info(f"[DRYRUN] Would download: {url}")
@@ -439,7 +439,11 @@ def install_app_bundle(
439
439
  if not ensure_app_stopped(tool_config, f"switch {name} to {version}"):
440
440
  return False
441
441
  if staged_bundle and staging:
442
+ if not macos_quarantine.clear_quarantine(staged_bundle):
443
+ return False
442
444
  _move_into_place(staged_bundle, bundle, staging)
445
+ elif not macos_quarantine.clear_quarantine(bundle):
446
+ return False
443
447
  _repoint_link(link, bundle)
444
448
  except (OSError, RuntimeError, subprocess.CalledProcessError) as exc:
445
449
  error(f"Failed to install {name}: {exc}")
@@ -226,6 +226,7 @@ def cmd_status_compact() -> None:
226
226
  """Show compact one-line-per-tool status."""
227
227
  ensure_versions_cache(TOOLS)
228
228
  rows: list[tuple[str, str, str, str, str]] = []
229
+ failed_checks: list[tuple[str, str]] = []
229
230
  for tool_name, tool_config in TOOLS.items():
230
231
  assessment = ToolUpgradeEvaluator(tool_name, tool_config).evaluate()
231
232
  status = assessment.status
@@ -250,6 +251,10 @@ def cmd_status_compact() -> None:
250
251
  )
251
252
 
252
253
  state = ver_status if ver_status else "?"
254
+ version_error = status.get("version_error")
255
+ if not status["version"] and version_error:
256
+ state = f"{Colors.RED}failed{Colors.NC}"
257
+ failed_checks.append((tool_name, version_error))
253
258
  shadowed = len(shadowed_copies(tool_name))
254
259
  if shadowed:
255
260
  tool_path += f" {Colors.YELLOW}(+{shadowed} shadowed){Colors.NC}"
@@ -278,6 +283,11 @@ def cmd_status_compact() -> None:
278
283
  print(fmt_row(headers))
279
284
  for row in rows:
280
285
  print(fmt_row(row))
286
+ for tool_name, version_error in failed_checks:
287
+ warning(
288
+ f"{tool_name}: version check failed ({version_error}); "
289
+ f"try 'code-aide upgrade {tool_name}' to reinstall it."
290
+ )
281
291
  for message in linked_version_mismatches():
282
292
  warning(message)
283
293
 
@@ -318,6 +328,12 @@ def cmd_status(args: argparse.Namespace) -> None:
318
328
  else:
319
329
  print(f" Status: {Colors.GREEN}✓ Installed{Colors.NC}")
320
330
 
331
+ if not status["version"] and status.get("version_error"):
332
+ warning(
333
+ f" Version check failed: {status['version_error']}. "
334
+ f"Try 'code-aide upgrade {tool_name}' to reinstall it."
335
+ )
336
+
321
337
  if status["version"]:
322
338
  _print_version_status(
323
339
  assessment, status["version"], tool_path, tool_config
@@ -33,6 +33,9 @@
33
33
  "command": "claude",
34
34
  "install_type": "script",
35
35
  "install_url": "https://claude.ai/install.sh",
36
+ "macos_quarantine_paths": [
37
+ "~/.local/bin/claude"
38
+ ],
36
39
  "install_sha256": "3a68d3406cf674e17bed1733a4dcf37805e2e47d87417700007d7e1aa766a944",
37
40
  "version_url": "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/latest",
38
41
  "prerequisites": [],
@@ -72,6 +75,9 @@
72
75
  ],
73
76
  "install_type": "script",
74
77
  "install_url": "https://antigravity.google/cli/install.sh",
78
+ "macos_quarantine_paths": [
79
+ "~/.local/bin/agy"
80
+ ],
75
81
  "install_sha256": "62966c07365423bd4dc209355060744058fb30d60f5323e2d360e39de64e5042",
76
82
  "version_manifest_url_template": "https://antigravity-cli-auto-updater-974169037036.us-central1.run.app/manifests/{platform}.json",
77
83
  "prerequisites": [],
@@ -89,6 +95,10 @@
89
95
  "command": "amp",
90
96
  "install_type": "script",
91
97
  "install_url": "https://ampcode.com/install.sh",
98
+ "macos_quarantine_paths": [
99
+ "~/.amp/bin",
100
+ "~/.local/bin/amp"
101
+ ],
92
102
  "install_sha256": "83b0a61b09cb653b92e47e039e3aba8bda60c62c0eea6e1467c1b1b12c258cc9",
93
103
  "install_script_path_prepend": [
94
104
  "~/.local/bin"
@@ -28,6 +28,7 @@ from code_aide.console import (
28
28
  warning,
29
29
  )
30
30
  from code_aide.npm_cache import npm_cache_environment, stop_process_group
31
+ from code_aide import macos_quarantine
31
32
  from code_aide.install_types import InstallType, get_tool_install_type
32
33
  from code_aide.release_assets import (
33
34
  install_marker_matches,
@@ -403,6 +404,9 @@ def install_direct_download(
403
404
  return False
404
405
  _extract_tarball(tarball_data, install_dir, cfg, version)
405
406
 
407
+ if not macos_quarantine.clear_quarantine(install_dir):
408
+ return False
409
+
406
410
  os.makedirs(bin_dir, exist_ok=True)
407
411
  symlinks = cfg.get("symlinks", {})
408
412
  link_paths = []
@@ -531,6 +535,8 @@ def install_tool(
531
535
  info(f"[DRYRUN] Would install npm package: {npm_package}")
532
536
  else:
533
537
  run_command(["npm", "install", "-g", npm_package], check=True)
538
+ if not macos_quarantine.clear_npm_quarantine(npm_package):
539
+ return InstallOutcome(False)
534
540
  npm_bin_dir = get_npm_global_bin_dir()
535
541
  if npm_bin_dir:
536
542
  bin_dirs = (npm_bin_dir,)
@@ -553,6 +559,8 @@ def install_tool(
553
559
  if dryrun:
554
560
  success(f"{tool_config['name']} verification passed")
555
561
  else:
562
+ if not macos_quarantine.clear_script_quarantine(tool_config):
563
+ return InstallOutcome(False)
556
564
  success(f"{tool_config['name']} installed successfully")
557
565
  info(tool_config["next_steps"])
558
566
  if "docs_url" in tool_config:
@@ -0,0 +1,95 @@
1
+ """Remove quarantine from tool-owned install artifacts on macOS."""
2
+
3
+ import os
4
+ import platform
5
+ import re
6
+ import shutil
7
+ import subprocess
8
+ from typing import Any
9
+
10
+ from code_aide.console import info, run_command, warning
11
+
12
+ QUARANTINE = "com.apple.quarantine"
13
+
14
+
15
+ def clear_quarantine(path: str) -> bool:
16
+ """Clear only quarantine, without following symlinks inside an install tree.
17
+
18
+ Callers supply a package directory, verified bundle, or resolved executable,
19
+ never a shared bin directory. No sudo or interactive approval is attempted.
20
+ """
21
+ if platform.system() != "Darwin":
22
+ return True
23
+ try:
24
+ # macOS Python does not expose os.removexattr. Apple's utility treats
25
+ # missing attributes as success with -r; -s never dereferences links.
26
+ run_command(["/usr/bin/xattr", "-r", "-d", "-s", QUARANTINE, path], timeout=60)
27
+ except (OSError, subprocess.SubprocessError) as exc:
28
+ detail = (
29
+ exc.stderr if isinstance(exc, subprocess.CalledProcessError) else str(exc)
30
+ )
31
+ warning(f"Could not clear macOS quarantine at {path}: {detail}")
32
+ warning("Installation files remain in place; fix their permissions and retry.")
33
+ return False
34
+ info(f"Cleared macOS quarantine from installed artifacts in {path}")
35
+ return True
36
+
37
+
38
+ def clear_npm_quarantine(package: str, prefix_args: list[str] | None = None) -> bool:
39
+ """Clear the installed package, including its nested native dependencies."""
40
+ if platform.system() != "Darwin":
41
+ return True
42
+ # Only package names, never paths, tags, URLs, or a whole npm scope.
43
+ if not re.fullmatch(r"(?:@[\w.-]+/)?[\w.-]+", package) or any(
44
+ part in (".", "..") for part in package.lstrip("@").split("/")
45
+ ):
46
+ warning(
47
+ f"Cannot locate installed npm package for quarantine cleanup: {package}"
48
+ )
49
+ return False
50
+ try:
51
+ root = run_command(
52
+ ["npm", "root", "-g", *(prefix_args or [])], timeout=30
53
+ ).stdout.strip()
54
+ if not os.path.isabs(root):
55
+ raise ValueError("npm did not report an absolute global package directory")
56
+ target = os.path.join(root, package)
57
+ if os.path.realpath(target) != os.path.join(os.path.realpath(root), package):
58
+ raise ValueError(
59
+ "the installed npm package is linked outside its directory"
60
+ )
61
+ return clear_quarantine(target)
62
+ except (OSError, ValueError, subprocess.SubprocessError) as exc:
63
+ warning(f"Could not clear macOS quarantine for {package}: {exc}")
64
+ return False
65
+
66
+
67
+ def clear_script_quarantine(cfg: dict[str, Any]) -> bool:
68
+ """Clear configured script artifacts and the resolved command, if present."""
69
+ if platform.system() != "Darwin":
70
+ return True
71
+ paths = [os.path.expanduser(p) for p in cfg.get("macos_quarantine_paths", [])]
72
+ command = shutil.which(cfg["command"])
73
+ if command:
74
+ paths.append(command)
75
+ succeeded = True
76
+ for path in dict.fromkeys(paths):
77
+ if os.path.exists(path):
78
+ succeeded = clear_quarantine(os.path.realpath(path)) and succeeded
79
+ return succeeded
80
+
81
+
82
+ def clear_brew_quarantine(package: str, *, cask: bool) -> bool:
83
+ """Clear one Homebrew package's artifacts after a successful upgrade."""
84
+ if platform.system() != "Darwin":
85
+ return True
86
+ try:
87
+ path = run_command(
88
+ ["brew", "--caskroom" if cask else "--prefix", package], timeout=30
89
+ ).stdout.strip()
90
+ if not os.path.isabs(path) or os.path.basename(path) != package.split("/")[-1]:
91
+ raise ValueError("Homebrew did not report the requested package directory")
92
+ return clear_quarantine(os.path.realpath(path))
93
+ except (OSError, ValueError, subprocess.SubprocessError) as exc:
94
+ warning(f"Could not clear macOS quarantine for {package}: {exc}")
95
+ return False
@@ -32,6 +32,7 @@ from code_aide.app_bundle import (
32
32
  remove_app_bundle,
33
33
  )
34
34
  from code_aide.constants import TOOLS
35
+ from code_aide import macos_quarantine
35
36
  from code_aide.path_copies import npm_prefix_for
36
37
  from code_aide.install_types import (
37
38
  InstallMethod,
@@ -78,7 +79,7 @@ def _upgrade_brew_formula(_name: str, cfg: Dict, detail: Optional[str]) -> bool:
78
79
  error(f"No brew formula detected for {cfg['name']}")
79
80
  return False
80
81
  run_command(["brew", "upgrade", detail], check=True, capture=False)
81
- return True
82
+ return macos_quarantine.clear_brew_quarantine(detail, cask=False)
82
83
 
83
84
 
84
85
  def _upgrade_brew_cask(_name: str, cfg: Dict, detail: Optional[str]) -> bool:
@@ -88,7 +89,7 @@ def _upgrade_brew_cask(_name: str, cfg: Dict, detail: Optional[str]) -> bool:
88
89
  if not _cask_app_stopped(cfg, detail, "upgrade it"):
89
90
  return False
90
91
  run_command(["brew", "upgrade", "--cask", detail], check=True, capture=False)
91
- return True
92
+ return macos_quarantine.clear_brew_quarantine(detail, cask=True)
92
93
 
93
94
 
94
95
  def _upgrade_npm(_name: str, cfg: Dict, detail: Optional[str]) -> bool:
@@ -96,22 +97,24 @@ def _upgrade_npm(_name: str, cfg: Dict, detail: Optional[str]) -> bool:
96
97
  if not npm_package:
97
98
  error(f"No npm package configured for {cfg['name']}")
98
99
  return False
100
+ prefix_args = _npm_prefix_args(cfg)
99
101
  run_command(
100
- ["npm", "install", "-g", *_npm_prefix_args(cfg), f"{npm_package}@latest"],
102
+ ["npm", "install", "-g", *prefix_args, f"{npm_package}@latest"],
101
103
  check=True,
102
104
  )
103
- return True
105
+ return macos_quarantine.clear_npm_quarantine(npm_package, prefix_args)
104
106
 
105
107
 
106
108
  def _upgrade_script(name: str, cfg: Dict, _detail: Optional[str]) -> bool:
107
109
  if get_tool_install_type(cfg) == InstallType.DIRECT_DOWNLOAD:
108
110
  return install_direct_download(name, cfg)
109
- return run_install_script(
111
+ installed = run_install_script(
110
112
  cfg["install_url"],
111
113
  cfg["name"],
112
114
  cfg.get("install_sha256"),
113
115
  env=get_install_script_env(cfg),
114
116
  )
117
+ return installed and macos_quarantine.clear_script_quarantine(cfg)
115
118
 
116
119
 
117
120
  def _upgrade_direct_download(name: str, cfg: Dict, _detail: Optional[str]) -> bool:
@@ -46,6 +46,8 @@ class ToolStatus(TypedDict, total=False):
46
46
  user: str | None
47
47
  usage: str | None
48
48
  errors: list[str]
49
+ # Why the installed tool's version could not be read, if it couldn't.
50
+ version_error: str | None
49
51
 
50
52
 
51
53
  InstallInfo = DetectedInstallInfo
@@ -348,6 +350,7 @@ def get_tool_status(tool_name: str, tool_config: Dict[str, Any]) -> ToolStatus:
348
350
  "user": None,
349
351
  "usage": None,
350
352
  "errors": [],
353
+ "version_error": None,
351
354
  }
352
355
 
353
356
  if not status_info["installed"]:
@@ -356,6 +359,8 @@ def get_tool_status(tool_name: str, tool_config: Dict[str, Any]) -> ToolStatus:
356
359
  if is_app_bundle_tool(tool_config):
357
360
  bundle = tool_location(tool_config)
358
361
  status_info["version"] = bundle_version(bundle) if bundle else None
362
+ if not status_info["version"]:
363
+ status_info["version_error"] = "could not read the app's Info.plist"
359
364
  return status_info
360
365
 
361
366
  command = tool_config["command"]
@@ -370,19 +375,27 @@ def get_tool_status(tool_name: str, tool_config: Dict[str, Any]) -> ToolStatus:
370
375
  check=False,
371
376
  stdin=subprocess.DEVNULL,
372
377
  )
373
- if result.returncode == 0:
374
- # Some tools print their version to stderr; prefer stdout.
375
- output = result.stdout.strip() or result.stderr.strip()
376
- if output:
377
- status_info["version"] = output.split("\n")[0]
378
+ # Some tools print their version to stderr; prefer stdout.
379
+ output = result.stdout.strip() or result.stderr.strip()
380
+ if result.returncode == 0 and output:
381
+ status_info["version"] = output.split("\n")[0]
382
+ elif result.returncode == 0:
383
+ status_info["version_error"] = "printed no version"
384
+ else:
385
+ last_line = output.splitlines()[-1].strip() if output else ""
386
+ status_info["version_error"] = (
387
+ last_line or f"exited with status {result.returncode}"
388
+ )
378
389
  except subprocess.TimeoutExpired:
379
390
  status_info["errors"].append("Version check timed out after 10s")
380
- except Exception:
391
+ status_info["version_error"] = "timed out after 10s"
392
+ except Exception as exc:
381
393
  _logger.debug(
382
394
  "Version check failed for %s (%s)",
383
395
  tool_name,
384
396
  " ".join(cmd),
385
397
  exc_info=True,
386
398
  )
399
+ status_info["version_error"] = str(exc) or type(exc).__name__
387
400
 
388
401
  return status_info
@@ -0,0 +1,23 @@
1
+ """Keep mocked installer tests from inspecting or modifying real installations."""
2
+
3
+ import pytest
4
+
5
+ from code_aide import macos_quarantine
6
+
7
+
8
+ @pytest.fixture(autouse=True)
9
+ def isolate_quarantine_cleanup(request, monkeypatch):
10
+ # These tests mock installers, sometimes using names of real local tools.
11
+ # Quarantine behavior is exercised with isolated artifacts in its own tests.
12
+ if request.module.__name__ in {
13
+ "test_macos_quarantine",
14
+ "test_quarantine_integration",
15
+ }:
16
+ return
17
+ for name in (
18
+ "clear_quarantine",
19
+ "clear_npm_quarantine",
20
+ "clear_script_quarantine",
21
+ "clear_brew_quarantine",
22
+ ):
23
+ monkeypatch.setattr(macos_quarantine, name, lambda *args, **kwargs: True)
@@ -284,6 +284,51 @@ class TestCmdStatus(unittest.TestCase):
284
284
  self.assertIn("ok", output)
285
285
  self.assertNotIn("old", output)
286
286
 
287
+ def _status_output(self, command, long_view=False):
288
+ tools = {
289
+ "x": {
290
+ "name": "Example Tool",
291
+ "command": "example",
292
+ "install_type": "npm",
293
+ "latest_version": "2.0.0",
294
+ }
295
+ }
296
+ status = {
297
+ "installed": True,
298
+ "version": None,
299
+ "user": None,
300
+ "usage": None,
301
+ "errors": [],
302
+ "version_error": "no platform package found",
303
+ }
304
+ args = type("Args", (), {"long": long_view})()
305
+ with (
306
+ mock.patch.dict(constants._TOOLS_DATA, tools, clear=True),
307
+ mock.patch.object(
308
+ commands_tools.shutil, "which", return_value="/opt/bin/example"
309
+ ),
310
+ mock.patch("code_aide.status.get_tool_status", return_value=status),
311
+ mock.patch(
312
+ "code_aide.status.detect_install_method",
313
+ return_value={"method": "npm", "detail": "example"},
314
+ ),
315
+ ):
316
+ buf = io.StringIO()
317
+ with contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf):
318
+ command(args)
319
+ return buf.getvalue()
320
+
321
+ def test_compact_status_reports_failed_version_check(self, _mock_cache):
322
+ output = self._status_output(lambda _args: commands_tools.cmd_status_compact())
323
+ self.assertIn("failed", output)
324
+ self.assertIn("x: version check failed (no platform package found)", output)
325
+ self.assertIn("code-aide upgrade x", output)
326
+
327
+ def test_long_status_reports_failed_version_check(self, _mock_cache):
328
+ output = self._status_output(commands_tools.cmd_status, long_view=True)
329
+ self.assertIn("Version check failed: no platform package found", output)
330
+ self.assertIn("code-aide upgrade x", output)
331
+
287
332
  def test_list_shows_migration_warning(self, _mock_cache):
288
333
  """cmd_list shows migration warning for deprecated install."""
289
334
  tools = {
@@ -0,0 +1,218 @@
1
+ """Quarantine cleanup boundaries and installer integration."""
2
+
3
+ import platform
4
+ import subprocess
5
+ from unittest import mock
6
+
7
+ import pytest
8
+
9
+ from code_aide import constants, install, operation_handlers
10
+ from code_aide import macos_quarantine as quarantine
11
+
12
+
13
+ @pytest.fixture
14
+ def darwin(monkeypatch):
15
+ monkeypatch.setattr(quarantine.platform, "system", lambda: "Darwin")
16
+
17
+
18
+ @pytest.mark.parametrize("system", ["Linux", "FreeBSD"])
19
+ def test_other_platforms_do_not_probe_or_modify(system, monkeypatch):
20
+ monkeypatch.setattr(quarantine.platform, "system", lambda: system)
21
+ with mock.patch.object(quarantine, "run_command") as run:
22
+ assert quarantine.clear_quarantine("/missing")
23
+ assert quarantine.clear_npm_quarantine("@openai/codex")
24
+ assert quarantine.clear_script_quarantine({"command": "codex"})
25
+ assert quarantine.clear_brew_quarantine("codex", cask=True)
26
+ run.assert_not_called()
27
+
28
+
29
+ @pytest.mark.parametrize(
30
+ "failure",
31
+ [
32
+ PermissionError("denied"),
33
+ subprocess.CalledProcessError(1, "xattr", stderr="denied"),
34
+ subprocess.TimeoutExpired("xattr", 60),
35
+ ],
36
+ )
37
+ def test_cleanup_failure_is_reported(darwin, capsys, failure):
38
+ with mock.patch.object(quarantine, "run_command", side_effect=failure) as run:
39
+ assert not quarantine.clear_quarantine("/package with spaces")
40
+ run.assert_called_once_with(
41
+ [
42
+ "/usr/bin/xattr",
43
+ "-r",
44
+ "-d",
45
+ "-s",
46
+ quarantine.QUARANTINE,
47
+ "/package with spaces",
48
+ ],
49
+ timeout=60,
50
+ )
51
+ assert "Could not clear macOS quarantine" in capsys.readouterr().out
52
+
53
+
54
+ def test_npm_uses_selected_prefix(tmp_path, darwin):
55
+ root = tmp_path / "prefix with spaces/lib/node_modules"
56
+ prefix_args = ["--prefix", str(tmp_path / "prefix with spaces")]
57
+ with (
58
+ mock.patch.object(
59
+ quarantine, "run_command", return_value=mock.Mock(stdout=str(root))
60
+ ) as run,
61
+ mock.patch.object(quarantine, "clear_quarantine", return_value=True) as clean,
62
+ ):
63
+ assert quarantine.clear_npm_quarantine("@openai/codex", prefix_args)
64
+ run.assert_called_once_with(["npm", "root", "-g", *prefix_args], timeout=30)
65
+ clean.assert_called_once_with(str(root / "@openai/codex"))
66
+
67
+
68
+ @pytest.mark.parametrize(
69
+ "package", ["../other", "@../other", "@openai", "/tmp/tool", "tool@latest"]
70
+ )
71
+ def test_npm_refuses_non_package_paths(package, darwin):
72
+ with mock.patch.object(quarantine, "run_command") as run:
73
+ assert not quarantine.clear_npm_quarantine(package)
74
+ run.assert_not_called()
75
+
76
+
77
+ def test_npm_refuses_linked_package(tmp_path, darwin):
78
+ root = tmp_path / "node_modules"
79
+ root.mkdir()
80
+ (root / "tool").symlink_to(tmp_path / "unrelated")
81
+ with mock.patch.object(
82
+ quarantine, "run_command", return_value=mock.Mock(stdout=str(root))
83
+ ):
84
+ assert not quarantine.clear_npm_quarantine("tool")
85
+
86
+
87
+ def test_npm_probe_timeout_reports_failure(darwin):
88
+ with mock.patch.object(
89
+ quarantine, "run_command", side_effect=subprocess.TimeoutExpired("npm", 30)
90
+ ):
91
+ assert not quarantine.clear_npm_quarantine("tool")
92
+
93
+
94
+ def test_script_resolves_only_executable_not_shared_bin(tmp_path, darwin):
95
+ binary = tmp_path / "versions/1.0/tool"
96
+ binary.parent.mkdir(parents=True)
97
+ binary.touch()
98
+ link = tmp_path / "bin/tool"
99
+ link.parent.mkdir()
100
+ link.symlink_to(binary)
101
+ with (
102
+ mock.patch.object(quarantine.shutil, "which", return_value=None),
103
+ mock.patch.object(quarantine, "clear_quarantine", return_value=True) as clean,
104
+ ):
105
+ assert quarantine.clear_script_quarantine(
106
+ {"command": "tool", "macos_quarantine_paths": [str(link)]}
107
+ )
108
+ clean.assert_called_once_with(str(binary.resolve()))
109
+
110
+
111
+ @pytest.mark.parametrize("cask", [True, False])
112
+ def test_brew_cleans_package_directory(tmp_path, darwin, cask):
113
+ root = tmp_path / "codex"
114
+ with (
115
+ mock.patch.object(
116
+ quarantine, "run_command", return_value=mock.Mock(stdout=str(root))
117
+ ) as run,
118
+ mock.patch.object(quarantine, "clear_quarantine", return_value=True) as clean,
119
+ ):
120
+ assert quarantine.clear_brew_quarantine("codex", cask=cask)
121
+ run.assert_called_once_with(
122
+ ["brew", "--caskroom" if cask else "--prefix", "codex"], timeout=30
123
+ )
124
+ clean.assert_called_once_with(str(root.resolve()))
125
+
126
+
127
+ @pytest.mark.parametrize("succeeded", [True, False])
128
+ def test_npm_install_cleans_before_reporting_success(darwin, succeeded):
129
+ cfg = {
130
+ "command": "tool",
131
+ "name": "Tool",
132
+ "install_type": "npm",
133
+ "npm_package": "tool",
134
+ "next_steps": "Run tool",
135
+ }
136
+ with (
137
+ mock.patch.dict(constants._TOOLS_DATA, {"tool": cfg}),
138
+ mock.patch.object(install, "command_exists", return_value=False),
139
+ mock.patch.object(install, "run_command"),
140
+ mock.patch.object(
141
+ install, "get_npm_global_bin_dir", return_value="/prefix/bin"
142
+ ),
143
+ mock.patch.object(
144
+ quarantine, "clear_npm_quarantine", return_value=succeeded
145
+ ) as clean,
146
+ mock.patch.object(install, "success") as success,
147
+ ):
148
+ assert bool(install.install_tool("tool")) is succeeded
149
+ clean.assert_called_once_with("tool")
150
+ assert success.called is succeeded
151
+
152
+
153
+ def test_failed_install_and_dryrun_never_clean(darwin):
154
+ cfg = {
155
+ "command": "tool",
156
+ "name": "Tool",
157
+ "install_type": "npm",
158
+ "npm_package": "tool",
159
+ }
160
+ with (
161
+ mock.patch.dict(constants._TOOLS_DATA, {"tool": cfg}),
162
+ mock.patch.object(install, "command_exists", return_value=False),
163
+ mock.patch.object(
164
+ install, "run_command", side_effect=subprocess.CalledProcessError(1, "npm")
165
+ ),
166
+ mock.patch.object(quarantine, "clear_npm_quarantine") as clean,
167
+ ):
168
+ assert not install.install_tool("tool")
169
+ assert install.install_tool("tool", dryrun=True)
170
+ clean.assert_not_called()
171
+
172
+
173
+ def test_npm_upgrade_preserves_prefix(darwin):
174
+ with (
175
+ mock.patch.object(
176
+ operation_handlers, "_npm_prefix_args", return_value=["--prefix", "/chosen"]
177
+ ),
178
+ mock.patch.object(operation_handlers, "run_command"),
179
+ mock.patch.object(
180
+ quarantine, "clear_npm_quarantine", return_value=False
181
+ ) as clean,
182
+ ):
183
+ assert not operation_handlers._upgrade_npm("tool", {"name": "Tool"}, "package")
184
+ clean.assert_called_once_with("package", ["--prefix", "/chosen"])
185
+
186
+
187
+ @pytest.mark.skipif(platform.system() != "Darwin", reason="macOS extended attributes")
188
+ def test_real_macos_nested_helpers_preserve_other_attributes_and_external_links(
189
+ tmp_path,
190
+ ):
191
+ package = tmp_path / "package with spaces"
192
+ helper = package / "node_modules/native/bin/codex-code-mode-host"
193
+ helper.parent.mkdir(parents=True)
194
+ helper.touch()
195
+ outside = tmp_path / "other-tool"
196
+ outside.mkdir()
197
+ unrelated = outside / "binary"
198
+ unrelated.touch()
199
+ (package / "linked-directory").symlink_to(outside, target_is_directory=True)
200
+ (package / "linked-binary").symlink_to(unrelated)
201
+
202
+ def xattr(*args):
203
+ return subprocess.run(
204
+ ["/usr/bin/xattr", *map(str, args)],
205
+ check=True,
206
+ capture_output=True,
207
+ text=True,
208
+ ).stdout
209
+
210
+ for path in (package, helper, unrelated):
211
+ xattr("-w", quarantine.QUARANTINE, "0081;00000000;code-aide-test;", path)
212
+ xattr("-w", "com.code-aide.test", "preserved", path)
213
+ assert quarantine.clear_quarantine(str(package))
214
+ assert quarantine.QUARANTINE not in xattr(helper)
215
+ assert quarantine.QUARANTINE not in xattr(package)
216
+ assert xattr("-p", "com.code-aide.test", helper).strip() == "preserved"
217
+ assert quarantine.QUARANTINE in xattr(unrelated)
218
+ assert quarantine.clear_quarantine(str(package)) # Missing attributes are harmless.
@@ -157,13 +157,16 @@ def test_explicit_cache_override_rejected_before_cache_creation(cache_home):
157
157
 
158
158
  def test_symlink_cache_parent_rejected(cache_home, tmp_path):
159
159
  target = tmp_path / "outside"
160
- target.mkdir(mode=0o755)
160
+ target.mkdir()
161
+ # Compare with the starting mode rather than a literal one: mkdir modes
162
+ # are reduced by the process umask, so the start varies by environment.
163
+ mode_before = target.stat().st_mode
161
164
  (cache_home / ".cache").symlink_to(target)
162
165
  with pytest.raises(ValueError, match="symlink"):
163
166
  with npm_cache_environment():
164
167
  pytest.fail("must reject symlink")
165
168
  assert not list(target.iterdir())
166
- assert target.stat().st_mode & 0o777 == 0o755
169
+ assert target.stat().st_mode == mode_before
167
170
 
168
171
 
169
172
  def test_real_timeout_stops_descendant_before_cleanup(cache_home, monkeypatch):
@@ -415,6 +415,13 @@ class TestMigrateInstallMethod(unittest.TestCase):
415
415
  class TestCmdUpgradeDefaultSelection(unittest.TestCase):
416
416
  """Tests for default cmd_upgrade behavior."""
417
417
 
418
+ def setUp(self):
419
+ # Selection uses fixture versions; refreshing would write fake tools
420
+ # into the user's real cache and make results depend on its age.
421
+ refresh = mock.patch.object(cli_commands_actions, "ensure_versions_cache")
422
+ refresh.start()
423
+ self.addCleanup(refresh.stop)
424
+
418
425
  def test_default_upgrades_only_out_of_date_installed_tools(self):
419
426
  tools = {
420
427
  "old": {
@@ -0,0 +1,133 @@
1
+ """Verify cleanup ordering across native install methods."""
2
+
3
+ import hashlib
4
+ import io
5
+ import plistlib
6
+ import tarfile
7
+ from unittest import mock
8
+
9
+ import pytest
10
+
11
+ from code_aide import app_bundle, constants, install, operation_handlers
12
+ from code_aide import macos_quarantine as quarantine
13
+
14
+
15
+ @pytest.fixture(autouse=True)
16
+ def darwin(monkeypatch):
17
+ monkeypatch.setattr(quarantine.platform, "system", lambda: "Darwin")
18
+ monkeypatch.setattr(quarantine.platform, "machine", lambda: "arm64")
19
+
20
+
21
+ @pytest.mark.parametrize(
22
+ "installer_ok,cleanup_ok", [(True, True), (True, False), (False, True)]
23
+ )
24
+ @pytest.mark.parametrize("upgrade", [True, False])
25
+ def test_script_install_and_upgrade(installer_ok, cleanup_ok, upgrade):
26
+ cfg = {
27
+ "name": "Tool",
28
+ "command": "tool",
29
+ "install_type": "script",
30
+ "install_url": "https://example.com",
31
+ "next_steps": "Run tool",
32
+ }
33
+ module = operation_handlers if upgrade else install
34
+ with (
35
+ mock.patch.dict(constants._TOOLS_DATA, {"tool": cfg}),
36
+ mock.patch.object(install, "command_exists", return_value=False),
37
+ mock.patch.object(module, "run_install_script", return_value=installer_ok),
38
+ mock.patch.object(
39
+ quarantine, "clear_script_quarantine", return_value=cleanup_ok
40
+ ) as clean,
41
+ ):
42
+ result = (
43
+ operation_handlers._upgrade_script("tool", cfg, None)
44
+ if upgrade
45
+ else install.install_tool("tool")
46
+ )
47
+ assert bool(result) is (installer_ok and cleanup_ok)
48
+ assert clean.called is installer_ok
49
+
50
+
51
+ @pytest.mark.parametrize("cask", [True, False])
52
+ def test_brew_upgrade_propagates_cleanup_failure(cask):
53
+ handler = (
54
+ operation_handlers._upgrade_brew_cask
55
+ if cask
56
+ else operation_handlers._upgrade_brew_formula
57
+ )
58
+ with (
59
+ mock.patch.object(operation_handlers, "run_command"),
60
+ mock.patch.object(operation_handlers, "_cask_app_stopped", return_value=True),
61
+ mock.patch.object(
62
+ quarantine, "clear_brew_quarantine", return_value=False
63
+ ) as clean,
64
+ ):
65
+ assert not handler("tool", {"name": "Tool"}, "package")
66
+ clean.assert_called_once_with("package", cask=cask)
67
+
68
+
69
+ @pytest.mark.parametrize("valid_checksum", [True, False])
70
+ def test_direct_download_cleans_after_verification_before_link(
71
+ tmp_path, valid_checksum
72
+ ):
73
+ data = io.BytesIO()
74
+ with tarfile.open(fileobj=data, mode="w:gz") as archive:
75
+ member = tarfile.TarInfo("package/helper")
76
+ member.size = 4
77
+ archive.addfile(member, io.BytesIO(b"test"))
78
+ content = data.getvalue()
79
+ destination = tmp_path / "versions/1"
80
+ link = tmp_path / "bin/tool"
81
+ cfg = {
82
+ "name": "Tool",
83
+ "latest_version": "1",
84
+ "install_dir": str(destination),
85
+ "bin_dir": str(link.parent),
86
+ "symlinks": {"tool": "helper"},
87
+ "download_url_template": "https://example.com/{version}/{os}/{arch}",
88
+ "download_sha256": (
89
+ hashlib.sha256(content).hexdigest() if valid_checksum else "wrong"
90
+ ),
91
+ }
92
+
93
+ def clear(path):
94
+ assert path == str(destination)
95
+ assert (destination / "helper").read_bytes() == b"test"
96
+ assert not link.exists()
97
+ return True
98
+
99
+ with (
100
+ mock.patch.object(install, "fetch_url", return_value=(content, {})),
101
+ mock.patch.object(quarantine, "clear_quarantine", side_effect=clear) as clean,
102
+ ):
103
+ assert install.install_direct_download("tool", cfg) is valid_checksum
104
+ assert clean.called is valid_checksum
105
+ assert link.exists() is valid_checksum
106
+
107
+
108
+ @pytest.mark.parametrize(
109
+ "dryrun,cleanup_ok", [(False, True), (False, False), (True, True)]
110
+ )
111
+ def test_existing_verified_bundle_cleanup(tmp_path, dryrun, cleanup_ok):
112
+ bundle = tmp_path / "v1/Tool.app"
113
+ (bundle / "Contents").mkdir(parents=True)
114
+ with (bundle / "Contents/Info.plist").open("wb") as handle:
115
+ plistlib.dump({"CFBundleShortVersionString": "1"}, handle)
116
+ link = tmp_path / "Tool.app"
117
+ link.symlink_to(bundle)
118
+ cfg = {
119
+ "name": "Tool",
120
+ "latest_version": "1",
121
+ "install_dir": str(tmp_path / "v{version}"),
122
+ "app_bundle_name": "Tool.app",
123
+ "app_link": str(link),
124
+ "download_url_template": "https://example.com/{version}/{arch}",
125
+ }
126
+ with (
127
+ mock.patch.object(app_bundle, "signature_ok", return_value=True),
128
+ mock.patch.object(
129
+ quarantine, "clear_quarantine", return_value=cleanup_ok
130
+ ) as clean,
131
+ ):
132
+ assert app_bundle.install_app_bundle("tool", cfg, dryrun=dryrun) is cleanup_ok
133
+ assert clean.called is not dryrun
@@ -410,6 +410,34 @@ class TestGetToolStatus(unittest.TestCase):
410
410
  status = self._run(returncode=1, stdout="1.2.3\n")
411
411
  self.assertIsNone(status["version"])
412
412
 
413
+ def test_nonzero_exit_records_last_output_line(self):
414
+ status = self._run(returncode=1, stderr="loading\nno platform package found\n")
415
+ self.assertIsNone(status["version"])
416
+ self.assertEqual(status["version_error"], "no platform package found")
417
+
418
+ def test_nonzero_exit_without_output_records_status(self):
419
+ status = self._run(returncode=3)
420
+ self.assertEqual(status["version_error"], "exited with status 3")
421
+
422
+ def test_success_without_output_records_error(self):
423
+ status = self._run(returncode=0)
424
+ self.assertEqual(status["version_error"], "printed no version")
425
+
426
+ def test_successful_check_has_no_error(self):
427
+ self.assertIsNone(self._run(stdout="1.2.3\n")["version_error"])
428
+
429
+ def test_timeout_records_error(self):
430
+ with (
431
+ mock.patch.object(cli_status, "is_tool_installed", return_value=True),
432
+ mock.patch.object(
433
+ cli_status.subprocess,
434
+ "run",
435
+ side_effect=subprocess.TimeoutExpired(["test-tool"], 10),
436
+ ),
437
+ ):
438
+ status = cli_status.get_tool_status("test", self._TOOL_CONFIG)
439
+ self.assertEqual(status["version_error"], "timed out after 10s")
440
+
413
441
  def test_not_installed_short_circuits(self):
414
442
  with mock.patch.object(
415
443
  cli_status, "is_tool_installed", return_value=False
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes