A web change is a FastAPI route in packages/studyloop/src/studyloop/web/routes/, registered in
packages/studyloop/src/studyloop/web/app.py, and an Alpine component in
packages/studyloop/src/studyloop/web/static/ that calls it — Alpine, HTMX and plain browser
JavaScript, not React (F12). It is proved by a TestClient test, a node --test unit test for
the component, and one Playwright journey in packages/studyloop/tests/e2e/.
- Start the app you will walk:
uv run studyloop webserveshttp://127.0.0.1:8567(the port is--port; it prints a sign-in address with a token, open that;--bind ADDRESSalso serves one other address of the machine behind Basic auth,--lanis deprecated). Then add the route module andinclude_routerit inweb/app.py. - Add or extend a component factory under
static/js/components/and bind it inindex.html. - Write the
TestClienttest and the component'snode --testfile. - Write one Playwright journey against the hermetic world in
tests/e2e/. - Run
just test-web,just test-jsand the coverage gate below.
- Routes: one
APIRouterper module inpackages/studyloop/src/studyloop/web/routes/. The factorycreate_app()inpackages/studyloop/src/studyloop/web/app.pyimports each module and callsapp.include_router(<module>.router, prefix="/api"); a developer-preview router (exercises) is included only when the server was started withstudyloop web --dev. - UI:
packages/studyloop/src/studyloop/web/static/index.htmlis the one page. Component logic is a factory per file inpackages/studyloop/src/studyloop/web/static/js/components/, imported bypackages/studyloop/src/studyloop/web/static/js/main.jsand assigned towindow, because Alpine evaluatesx-data="todayPanel()"in global scope (the header comment ofmain.jssays why factories, not classes). Pure helpers live inpackages/studyloop/src/studyloop/web/static/js/lib/. Vendored Alpine and HTMX are underpackages/studyloop/src/studyloop/web/static/vendor/; there is no bundler and no build step. - Tests:
packages/studyloop/tests/test_web_*.py(in-processTestClient),packages/studyloop/tests/js/*.test.js(Node's runner) andpackages/studyloop/tests/e2e/(a real server in a subprocess, driven by Playwright).
Read this slice top to bottom; every file is small enough to hold in your head.
- Route:
packages/studyloop/src/studyloop/web/routes/now.py(29 lines) — oneGET /nowwith validated query parameters, returning the same contract asstudyloop now --json. - Registration: the
app.include_router(now.router, prefix="/api")line inpackages/studyloop/src/studyloop/web/app.py. - UI:
packages/studyloop/src/studyloop/web/static/js/components/today-panel.jsfetches/api/nowin itsinit(); the markup binds it withx-data="todayPanel()"inpackages/studyloop/src/studyloop/web/static/index.html. - Route test:
packages/studyloop/tests/test_web_now.py(46 lines) — patches the engine the route calls, buildscreate_app(study_dirs=[]), asserts status and payload keys. - Component test:
packages/studyloop/tests/js/today-panel.test.js— stubsfetchby URL and proves the factory without a DOM.
uv run --group dev pytest packages/studyloop/tests/test_web_now.py -qTwo layers, both already shown in the testing cookbook:
- The
TestClientshape is the API template: a synthetic course directory undertmp_path, never the learner's. Assert the refusal status and the absence of a side effect for an invalid request. - The browser journey is
one real learner journey. Start
from
packages/studyloop/tests/e2e/test_contributor_browser_example.py:build_test_world()andstart_server()frompackages/studyloop/tests/e2e/_env.pygive you an isolated HOME, config, database and vault plus a real server on a port unique to your module; attachConsoleWatchbefore navigating and calldiagon failure.
just test-web
just test-js
uv run --group dev pytest packages/studyloop/tests/test_e2e_coverage_gate.py -q -k routejust test-web runs a fixed list of test_web_*.py files named in Justfile; a new file is not
in that list until you add it, so run yours focused as above and extend the list in the same pull
request. The default suite (just test) collects it regardless. just test-js runs
node --test packages/studyloop/tests/js/*.test.js (pass the glob, not the directory). Both are
in just preflight (F7).
The coverage gate reads the running app's route table and fails if a route has no test, or no
test that exercises a real server — which only a module under packages/studyloop/tests/e2e/ or
a browser test is. Skipped and xfailing tests do not count; a waiver needs a written reason.
just e2e is the full Playwright suite (about eight minutes). It is a release gate run by the
maintainer, one run per machine: the recipe takes the lock /tmp/studyloop-e2e.lock and waits
for any other run (F7). The default pytest selection deselects e2e (F7), so a green default
run says nothing about your journey; run it focused with the cookbook's just e2e <file> form
once, on your own machine, and say so in the pull request.
- Query and body parameters are validated in the route signature (patterns, bounds), and the handler calls a service — it does not open the database or read config itself.
- The route is registered with the
/apiprefix and appears increate_app(), not in a side-effecting import. - The component is a factory with no DOM access at construction, so
node --testcan load it;fetchandwindoware touched only inside methods. - Locators in the journey are role, label or stable id, with Playwright
expectdoing the waiting — nosleep, nonth(3), no JavaScript that changes state instead of clicking. - A refused request is asserted twice: the status, and that nothing was written.