@vitronai/themis 0.1.0-beta.0 → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,7 @@ All notable changes to this project are documented in this file.
6
6
 
7
7
  ### Changed
8
8
 
9
+ - Added a first-party `themis generate` / `themis scan` code-scan flow that generates deterministic contract tests for exported modules, React components, hooks, Next app/router files, route handlers, and Node services; emits richer machine-readable `--json` results for agents; writes `.themis/generate-map.json`, `.themis/generate-last.json`, `.themis/generate-handoff.json`, `.themis/generate-backlog.json`, and `.themis/fix-handoff.json`; supports project-level `themis.generate.js` providers, interaction/state adapters for React components and hooks, automatic `--write-hints` scaffolding, targeted regeneration, planning mode, scenario/confidence steering, review/update/clean workflows, strict quality gates, and backlog remediation commands; and fails generated tests with direct regeneration guidance when scanned sources drift.
9
10
  - Moved the package line from alpha to beta and defined beta compatibility expectations for CLI, artifacts, and the JS/TS package surface.
10
11
  - Tightened npm/package positioning around Themis as an intent-first unit test framework for AI agents in Node.js and TypeScript.
11
12
  - Updated publish-facing docs to consistently frame Themis as an AI verdict engine for human and agent review loops.
@@ -13,8 +14,22 @@ All notable changes to this project are documented in this file.
13
14
  - Expanded the HTML report with quick actions, failure-first triage, richer file cards, and test-level drilldown.
14
15
  - Added embedded brand/report asset visuals to the README.
15
16
  - Added project-aware JS/TS runtime support for TSX, ESM `.js`, `tsconfig` path aliases, `setupFiles`, and `jsdom` environments.
16
- - Added first-party snapshots, mocks, run-diff artifacts, and watch mode for tighter agent rerun loops.
17
+ - Removed first-party snapshot-file workflows in favor of direct contract assertions and generated flow contracts; retained mocks, run-diff artifacts, and watch mode for tighter agent rerun loops.
18
+ - Added a lightweight DOM-oriented `jsdom` UI test layer with `render`, `screen`, `fireEvent`, `waitFor`, `cleanup`, and UI matchers for text, attributes, and document presence.
19
+ - Added deterministic async UI test controls with fake timers, microtask flushing, and first-party fetch mocking for `jsdom` tests.
20
+ - Expanded generated React and Next component adapters with direct DOM-state contract assertions and provider-aware `wrapRender(...)` support in `themis.generate.js` / `themis.generate.cjs`.
21
+ - Added provider-driven `componentFlows` plus richer `applyMocks(...)` context so generated React/Next adapters can emit async behavioral flow contracts with mocked fetch/timer control.
22
+ - Added provider preset wrappers for router, React Query, Zustand, and Redux-style app patterns in `themis.generate.js` / `themis.generate.cjs`, plus richer inferred async input/submit/loading/success component flows.
23
+ - Added an incremental `themis migrate <jest|vitest>` scaffold and runtime compatibility imports for `@jest/globals`, `vitest`, and `@testing-library/react`.
24
+ - Added a zero-IPC `--isolation in-process` test mode plus `--cache` for faster local rerun loops and in-process watch execution.
25
+ - Deepened provider/app adapter presets with Next navigation and auth/session wrapper metadata alongside the existing router, React Query, Zustand, and Redux presets.
26
+ - Strengthened failure-to-fix automation with richer `.themis/fix-handoff.json` entries (`repairStrategy`, `candidateFiles`, `autofixCommand`) and added `.themis/migration-report.json` for migration inventories and next actions.
27
+ - Extended provider/app presets with route history/state, auth permissions/roles, query status/query keys, and store selector/action metadata for richer generated UI wrappers.
28
+ - Added richer generated DOM flow assertions for empty, disabled, retry, error, and recovery paths with role- and attribute-aware expectations.
29
+ - Added `themis migrate --rewrite-imports`, which rewrites matched Jest/Vitest/Testing Library imports to a local `themis.compat.js` bridge for more automated incremental migration.
30
+ - Added config-level `testIgnore` discovery patterns so repos can keep generated output, fixture sandboxes, and other local test noise out of default suite runs deterministically.
17
31
  - Added an in-repo VS Code extension scaffold for artifact-driven result viewing, reruns, and HTML report opening.
32
+ - Expanded the VS Code extension scaffold with generated-review navigation for source/test/hint mappings and unresolved generation backlog.
18
33
  - Refreshed README, AGENTS, and supporting docs to match the current package scope, JS/TS feature set, artifact contracts, and extension surface.
19
34
 
20
35
  ## 0.1.0-alpha.1 - 2026-02-13
package/README.md CHANGED
@@ -18,12 +18,13 @@ It is built to be the best test loop for agent workflows: deterministic reruns,
18
18
  ## Contents
19
19
 
20
20
  - [Quickstart](#quickstart)
21
+ - [Code Scan](#code-scan)
21
22
  - [Positioning](#positioning)
22
23
  - [Modern JS/TS Support](#modern-jsts-support)
23
24
  - [Commands](#commands)
24
25
  - [Agent Guide](#agent-guide)
25
26
  - [VS Code](#vs-code)
26
- - [Snapshots And Mocks](#snapshots-and-mocks)
27
+ - [Mocks And UI Primitives](#mocks-and-ui-primitives)
27
28
  - [Intent Syntax](#intent-syntax)
28
29
  - [Config](#config)
29
30
  - [TypeScript](#typescript)
@@ -52,8 +53,10 @@ Themis is built for modern Node.js and TypeScript projects:
52
53
  - `tsconfig` path alias resolution
53
54
  - `node` and `jsdom` environments
54
55
  - `setupFiles` for harness bootstrapping
55
- - first-party snapshots, mocks, and spies
56
- - `--watch` and `--rerun-failed` for tight local and agent rerun loops
56
+ - `testIgnore` patterns for deterministic discovery boundaries
57
+ - first-party mocks, spies, and deterministic UI primitives
58
+ - compatibility imports for `@jest/globals`, `vitest`, and `@testing-library/react`
59
+ - `--watch`, `--rerun-failed`, `--isolation in-process`, and `--cache` for tight local and agent rerun loops
57
60
 
58
61
  ## Visuals
59
62
 
@@ -66,6 +69,7 @@ Themis is built for modern Node.js and TypeScript projects:
66
69
  ```bash
67
70
  npm install -D @vitronai/themis
68
71
  npx themis init
72
+ npx themis generate src
69
73
  npx themis test
70
74
  ```
71
75
 
@@ -84,9 +88,83 @@ npx themis test --agent
84
88
  Stay in a local rerun loop while editing:
85
89
 
86
90
  ```bash
87
- npx themis test --watch --reporter next
91
+ npx themis test --watch --isolation in-process --cache --reporter next
88
92
  ```
89
93
 
94
+ Incrementally migrate existing Jest/Vitest suites:
95
+
96
+ ```bash
97
+ npx themis migrate jest
98
+ npx themis migrate jest --rewrite-imports
99
+ npx themis test
100
+ ```
101
+
102
+ ## Code Scan
103
+
104
+ Themis can scan your JS/TS source tree and generate deterministic unit-layer tests for exported modules, React components, React hooks, Next app components, Next route handlers, generic route handlers, and Node services:
105
+
106
+ ```bash
107
+ npx themis generate src
108
+ npx themis test
109
+ ```
110
+
111
+ Generated files land under `tests/generated` by default. Each generated test:
112
+
113
+ - checks the scanned export names when Themis can resolve them exactly
114
+ - asserts the normalized runtime export contract directly in generated source
115
+ - adds scenario adapters for React components/hooks, Next app/router files, route handlers, and service functions when Themis can infer or read useful inputs
116
+ - captures React interaction and hook state-transition contracts when event handlers or stateful methods are available
117
+ - asserts DOM-state and behavioral flow contracts directly for generated React and Next component adapters
118
+ - emits async behavioral flow contracts for generated React and Next component adapters when flow plans are inferred or hinted, including richer inferred input/submit/loading/success paths for common async forms
119
+ - supports provider-driven DOM flow contracts for empty, disabled, retry, error, and recovery states with attribute- and role-aware assertions
120
+ - fails with a regeneration hint when the source drifts after the scan
121
+
122
+ Themis also supports per-file generation hints with sidecars like `src/components/Button.themis.json` so humans and agents can provide props, component flows, args, route requests, and route context. When those sidecars do not exist yet, `--write-hints` can scaffold them automatically from the current source analysis.
123
+
124
+ For repo-wide generation defaults, add `themis.generate.js` or `themis.generate.cjs` at the project root. Providers in that file can match source paths, supply shared props/args/flow plans, register runtime mocks for generated UI scenarios, and wrap generated component renders so generated DOM contracts run inside the same provider shells humans use in app tests. Providers can also declare preset wrapper metadata for router, Next navigation, auth/session shells, React Query, Zustand, and Redux-style app state patterns, including route history/state, query status, auth permissions, and store selector/action metadata.
125
+
126
+ For CI and agent loops, Themis can also enforce generation quality instead of only writing files. Strict runs emit a structured backlog, fail on unresolved scan debt, and hand back exact remediation commands.
127
+
128
+ Use these flags to control the generation loop:
129
+
130
+ - `--json`: machine-readable payload for agents, including prompt-ready next steps
131
+ - `--plan`: alias for `--review --json` with persisted handoff artifacts
132
+ - `--review`: dry-run create/update/remove decisions without writing files
133
+ - `--update`: refresh existing generated files only
134
+ - `--clean`: remove generated files for the selected scope
135
+ - `--changed`: target changed files in a git worktree
136
+ - `--write-hints`: scaffold missing `.themis.json` sidecars so the next generate pass has explicit component props, hook args, service args, and route requests
137
+ - `--scenario`: limit generation to one adapter family such as `react-hook`, `next-app-component`, or `next-route-handler`
138
+ - `--min-confidence`: keep only entries at or above a confidence threshold
139
+ - `--strict`: fail the generate run on skips, conflicts, or entries below `high` confidence
140
+ - `--fail-on-skips`, `--fail-on-conflicts`: turn unresolved scan debt into a non-zero exit code
141
+ - `--require-confidence`: fail if selected generated tests fall below a confidence threshold
142
+ - `--files`, `--match-source`, `--match-export`, `--include`, `--exclude`: narrow the scan scope
143
+ - `--force`: replace a conflicting non-Themis file
144
+ - `--output <dir>`: change the generated test directory
145
+
146
+ Every generation run also writes:
147
+
148
+ - `.themis/generate-map.json`: source-to-generated-test mapping plus scenario/confidence metadata
149
+ - `.themis/generate-last.json`: the full machine-readable generate payload
150
+ - `.themis/generate-handoff.json`: a compact agent handoff artifact with prompt-ready next actions
151
+ - `.themis/generate-backlog.json`: unresolved skips, conflicts, and confidence debt with suggested fixes
152
+
153
+ Local test loops can also opt into a zero-IPC execution path:
154
+
155
+ - `npx themis test --isolation in-process`: executes suites in-process instead of worker mode
156
+ - `npx themis test --watch --isolation in-process --cache`: keeps a fast local rerun loop with file-level result caching
157
+ - `npx themis test --isolation worker`: keeps process isolation for CI or global-heavy suites
158
+
159
+ When generated tests fail, Themis also writes:
160
+
161
+ - `.themis/fix-handoff.json`: a deduped failure-to-fix artifact that maps generated failures back to source files, categories, repair strategies, candidate files, and remediation commands
162
+
163
+ Migration scaffolds also write:
164
+
165
+ - `.themis/migration-report.json`: a machine-readable inventory of detected Jest/Vitest compatibility imports and recommended next actions
166
+ - `themis.compat.js`: an optional local compatibility bridge used by `themis migrate --rewrite-imports`
167
+
90
168
  ## Why Themis
91
169
 
92
170
  See [`docs/why-themis.md`](docs/why-themis.md) for positioning, differentiators, and community messaging.
@@ -98,6 +176,11 @@ See [`docs/why-themis.md`](docs/why-themis.md) for positioning, differentiators,
98
176
  - Publish guide: [`docs/publish.md`](docs/publish.md)
99
177
  - VS Code extension notes: [`docs/vscode-extension.md`](docs/vscode-extension.md)
100
178
  - Agent result schema: [`docs/schemas/agent-result.v1.json`](docs/schemas/agent-result.v1.json)
179
+ - Generate result schema: [`docs/schemas/generate-result.v1.json`](docs/schemas/generate-result.v1.json)
180
+ - Generate map schema: [`docs/schemas/generate-map.v1.json`](docs/schemas/generate-map.v1.json)
181
+ - Generate handoff schema: [`docs/schemas/generate-handoff.v1.json`](docs/schemas/generate-handoff.v1.json)
182
+ - Generate backlog schema: [`docs/schemas/generate-backlog.v1.json`](docs/schemas/generate-backlog.v1.json)
183
+ - Fix handoff schema: [`docs/schemas/fix-handoff.v1.json`](docs/schemas/fix-handoff.v1.json)
101
184
  - Failures artifact schema: [`docs/schemas/failures.v1.json`](docs/schemas/failures.v1.json)
102
185
  - Changelog: [`CHANGELOG.md`](CHANGELOG.md)
103
186
  - Contributing: [`CONTRIBUTING.md`](CONTRIBUTING.md)
@@ -106,6 +189,25 @@ See [`docs/why-themis.md`](docs/why-themis.md) for positioning, differentiators,
106
189
  ## Commands
107
190
 
108
191
  - `npx themis init`: creates `themis.config.json` and a sample test.
192
+ - `npx themis generate src`: scans source files and generates contract tests under `tests/generated`.
193
+ - `npx themis generate src --json`: emits a machine-readable generation payload for agents and automation.
194
+ - `npx themis generate src --plan`: emits a planning payload and handoff artifact without writing generated tests.
195
+ - `npx themis generate src --review --json`: previews create/update/remove decisions without writing files.
196
+ - `npx themis generate src --review --strict --json`: fails fast on unresolved generation debt while still emitting a machine-readable plan.
197
+ - `npx themis generate src --write-hints`: scaffolds missing hint sidecars and uses them in the same generate pass.
198
+ - `npx themis generate src --update`: refreshes existing generated tests only.
199
+ - `npx themis generate src --clean`: removes generated tests for the selected scope.
200
+ - `npx themis generate src --changed`: regenerates against changed files in the current git worktree.
201
+ - `npx themis generate src --scenario react-hook --min-confidence high`: targets one adapter family at a confidence threshold.
202
+ - `npx themis generate app --scenario next-route-handler`: focuses generation on Next app router request handlers.
203
+ - `npx themis migrate jest`: scaffolds a Themis config/setup bridge for existing Jest suites.
204
+ - `npx themis migrate jest --rewrite-imports`: rewrites matched Jest/Vitest/Testing Library imports to a local `themis.compat.js` bridge file.
205
+ - `npx themis migrate vitest`: scaffolds the same bridge for Vitest suites.
206
+ - `npx themis generate src --require-confidence high`: enforces a quality bar for all selected generated tests.
207
+ - `npx themis generate src --files src/routes/ping.ts`: targets one or more explicit source files.
208
+ - `npx themis generate src --match-source "routes/" --match-export "GET|POST"`: narrows generation by source path and exported symbol.
209
+ - `npx themis generate src --output tests/contracts`: writes generated tests to a custom directory.
210
+ - `npx themis generate src --force`: replaces conflicting files in the target output directory.
109
211
  - `npx themis test`: discovers and runs tests.
110
212
  - `npx themis test --next`: next-gen console output mode.
111
213
  - `npx themis test --json`: emits JSON result payload.
@@ -113,9 +215,11 @@ See [`docs/why-themis.md`](docs/why-themis.md) for positioning, differentiators,
113
215
  - `npx themis test --reporter html`: generates a next-gen HTML report file.
114
216
  - `npx themis test --reporter html --html-output reports/themis.html`: writes HTML report to a custom path.
115
217
  - `npx themis test --watch`: reruns the suite when watched project files change.
218
+ - `npx themis test --watch --isolation in-process --cache`: runs a zero-IPC cached local loop for fast edit/rerun cycles.
116
219
  - `npx themis test --workers 8`: overrides worker count (positive integer).
220
+ - `npx themis test --isolation in-process`: runs test files in-process instead of worker processes.
221
+ - `npx themis test --cache`: enables file-level result caching for in-process local loops.
117
222
  - `npx themis test --environment jsdom`: runs tests in a browser-like DOM environment.
118
- - `npx themis test -u`: updates stored snapshots.
119
223
  - `npx themis test --stability 3`: runs the suite three times and classifies each test as `stable_pass`, `stable_fail`, or `unstable`.
120
224
  - `npx themis test --match "intent DSL"`: runs only tests whose full name matches regex.
121
225
  - `npx themis test --rerun-failed`: reruns failing tests from `.themis/failed-tests.json`.
@@ -136,9 +240,12 @@ Each run writes artifacts to `.themis/`:
136
240
  - `failed-tests.json`: compact failure list for retry loops.
137
241
  - `run-diff.json`: diff against the previous run, including new and resolved failures.
138
242
  - `run-history.json`: rolling recent-run history for agent comparison loops.
243
+ - `fix-handoff.json`: source-oriented repair handoff for generated test failures.
244
+ - `migration-report.json`: compatibility inventory and next actions for migrated Jest/Vitest suites.
245
+ - `themis.compat.js`: optional local compat bridge for rewritten migration imports.
139
246
  - `report.html`: interactive HTML verdict report.
140
247
 
141
- `--agent` output includes deterministic failure fingerprints, grouped `analysis.failureClusters`, stability classifications, and previous-run comparison data to help AI agents deduplicate and prioritize failures.
248
+ `--agent` output includes deterministic failure fingerprints, grouped `analysis.failureClusters`, stability classifications, previous-run comparison data, and a direct pointer to `.themis/fix-handoff.json` so AI agents can jump from generated failures to exact regeneration commands. Fix handoff entries also carry repair strategies, candidate files, and autofix commands for tighter failure-to-fix loops.
142
249
 
143
250
  Machine-facing reporters intentionally emit compact JSON. Agents and tooling should parse the payloads rather than depend on whitespace formatting.
144
251
 
@@ -150,14 +257,15 @@ The repo now includes a thin VS Code extension scaffold at [`packages/themis-vsc
150
257
 
151
258
  The extension is intentionally artifact-driven:
152
259
 
153
- - reads `.themis/last-run.json`, `.themis/failed-tests.json`, `.themis/run-diff.json`, and `.themis/report.html`
260
+ - reads `.themis/last-run.json`, `.themis/failed-tests.json`, `.themis/run-diff.json`, `.themis/generate-last.json`, `.themis/generate-map.json`, `.themis/generate-backlog.json`, and `.themis/report.html`
154
261
  - shows the latest verdict and failures in a sidebar
262
+ - adds generated-review navigation for source/test/hint mappings plus unresolved generation backlog
155
263
  - reruns Themis from VS Code commands
156
264
  - opens the HTML report inside a webview
157
265
 
158
266
  It does not replace the CLI. The CLI and `.themis/*` artifacts remain the source of truth.
159
267
 
160
- ## Snapshots And Mocks
268
+ ## Mocks And UI Primitives
161
269
 
162
270
  Themis now ships first-party test utilities for agent-generated tests:
163
271
 
@@ -171,10 +279,12 @@ const { fetchUser } = require('../src/api');
171
279
  test('captures a stable UI contract', () => {
172
280
  const user = fetchUser();
173
281
  expect(fetchUser).toHaveBeenCalledTimes(1);
174
- expect(user).toMatchSnapshot();
282
+ expect(user).toMatchObject({ id: 'u_1', name: 'Ada' });
175
283
  });
176
284
  ```
177
285
 
286
+ Themis intentionally avoids first-party snapshot-file workflows. Prefer direct assertions, generated contract tests, and explicit flow expectations over large opaque snapshots.
287
+
178
288
  Available globals:
179
289
 
180
290
  - `fn(...)`
@@ -184,7 +294,57 @@ Available globals:
184
294
  - `clearAllMocks()`
185
295
  - `resetAllMocks()`
186
296
  - `restoreAllMocks()`
187
- - `expect(value).toMatchSnapshot()`
297
+
298
+ For UI-oriented `jsdom` tests, Themis also ships a lightweight DOM layer:
299
+
300
+ - `render(ui)`
301
+ - `screen.getByText(...)`
302
+ - `screen.getByRole(...)`
303
+ - `screen.getByLabelText(...)`
304
+ - `fireEvent.click/change/input/submit/keyDown(...)`
305
+ - `waitFor(asyncAssertion)`
306
+ - `cleanup()`
307
+ - `useFakeTimers()`, `advanceTimersByTime(ms)`, `runAllTimers()`, `useRealTimers()`
308
+ - `flushMicrotasks()`
309
+ - `mockFetch(...)`, `resetFetchMocks()`, `restoreFetch()`
310
+
311
+ Example:
312
+
313
+ ```tsx
314
+ test('submits the form', async () => {
315
+ render(<button onClick={() => document.body.setAttribute('data-state', 'sent')}>Send</button>);
316
+
317
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));
318
+
319
+ await waitFor(() => {
320
+ expect(document.body).toHaveAttribute('data-state', 'sent');
321
+ });
322
+ });
323
+ ```
324
+
325
+ Network and async example:
326
+
327
+ ```ts
328
+ test('loads api state deterministically', async () => {
329
+ useFakeTimers();
330
+ const fetchMock = mockFetch({ json: { ok: true } });
331
+
332
+ let done = false;
333
+ setTimeout(async () => {
334
+ const response = await fetch('/api/status');
335
+ const payload = await response.json();
336
+ done = payload.ok;
337
+ }, 50);
338
+
339
+ advanceTimersByTime(50);
340
+ await flushMicrotasks();
341
+
342
+ expect(done).toBe(true);
343
+ expect(fetchMock).toHaveBeenCalled();
344
+ useRealTimers();
345
+ restoreFetch();
346
+ });
347
+ ```
188
348
 
189
349
  ## Intent Syntax
190
350
 
@@ -226,11 +386,13 @@ Easter egg aliases are also available: `cook`, `yeet`, `vibecheck`, `wipe`.
226
386
  "reporter": "next",
227
387
  "environment": "node",
228
388
  "setupFiles": ["tests/setup.ts"],
229
- "tsconfigPath": "tsconfig.json"
389
+ "tsconfigPath": "tsconfig.json",
390
+ "testIgnore": ["^tests/generated(?:/|$)"]
230
391
  }
231
392
  ```
232
393
 
233
394
  Modern JS/TS projects can opt into `environment: "jsdom"` for DOM-driven tests and `setupFiles` for hooks, polyfills, or harness bootstrapping.
395
+ Use `testIgnore` when you need local generated output, fixture folders, or scratch suites to stay out of the default discovery pass.
234
396
 
235
397
  ## TypeScript
236
398