Repository navigation
Conversation
…t; document symmetric npx remove (#121) Extends `tj uninstall`'s existing --remove-package opt-in (#430) to make `npx tokenjam uninstall` a complete, symmetric counterpart to `npx tokenjam onboard`: detect uv-tool installs (not just pipx/pip) and auto-run the matching removal command, and detect ephemeral runners (uvx/pipx run) to make --purge a safe no-op with an explanation instead of guessing at a removal command that doesn't apply. --purge is added as an alias for --remove-package so existing scripts/tests keep working. Co-Authored-By: Claude <[email protected]>
|
| Filename | Overview |
|---|---|
| tokenjam/cli/cmd_uninstall.py | Adds _installed_via_uv_tool, _is_ephemeral_runner, --purge alias, and shared _run_auto_uninstall helper. Logic is sound except _is_ephemeral_runner uses a broad /uv/ substring that matches uv-managed Python runtimes as well as ephemeral uvx venvs, causing --purge to be a false no-op for pip installs into uv Python. |
| tests/integration/test_cli_uninstall.py | Four new integration tests covering uv-tool removal, uv-tool reinstall hint, ephemeral no-op, and ephemeral prompt suppression. Tests are well-structured but test_remove_package_flag_non_pipx_prints_command lacks explicit mocks for _installed_via_uv_tool and _is_ephemeral_runner, coupling it to the test runner's Python path. |
| tests/unit/test_uninstall_runner_detect.py | New unit tests covering all three detection functions against empirically verified path strings for pipx venv, uv tool venv, plain pip, uvx cache, and pipx run cache. Coverage is thorough and tests are self-contained. |
| docs/claude-code-integration.md | Documents install/remove as a symmetric pair with --purge behavior for each runner type; content is accurate and consistent with the implementation. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["tj uninstall [--purge] [--yes]"] --> B[Clean data/config/daemon/MCP]
B --> C{_is_ephemeral_runner?}
C -- Yes --> D["Print: nothing persistent to remove"]
D --> E{--purge passed?}
E -- Yes --> F["Print: --purge is a no-op here"]
E -- No --> G[return]
F --> G
C -- No --> H["Print: package still installed"]
H --> I{--purge passed?}
I -- Yes --> J[do_remove = True]
I -- No --> K{--yes passed?}
K -- Yes --> L[do_remove = False]
K -- No --> M["Prompt user"]
M --> N{User confirms?}
N -- Yes --> J
N -- No --> L
J --> O[_remove_package]
O --> P{_installed_via_pipx AND pipx on PATH?}
P -- Yes --> Q["_run_auto_uninstall pipx"]
P -- No --> R{_installed_via_uv_tool AND uv on PATH?}
R -- Yes --> S["_run_auto_uninstall uv tool"]
R -- No --> T["Print manual command"]
L --> U["Print two-step reinstall hint"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["tj uninstall [--purge] [--yes]"] --> B[Clean data/config/daemon/MCP]
B --> C{_is_ephemeral_runner?}
C -- Yes --> D["Print: nothing persistent to remove"]
D --> E{--purge passed?}
E -- Yes --> F["Print: --purge is a no-op here"]
E -- No --> G[return]
F --> G
C -- No --> H["Print: package still installed"]
H --> I{--purge passed?}
I -- Yes --> J[do_remove = True]
I -- No --> K{--yes passed?}
K -- Yes --> L[do_remove = False]
K -- No --> M["Prompt user"]
M --> N{User confirms?}
N -- Yes --> J
N -- No --> L
J --> O[_remove_package]
O --> P{_installed_via_pipx AND pipx on PATH?}
P -- Yes --> Q["_run_auto_uninstall pipx"]
P -- No --> R{_installed_via_uv_tool AND uv on PATH?}
R -- Yes --> S["_run_auto_uninstall uv tool"]
R -- No --> T["Print manual command"]
L --> U["Print two-step reinstall hint"]
Comments Outside Diff (1)
-
tests/integration/test_cli_uninstall.py, line 89-99 (link)Incomplete mocking leaves test coupled to test-runner's Python path
test_remove_package_flag_non_pipx_prints_commandpatches_installed_via_pipxbut not_installed_via_uv_toolor_is_ephemeral_runner. The_isolatefixture'sshutil.which → Nonemask prevents an auto-run, but ifsys.executableduring the test happens to contain/uv/(e.g. a CI environment running under uvx or a uv-Python path),_is_ephemeral_runner()would returnTrueand the command would hit the early-return branch instead of reaching_remove_package— causing the expected"not a pipx- or uv-tool-managed venv"assertion to fail. Addingpatch.object(uninstall_mod, "_installed_via_uv_tool", return_value=False)andpatch.object(uninstall_mod, "_is_ephemeral_runner", return_value=False)would make the test fully hermetic.Prompt To Fix With AI
This is a comment left during a code review. Path: tests/integration/test_cli_uninstall.py Line: 89-99 Comment: **Incomplete mocking leaves test coupled to test-runner's Python path** `test_remove_package_flag_non_pipx_prints_command` patches `_installed_via_pipx` but not `_installed_via_uv_tool` or `_is_ephemeral_runner`. The `_isolate` fixture's `shutil.which → None` mask prevents an auto-run, but if `sys.executable` during the test happens to contain `/uv/` (e.g. a CI environment running under uvx or a uv-Python path), `_is_ephemeral_runner()` would return `True` and the command would hit the early-return branch instead of reaching `_remove_package` — causing the expected `"not a pipx- or uv-tool-managed venv"` assertion to fail. Adding `patch.object(uninstall_mod, "_installed_via_uv_tool", return_value=False)` and `patch.object(uninstall_mod, "_is_ephemeral_runner", return_value=False)` would make the test fully hermetic. How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
tokenjam/cli/cmd_uninstall.py:47-48
**`/uv/` path match is too broad — falsely ephemeral on uv-managed Python**
`"/uv/" in exe` will match any path component literally named `uv`, including uv's own Python runtime installations (`~/.local/share/uv/python/cpython-3.12.0-linux-x86_64/bin/python3`). A user who installed tokenjam with `pip install tokenjam` using a uv-managed Python (not a uv tool or uvx venv) would hit this branch and see "nothing persistent to remove; --purge is a no-op here" — silently skipping a real package removal.
Per the docstring, the empirically verified path for `uvx`/`uv tool run` ephemeral venvs always contains `archive-v0`. Tightening the check to `"/uv/archive-v0/" in exe` avoids the false positive for uv-managed Python while still catching all current ephemeral uvx venvs.
```suggestion
exe = sys.executable.replace("\\", "/")
return "/uv/archive-v0/" in exe or "/pipx/.cache/" in exe
```
### Issue 2 of 2
tests/integration/test_cli_uninstall.py:89-99
**Incomplete mocking leaves test coupled to test-runner's Python path**
`test_remove_package_flag_non_pipx_prints_command` patches `_installed_via_pipx` but not `_installed_via_uv_tool` or `_is_ephemeral_runner`. The `_isolate` fixture's `shutil.which → None` mask prevents an auto-run, but if `sys.executable` during the test happens to contain `/uv/` (e.g. a CI environment running under uvx or a uv-Python path), `_is_ephemeral_runner()` would return `True` and the command would hit the early-return branch instead of reaching `_remove_package` — causing the expected `"not a pipx- or uv-tool-managed venv"` assertion to fail. Adding `patch.object(uninstall_mod, "_installed_via_uv_tool", return_value=False)` and `patch.object(uninstall_mod, "_is_ephemeral_runner", return_value=False)` would make the test fully hermetic.
Reviews (1): Last reviewed commit: "feat(uninstall): consented --purge packa..." | Re-trigger Greptile
| exe = sys.executable.replace("\\", "/") | ||
| return "/uv/" in exe or "/pipx/.cache/" in exe |
There was a problem hiding this comment.
/uv/ path match is too broad — falsely ephemeral on uv-managed Python
"/uv/" in exe will match any path component literally named uv, including uv's own Python runtime installations (~/.local/share/uv/python/cpython-3.12.0-linux-x86_64/bin/python3). A user who installed tokenjam with pip install tokenjam using a uv-managed Python (not a uv tool or uvx venv) would hit this branch and see "nothing persistent to remove; --purge is a no-op here" — silently skipping a real package removal.
Per the docstring, the empirically verified path for uvx/uv tool run ephemeral venvs always contains archive-v0. Tightening the check to "/uv/archive-v0/" in exe avoids the false positive for uv-managed Python while still catching all current ephemeral uvx venvs.
| exe = sys.executable.replace("\\", "/") | |
| return "/uv/" in exe or "/pipx/.cache/" in exe | |
| exe = sys.executable.replace("\\", "/") | |
| return "/uv/archive-v0/" in exe or "/pipx/.cache/" in exe |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/cli/cmd_uninstall.py
Line: 47-48
Comment:
**`/uv/` path match is too broad — falsely ephemeral on uv-managed Python**
`"/uv/" in exe` will match any path component literally named `uv`, including uv's own Python runtime installations (`~/.local/share/uv/python/cpython-3.12.0-linux-x86_64/bin/python3`). A user who installed tokenjam with `pip install tokenjam` using a uv-managed Python (not a uv tool or uvx venv) would hit this branch and see "nothing persistent to remove; --purge is a no-op here" — silently skipping a real package removal.
Per the docstring, the empirically verified path for `uvx`/`uv tool run` ephemeral venvs always contains `archive-v0`. Tightening the check to `"/uv/archive-v0/" in exe` avoids the false positive for uv-managed Python while still catching all current ephemeral uvx venvs.
```suggestion
exe = sys.executable.replace("\\", "/")
return "/uv/archive-v0/" in exe or "/pipx/.cache/" in exe
```
How can I resolve this? If you propose a fix, please make it concise.
Summary
tj uninstall's existing opt-in package removal (--remove-package, Fix: clarify uninstall/reinstall two-step + optional package removal #430) with a--purgealias and full runner detection, makingnpx tokenjam uninstall [--purge]the complete, symmetric counterpart tonpx tokenjam onboard.uv tool installdetection alongside the existing pipx detection —--purgenow auto-runsuv tool uninstall tokenjamfor uv-tool installs, and the default (non-purge) closing hint prints the exact matching command (pipx uninstall/uv tool uninstall/pip uninstall) instead of only ever guessing pipx-or-pip._is_ephemeral_runner()detection (verified empirically against realuv/pipxinstalls — see code comments for the exact paths) so an ephemeral invocation (uvx/pipx run, including via thenpx tokenjamwrapper's runner fallback) makes--purgea safe no-op with an explanation, rather than guessing at a removal command for a package that was never persistently installed.docs/claude-code-integration.md.Resolves #121.
Test plan
python -m pytest tests/unit/ -k "uninstall or purge or runner" -q→ 20 passedpython -m pytest tests/unit/ tests/integration/ -q(full suite) → 2048 passed, 1 skipped (pre-existing)ruff checkclean on all touched/new files--purgeno-op pathMerge order: CC install/remove cluster — merge #117 → #118 → #121; this is #121, MERGE LAST (depends on #117 + #118 for a fully-clean uninstall).
🤖 Generated with Claude Code