diff --git a/AGENTS.md b/AGENTS.md index c1301d6..bf2a593 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,7 +77,7 @@ This repo **is** a CLI tool manager, so the word "upgrade" is overloaded: ## Index of scoped AGENTS.md - [cli_audit/AGENTS.md](./cli_audit/AGENTS.md) — Python package (21 modules) -- [scripts/AGENTS.md](./scripts/AGENTS.md) — Installation scripts (Bash, 34 scripts) +- [scripts/AGENTS.md](./scripts/AGENTS.md) — Installation scripts (Bash, 41 scripts) - [tests/AGENTS.md](./tests/AGENTS.md) — Test suite (pytest, 14 test files) ## Commands (verified 2026-04-16) @@ -137,8 +137,8 @@ This repo **is** a CLI tool manager, so the word "upgrade" is overloaded: **AI CLI Preparation v2.0** — Tool version auditing and installation management for AI coding agents. - **Modules:** 21 Python modules under `cli_audit/` (see [`cli_audit/AGENTS.md`](./cli_audit/AGENTS.md)) -- **Catalog:** 107 JSON tool definitions under `catalog/` -- **Installers:** 34 Bash scripts under `scripts/` (see [`scripts/AGENTS.md`](./scripts/AGENTS.md)) +- **Catalog:** 108 JSON tool definitions under `catalog/` +- **Installers:** 41 Bash scripts under `scripts/` (see [`scripts/AGENTS.md`](./scripts/AGENTS.md)) - **Phase 1:** Detection & auditing (complete) - **Phase 2:** Installation & upgrade management (complete) - **Entry point:** `audit.py` → `cli_audit` package diff --git a/CHANGELOG.md b/CHANGELOG.md index 86b46bc..414753c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0. ## [Unreleased] ### Added +- `agy` catalog entry (`catalog/agy.json` + `scripts/install_agy.sh`): the Google Antigravity CLI, installed with the official installer from antigravity.google. When `~/.local/bin` is already on `PATH`, the installer passes `--skip-path` so `~/.bashrc` and `~/.profile` get no extra PATH line (if Google changes the line it patches, it warns and runs the unpatched installer, which adds that line); updates run `agy update`. - `pi` catalog entry: the pi coding agent, installed from npm as `@earendil-works/pi-coding-agent` (the earlier `@mariozechner/pi-coding-agent` package is deprecated); upstream version from GitHub `earendil-works/pi`. - `jules` catalog entry: the Google Jules CLI (`@google/jules`), Google's asynchronous coding agent, with bash completion from `jules completion bash`. - `herdr` catalog entry (`catalog/herdr.json`): terminal multiplexer for coding agents, installed as a raw linux binary from GitHub releases (x86_64, aarch64) with bash completion. diff --git a/README.md b/README.md index c908ae2..f6c37d2 100644 --- a/README.md +++ b/README.md @@ -478,7 +478,7 @@ make test-parallel # Parallel via pytest-xdist ## Installation scripts -All 107 cataloged tools can be installed, upgraded, uninstalled, or reconciled via generic Make targets: +All 108 cataloged tools can be installed, upgraded, uninstalled, or reconciled via generic Make targets: ```bash # Generic pattern targets - work for ANY cataloged tool @@ -543,7 +543,7 @@ When ambiguous, the audit may report a generic bucket (e.g., `~/.local/bin`). Th ### Actions: install, upgrade, uninstall, reconcile -All pattern targets (`install-%`, `upgrade-%`, `uninstall-%`, `reconcile-%`) work for any of the 107 cataloged tools. They use a three-step fallback: dedicated script, then generic installer, then error. +All pattern targets (`install-%`, `upgrade-%`, `uninstall-%`, `reconcile-%`) work for any of the 108 cataloged tools. They use a three-step fallback: dedicated script, then generic installer, then error. ```bash # Upgrade any tool diff --git a/catalog/COVERAGE.md b/catalog/COVERAGE.md index 03b308f..f90326b 100644 --- a/catalog/COVERAGE.md +++ b/catalog/COVERAGE.md @@ -2,14 +2,14 @@ This file documents which tools have catalog entries and how each one is installed. -## Catalog entries (107) +## Catalog entries (108) -Counted from `catalog/*.json` on 2026-09-22. Every tool the audit tracks has a catalog entry; its `install_method` selects the installer (`scripts/installers/.sh`). `dedicated_script` runs the script named in the entry's `script` field. `auto` goes through the reconciliation system (`reconcile_tool` in `scripts/lib/reconcile.sh`). +Counted from `catalog/*.json` on 2026-11-28. Every tool the audit tracks has a catalog entry; its `install_method` selects the installer (`scripts/installers/.sh`). `dedicated_script` runs the script named in the entry's `script` field. `auto` goes through the reconciliation system (`reconcile_tool` in `scripts/lib/reconcile.sh`). | install_method | Count | Tools | |---|---|---| | `github_release_binary` | 38 | ast-grep, curlie, dasel, direnv, dive, fx, fzf, gh, gh-aw, gh-aw-firewall, git-absorb, git-branchless, git-lfs, gitleaks, glab, golangci-lint, google-workspace-cli, gosec, herdr, jq, just, kubectl, mlr, ninja, opengrep, qsv, rga, sd, shellcheck, shfmt, symfony, tfsec, trivy, vhs, watchexec, xsv, yq, zellij | -| `dedicated_script` | 18 | blesh, byobu, claude, composer, docker, gem, go, node, parallel, pip, python, ruby, rust, tmux, tree, uv, wslu, yarn | +| `dedicated_script` | 19 | agy, blesh, byobu, claude, composer, docker, gem, go, node, parallel, pip, python, ruby, rust, tmux, tree, uv, wslu, yarn | | `auto` | 13 | actionlint, bat, delta, difftastic, dust, fd, gup, hyperfine, jj, pnpm, ripgrep, scc, tokei | | `uv_tool` | 12 | ansible-core, bandit, black, flake8, gam, git-filter-repo, httpie, isort, pre-commit, ruff, semgrep, trustmux | | `package_manager` | 10 | bwrap, ctags, entr, git, php, pipx, poetry, prename, rename.ul, sponge | @@ -28,8 +28,8 @@ A sweep on 2026-07-22 (commit 9b6c053) audited the entries present in that commit for a bash-completion generator: each generator was executed and its output validated against `complete -…` / `compgen ` / `COMPREPLY`, then checked to confirm it registers the entry's own `binary_name`. codex, pip and -pipx were not installed then; see the end of this section. herdr, jules, pi -and vault were checked when they were added. Five entries are not audited: +pipx were not installed then; see the end of this section. agy, herdr, jules, +pi and vault were checked when they were added. Five entries are not audited: blesh, bw, bwrap, byobu, trustmux. **42 entries declare `bash_completion`** — 41 `command`, 1 `source_path` (rbenv). @@ -57,7 +57,7 @@ The completion file is named after `binary_name`, so a script that registers a ### No bash completion available -actionlint, ansible-core, aws, bandit, claude, ctags, curlie, difftastic, +actionlint, agy, ansible-core, aws, bandit, claude, ctags, curlie, difftastic, direnv, dust, entr, eslint, flake8, gam, gem, gemini, gh-aw-firewall, git, git-branchless, git-filter-repo, go, google-workspace-cli, gosec, httpie, hyperfine, isort, jq, ninja, opengrep, php, pi, pre-commit, prename, prettier, diff --git a/catalog/README.md b/catalog/README.md index 8dde570..dc8e90c 100644 --- a/catalog/README.md +++ b/catalog/README.md @@ -71,7 +71,7 @@ Install tools via system package managers (apt, brew, dnf, pacman). 2. The tool will automatically be available via `make install-`, `make upgrade-`, `make uninstall-`, and `make reconcile-` 3. No need to create a custom install script! -Currently **107 tools** are cataloged. +Currently **108 tools** are cataloged. ## Environment Variables @@ -96,6 +96,6 @@ make upgrade ## Architecture -All 107 tools have catalog entries. The generic installer (`scripts/install_tool.sh`) reads a tool's catalog JSON and delegates to the appropriate method-specific installer under `scripts/installers/`. Tools with complex installation needs (python, node, docker, rust, etc.) use `install_method: "dedicated_script"` to route to their existing bespoke scripts. +All 108 tools have catalog entries. The generic installer (`scripts/install_tool.sh`) reads a tool's catalog JSON and delegates to the appropriate method-specific installer under `scripts/installers/`. Tools with complex installation needs (python, node, docker, rust, etc.) use `install_method: "dedicated_script"` to route to their existing bespoke scripts. See [ADR-007](../docs/adr/ADR-007-generic-tool-installation-architecture.md) for the full architectural decision record. diff --git a/catalog/agy.json b/catalog/agy.json new file mode 100644 index 0000000..7a8f90e --- /dev/null +++ b/catalog/agy.json @@ -0,0 +1,17 @@ +{ + "name": "agy", + "category": "ai", + "install_method": "dedicated_script", + "description": "Google Antigravity CLI - AI coding agent that runs in your terminal", + "homepage": "https://antigravity.google/docs/cli/install", + "binary_name": "agy", + "script": "install_agy.sh", + "skip_upstream": true, + "version_command": "agy --version 2>/dev/null | grep -oE '[0-9]+\\.[0-9]+\\.[0-9]+' | head -1", + "guide": { + "display_name": "Google Antigravity CLI", + "install_action": "upgrade", + "order": 406 + }, + "notes": "Official installer: curl -fsSL https://antigravity.google/cli/install.sh | bash (binary in ~/.local/bin/agy, SHA512 checked against the release manifest). Updates itself in the background; 'agy update' updates on demand. First run signs in with a Google account." +} diff --git a/docs/API_REFERENCE.md b/docs/API_REFERENCE.md index e533b77..d11b194 100644 --- a/docs/API_REFERENCE.md +++ b/docs/API_REFERENCE.md @@ -125,7 +125,7 @@ class ToolCatalog: ```python from cli_audit import ToolCatalog -# Load catalog (107 tools) +# Load catalog (108 tools) catalog = ToolCatalog() entries = catalog.load_all() @@ -140,7 +140,7 @@ if catalog.has("fzf"): fzf = catalog.get("fzf") # List all tools -all_tools = catalog.list_all() # Returns list of 107 tool names +all_tools = catalog.list_all() # Returns list of 108 tool names ``` #### `cli_audit.collectors` - Upstream Version Collection diff --git a/docs/CATALOG_GUIDE.md b/docs/CATALOG_GUIDE.md index 8b239e9..e352194 100644 --- a/docs/CATALOG_GUIDE.md +++ b/docs/CATALOG_GUIDE.md @@ -15,7 +15,7 @@ The catalog system allows tool definitions to be managed as JSON files instead o - **Clear Separation**: Data (JSON) vs Logic (Python) **Location**: `catalog/` directory at project root -**Current Size**: 107 JSON tool definitions +**Current Size**: 108 JSON tool definitions ## Quick Start diff --git a/docs/INDEX.md b/docs/INDEX.md index 17f46d8..179c255 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -10,7 +10,7 @@ AI CLI Preparation is a specialized environment audit tool designed to ensure AI coding agents (like Claude Code) have access to all necessary developer tools. This documentation provides comprehensive technical details for developers, contributors, and integrators. -**Architecture:** Modular design with 21 specialized Python modules and 107 JSON tool catalog entries, evolved from a 3,387-line monolith to a maintainable, extensible system. +**Architecture:** Modular design with 21 specialized Python modules and 108 JSON tool catalog entries, evolved from a 3,387-line monolith to a maintainable, extensible system. **Project Status:** - **Phase 1 (Detection & Auditing):** ✅ Complete - Modular refactoring complete @@ -37,7 +37,7 @@ AI CLI Preparation is a specialized environment audit tool designed to ensure AI 2. **[CATALOG_GUIDE.md](CATALOG_GUIDE.md)** - JSON Catalog System ⭐ **NEW** - Tool definition schema and structure - - 107 JSON catalog entries + - 108 JSON catalog entries - Creating and managing catalog entries - ToolCatalog API and usage patterns - Community contribution workflows diff --git a/docs/TOOL_ECOSYSTEM.md b/docs/TOOL_ECOSYSTEM.md index 78cded6..06f1ffb 100644 --- a/docs/TOOL_ECOSYSTEM.md +++ b/docs/TOOL_ECOSYSTEM.md @@ -576,6 +576,14 @@ CLI_AUDIT_JSON=1 uv run python audit.py | jq '.[] | select(.category == "securit - **Install:** `npm install -g @google/gemini-cli` - **Upgrade:** `npm update -g @google/gemini-cli` +### agy +- **Purpose:** Google Antigravity CLI - AI coding agent that runs in your terminal +- **Executable:** `agy` +- **Upstream:** Official installer (https://antigravity.google/cli/install.sh); no release feed, the CLI updates itself +- **Use Case:** Terminal coding agent backed by Google models +- **Install:** `make install-agy` (runs the official installer) +- **Upgrade:** `agy update` + ### jules - **Purpose:** Google Jules CLI - terminal client for Jules, Google's asynchronous coding agent - **Executable:** `jules` diff --git a/scripts/AGENTS.md b/scripts/AGENTS.md index d5c2c25..e3afd7c 100644 --- a/scripts/AGENTS.md +++ b/scripts/AGENTS.md @@ -6,7 +6,7 @@ ## Overview -34 Bash scripts for installing developer tools with multiple actions: +41 Bash scripts for installing developer tools with multiple actions: - **install**: Fresh installation (default action) - **update**: Upgrade to latest version - **uninstall**: Remove installation @@ -25,6 +25,7 @@ - `install_tool.sh`: Main orchestrator - reads catalog, delegates to installers - `install_group.sh`: Install tool groups - `install_claude.sh`: Claude Code CLI (native installer) +- `install_agy.sh`: Google Antigravity CLI (official installer; `agy update` for updates) - `install_ansible.sh`, `install_brew.sh`, `install_composer.sh` - `install_docker.sh`, `install_gem.sh`, `install_parallel.sh`, `install_yarn.sh` - `install_tmux.sh`, `install_tree.sh` (single-binary utilities) @@ -128,7 +129,7 @@ make scripts-perms # Ensure all scripts are executable ./scripts/install_node.sh reconcile ``` -**Via Make (works for all 107 cataloged tools):** +**Via Make (works for all 108 cataloged tools):** ```bash make install-python # Install Python toolchain (dedicated script) make upgrade-python # Upgrade Python toolchain diff --git a/scripts/install_agy.sh b/scripts/install_agy.sh new file mode 100755 index 0000000..d33444d --- /dev/null +++ b/scripts/install_agy.sh @@ -0,0 +1,193 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MIT +# SPDX-FileCopyrightText: Netresearch DTT GmbH +# Dedicated installer for the Google Antigravity CLI (agy) +# Uses the official installer; updates go through the CLI's own updater +set -euo pipefail + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ACTION="${1:-install}" +INSTALLER_URL="https://antigravity.google/cli/install.sh" +BIN_DIR="$HOME/.local/bin" +AGY_BIN="$BIN_DIR/agy" +# curl may only use https, including on redirects +CURL_HTTPS_ONLY=(--proto '=https') + +# The agy to act on: the first agy on PATH, which is the copy a plain `agy` +# runs and the audit reports, else ~/.local/bin/agy (where the official +# installer puts it). Virtualenv and conda bins are environments, not +# installations; the patterns follow detect_all_installations in +# lib/capability.sh. +find_agy() { + local candidate + while IFS= read -r candidate; do + case "$candidate" in + */venv/bin/*|*/.venv/bin/*|*/venvs/*/bin/*|*/.venvs/*/bin/*|*/virtualenvs/*/bin/*|*/.virtualenvs/*/bin/*) continue ;; + */envs/*/bin/*|*/conda/*/bin/*|*/miniconda*/bin/*|*/anaconda*/bin/*) continue ;; + */env/bin/*) continue ;; + esac + printf '%s\n' "$candidate" + return 0 + done < <(type -P -a agy 2>/dev/null || true) + if [ -x "$AGY_BIN" ]; then + printf '%s\n' "$AGY_BIN" + fi +} + +get_current_version() { + local bin + bin="$(find_agy)" + [ -n "$bin" ] || return 0 + # macOS has no timeout(1) + if command -v timeout >/dev/null 2>&1; then + timeout 2 "$bin" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true + else + "$bin" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true + fi +} + +# True when a PATH entry is ~/.local/bin, also written with a trailing slash +# or through a symlinked parent +bin_dir_on_path() { + local entry resolved_bin="" resolved + local -a entries + [ -d "$BIN_DIR" ] && resolved_bin="$(cd "$BIN_DIR" && pwd -P)" + IFS=: read -r -a entries <<<"$PATH" + for entry in "${entries[@]}"; do + # Relative entries (., bin) depend on the current directory + case "$entry" in /*) ;; *) continue ;; esac + [ "${entry%/}" = "$BIN_DIR" ] && return 0 + if [ -n "$resolved_bin" ] && [ -d "$entry" ]; then + resolved="$(cd "$entry" && pwd -P)" || continue + [ "$resolved" = "$resolved_bin" ] && return 0 + fi + done + return 1 +} + +warn_path_line() { + echo "[agy] Warning: $1; the installer may add a PATH line to ~/.bashrc and ~/.profile" >&2 +} + +# Run the official installer. It downloads the binary, checks its SHA512 +# against the release manifest and then runs `agy install`, which appends a +# PATH line to ~/.bashrc and ~/.profile. When ~/.local/bin is already on PATH +# that line only moves the directory to the front, so pass --skip-path. +install_native() { + if ! command -v curl >/dev/null 2>&1; then + echo "[agy] curl is required for the official installer" >&2 + return 1 + fi + local work_dir installer_script + work_dir="$(mktemp -d "${TMPDIR:-/tmp}/cli-audit-agy.XXXXXX")" || return 1 + installer_script="$work_dir/install.sh" + + if ! curl "${CURL_HTTPS_ONLY[@]}" -fsSL "$INSTALLER_URL" -o "$installer_script"; then + echo "[agy] Failed to download $INSTALLER_URL" >&2 + rm -rf "$work_dir" + return 1 + fi + + # A dangling ~/.local/bin/agy makes the installer's cp refuse to write + if [ -L "$AGY_BIN" ] && [ ! -e "$AGY_BIN" ]; then + rm -f "$AGY_BIN" + fi + + if bin_dir_on_path; then + # The anchor is the line that hands over to `agy install`; if Google + # changes it, install without the patch rather than fail + if ! grep -qF '"$BINARY_PATH" install || true' "$installer_script"; then + warn_path_line "installer layout changed" + # sed without -i: BSD and GNU sed disagree on its argument + elif ! { sed 's/"\$BINARY_PATH" install || true/"\$BINARY_PATH" install --skip-path || true/' \ + "$installer_script" >"$installer_script.patched" && + mv "$installer_script.patched" "$installer_script"; }; then + warn_path_line "could not patch the installer" + fi + fi + + local rc=0 + bash "$installer_script" || rc=$? + rm -rf "$work_dir" + return "$rc" +} + +refresh_agy_snapshot() { + if [ -f "$DIR/lib/install_strategy.sh" ]; then + . "$DIR/lib/install_strategy.sh" + # The audit looks on PATH; let it see a fresh ~/.local/bin/agy + PATH="$BIN_DIR:$PATH" refresh_snapshot "agy" 2>/dev/null || true + fi +} + +report() { + local before="$1" after path + hash -r 2>/dev/null || true + after="$(get_current_version)" + path="$(find_agy)" + printf "[%s] before: %s\n" "agy" "${before:-}" + printf "[%s] after: %s\n" "agy" "${after:-}" + if [ -n "$path" ]; then printf "[%s] path: %s\n" "agy" "$path"; fi +} + +install_agy() { + local before existing + before="$(get_current_version)" + existing="$(find_agy)" + + if [ -n "$existing" ]; then + echo "[agy] Already installed at $existing; it updates itself (run: agy update)" >&2 + elif ! install_native; then + echo "[agy] Error: installation failed" >&2 + echo "[agy] Install manually: curl -fsSL $INSTALLER_URL | bash" >&2 + return 1 + fi + + report "$before" + refresh_agy_snapshot +} + +upgrade_agy() { + local before existing + existing="$(find_agy)" + if [ -z "$existing" ]; then + echo "[agy] Not installed, running install..." >&2 + install_agy + return $? + fi + before="$(get_current_version)" + if ! "$existing" update &2 + return 1 + fi + report "$before" + refresh_agy_snapshot +} + +uninstall_agy() { + if [ ! -e "$AGY_BIN" ] && [ ! -L "$AGY_BIN" ]; then + local other + other="$(command -v agy 2>/dev/null || true)" + if [ -n "$other" ]; then + echo "[agy] Not installed at $AGY_BIN; $other was installed another way, remove it by hand" >&2 + else + echo "[agy] Not installed at $AGY_BIN" >&2 + fi + return 0 + fi + rm -f "$AGY_BIN" + hash -r 2>/dev/null || true + echo "[agy] Removed $AGY_BIN" >&2 + echo "[agy] Left in place: settings and sign-in in ~/.config/antigravity, and any" >&2 + echo "[agy] 'Added by Antigravity CLI installer' PATH line in ~/.bashrc and ~/.profile" >&2 +} + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + case "$ACTION" in + install) install_agy ;; + update|upgrade) upgrade_agy ;; + uninstall) uninstall_agy ;; + reconcile) install_agy ;; + *) echo "Usage: $0 {install|update|upgrade|uninstall|reconcile}" ; exit 2 ;; + esac +fi diff --git a/tests/test_install_agy.py b/tests/test_install_agy.py new file mode 100644 index 0000000..51ebdc5 --- /dev/null +++ b/tests/test_install_agy.py @@ -0,0 +1,225 @@ +# SPDX-License-Identifier: MIT +# SPDX-FileCopyrightText: Netresearch DTT GmbH +"""Tests for the agy (Google Antigravity CLI) catalog entry and scripts/install_agy.sh.""" + +from __future__ import annotations + +import json +import os +import subprocess +import sys +from pathlib import Path + +import pytest + +skip_on_windows = pytest.mark.skipif(sys.platform == "win32", reason="Shell script tests require POSIX shell") + +PROJECT_ROOT = Path(__file__).parent.parent +SCRIPT = PROJECT_ROOT / "scripts" / "install_agy.sh" + +# The hand-over at the end of https://antigravity.google/cli/install.sh, +# copied verbatim; the fake binary records the arguments it is called with +FAKE_INSTALLER = """#!/bin/bash +set -euo pipefail +CUSTOM_DIR="" +BINARY_PATH="$HOME/.local/bin/agy" +mkdir -p "$HOME/.local/bin" +printf '#!/bin/sh\\necho "$*" >> "$HOME/agy-args"\\necho 1.5.19\\n' > "$BINARY_PATH" +chmod +x "$BINARY_PATH" +if [ -n "$CUSTOM_DIR" ]; then + # Run with custom directory and absorb non-fatal soft warning exits + "$BINARY_PATH" install --dir "$CUSTOM_DIR" || true +else + # Run standard configuration and absorb non-fatal soft warning exits + "$BINARY_PATH" install || true +fi +""" + +CURL_STUB = """#!/usr/bin/env bash +out="" +while [ $# -gt 0 ]; do + if [ "$1" = "-o" ]; then out="$2"; shift; fi + shift +done +cat "$CURL_PAYLOAD" > "$out" +""" + + +def _write_exe(path: Path, body: str) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(body) + path.chmod(0o755) + + +class TestAgyCatalog: + def test_catalog_entry(self): + data = json.loads((PROJECT_ROOT / "catalog" / "agy.json").read_text()) + assert data["name"] == "agy" + assert data["install_method"] == "dedicated_script" + assert data["script"] == "install_agy.sh" + assert data["binary_name"] == "agy" + assert data["skip_upstream"] is True + assert "agy --version" in data["version_command"] + + def test_script_is_executable(self): + assert os.access(SCRIPT, os.X_OK) + + +@skip_on_windows +class TestInstallAgy: + def _run( + self, + home: Path, + action: str, + path_has_bin: bool, + installer: str = FAKE_INSTALLER, + bin_entry: str | None = None, + extra_path: str = "", + env_home: Path | None = None, + cwd: Path | None = None, + ): + stubs = home / "stubs" + _write_exe(stubs / "curl", CURL_STUB) + payload = home / "payload" + payload.write_text(installer) + # A copy without scripts/lib, so refresh_snapshot does not write the + # repository's local_state.json + script = home / "scripts" / "install_agy.sh" + _write_exe(script, SCRIPT.read_text()) + path = f"{stubs}:/usr/bin:/bin" + if extra_path: + path = f"{extra_path}:{path}" + if path_has_bin: + path = f"{bin_entry or str(home) + '/.local/bin'}:{path}" + return subprocess.run( + ["bash", str(script), action], + capture_output=True, + text=True, + timeout=20, + cwd=cwd, + env={"HOME": str(env_home or home), "PATH": path, "CURL_PAYLOAD": str(payload)}, + ) + + def _args(self, home: Path) -> list[str]: + args = home / "agy-args" + return args.read_text().splitlines() if args.exists() else [] + + def test_install_skips_path_line_when_bin_dir_on_path(self, tmp_path: Path): + result = self._run(tmp_path, "install", path_has_bin=True) + assert result.returncode == 0, result.stderr + assert "install --skip-path" in self._args(tmp_path) + + def test_install_keeps_path_line_when_bin_dir_missing_from_path(self, tmp_path: Path): + result = self._run(tmp_path, "install", path_has_bin=False) + assert result.returncode == 0, result.stderr + assert "install" in self._args(tmp_path) + assert "install --skip-path" not in self._args(tmp_path) + + def test_install_skips_path_line_for_trailing_slash_entry(self, tmp_path: Path): + result = self._run(tmp_path, "install", path_has_bin=True, bin_entry=f"{tmp_path}/.local/bin/") + assert result.returncode == 0, result.stderr + assert "install --skip-path" in self._args(tmp_path) + + def test_install_skips_path_line_when_home_is_a_symlink(self, tmp_path: Path): + real = tmp_path / "real" + (real / ".local" / "bin").mkdir(parents=True) + link = tmp_path / "link" + link.symlink_to(real) + # HOME is the symlink, PATH holds the resolved directory + result = self._run(real, "install", path_has_bin=True, env_home=link) + assert result.returncode == 0, result.stderr + assert "install --skip-path" in self._args(real) + + def test_install_ignores_relative_path_entries(self, tmp_path: Path): + # "." resolves to ~/.local/bin only because the script runs from there + (tmp_path / ".local" / "bin").mkdir(parents=True) + result = self._run(tmp_path, "install", path_has_bin=True, bin_entry=".", cwd=tmp_path / ".local" / "bin") + assert result.returncode == 0, result.stderr + assert "install --skip-path" not in self._args(tmp_path) + + def test_install_replaces_dangling_symlink(self, tmp_path: Path): + binary = tmp_path / ".local" / "bin" / "agy" + binary.parent.mkdir(parents=True) + binary.symlink_to(tmp_path / "gone") + result = self._run(tmp_path, "install", path_has_bin=True) + assert result.returncode == 0, result.stderr + assert not binary.is_symlink() + assert "install --skip-path" in self._args(tmp_path) + + def test_install_warns_when_installer_layout_changed(self, tmp_path: Path): + changed = FAKE_INSTALLER.replace('"$BINARY_PATH" install || true', '"$BINARY_PATH" setup || true') + result = self._run(tmp_path, "install", path_has_bin=True, installer=changed) + assert result.returncode == 0, result.stderr + assert "installer layout changed" in result.stderr + assert self._args(tmp_path)[0] == "setup" + + def test_install_leaves_existing_binary_alone(self, tmp_path: Path): + _write_exe(tmp_path / ".local" / "bin" / "agy", '#!/bin/sh\necho "$*" >> "$HOME/agy-args"\n') + result = self._run(tmp_path, "install", path_has_bin=True) + assert result.returncode == 0, result.stderr + assert "Already installed" in result.stderr + assert not [a for a in self._args(tmp_path) if a.startswith("install")] + + def test_install_leaves_agy_elsewhere_on_path_alone(self, tmp_path: Path): + _write_exe(tmp_path / "opt" / "agy", '#!/bin/sh\necho "$*" >> "$HOME/agy-args"\n') + result = self._run(tmp_path, "install", path_has_bin=True, extra_path=f"{tmp_path}/opt") + assert result.returncode == 0, result.stderr + assert f"Already installed at {tmp_path}/opt/agy" in result.stderr + assert not (tmp_path / ".local" / "bin" / "agy").exists() + + def test_install_ignores_agy_in_a_virtualenv(self, tmp_path: Path): + _write_exe(tmp_path / "proj" / ".venv" / "bin" / "agy", '#!/bin/sh\necho "$*" >> "$HOME/agy-args"\n') + result = self._run(tmp_path, "install", path_has_bin=True, extra_path=f"{tmp_path}/proj/.venv/bin") + assert result.returncode == 0, result.stderr + assert "install --skip-path" in self._args(tmp_path) + assert (tmp_path / ".local" / "bin" / "agy").exists() + + def test_update_prefers_the_agy_on_path(self, tmp_path: Path): + # ~/.local/bin is not on PATH; the copy on PATH is the one a plain agy runs + _write_exe(tmp_path / ".local" / "bin" / "agy", '#!/bin/sh\necho "local $*" >> "$HOME/agy-args"\n') + _write_exe(tmp_path / "opt" / "agy", '#!/bin/sh\necho "opt $*" >> "$HOME/agy-args"\n') + result = self._run(tmp_path, "update", path_has_bin=False, extra_path=f"{tmp_path}/opt") + assert result.returncode == 0, result.stderr + assert "opt update" in self._args(tmp_path) + assert "local update" not in self._args(tmp_path) + + def test_update_uses_agy_elsewhere_on_path(self, tmp_path: Path): + _write_exe(tmp_path / "opt" / "agy", '#!/bin/sh\necho "$*" >> "$HOME/agy-args"\n') + result = self._run(tmp_path, "update", path_has_bin=True, extra_path=f"{tmp_path}/opt") + assert result.returncode == 0, result.stderr + assert "update" in self._args(tmp_path) + assert not (tmp_path / ".local" / "bin" / "agy").exists() + + def test_update_reports_failure(self, tmp_path: Path): + _write_exe(tmp_path / ".local" / "bin" / "agy", '#!/bin/sh\n[ "$1" = update ] && exit 3\nexit 0\n') + result = self._run(tmp_path, "update", path_has_bin=True) + assert result.returncode == 1 + assert "update' failed" in result.stderr + + def test_update_runs_agy_update(self, tmp_path: Path): + _write_exe(tmp_path / ".local" / "bin" / "agy", '#!/bin/sh\necho "$*" >> "$HOME/agy-args"\n') + result = self._run(tmp_path, "update", path_has_bin=True) + assert result.returncode == 0, result.stderr + assert "update" in self._args(tmp_path) + + def test_uninstall_removes_binary(self, tmp_path: Path): + binary = tmp_path / ".local" / "bin" / "agy" + _write_exe(binary, "#!/bin/sh\n") + result = self._run(tmp_path, "uninstall", path_has_bin=True) + assert result.returncode == 0, result.stderr + assert not binary.exists() + + def test_uninstall_names_agy_installed_elsewhere(self, tmp_path: Path): + _write_exe(tmp_path / "opt" / "agy", "#!/bin/sh\n") + result = self._run(tmp_path, "uninstall", path_has_bin=True, extra_path=f"{tmp_path}/opt") + assert result.returncode == 0, result.stderr + assert f"{tmp_path}/opt/agy was installed another way" in result.stderr + assert (tmp_path / "opt" / "agy").exists() + + def test_uninstall_removes_dangling_symlink(self, tmp_path: Path): + binary = tmp_path / ".local" / "bin" / "agy" + binary.parent.mkdir(parents=True) + binary.symlink_to(tmp_path / "gone") + result = self._run(tmp_path, "uninstall", path_has_bin=True) + assert result.returncode == 0, result.stderr + assert not binary.is_symlink() diff --git a/tests/test_update_fixes.py b/tests/test_update_fixes.py index 8fae8a7..5eb823f 100644 --- a/tests/test_update_fixes.py +++ b/tests/test_update_fixes.py @@ -636,8 +636,9 @@ def test_fd_candidates_field_preserved_in_catalog_entry(self): # 13. Dedicated scripts: uninstall handler contract (Issue #36) # =========================================================================== -# All 14 dedicated scripts from the catalog +# Dedicated scripts from the catalog DEDICATED_SCRIPTS = [ + "agy", "claude", "composer", "docker", @@ -657,7 +658,7 @@ def test_fd_candidates_field_preserved_in_catalog_entry(self): @skip_on_windows class TestDedicatedScriptUninstallHandler: - """Tests that all 14 dedicated scripts handle the uninstall action (Issue #36).""" + """Tests that the listed dedicated scripts handle the uninstall action (Issue #36).""" @pytest.mark.parametrize("catalog_name", DEDICATED_SCRIPTS) def test_dedicated_script_handles_uninstall_action(self, catalog_name):