diff --git a/NEXT_SESSION_PROMPT.md b/NEXT_SESSION_PROMPT.md index 416aff36..c7608c2a 100644 --- a/NEXT_SESSION_PROMPT.md +++ b/NEXT_SESSION_PROMPT.md @@ -1,193 +1,236 @@ -# Next session: three explicit asks, then keep splitting +# Next session: backfill monitor coverage, then keep splitting at 100% > **Paste this whole file into a fresh Claude session opened in `~/testsAndMisc`.** > It is self-contained. Do not go looking for the previous session's context. -Over-cap: **37 → 24** (20 shell, 2 kotlin, 1 dart, 1 markdown — this file). -17 commits pushed. **Python is done**: every `.py` is under the cap at 100% -line+branch coverage where the gate measures it. +Over-cap: **22** (18 shell, 2 kotlin, 1 dart, 1 markdown — this file). +Working tree clean, `main` in sync with origin. -The user has given three direct instructions. Do them in this order, each as -its own commit. They are already decided — do **not** re-litigate them. +Two standing decisions from the user, already made — do **not** re-litigate: + +1. **100% line coverage, always.** Every shell file you touch gets there. Not + "100% where cheap"; 100%. +2. **Split blind where there is no device.** Do not deploy to the phone, do not + ask to. Prove splits with tests, hashes and real runs instead. --- -## 1. Fix the `_VENDOR_KW` Intel bug +## 0. Read this first: coverage is measurable now -`python_pkg/vscode_optimizer/_hardware.py:22`: +`kcov 43` is installed and **works**, which changes what "tested" means here. +Use the wrapper, not raw kcov: -```python -_VENDOR_KW = {"nvidia": "NVIDIA", "amd": "AMD", "ati": "AMD", "intel": "Intel"} +```bash +bash meta/scripts/shell_coverage.sh [min-percent] +# e.g. +bash meta/scripts/shell_coverage.sh phone_focus_mode/lib/tests/test_dns_iptables.sh dns_iptables.sh +# -> dns_iptables.sh: 74/74 lines = 100.00% ``` -`_detect_gpu` does `for kw, vendor in _VENDOR_KW.items(): if kw in low:`. -Every real `lspci` display line contains **"VGA comp*ati*ble controller"**, so -`"ati"` matches unconditionally and `"intel"` is unreachable. **Intel iGPUs are -reported as AMD**, which switches on the GPU-accelerated terminal and AMD-only -Electron flags. This machine is unaffected only because `"nvidia"` is checked -first. +Defaults to a 100% minimum and exits 1 below it, naming the uncovered lines. -**Do:** +Two kcov traps, both of which fail **silently** and both already handled inside +the wrapper — do not go around it: -- Fix it so vendor detection keys on the device description rather than the - whole line — the text after the last `:` is already extracted into - `hw.gpu_model` one line above. Match against that, not `low`. -- Delete the `strict=True` xfail `test_detect_gpu_should_recognise_an_intel_igpu` - in `python_pkg/vscode_optimizer/tests/test_gpu_disk.py` and make it a normal - passing test. **The xfail is `strict=True`, so a fix without removing the - marker fails the suite** — that is deliberate. -- The parametrised `test_detect_gpu_maps_each_vendor_keyword` currently - _characterises_ the bug: two of its cases assert `"AMD"` for an Intel line and - for an unknown vendor. Update both to the correct expectations. -- Verify with a real run: `python3 -m python_pkg.vscode_optimizer --dry-run` - must still detect this machine's RTX 3090 as NVIDIA and propose the same - **18 changes**. Then confirm the repo gate: bare `pytest` (memory-capped) - at 100%. +- It must get the test script **directly**. Handed `bash script.sh` it + instruments the bash binary, finds no shell source, and reports `0/0 = 0.00%`, + which reads exactly like "nothing is covered" rather than "nothing was + measured". +- Per-line detail lives only in `cov.xml`. The `coverage.json` summary has the + percentage and nothing else, so it cannot tell you which lines are missing. -## 2. Split the `phone_focus_mode` scripts anyway +kcov measures **lines, not branches**, so `[ -n "$x" ] && thing` counts as +covered when only one side runs. That is why every new assertion must also be +**mutation-proofed**: break the code under it, confirm the test fails, restore. +That check caught three real defects last session and is not optional. -The user has accepted the deployment risk. **This does not mean skip the copy -lists** — it means proceed with the splits, doing them correctly. +## 1. Backfill `lib/monitor.sh` to 100% — do this first -`deploy.sh` has **two** hardcoded per-file lists and never deploys `lib/`: +The split shipped verbatim-proven and green (9/9), but measuring it afterwards +showed the tests barely touch it: -- an `adb_cmd push "$DEPLOY_DIR/" "/data/local/tmp/focus_stage/"` (~line 381) -- an `adb_root "cp /data/local/tmp/focus_stage/ $REMOTE_DIR/"` (~line 497) +| file | coverage | +| ------------------------------ | --------------------- | +| `lib/monitor.sh` | **44.44%** (48/108) | +| `lib/monitor_checks_policy.sh` | **7.69%** (5/65) | +| `lib/monitor_checks_health.sh` | **0%** — never loaded | -**Every new sibling must be added to BOTH, in the same commit.** Missing the -push leaves the copy pointing at a file that was never staged. Use a **sibling -file** beside the entry script, never a `lib/` member — these scripts source -`"$SCRIPT_DIR/.sh"` and `lib/` does not exist on the phone. +This is pre-existing debt that the split merely made visible; the probes were +untested before too. The user has asked for it closed now. -`tether_enforcer.sh` was done last session and is the worked example — read that -commit before starting. +**The work is an ADB stub layer.** Every `_check_*` probe shells out through +`adb_root_shell`, so reaching them means a fake `adb` that models battery, +storage, pidfiles, the hosts sha, launcher state, the companion package and the +boot script. Budget for roughly four times the size of the `dns_iptables` +harness. -Targets, cheapest first, with what can verify each: +Copy the pattern that already works — `lib/tests/dns_iptables_harness.sh`: -| file | lines | verifiable by | -| -------------------- | ----- | ------------------------------------------------------------------------------------ | -| `dns_enforcer.sh` | 325 | `lib/tests/test_dns_enforcer.sh` — **runnable** | -| `phone_backup.sh` | 333 | no test; not in deploy.sh's lists at all | -| `curfew_enforcer.sh` | 367 | no test | -| `hosts_enforcer.sh` | 421 | no test | -| `lib/monitor.sh` | 449 | `lib/tests/test_monitor.sh` — **runnable**; already a lib, not deployed by deploy.sh | -| `focus_daemon.sh` | 543 | no test | -| `config.sh` | 571 | **`python_pkg/focus_policy/loader.py` parses it** — see below | -| `deploy.sh` | 835 | not deployed itself; entry+`lib/` IS safe here | -| `focus_ctl.sh` | 1091 | no test | +- stage the subject into a `mktemp -d` beside a fake `config.sh`; +- put stubs on `PATH`, with **failure injection** (`_fail_op`) and state + seeding (`_seed_jumps`) so error branches are reachable — that is exactly how + `dns_iptables.sh` got from 91.89% to 100%, since all six missing lines were + error paths; +- run each case as a subprocess via a quoted heredoc, so `$0` resolves to the + staged copy and any `$VAR` reaches the subject unexpanded. -Start with `dns_enforcer.sh` and `lib/monitor.sh`: both have real test scripts, -so you can prove the split the way `tether_enforcer` was proved (run the test -before and after; the count must match exactly). +Keep the harness in its own file. Both test files must stay under 250 lines. -**`config.sh` is special.** `python_pkg/focus_policy/loader.py` is a -mini-interpreter that parses it as the live source of truth. Splitting it breaks -that loader unless the parser follows. `focus_policy` has 100% tests that will -catch it — run them. Plan the two changes together, or do `config.sh` last. +## 2. Then the remaining brief-scoped splits -## 3. Restructure the three parked files +Cheapest first. Each is one commit, each needs 100% on whatever it extracts. -Last session parked these because a verbatim function move cannot get them under -the cap. The user has authorised restructuring. **Restructuring means the -verbatim harness no longer applies, so each one needs a test or a real run -instead** — say plainly which you used. +| file | lines | notes | +| -------------------- | ----- | ---------------------------------------------------------- | +| `phone_backup.sh` | 333 | **PC-side** — bash, absent from `deploy.sh`, no list edits | +| `curfew_enforcer.sh` | 367 | phone; both deploy lists | +| `hosts_enforcer.sh` | 421 | phone; both deploy lists | +| `focus_daemon.sh` | 543 | phone; both deploy lists; heavy device I/O | +| `config.sh` | 571 | **see the warning below** | +| `deploy.sh` | 837 | **must come after every other phone split** | +| `focus_ctl.sh` | 1091 | phone; largest; heavy device I/O | -- **`install_plagiarism_tools.sh` (534, only 3 tiny functions).** ~500 lines of - top-level code. Wrap coherent stages in functions, then move those. This is - the most mechanical of the three; do it first. -- **`libre_translate.sh` (488, 18 funcs).** After the clean seams are taken, - `parse_args` (111 lines), `write_env_file`, `detect_container_user` and `main` - all assign **and** read the same configuration globals. Four attempts were - spent relocating them; that does not work. Restructure `parse_args` — e.g. - split the case body into per-flag helpers, or move the whole config-globals - cluster into one lib that owns both writes and reads. -- **`diagnose_pacman_hook_stall.sh` (493, 15 funcs).** Same shape: `run_one` - writes `LAST_ELAPSED`, `main` reads it. Also emits **SC2153** - (`PACMAN_BIN` vs `PACMAN_PID`) once split — that is a real shellcheck finding - to resolve, not to suppress. +### Ordering constraints — getting these backwards is expensive + +- **`deploy.sh` goes last.** Every enforcer split adds an entry to its two + hardcoded lists. Split `deploy.sh` first and those lists move into a new file, + so the "add to BOTH lists" step then points at a stale location. +- **`config.sh` is paired with `python_pkg/focus_policy/loader.py`.** Two + commits or one, but plan them together. + +### `config.sh`: the safety net the last brief promised does not exist + +The previous brief claimed `focus_policy`'s 100% tests would catch a bad +`config.sh` split. **They will not**, and this was verified: + +- the `pytest with coverage enforcement` hook is `types: [python]`, so a + `config.sh`-only commit runs **no tests at all**; +- `pre-push` `ci-mirror` runs pytest only for _changed packages_, and + `config.sh` is in no package; +- the `focus_policy` tests build **synthetic** `config.sh` fixtures in + `tmp_path` — they never read the real file, so they cannot regress on it. + +Use a parse fingerprint instead. Baseline of the current file: + +``` +1624750c9636492d225b8bb8555f4e2fa75ea64abc670b37c9557b80b9e1883a +``` + +Recompute it after the split with `load_policy(Path("phone_focus_mode/config.sh"))`, +`dataclasses.asdict`, `json.dumps(..., sort_keys=True, default=str)`, sha256. +Same hash = the loader still sees an identical policy. `time` objects are not +JSON-serialisable, hence the `default=`. Also run `pytest python_pkg/focus_policy` +by hand regardless of what the hooks say. + +## 3. Then the three restructures + +Verbatim moves cannot get these under the cap, so the hash tool does **not** +apply. Each needs a real test at 100%. + +- **`install_plagiarism_tools.sh` (534, only 3 tiny functions)** — ~500 lines of + top-level code. Wrap coherent stages in functions first, then move those. Most + mechanical of the three; do it first. Note `verify_shell_split.sh` only hashes + _function bodies_, so it is blind to top-level code — read `git diff` on the + entry script before committing. +- **`libre_translate.sh` (488, 18 funcs)** — the user chose the approach: move + the whole config-globals cluster into **one lib that owns both the writes and + the reads**. Do not try relocating `parse_args` alone; four attempts failed. +- **`diagnose_pacman_hook_stall.sh` (493, 15 funcs)** — `run_one` writes + `LAST_ELAPSED`, `main` reads it. Emits **SC2153** (`PACMAN_BIN` vs + `PACMAN_PID`) once split: a real finding to resolve, never to suppress. + +## 4. Last, and only after the rest + +**`install_leechblock.sh` (485)** and **`block_compulsive_opening.sh` (705)** are +copied to `/usr/local/…`, and `pacman_wrapper.sh:831` prefers the deployed copy +on **every pacman invocation**. Split them naively and every `pacman -S` on this +machine breaks. Teach the installer to deploy the directory first, in its own +commit, re-baseline, then split. + +You cannot run `sudo pacman -S` from the Bash tool — it deadlocks on `db.lck`. +Hand the user a `! sudo pacman -S ` line plus the expected output. --- -## Tooling — use it, don't rebuild it +## Tooling — use it, do not rebuild it -**`meta/scripts/extract_shell_functions.py`** — moves functions into a library. -Walks brace-by-brace and lifts only function blocks. **Never slice by line -range**: these scripts interleave top-level commands between function -definitions, and a range slice sweeps those into the library where they run at -source time and out of order. It refuses to guess when there is no `set -e` -anchor (as in the `#!/system/bin/sh` phone scripts) — place the source line by -hand there, after the existing `. "$SCRIPT_DIR/config.sh"`. +**`meta/scripts/check_file_length.sh --all`** — the 250-line gate. Run it +**before every commit**: a split that fixes one file while pushing its new +library over the cap is a net zero, and that happened twice in an earlier +session. Source extensions only; `third_party/` and `docs/superpowers/` are +excluded. -```bash -python3 meta/scripts/extract_shell_functions.py