BE-319: Split backend integration tests into seeded and snapshot groups#9006
BE-319: Split backend integration tests into seeded and snapshot groups#9006claude[bot] wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
PR SummaryLow Risk Overview
The seeded config keeps
Reviewed by Cursor Bugbot for commit 05656ce. Bugbot is set up for automated code reviews on this repo. Configure here. |
The seeded group (vitest.config.ts, src/tests/graph/) runs against the system graph seeded once per run by globalSetup and must never wipe it. The snapshot group (vitest.snapshot.config.ts, src/tests/subgraph/) wipes the graph and restores standalone snapshots, so test:integration runs it as a separate vitest invocation after the seeded group. A runtime guard in admin-server.ts makes resetGraph/restoreSnapshot refuse to run outside the snapshot group, keyed off the HASH_TEST_GROUP marker set by the snapshot config.
165923d to
05656ce
Compare
Requested by Tim Diekmann, Ahmad Sattar Atta · Slack thread
🌟 What is the purpose of this PR?
Follow-up to #9001, addressing review feedback: the boundary between tests that rely on the shared seeded graph and tests that wipe it was a path-prefix convention inside a single vitest run.
Before: one vitest run covered all test files, and a custom sequencer (
DestructiveTestsLastSequencer) identified destructive files by thesrc/tests/subgraph/path prefix and sorted them last. A destructive test added elsewhere would silently run mid-pack, wipe the graph seeded once per run byglobalSetup, and corrupt the shared seed for every test file after it — the ordering was a convention, not a guarantee.After: the suite is split into two explicit groups that run as separate, sequential vitest invocations:
vitest.config.ts,src/tests/graph/) keeps theglobalSetupseed and structurally cannot wipe the graph — its invocation contains no destructive file and completes before the destructive run starts;vitest.snapshot.config.ts,src/tests/subgraph/) owns the wipe: it has noglobalSetup, and its files reset the graph and restore standalone snapshots;resetGraph/restoreSnapshotthrow a clear error unless the snapshot group's config marker is present, so a destructive call from the seeded group fails immediately in the offending file instead of corrupting unrelated tests.The sequencer and the central registry file are gone; the groups are defined by the two configs over the existing directory layout (no test files were moved).
🔗 Related links
🔍 What does this change?
All changes are in
tests/hash-backend-integration:vitest.config.ts(seeded group):includeis now onlysrc/tests/graph/**/*.test.ts(18 files); keepsglobalSetup. TheDestructiveTestsLastSequencerand thesrc/tests/destructive-test-files.tsregistry are deleted. Options common to both groups are exported assharedTestConfig.vitest.snapshot.config.ts(new, snapshot group): includes onlysrc/tests/subgraph/**/*.test.ts(3 files:circular,friendship,simple); noglobalSetup; sets theHASH_TEST_GROUP=snapshotmarker via vitest'stest.env; writes coverage to./coverage-snapshotso it doesn't clean the seeded group's./coveragereport (codecov's uploader discovers both).package.json:test:integrationis nowvitest --run && vitest --run --config vitest.snapshot.config.ts— seeded group first, snapshot group second. CI is unchanged:.github/workflows/test.ymlinvokes this viaturbo run test:integration.src/tests/admin-server.ts:resetGraph()andrestoreSnapshot()callassertRunningInSnapshotGroup, which throws unlessprocess.env.HASH_TEST_GROUP === "snapshot". The error explains that destructive graph operations only run in the snapshot group and that a test file becomes destructive by placing it undersrc/tests/subgraph/. Other admin helpers (e.g.deleteUser, used by the seededuser.test.ts) are unguarded, as before. The module no longer imports fromvitest, so it is usable outside a vitest worker again (no other consumers exist today — verified by grep).tsconfig.json: adds the new config file toincludesotsc/typed eslint cover it.Guard mechanism: in vitest 4.1.8,
test.envfrom the config verifiably reachesprocess.envin test workers before any test file runs: the pool serializesenv: { ...viteConfig.env, ...config.env }into the worker context, and the worker'ssetupCommonEnvwrites each key through themetaEnvproxy, whosesettrap assignsprocess.env[key](verified in the installedvitest/dist/chunks/cli-api.*.js,setup-common.*.js, andinit.*.js, and confirmed empirically with a scratch vitest run against the repo's installed vitest). In the seeded group's invocation the marker is simply never set, so the guard throws there.Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
coverage/from the seeded run,coverage-snapshot/from the snapshot run); the codecov action auto-discovers lcov files, so both are uploaded.src/tests/email.test.tsis matched by neither config — unchanged frommain, whoseincludepatterns (graph/**+subgraph/**) also excluded it.🛡 What tests cover this?
The backend integration suite itself (
yarn test:integrationintests/hash-backend-integration): the seeded group exercises the shared seed on every run, and the three snapshot-group files exercise the guard's pass path on every run.Verification performed:
tsc --noEmitandeslintfor@tests/hash-backend-integration: the full dependency graph (wasm build, graph client codegen) cannot be built in my sandbox, so both were run on this branch and onmainin the same unbuilt-deps state and the outputs diffed — byte-identical (pre-existing errors from unbuilt workspace deps on both; zero findings introduced by this change).oxfmt --checkpasses on all five changed files.vitest list --filesOnlyrun with both configs proves the partition: the seeded config lists exactly the 18src/tests/graph/**files, the snapshot config lists exactly the 3src/tests/subgraph/**files — no overlap, and together they cover every file the single config onmainincluded.test.env→process.envmechanism was verified in the installed vitest 4.1.8 dist and confirmed empirically (a scratch test assertingprocess.env.HASH_TEST_GROUP === "snapshot"passes under a config setting it viatest.env).❓ How to test this?
yarn workspace @tests/hash-backend-integration test:integration— the seeded group runs first against theglobalSetupseed, then the snapshot group runs the threesubgraph/files in a second vitest invocation.await resetGraph()to any seeded-group test file — it fails immediately with an error explaining that destructive graph operations only run in the snapshot group (vitest.snapshot.config.ts) and how to place a test there.Generated by Claude Code