# Behavior traces — vitest-dev/vitest

> Canonical page: https://codevetter.com/unpack/vitest/behavior-traces

# Behavior traces — vitest-dev/vitest

Scanned commit 4ee66c021e0592c886dbab727f0f8da9366f99ab (2026-10-02). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Three core flows were followed across their implementing files: CLI startup, primary test execution, and snapshot persistence. Additional traces cover UI authentication, report replay, and shutdown. Ordering matters because configuration, servers, workers, reporters, and filesystem artifacts have separate lifetimes. These are source-derived walkthroughs, not observed runtime executions.
- Startup begins vitest.mjs → cli.ts → createCLI().parse() → run/start → startVitest → prepareVitest; run preserves watch mode when --watch is supplied. — [packages/vitest/vitest.mjs#L1-2](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/vitest.mjs#L1-L2) [packages/vitest/src/node/cli.ts#L1-3](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/cli.ts#L1-L3) [packages/vitest/src/node/cli/cac.ts#L268-272](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/cli/cac.ts#L268-L272) [packages/vitest/src/node/cli/cac.ts#L302-310](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/cli/cac.ts#L302-L310)
- prepareVitest → createVitest → resolveConfig → new Vitest → _start → _setRootConfig → _attachRootServer → _attachProjectServers establishes the coordinator before startVitest invokes start or an alternate maintenance mode. — [packages/vitest/src/node/cli/cli-api.ts#L146-156](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/cli/cli-api.ts#L146-L156) [packages/vitest/src/node/cli/cli-api.ts#L234-249](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/cli/cli-api.ts#L234-L249) [packages/vitest/src/node/create.ts#L44-55](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/create.ts#L44-L55) [packages/vitest/src/node/core.ts#L215-219](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/core.ts#L215-L219)
- Vitest.start initializes coverage and reporters, discovers specifications, optionally preparses them, populates file statistics, and calls runFiles; empty discovery has special changed/related watch handling. — [packages/vitest/src/node/core.ts#L858-892](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/core.ts#L858-L892) [packages/vitest/src/node/core.ts#L895-925](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/core.ts#L895-L925)
- runFiles creates the pool, clears invalidations/snapshot/errors, initializes global setup, and calls pool.runTests; worker run resolves runner/environment/coverage concurrently, then startTests collects modules and runs suites. — [packages/vitest/src/node/core.ts#L1056-1077](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/core.ts#L1056-L1077) [packages/vitest/src/runtime/runBaseTests.ts#L28-42](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/runtime/runBaseTests.ts#L28-L42) [packages/vitest/src/runtime/runBaseTests.ts#L52-81](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/runtime/runBaseTests.ts#L52-L81) [packages/vitest/src/runtime/runner/run.ts#L1039-1052](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/runtime/runner/run.ts#L1039-L1052)
- Snapshot persistence follows TestRunner.onBeforeRunSuite → SnapshotClient.setup → SnapshotState.create, then matcher delegation → SnapshotClient.match; suite completion calls finish → pack → save and reports snapshotSaved. — [packages/vitest/src/runtime/runners/test.ts#L154-162](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/runtime/runners/test.ts#L154-L162) [packages/vitest/src/integrations/snapshot/chai.ts#L276-299](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/integrations/snapshot/chai.ts#L276-L299) [packages/snapshot/src/client.ts#L77-88](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/snapshot/src/client.ts#L77-L88) [packages/snapshot/src/port/state.ts#L607-633](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/snapshot/src/port/state.ts#L607-L633)
- SnapshotState.save selects external, inline, or raw persistence; external saveSnapshotFile sorts and serializes entries, skips identical content, and NodeSnapshotEnvironment creates directories and writes UTF-8. — [packages/snapshot/src/port/state.ts#L410-438](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/snapshot/src/port/state.ts#L410-L438) [packages/snapshot/src/port/utils.ts#L104-126](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/snapshot/src/port/utils.ts#L104-L126) [packages/snapshot/src/env/node.ts#L31-40](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/snapshot/src/env/node.ts#L31-L40)
- UI login validates ?token=, sets an HttpOnly SameSite=strict cookie, redirects to the clean UI base, and injects the API token into authorized HTML; WebSocket upgrades separately require isValidApiRequest. — [packages/ui/node/index.ts#L41-84](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/ui/node/index.ts#L41-L84) [packages/ui/node/index.ts#L140-162](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/ui/node/index.ts#L140-L162) [packages/vitest/src/api/setup.ts#L44-62](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/api/setup.ts#L44-L62)
- Report replay reads blobs, reconstructs specifications, replays file events, and merges coverage; shutdown waits for the active run, tears down global setup in reverse project order, closes the pool, then closes project servers. — [packages/vitest/src/node/core.ts#L698-739](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/core.ts#L698-L739) [packages/vitest/src/node/core.ts#L1645-1691](https://github.com/vitest-dev/vitest/blob/4ee66c021e0592c886dbab727f0f8da9366f99ab/packages/vitest/src/node/core.ts#L1645-L1691)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
