# Test an extension
URL: /documentation/extensions/testing



## Goal [#goal]

Run the narrowest test that proves each boundary an extension touches, then finish with a real package-level round trip — so a change that passes a source-level unit test but breaks the installed artifact is caught before release, not after.

## Before you start [#before-you-start]

* Know which boundary your change actually touches. A new tool touches contract and registry boundaries; a new skill touches the contract boundary and the host-discovery half of the package boundary; a widget change touches the interface boundary; anything shipping to users touches the release boundary regardless of what else it touches.
* `pnpm install` at the repo root. Several suites below rebuild the façade or the plugin bundle as a prerequisite step, not as something you run separately first.

## Steps [#steps]

<Steps>
  <Step>
    ### Contract tests — schemas, discriminators, typed failures [#contract-tests--schemas-discriminators-typed-failures]

    Prove that a tool's input schema rejects what it should, its `execute` never throws for an ordinary failure, and its description keeps the `describe()` three-block shape. The per-tool matrix suite already exercises this across the registry:

    ```bash
    pnpm vitest run tests/contract/strata19-tool-matrix
    ```

    For a new skill, the equivalent is the skills-coverage suite — see [Package a skill](/documentation/extensions/skills)'s Verify section for exactly what it checks.
  </Step>

  <Step>
    ### Registry tests — projections, detector declarations, manifest coverage [#registry-tests--projections-detector-declarations-manifest-coverage]

    Prove the two-sided registries stay exhaustive over each other:

    ```bash
    pnpm audit:projections          # tool-projection-registry.ts vs. the live facadeTools registry
    pnpm gate:detector-registry     # detector-catalog.ts vs. the real AST of every scan root
    ```

    Both are deterministic and fast — run them on every registry-touching change, not only before release. [Add an MCP tool](/documentation/extensions/mcp-tools) and [Add a detector](/documentation/extensions/detectors) name the specific failure strings each one produces.
  </Step>

  <Step>
    ### Behavior tests — real graph, storage, or dispatcher logic [#behavior-tests--real-graph-storage-or-dispatcher-logic]

    Write a fixture that can fail for the intended reason, not one that only confirms the happy path. Run the plugin's own unit and end-to-end suite:

    ```bash
    pnpm test:plugin
    ```

    This rebuilds `mcp-dist` and the façade first, runs the confession-flow suites without file parallelism (they share process-level state), then runs every other suite under `tests/unit/plugin` and `tests/e2e/plugin`.
  </Step>

  <Step>
    ### Package tests — a clean install, not a source tree [#package-tests--a-clean-install-not-a-source-tree]

    A source-level unit test proves your function works. It does not prove the *packaged* plugin works — a missing bundled dependency, a stale generated artifact, or a broken `.mcp.json` launcher only shows up when something actually copies the plugin and spawns it. The package suite does exactly that:

    ```bash
    pnpm vitest run tests/e2e/plugin/strata19-package-e2e.test.ts
    ```

    It copies the plugin to a temporary directory and launches its committed `.mcp.json` command verbatim — no shortcuts through the source tree. `tests/e2e/plugin/strata19-bare-install-journey-e2e.test.ts` and `strata19-local-graph-e2e.test.ts` cover the zero-`node_modules` install path specifically (no native tree-sitter, no `npm install`), which is the default state of a fresh clone.
  </Step>

  <Step>
    ### Interface tests — real view models, real screenshots [#interface-tests--real-view-models-real-screenshots]

    For a widget change, render the actual view model rather than asserting on props in isolation, and confirm it visually:

    ```bash
    apps/web/node_modules/.bin/playwright test --config=playwright.config.ts --project=widget
    ```

    (`pnpm test:widget-visual` runs the same command.) Exercise keyboard and reduced-motion behavior where the component has it, and inspect the resulting screenshot rather than trusting that the test passed for the reason you expect — a widget rendered standalone via `setContent`, rather than from a real origin, has previously produced a blank pane that looked like three separate, convincing defects.
  </Step>

  <Step>
    ### Release tests — rebuild, verify parity, verify checksums [#release-tests--rebuild-verify-parity-verify-checksums]

    Before anything ships, run the same checks CI runs against the committed tree:

    ```bash
    pnpm build:plugin
    pnpm vitest run tests/e2e/strata19/local-product-release.spec.ts
    pnpm verify:strata19-plugin-parity
    pnpm verify:strata19-checksums
    ```

    The release journey (`local-product-release.spec.ts`) drives the generated plugin, its real `.mcp.json` command, and the shipped hook against a real temporary Git repository — it requires a planted high-severity finding to block a pinned contract, refuses a replaced always-pass target, and only permits a human-revised contract after the source defect is actually repaired. [Interface and packaging](/documentation/extensions/interface-and-packaging) owns the full rebuild-and-reinstall loop these commands are the tail end of.
  </Step>
</Steps>

## Verify [#verify]

A change is release-ready when all of these are true, not just the one boundary you were focused on:

* The contract and registry suites for your change pass with no drift.
* `pnpm test:plugin` is green.
* A package-level test (`strata19-package-e2e.test.ts`, or the bare-install/local-graph suites for anything touching zero-install behavior) round-trips a real tool call against a freshly copied plugin.
* For a widget change, the Playwright `widget` project passes and the screenshot shows what you intended, not a blank or stale frame.
* `pnpm verify:strata19-plugin-parity` and `pnpm verify:strata19-checksums` are clean against the artifact you actually built, not a cached one from an earlier version.

## If it doesn't work [#if-it-doesnt-work]

* **A source-level unit test passes but the packaged plugin doesn't work.** This is exactly the gap the package suite exists to catch — a unit test cannot prove a versioned installed copy works, because it never spawns one. Run `strata19-package-e2e.test.ts` before concluding the change is done.
* **`pnpm test:plugin` fails only under full parallelism.** The confession-flow suites are run with `--no-file-parallelism` deliberately because they share process-level state; if you're invoking a subset manually, keep that flag for anything in that family.
* **The widget test passes but a real host still shows stale or blank content.** Confirm you rebuilt after your last source edit and that the installed cache actually matches — see [Interface and packaging](/documentation/extensions/interface-and-packaging)'s verify-it-landed step (`diff -q` against the version-keyed cache directory).
* **`verify:strata19-plugin-parity` or `verify:strata19-checksums` fails after a clean rebuild.** These check the committed artifact against what the source says it should build to, and against its own checksum manifest, respectively — a real mismatch here means the release, not the test, is wrong; fix the release rather than the check.

## Related [#related]

* [Interface and packaging](/documentation/extensions/interface-and-packaging) — the rebuild-and-reinstall loop the release tests in this page verify.
* [Add an MCP tool](/documentation/extensions/mcp-tools) — the contract these tests are proving for a new tool.
* [Add a detector](/documentation/extensions/detectors) — the registry consistency `gate:detector-registry` enforces.
* [Package a skill](/documentation/extensions/skills) — the skills-coverage contract test named in this page's first step.
