Repository navigation
feat: Vitest adapter — per-test V8 trace, same journey attribution - #170
Merged
Merged
Conversation
) testgraph.vitest_adapter runs a Vitest suite once and attributes journeys the way pytest_adapter does. harness/plugin/tgtrace-vitest.ts (TypeScript, shipped beside tgtrace.py) takes V8 precise coverage per test and writes one atomic part file per test file; Vitest's JSON reporter gives verdicts; attribute / journey_entries / write_outcomes are reused unchanged. The setup file is injected through a generated config in a temp dir that imports the repo's own config and mergeConfigs it in, with a node_modules symlink so vitest resolves as the repo's tests see it. Nothing is written into the target repo. Refusals (no vitest install, no or truncated report, a broken part, tests run but no trace) exit 2. pytest_adapter.render labels the runner, so both adapters share it.
A broken or partial run is a refusal (exit 2), never a verdict.
V1 a passed/failed test with no trace refuses (count + example id); a
reporter "pending" test (killed worker) refuses instead of reading as skip
V2 trace recorded in onTestFinished (from beforeEach), which still fires when
the repo's afterEach throws; V1 backstops it
V3 duplicate test ids refuse (report side and setup-file side). Chosen over
worst-status/union: with one id for two tests the join cannot say which
verdict belongs to which trace, so any merge is a guess
V4 a file that failed outside any test (import error, throwing beforeAll)
refuses by name; the reporter marks beforeAll-skipped tests "skipped"
V5 realpath for cwd, TGTRACE_ROOT and the id root (Python and TS)
V6 the generated config no longer forces `root`
V7 all-skipped and no-match runs are empty successes; test.projects and
vitest.workspace.* are refused up front with their real cause
V8 --coverage.enabled=false
V9 empty describe names kept in the TS id, as ancestorTitles keeps them
V10 temp node_modules is a dir of per-entry symlinks so Vite's .vite-temp stays
in the temp dir (--configLoader runner rejected: no __dirname)
V11 report shape validated, refusal instead of a crash
V12 default-export config awaited whether function result or Promise
Adds a real-Vitest integration class (TG_VITEST_NODE_MODULES) covering the
above; `execute` factored out of run() so it can be driven directly.
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #122 (the Vitest half; Playwright is separate)
What
python3 -m testgraph.vitest_adapter --repo <path>runs a Vitest suite once and records which journeys its tests actually ran. It does whatpytest_adapterdoes for pytest suites: the same attribution against journey entry symbols, the same ledger rows taggededge_provenance=trace, and the same--dry-run,--jsonand--trace-outoptions.How
Recording what ran:
harness/plugin/tgtrace-vitest.tsis a Vitest setup file written in TypeScript. It ships next totgtrace.pyand imports onlyvitestand Node built-ins. For each test it collects V8 precise coverage throughnode:inspector, resetting the counters before the test and reading them inonTestFinished. Then it writes one part file per test file, atomically.Verdicts: these come from Vitest's JSON reporter. A test's id is
<relfile>::<describe> > ... > <title>, built the same way on both sides.Reused code:
attribute,journey_entries,write_outcomesandrenderare shared with the pytest adapter unchanged.rendernow shows which runner it reports for.Injection, with nothing written into the target repo: Vitest has no
--setupFilesflag. So a generated config in a temp dir imports the repo's ownvitest.config.*(orvite.config.*), whether it exports an object, a function or a Promise, and merges the setup file in withmergeConfig. The temp dir'snode_modulesis a real directory of symlinks to the repo's own entries, so Vite's config bundle lands in the temp dir. Vitest's normalnode_modules/.vitecache is still written, as with anyvitest run.What it refuses (exit 2): any broken or partial run.
afterAllthrew)beforeAll)test.projectsconfig or workspace file: projects don't inheritsetupFilesA run where every test is skipped, or a
-tfilter matches nothing, is an empty successful run, not a refusal.Other settings: coverage is turned off on the command line, because the repo's own V8 coverage would fight over the same counters. The repo's
rootis left alone.Tried and dropped:
afterEachas the collector: Vitest runsafterEachhooks in reverse order and stops at the first one that throws, so a failing test lost its trace.--configLoader runner: it doesn't define__dirname, which real configs use.rootin the generated config: it changed which tests ran.Measured (base
fc3d000vs this branch, Linux, Python 3.14 + pytest 9.0.3 / Python 3.11 without pytest, Node 22.23.5, Vitest 4.1.9)--dry-run. Journeys J1 (18 tests), J2 (5), J6 (9), J10 (12) and J13 (17) all pass, with Vitest exiting 0. Every traced test joined to its verdict, both ways. The other 9 journeys are pages and components with no unit test reaching them. The repo's working tree was unchanged afterwards (git status).Ran 664 tests ... OKon 3.14, andRan 664 tests ... OK (skipped=4)on 3.11 (571 on base). A real-Vitest test class builds small fixture projects and runs actual Vitest. It runs when Node and a Vitest install are available (TG_VITEST_NODE_MODULES) and skips cleanly otherwise. CI has no Node, so CI runs only the hermetic tests.failures=15, errors=25). Mutation check: I reverted each fix one at a time, and each revert turned at least one test red (17 of 17 checks, including all three sides of the duplicate-id fix and the extrapendingrefusal).tsc --noEmit --stricton the setup file exits 0.Known limits
verifydoesn't run Vitest suites yet: no running only the selected journeys' tests, and no@tg:declarations. That's the next step.reconcilewould need source maps for a full footprint..concurrenttests in one file share a coverage window, so their traces can bleed into each other or lose calls. No warning is shown.beforeAllin the same file can't be told apart fromit.skipthrough the reporter. USAGE.md documents this.runandmainrepeat about 120 lines ofpytest_adapter's. Sharing one runner-neutralrunis a follow-up (review V13).