# Faster verification

Full checks work as before. For deterministic **Vitest 4** projects, Hybrid can reuse an unchanged full result or run tests related to a known source change. It always labels which happened. Reviewer approval remains separate.

Ask your planning agent to establish the input contract from your actual tests and dependencies. Keep full checks if those assumptions cannot be established. This first adapter supports exactly `"test": "vitest run"`, without `pretest` or `posttest`; other scripts still execute normally.

Example in the project's `package.json`:

```json
{
  "scripts": { "test": "vitest run" },
  "hybrid": {
    "verification": {
      "version": 1,
      "scripts": {
        "test": {
          "runner": "vitest",
          "deterministic": true,
          "externalInputs": false,
          "unrelatedDocuments": ["README.md"],
          "outputs": ["node_modules/.vite"],
          "relatedSources": ["src/money.ts"]
        }
      }
    }
  }
}
```

These are **explicit project assertions**, not conclusions inferred by the plugin:

- `deterministic`: the same inputs produce the same test outcome. Time, randomness and external service state must not affect it.
- `externalInputs: false`: tests read only bound project files, installed dependencies and the child process environment. Git history/status, user-home files, OS services, global tools launched by tests and other undeclared external state are not covered. Such checks must run fresh.
- `unrelatedDocuments`: literal Markdown/text files proven not to affect any test. No globs. All other project files, including Git-ignored fixtures and `.env`, are fingerprinted.
- `outputs`: disposable output directories that tests never use as inputs. Supported: `coverage`, `node_modules/.vite`, `node_modules/.vite-temp`. Never exclude test fixtures or source. Output exclusion is an assertion; a test that reads its prior cache is not eligible.
- `relatedSources`: existing implementation modules with a known static import relationship to tests, including transitive consumers. Do not declare modules with computed imports, runtime file loading, global side effects across test files, custom loader dependencies or dependencies outside Vitest's graph. A conservative scan rejects common dynamic-loading cases; it is **not a general dependency proof**. Omit this list when unsure; unchanged-input reuse still works.

Every optimization starts with a successful, complete, nonempty full Vitest run. The receipt binds the project, contract, complete nonexcluded file inventory, installed dependency bytes, file permissions, lockfiles, configuration, Node/platform, pnpm implementation and child environment. Secrets are hashed, never copied into receipts. Raw test output can still contain what your tests print, just as with ordinary verification.

An exact match may reuse the previous result and reports its original execution time. Changes limited to declared static sources may run `vitest related --run`; that result is **selected-tests-only**, not a full-suite pass. An empty selection falls back to full verification. Unknown/new/deleted files, changed tests/fixtures/configuration, toolchain or environment changes use a full run. External links or unsupported launchers disable optimization. A failed fresh full attempt invalidates the older success. Reuse is local to the project; nothing is uploaded to a cache service.

For a fresh full check, the agent calls:

```json
{ "action": "verify", "script": "test", "verificationMode": "full" }
```

Use fresh full checks for final acceptance or whenever the dependency assumptions are uncertain. Existing typecheck, lint and build scripts still run in full. No verification result grants reviewer approval, and no automatic model or environment changes are made.

## Automatic cost choice

Once a project has the contract above, no speed settings are needed. The first run measures full execution and the additional input-binding work. Later runs choose ordinary full checks without that hashing when it costs at least as much as running the suite. Supported Vitest runs still validate a complete, nonempty passing report.

Ordinary runs keep measuring execution time. If the suite grows enough to make optimization worthwhile, Hybrid recalibrates and can reuse unchanged results again. A new targeted selection is measured on its first use; if selection plus binding is slower than full execution, later matching corrections use full checks instead.

Results include the reason, execution time and input-binding time. Timing history is a local performance hint, never evidence of correctness or reviewer approval. A missing or invalid history causes calibration; a failed history write does not discard the check result. A forced full check skips optimization hashing and does not create a reusable receipt.

The initial calibration and a first targeted trial can be slower. Decisions use previous observations, so machine load and changing workloads can still affect the next run; this is not a promise that every call will be faster. Browser scenario/evidence reuse is a separate feature and is not included here.

Reference: [Vitest related CLI and its static import limitations](https://vitest.dev/guide/cli.html#vitest-related).
