# 060 — Testing on the addon side (A05–A10)

Created: 2026-11-06
Updated: 2026-11-06

The master testing plan is WEB `docs/plan/account-sync/07-testing.md` (layers, scenarios §6, budgets §7). This is
how to run the addon's part. Rules of this repo's `AGENTS.md` §Testování apply.

## 1. Offline tests

- New: `tests/test_account_contract.py`, `test_account_outbox.py`, `test_account_docs.py`, `test_account_settings.py`,
  `test_account_apply.py`, `test_account_switch.py`, `test_account_backup.py`, `test_account_foryou.py`.
- Stubs: `tests/kodi_stubs.py`, `scripts/library_harness/stubs.py`; temp profile per test; `store.set_path()`.
- Run one file at a time: `python3 -m unittest tests/test_account_outbox.py` (never `discover`).
- Contract fixture: read WEB `tests/fixtures/sync/contract-v1.json` by absolute path.

## 2. Account harness (`scripts/account_harness/`)

| Script | What |
|---|---|
| `client.py` | one headless device: real `wcs/account` + `wcs/library2` with stubs in a temp profile; commands `pair`, `sync`, `act <action>`, `dump` |
| `sim.py` | the simulator (WEB 07 §4): several `client.py` processes + a web actor + the fault proxy; `--seeds`, `--devices`, `--faults`, `--clock-skew` |
| `proxy.py` | the fault proxy |
| `seeds.json` | every seed that ever failed (regression, run by `sim.py --regression`) |

The backend comes from WEB: `node scripts/harness/sync-backend.mjs --ttl 30 --proxy` (prints `SYNC_FRONTEND`,
`APPROVE_URL`; credentials never printed). Stop it afterwards; check `lsof -i :5239 -i :4139`.

## 3. Isolated Kodis

`scripts/install_harness/fresh_kodi.py up && … install && … key` — then set `account_server` in the test profile
to the harness frontend (`builtin`/`rpc` command or a profile settings file before start). A second instance needs its
own root and JSON-RPC port (9193): extend the script with `--root`/`--port` if it cannot yet (A10.1). Always `down`
at the end. Fault hooks (`DATA/harness/ENABLED` + `switch_crash_at`) work only in these profiles and in the workspace
Kodi with the harness enabled.

## 4. The workspace Kodi (Standa's Mac Kodi)

Only in A01 (signed out, the cleanup regressions) and A10.3 (sign-in/out). Before A10.3: Kodi free (no other agent),
full copy of `DATA` to the scratchpad, `sha256` list of every file, then sign in to the Mac test account; after
sign-out compare; any difference → restore the copy and report. Never sign the workspace Kodi in to an account other
than the test admin account of `~/.milionar-test/keys.json`.

## 5. Performance

`scripts/skin_harness/ux/throttle.py 5`, `wcs/skin/perflog.py` lines in `kodi.log`, the A00.3 measurements repeated
signed out (A01.4, A05.8) and signed in (A10.4). The TV (`fresh_tv.py`, skill `kodi-tv`) only when Standa asks in
that task.

## Result

2026-11-06: `scripts/account_harness/` — `client.py` (a headless device on the real code; persistent profile,
clock skew), `device_proc.py`, `test_two_devices.py`, `sim.py` + `sim_actors.py` + `sim_proxy.py` + `sim_check.py`
(simulator, WEB T27), `sim_load.py` (A09.4), `seeds.json` (regression seeds of every bug the simulator found). Results
in WEB `docs/plan/account-sync/11-status.md`.

2026-11-06 (A09.3/A09.4): the 1 000-seed runs found four more bugs (seeds 49, 30, 1564, 1309), all fixed on the WEB
server (WEB T32–T35, migration 020, `server/account/touch.ts`); no addon code changed. With every fix: `sim.py --seeds
1-1000` and `--seeds 1001-2000` (`--actions 40-300`, all faults and kills) each 1 000 / 1 000; `sim_load.py --minutes
30` converged (push p95 16 ms, pull p95 20 ms, propagation p95 23 ms). `test_two_devices.py` updated to the harness
client's current `sync()`/`dump()` format; `sim_load.py` propagation computed with bisect (the old loop was quadratic).
