Collab Editor - Test Plan
Companion document to SPECIFICATION.md. Covers the critical paths that, if broken, would cause data loss, publishing failures, or security holes. Intentionally not exhaustive - the project is evolving fast, and these tests are chosen to survive refactors.
Principles
- Test behavior, not implementation details.
- Focus on what breaks silently (data loss, corrupt publish, auth bypass).
- Keep tests decoupled from internals so they survive refactors.
- Fast to run - no heavy dependencies (Playwright PDF, real HF API) in the main suite.
Stack
| Layer |
Tool |
Scope |
| Backend unit/integration |
Vitest + Supertest |
Publisher, API routes, auth guards |
| Yjs helpers |
In-memory Y.Doc fixtures |
Publisher extraction, storage logic |
| Frontend unit |
Vitest + Testing Library |
Agent tool execution, undo batching |
| E2E |
Playwright (backend/e2e, frontend/tests) |
Critical editor flows: load, edit, comments, publish round-trip |
E2E is opt-in (npm run test:e2e in backend/, plus Playwright specs in frontend/tests/); the fast suite (npm run test) stays hermetic and Playwright-free so it can run in CI without a browser install.
1. Publisher Pipeline (P0)
The core value of the product. If publishing breaks, the article disappears.
1.1 Y.Doc extraction
| # |
Test |
Given / When / Then |
Priority |
| 1.1.1 |
Extract frontmatter from Y.Doc |
Given a Y.Doc with title, authors, affiliations in Y.Map("frontmatter") / When extractFromYDoc runs / Then returned object contains all frontmatter fields with correct types |
P0 |
| 1.1.2 |
Extract content from empty doc |
Given a Y.Doc with an empty Y.XmlFragment("default") / When extracted / Then returns empty content without throwing |
P0 |
| 1.1.3 |
Extract with citations |
Given a Y.Doc with entries in Y.Map("citations") / When extracted / Then citations map is included in output as CSL-JSON |
P0 |
1.2 HTML generation
| # |
Test |
Given / When / Then |
Priority |
| 1.2.1 |
Produces valid self-contained HTML |
Given extracted doc data / When renderArticleHTML runs / Then output is valid HTML with inline CSS, no external stylesheet links |
P0 |
| 1.2.2 |
CSS variables resolved |
Given template CSS with @custom-media / When resolveCustomMedia runs / Then output contains only standard @media rules, no @custom-media |
P0 |
| 1.2.3 |
TOC generated from headings |
Given content with h2 and h3 / When rendered / Then HTML contains TOC nav with matching anchor links |
P1 |
| 1.2.4 |
Theme toggle present |
Given any doc / When rendered / Then output contains theme toggle SVG (sun/moon) and associated script |
P1 |
| 1.2.5 |
Bibliography injected |
Given doc with citations / When rendered / Then HTML contains bibliography section with formatted entries |
P0 |
1.3 Post-processing
| # |
Test |
Given / When / Then |
Priority |
| 1.3.1 |
Accordion to details/summary |
Given HTML with accordion div / When post-processed / Then output uses <details> and <summary> tags |
P1 |
| 1.3.2 |
htmlEmbed to iframe |
Given HTML with htmlEmbed node / When post-processed / Then output contains <iframe> with correct src |
P0 |
| 1.3.3 |
Mermaid to pre block |
Given HTML with mermaid node / When post-processed / Then output contains <pre class="mermaid"> |
P1 |
1.4 Publish idempotency and restore
| # |
Test |
Given / When / Then |
Priority |
| 1.4.1 |
Publish twice gives same result |
Given a Y.Doc / When published twice / Then both HTML outputs are byte-identical (no timestamps or random IDs) |
P0 |
| 1.4.2 |
Published article restored on boot |
Given published assets in HF dataset but empty local FS / When ensurePublishedRestored runs / Then data/published/default/index.html exists locally |
P0 |
| 1.4.3 |
GET / serves published article |
Given local published index.html exists / When GET / / Then response is the published HTML with 200 |
P0 |
2. Persistence and HF Storage (P0)
Data loss is game over for a collaborative editor.
2.1 Local persistence
| # |
Test |
Given / When / Then |
Priority |
| 2.1.1 |
Store writes .yjs file |
Given a Y.Doc update triggers debouncedSave via onChange / When the debounce (2s) elapses / Then data/<name>.yjs exists and contains valid Yjs binary |
P0 |
| 2.1.2 |
Fetch reads local file |
Given data/default.yjs exists / When Database.fetch / Then Y.Doc is hydrated with stored content |
P0 |
| 2.1.3 |
Fetch falls back to HF pull |
Given no local .yjs file but HF dataset has one / When Database.fetch / Then file is pulled from HF and Y.Doc is hydrated |
P0 |
2.2 HF dataset sync
| # |
Test |
Given / When / Then |
Priority |
| 2.2.1 |
Push debounced at 10s |
Given two rapid store calls / When 10s elapses / Then only one HF push is made |
P1 |
| 2.2.2 |
flushAll on SIGTERM |
Given pending debounced pushes / When SIGTERM received / Then all pending data is pushed before exit |
P0 |
2.3 Image upload
| # |
Test |
Given / When / Then |
Priority |
| 2.3.1 |
Upload returns proxy URL |
Given a valid image file / When POST /api/upload / Then response contains a /d/images/... URL routed through the editor's dataset proxy (the underlying HF dataset is private) |
P1 |
| 2.3.2 |
Reject oversized file |
Given a file > 10MB / When POST /api/upload / Then response is 413 or 400 with error message |
P1 |
| 2.3.3 |
Proxy serves images |
Given an uploaded image / When GET /d/images/<file> / Then 200 + image bytes (proxy attaches a server-side token to fetch the private HF dataset) |
P1 |
| 2.3.4 |
Proxy whitelist |
Given any path under /d/articles/... (raw Y.js drafts) / When GET / Then 404 - never expose drafts via the proxy |
P0 |
2.4 Storage status & disaster recovery
| # |
Test |
Given / When / Then |
Priority |
| 2.4.1 |
Status surfaces dataset error |
Given createRepo returns 403 / When GET /api/storage/status / Then response lastError.stage === "dataset-create" with statusCode: 403 |
P0 |
| 2.4.2 |
Status clears on recovery |
Given a previous push error / When the next push succeeds / Then lastError is null and lastCloudPushAt is updated |
P1 |
| 2.4.3 |
Status auth-gated |
Given an anonymous request (oauthEnabled) / When GET /api/storage/status / Then 403 - don't leak dataset error details |
P1 |
| 2.4.4 |
Eager creation on login |
Given a successful /api/auth/status with canEdit / When the request completes / Then ensureDatasetExists has been attempted (success surfaces within one storage-status poll, failure surfaces too) |
P0 |
| 2.4.5 |
Admin export streams .yjs |
Given an editor user / When GET /api/admin/export-doc?name=default / Then 200 + Content-Disposition: attachment + raw .yjs body |
P1 |
| 2.4.6 |
Admin export auth-gated |
Given a non-canEdit request / When GET /api/admin/export-doc / Then 403 |
P0 |
2.5 Real-life data-safety scenarios
backend/tests/scenarios/ runs a real server process and browser-equivalent tabs (Y.Doc kept across reloads like y-indexeddb, real HocuspocusProvider), each behind a chaos proxy that can freeze the connection (laptop asleep, half-open socket), drop it (offline) or outlive a server that died. Every scenario checks that every word any tab typed is on every tab and in what a cold restart reloads, or, when CRDT rules remove it, that it is kept in "Removed text" and can be put back.
| # |
Scenario |
Priority |
| 2.5.1 |
A tab asleep while a colleague writes keeps its edits and gets theirs |
P0 |
| 2.5.2 |
A tab asleep across a deploy (SIGTERM + restart) reconnects without loss |
P0 |
| 2.5.3 |
30 offline paragraphs merge back after a SIGTERM and a SIGKILL restart |
P0 |
| 2.5.4 |
SIGKILL inside the save debounce loses nothing while the tab stays open |
P0 |
| 2.5.5 |
SIGKILL right after the tab closed: reopening the tab restores the text |
P0 |
| 2.5.6 |
Offline edits inside a paragraph someone deleted are rescued and put back |
P0 |
| 2.5.7 |
A stale tab deleting a paragraph someone kept writing in: their words are rescued |
P0 |
| 2.5.8 |
Deleting your own text is not reported |
P1 |
| 2.5.9 |
"Undo agent's changes" keeps (rescues) what a human typed in the agent's paragraph |
P0 |
| 2.5.10 |
Restoring a version rescues what an offline tab typed in a replaced block |
P0 |
| 2.5.11 |
A stale tab's select-all + delete only removes what that tab could see |
P0 |
The same checks run against HF storage (cloud-storage.test.ts): the server persists to a fake Hub (fake-hub/, swapped in for @huggingface/hub by a Node loader hook, so all of hf-storage.ts runs for real) whose repos outlive server processes, and every rebuild starts on a wiped disk like a Space container. FakeHub.faults() injects 503s, network errors, expired tokens (401), bucket-less tokens (403) and latency.
| # |
Scenario |
Priority |
| 2.5.12 |
A rebuild on an empty disk (SIGTERM, then SIGKILL after the push) reloads everything from the bucket |
P0 |
| 2.5.13 |
HF down for a while: the failure is reported, the backlog lands once HF is back |
P0 |
| 2.5.14 |
HF down during a rebuild with every tab closed: reopening the tab brings the work back |
P0 |
| 2.5.15 |
HF unreachable when the new container starts: no empty article, the open tab syncs once HF is back |
P0 |
| 2.5.16 |
Token expired mid-session and across a restart: nothing lost once a valid token is back |
P0 |
| 2.5.17 |
Slow Hub (1.5 s per call): the shutdown flush of a deploy still lands |
P1 |
| 2.5.18 |
Token without bucket access: live state stays on the dataset |
P1 |
| 2.5.19 |
Two servers on the same storage (overlapping deploy, local dev on the prod dataset) keep each other's work |
P0 |
| 2.5.20 |
Non-stop group editing (never a 2 s pause) reaches the disk and HF |
P0 |
| 2.5.21 |
The last writer leaving (private window, MCP agent) keeps their words when someone opens the article right after |
P0 |
Known limit: if HF is down when the container is rebuilt, edits that never reached HF only come back when a tab that holds them reopens the article (its IndexedDB copy). If nobody reopens, they are lost.
Not covered here: browser-only behaviour (y-prosemirror schema handling, refocus lock, real IndexedDB), which needs the Playwright suite.
2.6 Load test
backend/tests/load/ is a manual tool, not part of npm run test (no .test.ts):
cd backend
npm run test:load -- --users N --agents K --minutes M [--slow-cpu] [--chaos] [--stress] [--profile DIR]
What it simulates, against a real server process persisting to the fake Hub with the production push timings:
N users spread over child processes (client-worker.ts), each typing keystroke by keystroke at a relative cursor position and publishing awareness (cursor, name). Users work in bursts (about 40% active at any time), or all the time with --stress.
- Churn: wifi drops, laptops going to sleep and reloads, so tabs keep leaving and rejoining (
--no-churn disables it).
K MCP agents reading the article and inserting or revising blocks through the real MCP endpoint.
- A 15k-word seed article (
--words).
--chaos: a 20 s HF outage, then a deploy (SIGTERM, restart on a wiped disk) mid-run.
--slow-cpu: the server runs under taskpolicy -c background (efficiency cores, lowest QoS), a rough stand-in for a Space's shared vCPUs.
--profile DIR: writes a V8 CPU profile of the server.
What it measures, every 15 s and over the whole run: propagation latency from the writer's transaction to every other tab (p50 / p95 / p99), server CPU and RSS, HTTP round trip, agent tool latency, Hub pushes. Final checks: every completed word is on every tab, all tabs hold identical text, and the same text is in the cloud copy and on a fresh container started from it.
Results on an M1 Pro, 3 min per run, 2 agents, 15k-word article. Every run ended with nothing lost and no divergence.
| Run |
Keystrokes/s |
Propagation latency |
Server CPU |
10 users, --slow-cpu |
16 |
p50 6 ms, p95 34 ms |
6% avg |
30 users, --slow-cpu |
52 |
p50 9 ms, p95 35 ms |
17% avg |
20 users, --slow-cpu --chaos |
- |
nothing lost through the HF outage and the deploy (about 25 s of downtime during the restart) |
- |
| 60 users |
99 |
p50 3 ms, p95 40 ms, p99 403 ms |
17% avg, 42% max, RSS ~360 MB |
30 users, --stress (all typing non-stop) |
139 |
p50 2 ms, p95 5 ms |
14% avg |
| 100 users |
155 |
p50 7 ms, p95 194 ms, p99 443 ms |
31% avg, 64% max |
Notes:
- With
--slow-cpu the OS deschedules the server process, so its latency spikes (1-2 s) are partly scheduling artifacts rather than server work: a CPU profile shows few samples during the stalls.
- At 100 users the client simulation itself was loaded (worker event loop lag up to ~190 ms), which inflates the tail latency.
- Steady-state cost is dominated by fan-out: each keystroke and cursor move is written to every connected socket, so the cost grows with the square of the number of users.
- Two users typing at exactly the same spot interleave their characters (normal CRDT behaviour). That is why simulated users jump to the start of paragraphs rather than all typing at the end of the same one.
Bugs it found, now fixed and covered by 2.5.20 and 2.5.21:
- Disk saves and HF pushes were postponed for as long as someone kept typing: with no 2 s pause there was no save. The Database
store hook now flushes the pending save (Hocuspocus calls it at most every 10 s while editing), and the HF push waits at most 3x its debounce.
- A reconnect within 2 s of the last writer leaving reloaded the stale disk copy and dropped their last edits. The save is now flushed before the document unloads, and a reloaded document writes the previous instance's pending state first.
3. API Routes - HTTP Contracts (P1)
Test the request/response shape, not the internal logic.
3.1 Publish
| # |
Test |
Given / When / Then |
Priority |
| 3.1.1 |
Publish returns success |
Given a valid Y.Doc in Hocuspocus / When POST /api/publish / Then response contains { success: true, htmlUrl } |
P0 |
| 3.1.2 |
Publish writes local HTML |
Given POST /api/publish succeeds / When checking local FS / Then data/published/default/index.html exists |
P0 |
3.2 Chat (AI Agent)
| # |
Test |
Given / When / Then |
Priority |
| 3.2.1 |
Stream returns valid SSE |
Given a chat message / When POST /api/chat / Then response is text/event-stream with parseable SSE events |
P1 |
| 3.2.2 |
Tool calls included in stream |
Given a prompt that triggers a tool / When streamed / Then SSE contains tool_call events with name and arguments |
P1 |
3.3 Citations
| # |
Test |
Given / When / Then |
Priority |
| 3.3.1 |
Resolve DOI to CSL-JSON |
Given a valid DOI string / When POST /api/citations/resolve / Then response contains CSL-JSON with title and authors |
P1 |
| 3.3.2 |
Import BibTeX |
Given a valid BibTeX string / When POST /api/citations/import-bib / Then response contains CSL-JSON entries |
P1 |
| 3.3.3 |
Format to HTML bibliography |
Given CSL-JSON entries + style / When POST /api/citations/format / Then response contains HTML string |
P1 |
3.4 Auth status
| # |
Test |
Given / When / Then |
Priority |
| 3.4.1 |
Unauthenticated status |
Given no cookie / When GET /api/auth/status / Then { authenticated: false, canEdit: false } |
P1 |
| 3.4.2 |
Authenticated status |
Given valid hf_access_token cookie / When GET /api/auth/status / Then { authenticated: true, canEdit: true, user: {...} } |
P1 |
4. Auth and Security (P0)
4.1 Route protection
| # |
Test |
Given / When / Then |
Priority |
| 4.1.1 |
Publish requires auth |
Given OAuth enabled + no cookie / When POST /api/publish / Then 401 or 403 |
P0 |
| 4.1.2 |
Reset-document requires auth |
Given OAuth enabled + no cookie / When POST /api/admin/reset-document / Then 401 or 403 |
P0 |
| 4.1.3 |
Upload requires edit access |
Given no cookie or an invalid token / When POST /api/upload / Then 401; given a valid user without write access / Then 403; given an editor and a PNG/JPEG/GIF/WebP/AVIF image / Then 200 (other content, SVG included, gets 415) |
P0 |
| 4.1.4 |
Upload rate-limited per IP |
Given more than 30 uploads within 60s from the same IP / When POST /api/upload / Then 429 with Retry-After header (checked before auth, so floods never reach the whoami lookup) |
P1 |
4.2 OAuth flow
| # |
Test |
Given / When / Then |
Priority |
| 4.2.1 |
CSRF state validated |
Given an OAuth callback with wrong state / When GET /auth/callback / Then rejected (400 or redirect to error) |
P0 |
| 4.2.2 |
Cookie set on success |
Given valid OAuth callback / When processed / Then hf_access_token cookie is set (httpOnly, secure, sameSite: none) |
P0 |
4.3 WebSocket auth
| # |
Test |
Given / When / Then |
Priority |
| 4.3.1 |
WS rejected without token |
Given OAuth enabled / When WebSocket connects to /collab without token / Then connection rejected |
P0 |
| 4.3.2 |
WS accepted with valid token |
Given OAuth enabled + valid token / When WebSocket connects to /collab / Then connection accepted, sync starts |
P1 |
4.4 XSS (known risk from spec)
| # |
Test |
Given / When / Then |
Priority |
| 4.4.1 |
Licence field escaped |
Given meta.licence containing <script>alert(1)</script> / When published HTML rendered / Then script tag is escaped or stripped |
P0 |
| 4.4.2 |
Bibliography HTML sanitized |
Given biblioHtml containing malicious script / When injected into published page / Then script is escaped or stripped |
P0 |
5. AI Agent - Plumbing (P1)
We do NOT test LLM output quality. We test the infrastructure around it.
5.1 Context building
| # |
Test |
Given / When / Then |
Priority |
| 5.1.1 |
Context includes doc text |
Given a doc with content / When building chat context / Then context object contains document text |
P1 |
| 5.1.2 |
Context includes selection |
Given a text selection / When building chat context / Then context object contains selection text and position |
P1 |
| 5.1.3 |
Context includes frontmatter |
Given doc with title and authors / When building chat context / Then context object contains frontmatter fields |
P1 |
5.2 Tool execution (client-side)
| # |
Test |
Given / When / Then |
Priority |
| 5.2.1 |
replaceSelection applies |
Given a selection in the editor / When replaceSelection tool called with new text / Then selection is replaced in the TipTap doc |
P1 |
| 5.2.2 |
applyDiff does search/replace |
Given doc with "Hello world" / When applyDiff called with search="world" replace="editor" / Then doc contains "Hello editor" |
P1 |
| 5.2.3 |
updateFrontmatter modifies map |
Given frontmatter with title "Old" / When updateFrontmatter called with title="New" / Then Y.Map("frontmatter").get("title") is "New" |
P1 |
5.3 Undo batching
| # |
Test |
Given / When / Then |
Priority |
| 5.3.1 |
Agent edits batch into one undo |
Given agent executes 3 tool calls (replaceSelection + applyDiff + updateFrontmatter) / When user presses Cmd+Z once / Then all 3 changes are reverted |
P0 |
| 5.3.2 |
Manual edits not in agent batch |
Given user types text then agent edits / When user presses Cmd+Z / Then only agent edits are reverted, user text remains |
P1 |
6. Embed Studio (P1)
The studio's UI is checked by hand (no browser in the hermetic suite). These tests pin the logic behind it: what the agent writes, how iterations are kept and undone, and how failures reach the user.
6.1 Helpers (frontend/tests/embed-studio-helpers.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.1.1 |
Out of credits |
Given HTTP 402: ...credits... / When described / Then kind credits, a link to the HF billing page, retryable |
P1 |
| 6.1.2 |
Rate limit and auth |
Given HTTP 429, HTTP 401 or the missing-token JSON body / When described / Then kinds rate and auth |
P1 |
| 6.1.3 |
Unknown errors |
Given HTTP 500: upstream exploded / When described / Then the detail drops the prefix and the error stays retryable; Failed to fetch is network |
P1 |
| 6.1.4 |
Starter chips |
Given an attached accuracy.csv / When the studio is empty / Then 4 starters, the first one about that file; banners get 4 banner starters |
P1 |
| 6.1.5 |
Follow-up chips |
Given a chart with hardcoded colors and a legend / When follow-ups are computed / Then 3 chips, palette first, legend second; none for an empty chart |
P1 |
| 6.1.6 |
Polished chart |
Given a chart using the palette, describe, highlight, tooltip and a source / Then only the 360 px follow-up is left |
P1 |
| 6.1.7 |
One automatic fix per user message |
Given a guard / When the user sends, then an automatic fix is sent / Then a second automatic fix is refused until the user sends again |
P0 |
| 6.1.8 |
Fix prompt |
Given a preview error / Then the message sent to the agent quotes it |
P1 |
6.2 Versions (frontend/tests/embed-versions.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.2.1 |
One version per agent turn |
Given three writes, two in turn u1 / Then two versions, u1 holding its last write |
P0 |
| 6.2.2 |
Tools record versions |
Given createEmbed then patchEmbed in one turn / Then the embed holds the patched HTML and one version stamped with the author |
P0 |
| 6.2.3 |
No duplicates |
Given the same HTML recorded twice / Then one version |
P1 |
| 6.2.4 |
Pruning |
Given 5 versions and a cap of 3 / Then versions 3, 4, 5 are kept |
P1 |
| 6.2.5 |
Restore appends |
Given v1 and v2 / When v1 is restored / Then v3 is a copy of v1 with from: 1 |
P0 |
| 6.2.6 |
Undo walks back |
Given A, B, C / When "Undo last change" twice / Then B, then A, then nothing left to undo |
P0 |
| 6.2.7 |
Rename moves history |
Given a scratch chart renamed by createEmbed({ filename }) / Then its versions follow the new name |
P1 |
| 6.2.8 |
Shared history |
Given a version recorded on one Y.Doc / When synced to another / Then the other lists it and its observer fires |
P1 |
| 6.2.9 |
Title and source |
Given createEmbed with a title and a source / Then onMeta receives both for the node |
P1 |
6.3 Preview errors and inference errors (backend)
| # |
Test |
Given / When / Then |
Priority |
| 6.3.1 |
Reporter only in the studio |
Given buildEmbedSrcdoc without studio / Then no embedError relay in the document |
P0 |
| 6.3.2 |
Reporter runs first |
Given studio: true / Then the reporter precedes the runtime and the fragment |
P0 |
| 6.3.3 |
What is relayed |
Given studio: true / Then window errors, unhandled rejections, embed:error and embed:ready are posted to the parent |
P0 |
| 6.3.4 |
Provider status kept |
Given an APICallError with status 402 / 429 (also as a wrapped cause) / When formatted / Then HTTP <status>: <message from the JSON body> |
P1 |
| 6.3.5 |
Missing token |
Given no HF token / When POST /api/chat or /api/embed-chat / Then 401 with a "Hugging Face token" message |
P1 |
6.3.1 to 6.3.3 live in backend/tests/embed-doc.test.ts, 6.3.4 in backend/tests/stream-errors.test.ts, 6.3.5 in backend/tests/agent-chat.test.ts.
6.4 Drafts and "Apply to article" (frontend/tests/embed-drafts.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.4.1 |
Agent writes stay in the draft |
Given an applied chart / When the agent patches it / Then Y.Map("embeds") is unchanged and the draft holds the patch, its base and its author |
P0 |
| 6.4.2 |
Apply publishes |
Given a new chart created in a draft with a title and a source / When applied / Then the embed exists, the draft is gone and the result asks for a node with that title and source |
P0 |
| 6.4.3 |
Nothing to apply |
Given no draft, or an empty one / When applied / Then null and no embed written |
P1 |
| 6.4.4 |
Clean draft |
Given a draft equal to the applied HTML / Then it is not dirty (closing drops it silently) |
P1 |
| 6.4.5 |
No rename once in the article |
Given a chart already applied / When createEmbed({ filename }) / Then the file keeps its name |
P0 |
| 6.4.6 |
Draft names are taken |
Given a new draft named accuracy.html / When another new chart asks for accuracy / Then it gets accuracy-2.html |
P1 |
6.5 Shared conversation and presence (frontend/tests/embed-drafts.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.5.1 |
Readable text only |
Given a turn with a tool call carrying chart HTML / When synced twice as the reply grows / Then two entries, updated in place, no HTML stored |
P1 |
| 6.5.2 |
Same thread for everyone |
Given a thread on one Y.Doc / When synced to another / Then the rebuilt messages keep their ids (the turn ids of versions) and authors |
P1 |
| 6.5.3 |
Cap, rename, clear |
Given a cap of 3 / Then the oldest entries go; the thread follows a rename and can be cleared |
P1 |
| 6.5.4 |
Presence |
Given awareness states / Then other tabs on the same chart are listed once per person, never this tab, with sanitized colors |
P1 |
6.6 Before / after code diff (frontend/tests/embed-data-diff.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.6.1 |
Line diff |
Given two versions / Then removed, added and unchanged lines in order, with counts |
P1 |
| 6.6.2 |
Collapsed context |
Given one change in 30 lines / Then unchanged runs collapse to skip markers with 2 lines of context |
P1 |
| 6.6.3 |
Size guard |
Given more than 3000 lines / Then the diff is refused (null) |
P1 |
6.7 Data drawer, pasted tables, streaming progress (frontend/tests/embed-data-diff.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.7.1 |
Column types |
Given dates, numbers with a stray n/a, booleans, text and an empty column / Then each column gets its type |
P1 |
| 6.7.2 |
Used by this chart |
Given a chart naming the file or inlining most of its columns / Then the file is flagged; one shared column is not enough |
P1 |
| 6.7.3 |
Pasted table detection |
Given TSV, quoted CSV, prose, or a header with one row / Then tables are detected, prose and too-short pastes are not |
P1 |
| 6.7.4 |
Pasted table storage |
Given a ; table / Then it is stored as CSV under the first free pasted-data name |
P1 |
| 6.7.5 |
Streaming progress |
Given a createEmbed part in input-streaming / Then its partial HTML line count and "Writing chart... N lines" |
P1 |
| 6.7.6 |
No false progress |
Given a complete input or another tool streaming / Then no progress is reported |
P1 |
6.8 Automatic check after each iteration (backend/tests/embed-check.test.ts)
The route is tested with a fake runner, so the hermetic suite never starts Chromium. The real check (src/embed-check/check.ts, shared with npm run check:embeds) is exercised by the checker scripts.
| # |
Test |
Given / When / Then |
Priority |
| 6.8.1 |
Named checks |
Given a warning on overlap and a warning plus a failure on contrast / Then 6 of 8 checks pass, 1 warning, 1 failure, with the messages per check |
P1 |
| 6.8.2 |
Clean chart |
Given no issue / Then "8 checks passed" |
P1 |
| 6.8.3 |
Route runs the checker |
Given POST /api/embed-check with HTML and banner: true / Then the runner gets both and the summary label is returned |
P1 |
| 6.8.4 |
Input guards |
Given no HTML, HTML over 512 000 characters, or checks disabled / Then 400, 413, 503 |
P1 |
| 6.8.5 |
Crash is reported |
Given a runner that throws (no Chromium) / Then 503 with the first line of the error, and the next check still runs |
P1 |
| 6.8.6 |
One at a time |
Given three concurrent requests / Then the runner never runs two checks at once |
P1 |
6.9 Gallery starters (backend/tests/embed-check.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.9.1 |
Starters API |
Given GET /api/embed-starters / Then the curated list without HTML, including a banner; GET by slug returns HTML calling Embed.mount; unknown slug is 404 |
P1 |
6.10 Embed document: scripts, tweaks, inspector (backend/tests/embed-doc.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.10.1 |
Several scripts |
Given a fragment with the data-embed-config JSON block and the chart script / Then both keep their closing tags (before, everything after the first script was swallowed) |
P0 |
| 6.10.2 |
Stray closing tag |
Given '</script>' inside a JS string / Then it is escaped and the real closing tag kept |
P0 |
| 6.10.3 |
Runtime reads tweaks |
Given any embed document / Then the runtime reads script[data-embed-config] and listens to embedConfig; the agent prompt asks for the block |
P1 |
| 6.10.4 |
Inspector |
Given studio: true / Then the point-and-click inspector is in the document, off by default; published documents have none |
P1 |
6.11 Tweak panel config block (frontend/tests/embed-config.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.11.1 |
Declared settings |
Given text, color, range, select and toggle settings / Then five fields in order with their bounds and values |
P1 |
| 6.11.2 |
Loose declarations |
Given bare values and an options list with an unknown value / Then types and labels are inferred, the select falls back to its first option |
P1 |
| 6.11.3 |
No panel |
Given no block, invalid JSON or only unusable fields / Then null |
P1 |
| 6.11.4 |
Write-back |
Given new values / Then the block holds them, keeps bounds and the chart script, ignores unknown keys, and is unchanged when values are equal |
P0 |
| 6.11.5 |
Inline label edits |
Given a clicked label equal to a text setting / Then that setting is found |
P1 |
6.12 Inspect and check prompts (frontend/tests/embed-config.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 6.12.1 |
Selected element context |
Given a picked <text> / Then the chip label and the context sent to the agent carry its classes, text, selector and bound data |
P1 |
| 6.12.2 |
Fix prompt from the check |
Given a summary with a failure and a warning / Then the failure comes first, passing checks are left out |
P1 |
7. MCP charts and publishing (P0/P1)
What an external agent does with charts and publishing (MCP.md). The rendering check is replaced by a fake runner or turned off (ENABLE_EMBED_CHECK=false), so no test starts Chromium.
7.1 Embed contract and check queue (backend/tests/embed-contract.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 7.1.1 |
Valid fragment |
Given a chart that follows the contract / Then no error, no warning, its root class |
P0 |
| 7.1.2 |
Refused fragments |
Given a full document, no root class, no or a mismatched Embed.mount, broken config JSON, or over 512 000 characters / Then an error each |
P0 |
| 7.1.3 |
Warnings |
Given fetch, a hardcoded color, no describe, no config block / Then warnings; banners skip the describe and config ones |
P1 |
| 7.1.4 |
Names |
Given "Model Accuracy (v2).html" / Then model-accuracy-v2 |
P1 |
| 7.1.5 |
Static fallback |
Given checks disabled / Then the static contract check, mode: "static", with a note |
P0 |
| 7.1.6 |
Crash fallback |
Given a runner that fails to launch Chromium / Then static checks and the reason, never a tool failure |
P0 |
| 7.1.7 |
One at a time |
Given 3 checks queued / Then they never overlap, and a 4th is refused with CheckBusyError |
P0 |
| 7.1.8 |
Shared with the PDF |
Given a PDF export holding the Chromium lock / Then a check waits for it |
P1 |
7.2 Create and place a chart (backend/tests/mcp-embeds.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 7.2.1 |
Contract errors |
Given HTML without root class or mount / When create_embed / Then invalid_embed with the errors, nothing written |
P0 |
| 7.2.2 |
Create |
Given a valid chart with a data file / Then model-accuracy.html v1, not inserted, the browser check; the human peer gets the embed, the file shape and a version by "Claude Code", no node |
P0 |
| 7.2.3 |
Existing name |
Given the same name / Then already_exists with the latest version |
P1 |
| 7.2.4 |
Self-correction |
Given a chart that throws / Then check.status: FAIL with the message; a patch with expected_version: 1 makes v2 and the check passes |
P0 |
| 7.2.5 |
Insert with expected_rev |
Given a stale anchor rev / Then rev_conflict; with the current rev the node lands after the heading with the create title and "Source: ..." |
P0 |
| 7.2.6 |
Insert guards |
Given a chart already placed, or an unknown one / Then already_inserted, not_found |
P1 |
| 7.2.7 |
Batch |
Given apply_edits with insert_blocks + insert_embed / Then all or nothing |
P1 |
7.3 Update, versions, drafts (backend/tests/mcp-embeds.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 7.3.1 |
expected_version |
Given a stale version / Then version_conflict with the latest one |
P0 |
| 7.3.2 |
Config and caption |
Given an unknown key / Then invalid_request with the known keys; given config, description and source / Then the HTML and the node's caption change, v2 |
P0 |
| 7.3.3 |
Studio draft guard |
Given a person's unapplied draft / Then draft_in_progress; with force the article version changes and the draft stays |
P0 |
| 7.3.4 |
Restore |
Given v3 / When restore_embed_version v1 / Then v4 is a copy of v1 (kind: restore, from: 1) |
P0 |
| 7.3.5 |
Session undo |
Given a chart update / When undo / Then the chart is back |
P1 |
| 7.3.6 |
Read |
Given two charts / Then list_embeds and get_embed give placement, data files and versions; include_html: false drops the HTML |
P1 |
7.4 Publish (backend/tests/mcp-embeds.test.ts, backend/tests/publish-service.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 7.4.1 |
Publish |
Given the article with a chart / When publish / Then succeeded with absolute URLs, no PDF here; the page contains the title and the chart; get_publish_status has the job and the last publish by the agent |
P0 |
| 7.4.2 |
Republish |
Given new text / When publishing again / Then the page has it |
P1 |
| 7.4.3 |
Version |
Given a publish by the agent / Then a publish version attributed to the agent |
P1 |
| 7.4.4 |
Article info |
Then title, 2 embeds, publishable, documents: "single", the public URL and the last publish |
P1 |
| 7.4.5 |
Other document |
Given a session on ?doc=scratch / Then not_publishable |
P1 |
| 7.4.6 |
Idempotent |
Given a running publish / When another starts / Then the running job comes back (started: false); once done, a new one starts |
P0 |
| 7.4.7 |
Failure |
Given a failing publish / Then the job reports the error and the last publish is unchanged |
P1 |
| 7.4.8 |
Wait timeout |
Given a publish that never ends / Then wait returns it still running |
P1 |
7.5 Machine paths (backend/tests/mcp-embeds.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 7.5.1 |
JSON 404 |
Given unknown /.well-known/..., /mcp/..., /api/... paths / Then 404 JSON { error, path }; other paths still get the editor page |
P0 |
7.6 Permissions with OAuth on (backend/tests/mcp-auth.test.ts)
| # |
Test |
Given / When / Then |
Priority |
| 7.6.1 |
No or bad token |
Then 401 with WWW-Authenticate: Bearer |
P0 |
| 7.6.2 |
Discovery |
Given OAuth on / Then /.well-known/oauth-protected-resource/mcp is a JSON 404, not the login page |
P0 |
| 7.6.3 |
Editor publishes |
Given a valid editor token / When publish / Then succeeded, started by "Claude Code (alice)" |
P0 |
| 7.6.4 |
No write access |
Given a user without write access to the Space / Then 403 at initialize, so no tool (publish included) is reachable |
P0 |
7.7 Scenario: add a chart and publish (backend/tests/scenarios/mcp-embeds.test.ts)
Real server process, a person in a tab, the SDK client, rendering check off.
| # |
Scenario |
Priority |
| 7.7.1 |
Create (static check), a stale insert refused after the person retitles the heading, insert, update, restore, publish; after a SIGTERM the disk copy has the chart, its node, versions 1 to 3 and the data file |
P0 |
| 7.7.2 |
"Undo its changes" from the editor removes the agent's chart and its node, keeps the person's text |
P0 |
What we do NOT test (and why)
| Area |
Reason |
| Yjs real-time sync |
Yjs/Hocuspocus are mature libs - testing their CRDT sync is noise |
| Visual rendering of components |
Project evolves too fast, snapshot tests would break constantly |
| PDF generation (Playwright) |
Heavy dependency, visual output - better as a manual smoke test |
| Slash commands / Bubble toolbar |
UI that will change - covered by the opt-in Playwright suite instead of the hermetic one |
| CSS architecture |
Not meaningfully unit-testable |
| TipTap extension registration |
Framework internals, not business logic |
Summary
| Section |
P0 tests |
P1 tests |
Total |
| 1. Publisher Pipeline |
8 |
4 |
12 |
| 2. Persistence / Storage |
4 |
3 |
7 |
| 3. API Routes |
2 |
6 |
8 |
| 4. Auth / Security |
5 |
2 |
7 |
| 5. AI Agent |
1 |
7 |
8 |
| 6. Embed Studio |
14 |
45 |
59 |
| 7. MCP charts and publishing |
22 |
14 |
36 |
| Total |
56 |
81 |
137 |
Start with the 20 P0 tests. They cover the "if this breaks, we lose data or trust" surface. Add P1 tests as the codebase stabilizes.