choruz-ci-test-reliability
Skill1.1k starsChanged 19 days agoApache-2.0View on GitHub
Design, review, and diagnose Choruz tests and fixtures that can fail nondeterministically under CI concurrency: parallel Playwright workers sharing one PostgreSQL and one API, vitest workers, cargo tests on a shared test database, clocks, ports, and asynchronous teardown. Use when adding or changing tests with those risks, investigating a flaky CI run, or reviewing test isolation.
- Reads credentials
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .agents/notes/implemented/AGENTS.mdAGENTS.md
- docs/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- choruz-archive-agent-notesSkill
- choruz-code-reviewSkill
- choruz-docSkill
- choruz-find-simplificationsSkill
- choruz-merging-stacked-prsSkill
- choruz-pre-push-checksSkill
- choruz-pre-simplify-auditSkill
- choruz-prose-standardSkill
- choruz-prSkill
- choruz-record-demoSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 7 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
When loaded from a personal skills directory, resolve repository links from this skill's canonical …
- Very specific: line 27
Create what you assert on.
- Very specific: line 28
Never compare absolute counts taken at two moments (countAfter === countBefore): another worker can add a row in between.
- Distinctive: line 29
Never assume an empty workspace, an empty conversation list, or that a default agent exists.
- Very specific: line 30
Use data-conversation-id and other stable attributes instead of visible text that other workers can also produce.
- Very specific: line 43
Wait for the observable condition: expect(locator).toHaveCount(n), expect.poll(...), a readiness endpoint, an owned promise.
- Distinctive: line 45
Use a timeout only to bound a wait, never as the condition that makes the assertion correct.
- Distinctive: line 46
When time itself is the subject, inject or fake the clock and always restore real timers.
- Distinctive: line 57
Verify external state (a row, an event, a file, a process exit) instead of trusting the component's self-report.
- Distinctive: line 61
Do not present these as root-cause fixes:
- Distinctive: line 70
Never skip, disable or quarantine a test to get CI green.
- Distinctive: line 75
Read the test for shared state: unseeded data, absolute counts, first-item locators, fixed waits, mocks broader than the test.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill 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
Reliable Choruz CI tests
When loaded from a personal skills directory, resolve repository links from this skill's canonical .agents/skills/choruz-ci-test-reliability/ location in the active Choruz checkout, not from the installed copy.
Build tests that remain correct under the repository's real CI topology, not only when run alone on a quiet workstation. This skill owns isolation and reliability decisions; docs/testing/pr-test-policy.md owns which tests a change must add, and choruz-pre-push-checks owns which commands to run before a push.
Model the execution topology
Assume these layers overlap unless the active configuration proves otherwise:
- Playwright:
apps/web/playwright.config.tsruns withfullyParalleland two workers on CI (CHORUZ_E2E_WORKERS), sharded across jobs (--shard=n/m). Every worker talks to the same API, the same PostgreSQL and the same pipeline started byinfra/host/web_e2e.sh; only the browser context is private.retries: 1on CI means a test that passes on retry is reported as flaky, not as passing. - vitest:
apps/webunit tests run in worker processes; module state,process.env, timers andlocalStoragemocks are per file, not per test. - cargo: integration tests under
crates/andservices/share the database created byinfra/host/setup_test_database.sh; tests in one binary run on parallel threads. - Jobs: the e2e shards, the Rust jobs and the smoke jobs run at the same time on separate runners; they do not share a host, but they do share GitHub's artifact and cache services.
Process isolation does not isolate database rows, ports, predictable filesystem paths or inherited child processes. For every acquired resource, identify its owner, its allocation mechanism, its readiness signal, its cleanup, and its quiescent completion signal.
Own your data
The single most common Choruz flake is a test that reads global state another worker is writing.
- Create what you assert on. Seed a group with
createGroup(page, token, principal.id, uniqueName("…")), an agent withprovisionAgent, a message withsendMessage; then assert on those ids and names, never on "at least one exists" or "the first item". - Never compare absolute counts taken at two moments (
countAfter === countBefore): another worker can add a row in between. Assert the filtered result is empty and the restored list contains the seeded item, or usetoBeGreaterThanOrEqualwith the seeded item present. - Never assume an empty workspace, an empty conversation list, or that a default agent exists.
- Use
data-conversation-idand other stable attributes instead of visible text that other workers can also produce. - In cargo tests, give rows unique names or ids per test and scope queries to them; never truncate a shared table.
Allocate resources atomically
- Ports come from the environment (
CHORUZ_API_PORT,CHORUZ_WEB_PORT,CHORUZ_PIPELINE_METRICS_PORT,CHORUZ_PG_PORT) thatweb_e2e.shalready isolates per run; a test never binds a fixed port of its own. A Rust test that needs a listener binds port 0 and reads the assigned address. - Temporary files use a private per-test directory (
tempfile::tempdir(),mkdtemp), never a predictable path. - Route mocks (
page.route) match the exact request the test owns, not a prefix another flow also hits.
Synchronize on state
A fixed waitForTimeout is not evidence that setup completed or that cleanup settled.
- Wait for the observable condition:
expect(locator).toHaveCount(n),expect.poll(...), a readiness endpoint, an owned promise. - Message delivery in the web app arrives through the sync feed; wait for the bubble with the seeded content, not for a duration.
- Use a timeout only to bound a wait, never as the condition that makes the assertion correct.
- When time itself is the subject, inject or fake the clock and always restore real timers.
Dispose to quiescence
Register cleanup right after acquisition so an assertion failure also releases the resource. Cleanup stops new requests, detaches listeners, restores globals, terminates owned work, and awaits child exit or server close. Calling abort() or kill() without awaiting completion is incomplete teardown.
Prove the intended regression
- Establish assertion strength and safe negative controls through the policy's behaviour acceptance evidence. A repeatably green test can still assert the wrong result; isolation does not prove product correctness.
- For a fixed flake, run the spec repeatedly with the CI settings:
bash infra/host/web_e2e.sh tests/e2e/<spec> --repeat-each=3. - For a race, use barriers to prove overlap; repeated execution alone is not a race test.
- Verify external state (a row, an event, a file, a process exit) instead of trusting the component's self-report.
Reject flake-masking fixes
Do not present these as root-cause fixes:
- raising a timeout without naming the awaited state;
- adding retries or
test.fixme/test.skip; - making a whole file serial to hide one shared resource;
- swallowing an error or unhandled rejection;
- weakening an assertion or normalizing away unstable behaviour;
- adding a sleep before cleanup or an assertion.
Never skip, disable or quarantine a test to get CI green; fix the isolation.
Diagnose an existing flake
- Download the shard's Playwright artifact (
playwright-<shard>.zip, orplaywright-full-<shard>.zip) and read the trace and screenshot of the failed attempt; the retry's pass is not evidence. - Read the test for shared state: unseeded data, absolute counts, first-item locators, fixed waits, mocks broader than the test.
- Reproduce locally with the CI settings (
CI=1, two workers,--repeat-each=3) and the neighbouring specs of the same shard, since the interfering worker is usually one of them. - Fix the isolation, then run the repeat locally before pushing. A diagnosis-only request is read-only: report the cause and evidence unless the user also asks for a fix.
Validate and report
Run the smallest focused regression for the affected behaviour, plus topology-specific evidence only when the change owns that risk: restoration evidence for global mutation, quiescent-teardown evidence for lifecycle work, a negative control for a new guard. Report exact commands and observed results; do not describe retries, skipped tests, or pending CI as passing.
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.

