|
| 1 | +# Lane W — wave 2 implementation brief (W1–W5) |
| 2 | + |
| 3 | +Read first: `briefs/00-common.md`, `briefs/W-web-labs.md` (owned globs, forbidden list — still |
| 4 | +binding, with the two additions below), `council/2026-10-04-m0-arbitration.md` **Q2** (the route |
| 5 | +ruling you implement), `specs/web-ui/spec.md` and `specs/session-transports/spec.md` (this |
| 6 | +change's deltas), `design.md` §2 and §7. Lanes S, C, R, T are **merged on `main`**: start with |
| 7 | +`git merge main` in your worktree (`/Users/ataylor/code/personal/tools/studyloop-wt/module-web-labs`, |
| 8 | +branch `feat/module-web-labs`, currently at the wave-0 base), prove the import path |
| 9 | +(`studyloop.__file__` under the worktree), then work red-first exactly as the other lanes did: |
| 10 | +failing test → `evidence/W/<name>.red.txt` (command on line 1, sha + UTC) → implementation → |
| 11 | +`.green.txt`; pre-commit through `git commit`, never `--no-verify`/`SKIP=`; nothing pushed; nothing |
| 12 | +written to the main checkout. |
| 13 | + |
| 14 | +## The code you build on (all on `main`; read, do not edit) |
| 15 | + |
| 16 | +- **Hop (lane R)** `modules/hop.py`: `ROUTE = "/api/modules/practice-check"`, `TOKEN_HEADER = |
| 17 | + "X-StudyLoop-Session-Token"`, state-file keys `TOKEN_KEY = "practice_check_token"`, `PORT_KEY = |
| 18 | + "web_port"`, `SESSION_KEY = "study_session_id"`; the body is exactly `hop.ENVELOPE_FIELDS` |
| 19 | + (`check_result_fields`); `_outcome_from_response` maps any non-2xx to `error "http <code>"`, so |
| 20 | + the server's status codes are the contract the learner sees. Read lines 85–100 and 254–300. |
| 21 | +- **Envelope (lane T)** `session/module_delivery.py`: `validate_envelope(mapping) -> |
| 22 | + PracticeCheckEnvelope` (`extra=forbid`; raises `EnvelopeValidationError` naming fields, never |
| 23 | + values), `async deliver_to_active_session(envelope) -> DeliveryOutcome` with `status` one of |
| 24 | + `delivered | no_active_session | transport_closed | timed_out | unsupported_framing | error` |
| 25 | + and a `reason`. The server never renders text itself for the wire — T renders inside `deliver`. |
| 26 | +- **Store / manifest (lane C)** `modules/store.py` (`load_lockfile()`, `LockEntry`, |
| 27 | + `snapshot_dir(entry)`), `modules/manifest.py` (`Manifest.prerequisites[].id`), decks under |
| 28 | + `<snapshot>/decks/*.json` (`PracticeDeck` from lane S); fixture module |
| 29 | + `tests/fixtures/modules/valid-scaffold` and `tests/fixtures/modules/runner-offline`. |
| 30 | +- **Runner (lane R)** `cli/_drill.py` carries `prerequisites: tuple[str, ...] = ()` and a |
| 31 | + `TODO(module-contract-v1)` at ~line 239: wire `Manifest.prerequisites[].id` from the located |
| 32 | + module's `module.yaml` into it and delete the TODO (owned-glob addition #1: that block only). |
| 33 | +- **Session state** `session_state.py`: `write_session_state(dict)` / `read_session_state()`; |
| 34 | + files are written `0o600` via `_write_file_secure`. `session/orchestrator.py:276-278` writes |
| 35 | + `web_pid`/`web_port` when the web process claims a session — mint the token there (owned-glob |
| 36 | + addition #2: those lines plus a helper beside them). |
| 37 | +- **Seam test** `tests/test_module_lane_seams.py` shows the three lanes' real code together. |
| 38 | + |
| 39 | +## Tasks |
| 40 | + |
| 41 | +**W1 (red-only commit).** `tests/test_web_modules.py` (`TestClient`): session options carry no |
| 42 | +Labs entry with an empty lockfile and a Labs entry listing deck/task ids and prompts after an |
| 43 | +install (use `ModuleStore(tmp).add(valid-scaffold)` with `store.default_store_root` patched); |
| 44 | +`POST /api/modules/practice-check` without the header → 401, with a wrong token → 403, from a |
| 45 | +non-loopback client address → 403, a body with an extra field → 422 naming the field, a valid |
| 46 | +body → 200 with `{"status": <DeliveryStatus>, "reason": ...}` (with no active session the status |
| 47 | +is `no_active_session`), the same `(attempt_id, phase)` again → 409, a sixth envelope within a |
| 48 | +minute for one session → 429; `tests/js/module-labs.test.js` for the component. Verify every test |
| 49 | +red (no route, no component), keep it red. |
| 50 | + |
| 51 | +**W2.** `web/routes/modules.py`: the route per M0 Q2 — loopback check on `request.client.host` |
| 52 | +(not a header); token compared in constant time against `practice_check_token` in the session |
| 53 | +state; the session named by the token is the active one or 403; replay dedup on `(attempt_id, |
| 54 | +phase)` and the rate limit (one envelope per phase per attempt; burst 5/min per session) in |
| 55 | +process memory keyed by session; `validate_envelope` then `await deliver_to_active_session`; the |
| 56 | +outcome's `status`/`reason` returned as JSON with 200 — a delivery that did not land is a 200 |
| 57 | +whose status says so, because the hop already treats non-2xx as its own error. `GET |
| 58 | +/api/modules/labs` (or the `_options.py` entry) lists installed modules' decks and tasks **by id |
| 59 | +and prompt only — never `hint`, `solution` or `mentorNotes`** (web-ui spec scenario 3). Labs in |
| 60 | +`index.html`/`components.js`/`style.css` + `static/js/labs.js`, hidden when the lockfile is |
| 61 | +empty; start = `POST /api/modules/labs/start` which runs `studyloop drill setup` for the chosen |
| 62 | +drill **inside the one claimed session** (reuse the session's existing subprocess/run machinery — |
| 63 | +read `web/routes/session/` first; no second session, no browser-side execution) and is |
| 64 | +cancellable. W1 tests green; `just test-web`, `just test-js` green. |
| 65 | + |
| 66 | +**W3.** `cli/__init__.py`: add `"module": "studyloop.cli._module:module_group"` and `"drill": |
| 67 | +"studyloop.cli._drill:drill_group"` to the LazyGroup map (Click, not Typer); `web/app.py`: one |
| 68 | +`include_router` line. `_drill.py`: the prerequisites wiring above. Verify `studyloop module |
| 69 | +--help`, `studyloop drill --help`, the API route table, and that `test_module_cli.py`'s |
| 70 | +"root CLI has no `module` command" test is **updated, not deleted** (it now asserts the |
| 71 | +registration). Add a `test_module_lane_seams.py` case: a located module's manifest prerequisites |
| 72 | +reach `runner.resolve_prerequisites` (fake tool on a scratch PATH). |
| 73 | + |
| 74 | +**W4.** `tests/e2e/test_module_labs_journey.py` (Playwright, existing `just e2e` tier, hermetic |
| 75 | +world with a fake agent — read `tests/e2e/_env.py` and `test_body_double_journey.py` for the |
| 76 | +pattern): list → start inside the claimed session → the mentor pane shows the delivered block |
| 77 | +(`<<<studyloop:practice_check` … `<<<end studyloop:practice_check>>>`, every tail line prefixed |
| 78 | +`| `) → cancel → reload re-attaches → keyboard (Tab/Shift-Tab/Escape) → `module remove` → Labs |
| 79 | +gone; explicit module timeout. `just e2e` takes the machine lock: run it alone, once, and keep the |
| 80 | +transcript; it is NOT part of `just preflight`. |
| 81 | + |
| 82 | +**W5.** Docs lease is free (contributor guide merged at 6a3f45d2; lane S3 — `docs/module-contract.md` |
| 83 | +— is unstarted, so you own it too: write that page from the spec deltas and `module new --help`, |
| 84 | +with the "Adding a module" checklist, under the contributor-guide rules in |
| 85 | +`docs/contributor-documentation.md`; the drift test `test_contributor_guide_drift.py` pins every |
| 86 | +command and path you show — run it). `CHANGELOG.md` under `[Unreleased]` → Added, one learner-facing |
| 87 | +bullet per user-visible change (module add/check/new, drill, Labs). `acceptance/test_module_kdrill_live.py` |
| 88 | +gated `STUDYLOOP_ACC=1 STUDYLOOP_LIVE=1` with a sentinel-cluster assertion, skipping cleanly |
| 89 | +without the env vars; UAT rubric for Personas A and B under `acceptance/uat/` (design.md §6). |
| 90 | +`just docs` strict green. |
| 91 | + |
| 92 | +## Gate before you report |
| 93 | + |
| 94 | +`env -u VIRTUAL_ENV just test-web && just test-js`; `uv run pytest packages/studyloop/tests/test_web_modules.py |
| 95 | +packages/studyloop/tests/test_module_cli.py packages/studyloop/tests/test_module_lane_seams.py |
| 96 | +packages/studyloop/tests/test_contributor_guide_drift.py packages/studyloop/tests/test_docs_drift.py |
| 97 | +-q -p no:cacheprovider`; `just lint && just typecheck`; `just docs`; `just e2e` once for W4. The |
| 98 | +coordinator runs the full preflight at merge. Tick W1–W5 in `tasks.md` (that file only). |
| 99 | + |
| 100 | +## Report (≤ 900 words) |
| 101 | + |
| 102 | +Verbatim commit log; red/green transcript list; the route's status-code table as implemented; |
| 103 | +the rendered Labs list for `valid-scaffold` (ids and prompts only); the e2e transcript summary |
| 104 | +line; every contract gap you decided rather than guessed, as the other lanes did. |
0 commit comments