diff --git a/ai-note.md b/ai-note.md
index ac9a496..1bd3092 100644
--- a/ai-note.md
+++ b/ai-note.md
@@ -2,20 +2,20 @@
Short working handover for the next model. Keep it short.
-- `TODO.md` (Norwegian) is the requirement specification. Sections 1–18 are the binding spec; sections 19–30 are short summaries of the rounds that are implemented and verified, and section 31 is the round in progress. The full reasoning is in the git history.
+- `TODO.md` (Norwegian) is the requirement specification. Sections 1–18 are the binding spec; sections 19–31 are short summaries of the rounds that are implemented and verified, and section 32 is the round that has not been started. The full reasoning is in the git history.
- The binding rules live in `TODO.md` and `README.md`. This note does not repeat them — it carries the handover, the rules that are easy to get wrong, and the traps that already cost time.
- `HANDOVER.md` was deleted as outdated. Do not recreate it.
## Status
-- **Done and verified:** sections 1–30, and section 18 steps 1–11. Schema version 12. 416 green tests.
-- **Section 30 is done and verified.** The StartOS package lives in this repository beside the application: `startos/`, `Dockerfile`, `.dockerignore`, `Makefile`, `package.json`, `tsconfig.json`, `.prettierrc`, `LICENSE`, `icon.svg`, `instructions.md`, `UPDATING.md`, `AGENTS.md`, `README.md`, and `CLAUDE.md`. It built clean with `make x86` into `vardkey_x86_64.s9pk`, was sideloaded onto a StartOS 0.4.0 box, and runs there: the service shows **Running**, the health check reports **The web interface is ready**, and **Open UI** opens the VardKey web app. Sections 14, 16 and 17 were exercised on that box and are ticked in `TODO.md`.
-- **Next work: section 31 — the eight points before version 1.** **In progress: points 7, 5, 4, 3, 2 and 1 are done.** Point 6 (the installable PWA) has its service worker, its registration and its offline state in place; the manifest, its `` and the two PWA icons wait for the artwork, because the manifest needs a 192 and a 512 px icon. Point 8 (the icon) waits for the same artwork. The plan, the order and the file lists live in `TODO.md` section 31; the state of the round is at the top of that section. Read it there before touching anything.
-- **Two things are still deliberately left in section 30, and both need the user's go-ahead.** Do **not** raise the package version from `0.1.0:0` to `1.0.0:0`, and do **not** draw the real `icon.svg`. Section 31 comes first, and it carries the icon as its eighth point.
-- **A round stops when it is done.** Section 31 is the round. Do not roll into the version bump, into section 18 step 12, or into anything after it.
-- **Verified how:** the automated suite, the user's manual browser testing, and the install and test round on a StartOS 0.4.0 box. The manual tests in section 16 are all run.
+- **Done and verified:** sections 1–31, and section 18 steps 1–11. Schema version 12. 422 green tests.
+- **Section 30 is done and verified.** The StartOS package lives in this repository beside the application: `startos/`, `Dockerfile`, `.dockerignore`, `Makefile`, `package.json`, `tsconfig.json`, `.prettierrc`, `LICENSE`, `icon.svg`, `instructions.md`, `UPDATING.md`, `AGENTS.md`, `README.md`, and `CLAUDE.md`. It built clean with `make x86` into `vardkey_x86_64.s9pk`, was sideloaded onto a StartOS 0.4.0 box, and runs there: the service shows **Running**, the health check reports **The web interface is ready**, and **Open UI** opens the VardKey web app.
+- **Section 31 is done.** All seven of its points are in: the admin login, deleting all data, the dated export name, the address path on the key card, the model/service label, the installable PWA, and the flexible threshold. The schema is 12 and the package version is still `0.1.0:0`.
+- **Next work: section 32 — the icon and version 1. Not started.** It holds the real `icon.svg` and the 192 and 512 px PWA PNGs, both of which need the user's artwork, and the raise from `0.1.0:0` to `1.0.0:0`. **Do not start it, do not draw an icon, and do not raise the version unless the user asks.** Section 18 step 12 waits on the same decision.
+- **A round stops when it is done.** Section 31 is finished; section 32 is a separate round.
+- **Verified how:** the automated suite, the user's manual browser testing, and the install and test round on a StartOS 0.4.0 box.
- **Tests:** the user runs them: `python3 -m unittest discover -s tests`. They run on a Windows copy at `C:\Users\\Downloads\helsesjekk`, so they must pass there as well as on Linux.
-- **Future work, deliberately not built:** nothing is left here. The last item — more than three keys, and another threshold than 2-of-3 — was done in section 31 point 7.
+- **Known gap, not fixed:** `docs/application.md` and `README.md` still describe the API as it was before section 31. They are missing the login/session endpoints, the gating and the CSRF rule, the renamed maintenance command, and the dated export name. Section 31 did not update them.
## Section 30 — the StartOS package
@@ -27,7 +27,7 @@ The decisions are recorded in `TODO.md` section 30; this is what the next model
The application and the package share one repository, at the root. That is a deliberate deviation from the guide's "a package repo is not a fork of the application": the rule assumes a published upstream image or a git submodule, and VardKey has neither. `AGENTS.md` states the deviation so nobody adds an `upstream-project/` submodule to "fix" it.
-The image is built by the root `Dockerfile`, referenced as `dockerBuild: {}` in `startos/manifest/index.ts`, which makes the build context the repository root. **Anything the `Dockerfile` does not `COPY` is not in the image.** In particular `static/` must be copied: `app.py` answers `/health` from code, but every page is read from `ROOT/static`, so an image without it reports a healthy service whose entire UI answers `404`. `maintenance.py` is copied too, for the `Delete history` action. New static files must be added to both the `Dockerfile` and `STATIC_FILES` — section 31 still owes the login page, `session.js`, the manifest, `sw.js` and the PWA icons.
+The image is built by the root `Dockerfile`, referenced as `dockerBuild: {}` in `startos/manifest/index.ts`, which makes the build context the repository root. **Anything the `Dockerfile` does not `COPY` is not in the image.** The modules go in with `COPY *.py ./` and the assets with `COPY static ./static`; `.dockerignore` keeps `tests`, `data`, `node_modules`, `javascript` and the build output out of the context, so the wildcard picks up exactly the application modules. `static/` must be copied: `app.py` answers `/health` from code, but every page is read from `ROOT/static`, so an image without it reports a healthy service whose entire UI answers `404`.
There is no CI. The guide assumes GitHub Actions; this repository is on Gitea, so there are no `.github/workflows/` and there must not be any. The `.s9pk` is built locally with `make`.
@@ -39,7 +39,12 @@ The readiness check is `checkWebUrl` against `http://127.0.0.1:8080/health`, not
### Actions
-`startos/actions/deleteHistory.ts` is the first action, registered through `Actions.of()` in `startos/actions/index.ts`, with its strings in `startos/i18n/dictionaries/`. Section 31 point 1 adds `setAdminPassword.ts` the same way, and its command reaches the container through `maintenance.py`.
+Two actions, both registered through `Actions.of()` in `startos/actions/index.ts`, with their strings in `startos/i18n/dictionaries/`:
+
+- `deleteAllData.ts` (`delete-all-data`) runs `maintenance.py delete-all-data` in a `withTemp` subcontainer, behind a confirmation toggle the handler enforces.
+- `setAdminPassword.ts` (`set-admin-password`) runs `maintenance.py set-admin-password` the same way and shows the generated credentials once.
+
+Both reach the container through `maintenance.py`, so the image has to carry it. The generated password never travels into the container: `maintenance.py` generates it there and prints it, which is the packaging guide's own password-reset pattern.
### Backups
@@ -49,45 +54,23 @@ The readiness check is `checkWebUrl` against `http://127.0.0.1:8080/health`, not
The skeleton files (`package.json`, `tsconfig.json`, `Makefile`, `.prettierrc`, `startos/sdk.ts`, `startos/index.ts`, `startos/i18n/`, `startos/fileModels/.gitkeep`, `assets/.gitkeep`) were written to match the Start9 template rather than generated by `s9pk init-workspace`, because that command was not available in the environment that wrote them. The successful build and install confirm they are equivalent; `@start9labs/start-sdk` is pinned to `3.0.4` and that is the version the `.s9pk` was built with. No reconciliation is outstanding.
-The `icon.svg` in the repository is a minimal placeholder, kept so the build has an icon to pack. Section 30 defers the real one; section 31 point 8 brings it in.
+The `icon.svg` at the repository root is a minimal placeholder, kept so the build has an icon to pack. `static/icon.svg` is the icon the manifest points at. Both are replaced with the real artwork in section 32.
### Documentation layout
-`README.md` is the StartOS package README, with the guide's fixed heading set. The application's own reference — the HTTP API, the alerts table, the schema history — moved to `docs/application.md`, which is what `instructions.md` links to under `## Documentation`. `AGENTS.md` is the repo-specific agent context, and `CLAUDE.md` is the one-line `@AGENTS.md` import. Section 31 changes all of them: new endpoints, a new schema version, and two new actions.
+`README.md` is the StartOS package README, with the guide's fixed heading set. The application's own reference — the HTTP API, the alerts table, the schema history — moved to `docs/application.md`, which is what `instructions.md` links to under `## Documentation`. `AGENTS.md` is the repo-specific agent context, and `CLAUDE.md` is the one-line `@AGENTS.md` import. **Both `README.md` and `docs/application.md` are behind the code** (see the gap under Status).
-## Section 31 — the eight points before version 1
+## Section 31 — the points before version 1 (done)
-Decided 10.10.2026. **In progress.** The plan, the per-point file lists and the tests are in `TODO.md` section 31; this is what is easy to get wrong.
+Decided 10.10.2026, finished after section 30. Seven points, done in the order 7, 5, 4, 3, 2, 1, 6 — the data model first, because everything else builds on it. The icon was split out into section 32.
-### Where the round stands
+What it added, in one place:
-- **Done: points 7, 5, 4, 3, 2 and 1.** The schema is 12. `maintenance.py` (with `delete-history` and `set-admin-password`), `startos/actions/deleteHistory.ts`, `startos/actions/setAdminPassword.ts`, and the test modules `test_multisig_setup.py`, `test_key_model.py`, `test_key_status.py`, `test_export_filename.py`, `test_maintenance.py` and `test_pwa.py` are all in the repository. Point 1 added `auth.py`, `static/login.html`, `static/login.js`, `static/session.js`, the login/logout/session/create-admin routes and the gating in `app.py`, and the CSRF double-submit on every state-changing POST. `auth.py` is the only place that knows the credential: `hash_password`, `verify_password`, `normalize_admin_username`, `validate_admin_credentials`, `get_admin`, `admin_configured`, `set_admin`, `authenticate`, `session_secret`, `create_session_token`, `verify_session_token`, `new_csrf_token` and `csrf_tokens_match`, with the constants `SESSION_COOKIE`, `CSRF_COOKIE` and `CSRF_HEADER`. **Build on this. Do not invent a second session mechanism.**
-- **Partly done: point 6, the PWA.** `static/sw.js` caches only the shell, and it does it with an allowlist of the shell paths, so it never names the API, `/health` or the login page. `static/app.js` registers the worker and shows a clear offline state. `static/sw.js` is in `STATIC_FILES` and `app.py` lists `/sw.js`. **Still owed by point 6:** `static/manifest.webmanifest`, its `` in the five pages, and the `STATIC_FILES` entry for it — all of which wait for the artwork, because the manifest needs a 192 and a 512 px icon.
-- **Not started: point 8, the icon.** It waits for the user's artwork; the placeholder `icon.svg` stays until then.
-- **The order is 7, 5, 4, 3, 2, 1, 6, 8** — the data model first, because everything else builds on it. Do not reorder it back.
-
-### The order is not the numbering
-
-The eight points are numbered by the user but are done in the order 7, 5, 4, 3, 2, 1, 6, 8 — the data model first, because everything else builds on it. Do not reorder it back.
-
-**The schema went 11 → 12** (points 7 and 5), and **the package version stays at `0.1.0:0`**. Nothing in this round touches `startos/versions/`.
-
-### It amends three parts of the binding spec
-
-- **Section 1 forbids "PWA/offline-database".** The user has decided on an **installable PWA without offline data**: the shell may be cached, no API response may be, and there is no offline data entry. The prohibition now reads as "no offline database and no offline recording of checks".
-- **Sections 2 and 15 forbid asking for and storing "passwords".** That is about *wallet* secrets. The admin login password is a different thing and is the only credential the app stores, as a `hashlib.scrypt` hash. Both sections must be reworded so this is explicit, or the code contradicts the spec.
-- **Section 3's unchecked box** — "do not build general support for many setups yet" — is closed by point 7. It stays **one** setup; only its threshold and key count become configurable.
-
-### The traps, per point
-
-- **Point 7, dynamic key count — done.** `KEY_COUNT` is no longer a constant; it is read from `app_settings`, and `keys.key_number`'s CHECK was loosened through a table rebuild with `PRAGMA foreign_keys = OFF` and `PRAGMA foreign_key_check` before commit. `tests/test_health_check_form.py` no longer asserts the three hard-coded `key_N_name` fields in `setup.html`; it asserts the markup `setup.js` generates.
-- **Point 5, the model/service field — done.** One nullable column through `OPTIONAL_COLUMNS`, so no rebuild. It is **documentation only**: not a wallet-software choice, not part of the alert source, not part of a key's identity, so it is not locked. The key's `name` keeps doing everything it does today (section 25.4 and section 28). The label switches with the type — "Model" for hardware, "Service" for cloud — but the column name does not.
-- **Point 4, the address path on the card — done.** `GET /api/key-status` now returns `address_path`, and an empty path does not render an empty line.
-- **Point 3, the dated export name — done.** `static/index.html` no longer carries a `download` attribute with a value, because one **overrides the server's `Content-Disposition` filename**; the server names the file `YYYY-MM-DD-vardkey-export.csv`.
-- **Point 2, delete history — done.** `alert_acknowledgements` has **no foreign key**, so it does not cascade and is deleted explicitly; `key_checks` and `ai_security_checks` do cascade. The key setup, `app_settings` and `wallet_software` stay. `maintenance.py` is `COPY`ed into the image, or the action would fail at runtime on the box while the tests stayed green.
-- **Point 1, the admin password — done.** The first run has no admin, so the login page can *create* one; every route except `GET /health` is gated, with `401` on the API and a redirect on the pages; the session is a signed cookie with `HttpOnly` and `SameSite=Strict`; and every state-changing POST needs the double-submit CSRF token. The StartOS action generates the password **inside the container** and shows it once, because the SDK documents no way to feed stdin to a `withTemp` command and an argument would be visible in the process list — that is the packaging guide's own password-reset pattern.
-- **Point 6, the PWA — partly done.** The service worker must cache **only** the shell — never `/api/*`, never `/health`, never the login page, or the app shows stale or unauthenticated data. It is served from the root, because its scope is bounded by its path, so `/sw.js` is in `STATIC_FILES`. It only registers in a secure context: fine on StartOS over HTTPS and on `http://localhost`, but not on a LAN IP over plain HTTP, and that belongs in the docs. The shell comes from the cache while every fetch fails, so the UI needs a clear offline state instead of empty cards. The manifest needs 192 and 512 px icons from point 8, so `manifest.webmanifest` and its `STATIC_FILES` entry are the last pieces to land.
-- **Point 8, the icon.** The user supplies the artwork. The package `icon.svg` is capped at 40 KiB, and the PWA needs 192 and 512 px PNGs. It is not part of the version bump.
+- **Schema 12.** `app_settings` (`multisig_threshold`, `multisig_key_count`, `admin_username`, `admin_password_hash`, `session_secret`) and a nullable `keys.model`. The `key_number` CHECK was loosened through a table rebuild with `PRAGMA foreign_keys = OFF` and `PRAGMA foreign_key_check` before commit.
+- **The admin login.** `auth.py` is the only place that knows the credential: `hashlib.scrypt` with a random salt per password, a signed session cookie (HMAC-SHA256 over an expiry, keyed by `session_secret`, no session table), and a double-submit CSRF token. Every route except `GET /health` needs a session: `401` on the API, a redirect to `/login` on the pages, and a CSRF requirement on every state-changing POST.
+- **`maintenance.py`**, with `delete-all-data` and `set-admin-password`.
+- **The installable PWA**, without offline data: `static/sw.js`, `static/manifest.webmanifest`, `static/icon.svg`, the registration and offline state in `static/app.js`, and the manifest link on the five pages.
+- **The flexible threshold** (`2 ≤ key_count ≤ 15`, `1 ≤ threshold ≤ key_count`), still for **one** setup only.
### Compatibility rules that apply to all of them
@@ -101,6 +84,15 @@ From version 1 the app has to survive future updates without breaking data or co
- A backup taken on an older version must restore and migrate forward.
- The CSV column names are a contract and do not change without a section saying so.
+## Section 32 — the icon and version 1 (not started)
+
+Two things, both waiting on the user:
+
+- **The icon.** The user supplies the artwork. The package `icon.svg` is capped at 40 KiB; the PWA needs 192 and 512 px PNGs in `static/`, and both go into the manifest's `icons` entry and into `STATIC_FILES` in `app.py`. The placeholder SVG the manifest points at today carries `sizes: "any"`, which is what the manifest test asserts.
+- **The version raise**, from `0.1.0:0` to `1.0.0:0`, together with section 18 step 12.
+
+Nothing else belongs to this round: no schema change, no new endpoint, and no new feature. **Do not start it.**
+
## Sections 27 and 28 — implemented and verified
What the code does now, and the parts that are easy to get wrong:
@@ -137,6 +129,7 @@ What the code does now, and the parts that are easy to get wrong:
- **The prohibition lists** in sections 1 and 13 of `TODO.md` stay unticked. They are standing prohibitions, to be re-confirmed before release — with the one amendment section 31 records for the installable PWA.
- **Whether a date is overdue is decided in the browser**, so `/api/key-status` stays independent of the current date.
- **`/api/previous-values` still returns a `security` map** that nothing consumes any more, and its `address_path` per key is no longer used by the form, which pre-fills the path from `keys.address_path`. Both are deliberate: removing them would shrink the endpoint, but nothing breaks while they stay.
+- **`delete_all_data()` deletes the checks before the keys.** `key_checks.key_id` is `ON DELETE RESTRICT`, so the other order fails. The acknowledgements are deleted explicitly, because they have no foreign key at all.
## Data model (schema version 12)
@@ -144,9 +137,9 @@ What the code does now, and the parts that are easy to get wrong:
- `health_checks`: `checked_at`, `next_check_due`, `wallet_software`, `software_version`, `software_compatibility_status`, `software_comments`, `contact_info_verified`, `comments`, plus the legacy `sparrow_version` / `nunchuk_version`. `wallet_software` and `contact_info_verified` are free text.
- `key_checks`: one row per submission — `available`, `hardware_works`, `firmware_version`, `seed_backup_verified`, `address_path_verified`, `address_path`, `comments`. The two cloud columns are gone.
- `ai_security_checks`: `provider` (free text), `status`, `comments`, with `UNIQUE (health_check_id, provider)`.
-- `wallet_software`: `name`, `created_at`. Stored whole, seeded with `Sparrow Wallet` when the list is empty, never emptied through the API.
+- `wallet_software`: `name`, `created_at`. Stored whole, seeded with `DEFAULT_WALLET_SOFTWARE` (`Sparrow Wallet`) when the list is empty, never emptied through the API. `delete_all_data()` empties it, and the seed puts the default back.
- `alert_acknowledgements`: `code`, `source`, `key_id`, `check_id`, `reason`, `acknowledged_at`. `reason` holds the action name that closed the alert, and `key_id` holds the key the alert belonged to, or `NULL` for a software alert from the settings list.
-- `app_settings`: `name` (PRIMARY KEY), `value`. Holds `multisig_threshold`, `multisig_key_count`, `admin_username`, `admin_password_hash` and `session_secret`. Added by section 31 point 7; the credential keys are point 1's.
+- `app_settings`: `name` (PRIMARY KEY), `value`. Holds `multisig_threshold`, `multisig_key_count`, `admin_username`, `admin_password_hash` and `session_secret`. `delete_all_data()` removes the two multisig rows, so the 2-of-3 default applies again, and keeps the three credential rows.
- `tool_checks` no longer exists.
- Startup migration rebuilds `keys` when it still has `device` or the old `key_number` CHECK, `key_checks` when it uses the old layout or still holds the two cloud columns, and `health_checks` and `key_checks` when their `CHECK` constraints still allow the old values. It then drops `tool_checks` if it is there, and adds the newer columns through `OPTIONAL_COLUMNS`.
- The table definitions are `{table}` templates, so a rebuild can create the same table under a temporary name. `health_checks` is a parent table, so the whole migration runs with `PRAGMA foreign_keys = OFF`, checks `PRAGMA foreign_key_check` before committing, and rolls back on any failure.
@@ -155,15 +148,15 @@ What the code does now, and the parts that are easy to get wrong:
## API
-Pages: `/`, `/setup`, `/settings`, `/health-check`, `/history`, `/login`. Endpoints: `GET /health`, `GET /api/session`, `POST /api/admin`, `POST /api/login`, `POST /api/logout`, `GET /api/setup`, `POST /api/setup`, `GET /api/keys`, `GET /api/key-status`, `GET /api/previous-values`, `GET /api/settings`, `POST /api/settings/keys`, `POST /api/settings/wallet-software`, `POST /api/keys//rotate`, `GET /api/health-checks`, `GET /api/health-checks/`, `GET /api/alerts`, `POST /api/alerts/acknowledge`, `GET /api/export`, `POST /api/health-checks`. Field details are in `docs/application.md`.
+Pages: `/`, `/setup`, `/settings`, `/health-check`, `/history`, `/login`. Endpoints: `GET /health`, `GET /api/session`, `POST /api/admin`, `POST /api/login`, `POST /api/logout`, `GET /api/setup`, `POST /api/setup`, `GET /api/keys`, `GET /api/key-status`, `GET /api/previous-values`, `GET /api/settings`, `POST /api/settings/keys`, `POST /api/settings/wallet-software`, `POST /api/keys//rotate`, `GET /api/health-checks`, `GET /api/health-checks/`, `GET /api/alerts`, `POST /api/alerts/acknowledge`, `GET /api/export`, `POST /api/health-checks`. Field details are in `docs/application.md` — which is behind the code, see the gap under Status.
+
+Maintenance commands, run inside the container by the StartOS actions and usable by hand: `maintenance.py delete-all-data` and `maintenance.py set-admin-password`. Neither is an HTTP endpoint.
The rotate payload is `replaced` + `keep_name` + `name` + `type` + `address_path`, and `type` is optional. `GET /api/health-checks/` also returns `closed_alerts`. The settings page has two sections, and `POST /api/settings/keys` is what a rename alone goes through.
-**Section 31 has already added** `threshold` and `key_count` to `POST /api/setup`, `model` to the key payloads, and `address_path` plus the two multisig numbers to `GET /api/key-status`. **Point 1 added** `GET /api/session`, `POST /api/admin`, `POST /api/login` and `POST /api/logout`, the gating of every route except `GET /health` (`401` on the API, a redirect on pages), and the CSRF requirement on every state-changing POST. `GET /health` stays open.
-
Five things that are easy to break:
-- New static files must be added to `STATIC_FILES` in `app.py`, or they return `404`. That includes `/settings`, `/settings.js`, and everything section 31 still owes: the login page, `session.js`, the manifest, `sw.js` and the PWA icons.
+- New static files must be added to `STATIC_FILES` in `app.py`, or they return `404`. That includes `/settings`, `/settings.js`, `/login`, `/login.js`, `/session.js`, `/sw.js`, `/manifest.webmanifest` and `/icon.svg`.
- `/api/setup`, `/api/settings`, `/api/alerts`, `/api/key-status`, `/api/previous-values` and `/api/session` are extra endpoints that are not in the minimum list in section 11.
- `STORAGE_ERRORS` in `app.py` includes `RuntimeError`, because `list_keys()` raises it for a partial setup. Keep it there, or a broken database answers with a traceback instead of a `500`. It also includes `ValueError`, so `validate_admin_credentials()` has to be called in its own `try` and mapped to a `400` before the storage handler.
- The settings, rotation and acknowledgement endpoints keep the same error handling as the existing ones: a bad payload is a `400`, an unknown key or alert is a `404`, a locked or duplicate address path is a `409`, and a broken database is a `500`. `DuplicateAddressPath` and `WalletSoftwareNameInUse` must be caught before the general `ValidationError` — in `_save_key_settings` and `_rotate_key` respectively — or the `409` turns into a `400`. A missing or invalid session is a `401`, and a missing CSRF token is a `403`.
@@ -172,16 +165,19 @@ Five things that are easy to break:
## Traps that already cost time — do not repeat
- **`with sqlite3.connect(...)` does not close the connection.** It only commits or rolls back the transaction. On Windows the database file stays locked and `TemporaryDirectory.cleanup()` fails with `WinError 32`. Always close explicitly with `try`/`finally`; see `write_schema()` in `tests/test_database.py`.
+- **A module the image is missing is a runtime error, not a build error.** `auth.py` was left out of the `Dockerfile` because the module list was written before it existed, and both `app.py` and `maintenance.py` then died with `ModuleNotFoundError` inside the container while every test stayed green. The `COPY *.py ./` line is what stops that recurring. After any change to the image, check the modules, not just the tests.
+- **Every server test module needs a session, and a redirect makes a missing one look like a pass.** A page fetched without a session answers `302 → /login`, and `urllib` follows it, so an assertion on page markup reads the login page's HTML instead of failing with `401`. That is what happened to `tests/test_pwa.py` `ManifestTests.test_every_page_links_the_manifest`. Use `tests/server_session.py`'s `SessionMixin`, and note that the manifest and the icon are open while the pages are not.
- **A `required` control inside a `display:none` container still blocks submission.** The browser refuses to submit and logs "An invalid form field is not focusable". Hiding a section is not enough: the required flags must be cleared, or the section must render something other than required fields. That is why `renderSecurityChecks()` shows an empty note instead of cards when a key could not be checked, why `syncUncheckableState()` clears the flags on the wallet software and the compatibility select — also for a cloud key, whose grid is hidden — and why `syncRequiredFields()` clears the flag on `hardware_works` and `seed_backup_verified`. The rotation fields follow the same rule: the type is `disabled` until the key is marked for rotation, the path is `disabled` when the key has a saved check and is not marked, and the script refuses to send an empty path. The login page sidesteps it with two separate forms, so only the visible one is ever validated.
- **The mismatch confirmation follows its warning.** `#address-path-confirmed` is `required` only while `#address-path-warning` is visible, so the browser itself stops the submission and a required control is never hidden.
+- **`make x86` runs `prettier --check startos`, and the config is the SDK's own.** `.prettierrc` is the single line `"@start9labs/start-sdk/prettier.config.json"`, which is `{ trailingComma: "all", tabWidth: 2, semi: false, singleQuote: true }` — everything else is prettier's default, so `printWidth` is 80 and `quoteProps` is `"as-needed"`. That last one silently unquotes a single-word i18n key (`Username: 21`, not `'Username': 21`), and 80 columns decides when an array element or an argument collapses onto one line. Write it the way prettier would, or run `npx prettier --config node_modules/@start9labs/start-sdk/prettier.config.json --write startos`.
- **The page heading uses `class="eyebrow"` too.** A regex over `health-check.html` finds `Annual security check` before the numbered sections. `settings.html` starts with `Settings`, then `01 / Wallet software` and `02 / Key rotation`. A test on the section order must expect that first. `tests/test_health_check_form.py` asserts those two lists **exactly**, so a new eyebrow on either page breaks it — the section 29 description line went on the dashboard only.
- **Do not assert on the quoting style of the JavaScript.** `static/health-check.js` uses single quotes for constant selectors and template literals where a `${...}` substitution is needed, and `static/settings.js` uses double quotes. Assert on the selector text, e.g. `[name=\"address_path\"]`, and on quote-free substrings such as `/api/settings` and `/settings?rotate=`.
- **`clean_record()` in `tests/test_alerts.py` has a fixed provider list and carries `key_id` and `wallet_software`.** A test that needs another provider must replace the entry itself, and the recorded software is `Sparrow Wallet`, which is what a software alert names. A test that exercises the cloud-key form of `software_incompatible` has to pass `cloud_names` to `build_alerts()`.
-- **`sample_payload()` / `unavailable_payload()` are duplicated in `tests/test_validation.py`, `tests/test_database.py` and `tests/test_app.py`.** They build the labels from the key's name and the selected software, they always send `contact_info_verified`, and for a hardware key `hardware_works`. They must send the key's **own** `address_path`, because the server compares it with the stored one. Section 31 added a `model` field to them and a `threshold`/`key_count` pair to the setup fixtures.
+- **`sample_payload()` / `unavailable_payload()` are duplicated in `tests/test_validation.py`, `tests/test_database.py`, `tests/test_app.py` and `tests/test_maintenance.py`.** They build the labels from the key's name and the selected software, they always send `contact_info_verified`, and for a hardware key `hardware_works`. They must send the key's **own** `address_path`, because the server compares it with the stored one. Section 31 added a `model` field to them and a `threshold`/`key_count` pair to the setup fixtures.
- **Every test fixture uses one address path per key** (`ADDRESS_PATH`, `SECOND_ADDRESS_PATH`, `THIRD_ADDRESS_PATH`), because the setup refuses duplicates. `tests/test_app.py` also has `ROTATION_PATHS` and the `rotate()` helper, which picks an unused path per key so a test can rotate several keys in one run.
- **`validate_health_check()` takes a third argument** (the wallet software list), and `validate_rotation()` takes a fourth for the same reason. `tests/test_validation.py` and `tests/test_database.py` wrap the first one in a small `validate()` helper.
-- **`tests/test_app.py` has seven test classes.** `ServerTestCase` starts the server and now keeps the session and CSRF cookies a sign-in returns; `AppHandlerTests`, `RenamedSetupTests`, `SettingsApiTests`, `RotationApiTests` and `AcknowledgementApiTests` store the default or renamed setup and call `authenticate()`; `AuthApiTests` starts from a database with **no admin** and covers the gating, the first-run admin, the login and logout, and the CSRF check; and `KeySetupApiTests` creates its admin through `POST /api/admin` and otherwise starts from an empty database. A new test must go in the class whose setup it needs. Every request helper sends the cookies and the CSRF header, and `assert_status()` is the one place an error status is expected.
-- **The other server test modules share `tests/server_session.py`.** `test_export_filename.py`, `test_key_model.py`, `test_key_status.py` and `test_multisig_setup.py` mix in `SessionMixin`, which signs in through the API and carries the cookies; each class calls `authenticate()` at the end of its own `setUp`. **A test that switches `DATABASE_PATH` to another file has to call `authenticate()` again**, because the session secret lives in the database, so the old cookie is signed with the wrong secret and every request answers `401`. This cost a full test run once.
+- **`tests/test_app.py` has seven test classes.** `ServerTestCase` starts the server and keeps the session and CSRF cookies a sign-in returns; `AppHandlerTests`, `RenamedSetupTests`, `SettingsApiTests`, `RotationApiTests` and `AcknowledgementApiTests` store the default or renamed setup and call `authenticate()`; `AuthApiTests` starts from a database with **no admin** and covers the gating, the first-run admin, the login and logout, and the CSRF check; and `KeySetupApiTests` creates its admin through `POST /api/admin` and otherwise starts from an empty database. A new test must go in the class whose setup it needs. Every request helper sends the cookies and the CSRF header, and `assert_status()` is the one place an error status is expected.
+- **The other server test modules share `tests/server_session.py`.** `test_export_filename.py`, `test_key_model.py`, `test_key_status.py`, `test_multisig_setup.py` and `test_pwa.py` mix in `SessionMixin`, which signs in through the API and carries the cookies; each class calls `authenticate()` at the end of its own `setUp`. **A test that switches `DATABASE_PATH` to another file has to call `authenticate()` again**, because the session secret lives in the database, so the old cookie is signed with the wrong secret and every request answers `401`. The mixin resolves the path with `app.get_database_path()`, so the admin lands in the file the server actually reads.
- **Section 19 records one key per submission**, so a `Check id` in the export can cover up to three keys only for rows saved before section 19. A legacy record with several `key_checks` is read through its first one when an alert needs the key it belongs to.
- **The database path default is repeated in sixteen places.** `database.py` carries `database_path="data/vardkey.sqlite3"` as the default of every storage function (fifteen of them), and `app.py` carries it in `get_database_path()`. A missed one makes a single code path read or create the other file, silently. Grep for the old name before and after a rename round.