ai-chat-ui / tests
CLAUDE.md71 starsChanged 3 months agoMITView on GitHub
All deterministic tests drive the real FastAPI server at tests/server/server.py, which uses pydantic-ai's FunctionModel to return predictable streams. The models mapping is the authoritative fixture registry. A spec picks an entry via sendMessage(page, '<name>', '<message>'). When you need new behavior, add a FunctionModel to the server's models dict and select it from the spec. Do not introduce page.route mocks — they duplicated the SSE wire format and drifted on the SDK v5→v6 bump, which is why we switched.
In this repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
The file
We split this CLAUDE.md into the rules it gives an agent
9 rules. About 0 are common, 2 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 5
All deterministic tests drive the real FastAPI server at tests/server/server.py, which uses pydantic-ai's FunctionModel to return …
- Very specific: line 7
When you need new behavior, add a FunctionModel to the server's models dict and select it from the spec.
- Very specific: line 11
Prefer accessible selectors: getByRole, getByPlaceholder, getByText, getByLabel
- Very specific: line 12
Use data-testid (or data-tool-name on Tool) only when no semantic selector exists
- Distinctive: line 13
Never use CSS selectors or XPath
- Very specific: line 23
Use web-first assertions (expect(locator).toBeVisible()) — they auto-retry
- Very specific: line 24
Never use page.waitForTimeout() — use expect with auto-retry, page.waitForFunction, or the waitForPersisted helper in e2e/conversation.ts …
- Very specific: line 42
Test names: describe user behavior, not implementation (approve runs the tool and shows the result)
- Distinctive: line 46
Every new user-facing feature needs at least one deterministic E2E spec
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Testing Standards
Paradigm: server-driven, no page.route mocks
All deterministic tests drive the real FastAPI server at tests/server/server.py, which uses pydantic-ai's FunctionModel to return predictable streams. The models mapping is the authoritative fixture registry. A spec picks an entry via sendMessage(page, '<name>', '<message>').
When you need new behavior, add a FunctionModel to the server's models dict and select it from the spec. Do not introduce page.route mocks — they duplicated the SSE wire format and drifted on the SDK v5→v6 bump, which is why we switched.
Selectors
- Prefer accessible selectors:
getByRole,getByPlaceholder,getByText,getByLabel - Use
data-testid(ordata-tool-nameonTool) only when no semantic selector exists - Never use CSS selectors or XPath
Test isolation
- Each test gets a fresh browser context (Playwright default)
- Tests must not depend on each other or share state
- The server is shared across tests; specs must be idempotent against shared server state
Assertions
- Use web-first assertions (
expect(locator).toBeVisible()) — they auto-retry - Never use
page.waitForTimeout()— useexpectwith auto-retry,page.waitForFunction, or thewaitForPersistedhelper ine2e/conversation.ts(polls IndexedDB) - Assert on user-visible outcomes, not implementation details
File layout
tests/server/— the FastAPI test server (Python, owned byuv)tests/e2e/deterministic/*.spec.ts— Playwright specs againstFunctionModelfixtures (run on every PR)tests/e2e/offline/*.spec.ts— Playwright specs against the builtoffline/index.html, run on every PR underplaywright.offline.config.ts(notE2E_TEST_DIR) because they needvite previewserving the artifact rather than the dev servertests/e2e/llm/*.spec.ts— live-provider Playwright specs (gated onworkflow_dispatch)tests/e2e/{conversation,sidebar,tools}.ts— shared spec helperstests/headless/*.test.ts— Vitest tests that exercise the wire protocol directly viaTestChat(no browser)tests/chat-client.ts,tests/global-setup.ts— Vitest server-spawn helpers
Naming
- Playwright spec files:
*.spec.ts - Vitest headless files:
*.test.ts - Describe blocks: feature area (
chat,sidebar,tool approval) - Test names: describe user behavior, not implementation (
approve runs the tool and shows the result)
When to add tests
- Every new user-facing feature needs at least one deterministic E2E spec
- Bug fixes should include a regression test when feasible
- New tool-shape behavior (approval, streaming, errors) should be exercised by a headless test in
tests/headless/first, then a deterministic Playwright spec
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

