WorldWideView's Vitest setup is already wired and CI already runs
\`pnpm test\` on every PR. What's missing is tests for the systems
that actually break: the plugin lifecycle plumbing (data bus, cache,
polling) and the camera adapter aggregator that the UI hits on every
layer toggle.
This PR adds a focused first batch — 12 tests across 4 files — covering
the most common failure modes we've actually seen in practice. The
intent is to land the patterns alongside the tests so the next
contributor (human or agent) can copy the shape rather than improvise.
## What's tested
| File | Coverage | Tests |
| ---- | -------- | ----- |
| src/core/data/DataBus.test.ts | emit/subscribe round-trip, unsubscribe correctness, handler-failure isolation | 3 |
| src/core/data/CacheLayer.test.ts | memory-tier get/set, TTL expiry + eviction | 2 |
| src/core/data/PollingManager.test.ts | immediate-run on start(), interval scheduling, stop() cancels | 3 |
| src/app/api/camera/adapters/registry.test.ts | resolveSources for "all" / null / "none" / mixed-with-unknowns | 4 |
Each test answers one question: what regression does it catch that
we'd otherwise find by user bug report?
## Config change
vitest.config.ts now includes \`src/app/**/*.{test,spec}.*\` so API-route
tests under \`src/app/api\` are picked up by \`pnpm test\`. Previously only
\`src/lib\`, \`src/core\`, \`src/plugins\`, and \`packages\` were scanned —
api-route handlers had no test home.
## Docs
\`docs/testing.md\` gets four new sections:
- **Patterns** — plain-function, stateful-singleton, mock-with-vi.mock,
fake-timers — with a callout for the \`runOnlyPendingTimersAsync\`
double-counting gotcha we hit while writing PollingManager tests.
- **What NOT to Test (Yet)** — Cesium-heavy components, live DB
round-trips, dynamic plugin imports.
- **Philosophy** — small focused suite > large expensive one, test
pure logic, add a test when you fix a bug.
Original overview/test-types/run-commands sections are unchanged.
## Verification
Locally (Node 22 + pnpm 9.15.4):
\`\`\`
Test Files 17 passed (17)
Tests 127 passed (127)
\`\`\`
Existing 115 tests still pass; new 12 land cleanly.
## What's next (not in this PR)
The list of load-bearing systems still without coverage:
- PluginManager (the central plugin lifecycle orchestrator)
- The new plugin-backend supervisor + proxy (PR #100)
- The agent bus (PR #79)
- Plugin marketplace install/uninstall round-trip
- React component tests for LayerPanel and DataBusSubscriber
Worth a follow-up batch once the patterns from this PR are familiar.
Co-authored-by: Sapphire <sapphire@tiktokcoach>