diff --git a/.claude/skills/run-tests/SKILL.md b/.claude/skills/run-tests/SKILL.md index f185c927..946e871e 100644 --- a/.claude/skills/run-tests/SKILL.md +++ b/.claude/skills/run-tests/SKILL.md @@ -8,8 +8,11 @@ allowed-tools: - Bash(python -m pytest *) - Bash(python -c *) - Bash(python --version *) - - Bash(git rev-parse *) + - Bash(UV_PROJECT_ENVIRONMENT=py* uv run python *) + - Bash(UV_PROJECT_ENVIRONMENT=py* uv run pytest *) - Bash(UV_PROJECT_ENVIRONMENT=py* uv sync *) + - Bash(UV_PROJECT_ENVIRONMENT=py* uv pip show *) + - Bash(git rev-parse *) - Bash(ls *) - Bash(cat *) - Bash(jq * .pytest_cache/*) @@ -17,6 +20,7 @@ allowed-tools: - Grep - Glob - Task + - AskUserQuestion --- Run the `tractor` test suite using `pytest`. Follow this @@ -91,41 +95,104 @@ python -m pytest tests/ -x --tb=short --no-header --tpt-proto uds python -m pytest tests/ -x --tb=short --no-header -k "cancel and not slow" ``` -## 3. Pre-flight checks (before running tests) +## 3. Pre-flight: venv detection (MANDATORY) -### Worktree venv detection +**Always verify a `uv` venv is active before running +`python` or `pytest`.** This project uses +`UV_PROJECT_ENVIRONMENT=py` naming (e.g. +`py313`) — never `.venv`. -If running inside a git worktree (`git rev-parse ---git-common-dir` differs from `--git-dir`), verify -the Python being used is from the **worktree's own -venv**, not the main repo's. Check: +### Step 1: detect active venv + +Run this check first: + +```sh +python -c " +import sys, os +venv = os.environ.get('VIRTUAL_ENV', '') +prefix = sys.prefix +print(f'VIRTUAL_ENV={venv}') +print(f'sys.prefix={prefix}') +print(f'executable={sys.executable}') +" +``` + +### Step 2: interpret results + +**Case A — venv is active** (`VIRTUAL_ENV` is set +and points to a `py/` dir under the project +root or worktree): + +Use bare `python` / `python -m pytest` for all +commands. This is the normal, fast path. + +**Case B — no venv active** (`VIRTUAL_ENV` is empty +or `sys.prefix` points to a system Python): + +Use `AskUserQuestion` to ask the user: + +> "No uv venv is active. Should I activate one +> via `UV_PROJECT_ENVIRONMENT=py uv sync`, +> or would you prefer to activate your shell venv +> first?" + +Options: +1. **"Create/sync venv"** — run + `UV_PROJECT_ENVIRONMENT=py uv sync` where + `` is detected from `python --version` + (e.g. `313` for 3.13). Then use + `py/bin/python` for all subsequent + commands in this session. +2. **"I'll activate it myself"** — stop and let the + user `source py/bin/activate` or similar. + +**Case C — inside a git worktree** (`git rev-parse +--git-common-dir` differs from `--git-dir`): + +Verify Python resolves from the **worktree's own +venv**, not the main repo's: ```sh python -c "import tractor; print(tractor.__file__)" ``` -If the path points outside the worktree (e.g. to -the main repo), set up a local venv first: +If the path points outside the worktree, create a +worktree-local venv: ```sh UV_PROJECT_ENVIRONMENT=py uv sync ``` -where `` matches the active cpython minor -version (detect via `python --version`, e.g. -`py313` for 3.13, `py314` for 3.14). Then use -`py/bin/python` for all subsequent commands. +Then use `py/bin/python` for all commands. -**Why this matters**: without a worktree-local venv, -subprocesses spawned by tractor resolve modules from -the main repo's editable install, causing spurious -`AttributeError` / `ModuleNotFoundError` for code -that only exists on the worktree's branch. +**Why this matters**: without the correct venv, +subprocesses spawned by tractor resolve modules +from the wrong editable install, causing spurious +`AttributeError` / `ModuleNotFoundError`. -### Import + collection checks +### Fallback: `uv run` -Always run these, especially after refactors or -module moves — they catch import errors instantly: +If the user can't or won't activate a venv, all +`python` and `pytest` commands can be prefixed +with `UV_PROJECT_ENVIRONMENT=py uv run`: + +```sh +# instead of: python -m pytest tests/ -x +UV_PROJECT_ENVIRONMENT=py313 uv run pytest tests/ -x + +# instead of: python -c 'import tractor' +UV_PROJECT_ENVIRONMENT=py313 uv run python -c 'import tractor' +``` + +`uv run` auto-discovers the project and venv, +but is slower than a pre-activated venv due to +lock-file resolution on each invocation. Prefer +activating the venv when possible. + +### Step 3: import + collection checks + +After venv is confirmed, always run these +(especially after refactors or module moves): ```sh # 1. package import smoke check