Chroma-t2t
@chroma/t2t — test-to-test utilities for Chroma apps: Node test bridge, snapshot smoke checks, and persist round-trip validation.
Chroma-t2t is the canonical @chroma/t2t plugin: dev and smoke-test helpers for Chroma apps that use chroma-fs persistence.
- Plugin folder:
chroma-t2t - Package id:
@chroma/t2t - Source: workspace
Chroma-t2t/(nested-repo ready, likeChroma-Router/) - License: GNU GPL version 3 (
LICENSEin the package root)
When you run chroma install, the plugin is copied into ~/.chroma/plugins/chroma-t2t/ from Chroma-t2t/ when present in the workspace, else from Chroma/cli/plugins/chroma-t2t/. Add "chroma-t2t" to your app's chroma.json plugins array and wire bootstrapT2t in plugins/loader.js.
What it provides
| API | Purpose |
|---|---|
bootstrapT2t(options) | Bootstrap hook — exposes the t2t API and optionally attaches globalThis.__chromaT2t |
createTestApi(options) | Build the API without global attachment |
assertPersistRoundTrip(adapters, options) | Export → reset → import round-trip through app-provided persist adapters |
smokeSnapshot(snapshot, collectionKeys) | Assert snapshot collections are arrays |
createPersistRoundTrip(adapters) | Bind adapters into a reusable round-trip function |
createSnapshotSmoke(getSnapshot, keys) | Bind snapshot getter + collection keys |
runNodeTests(options) | Spawn npm test (Node-only; returns usage info in the browser) |
runAll() | Run configured smoke + persist checks (optional Node suite via includeNodeTests) |
Quick start
import { bootstrapT2t } from "./plugins/chroma-t2t/index.js";
await bootstrapT2t({
persist: {
adapters: {
reset,
createMemoryStorage,
hydrate,
setPersisted,
flush,
getSnapshot,
buildExportPayload,
serializeExport,
parseImport,
validateImport,
applyImport,
},
seed: { settings: { theme: "system" } },
verify: (snapshot) => {
if (!snapshot.settings) throw new Error("settings missing after round-trip");
},
},
snapshot: {
getSnapshot,
collectionKeys: ["transactions", "categories", "accounts", "budgets"],
},
});
// In devtools console:
globalThis.__chromaT2t.runAll();Node test bridge
From a vendored copy inside an app:
node plugins/chroma-t2t/node/run-tests.mjsThe script spawns npm test from the project root (same pattern as the legacy chroma-test plugin).
Loader wiring
if (name === "chroma-t2t") {
const { bootstrapT2t } = await import("./chroma-t2t/index.js");
loaded.t2t = await bootstrapT2t({
persist: { adapters: appPersistAdapters, /* seed, verify */ },
snapshot: { getSnapshot, collectionKeys: ["items"] },
});
}Pass app-specific adapters in main.js — the plugin stays generic and does not import app logic.
Install and sync
| Command | Result |
|---|---|
chroma install | Copies chroma-t2t to ~/.chroma/plugins/chroma-t2t/ |
./scripts/sync-chroma-plugins.sh | Refreshes Chroma/cli/plugins/chroma-t2t/, Chroma-CLI/plugins/chroma-t2t/, and example templates |
Edit Chroma-t2t/, then run ./scripts/sync-chroma-plugins.sh before packaging or committing vendored copies.
Related docs
- Plugin Standard —
chroma.plugin.jsoncontract and loader pattern - Extensions & Plugins — built-in plugin table
- CLI —
chroma install,chroma new