@kybernesis/brain-testkit 0.8.2 → 0.8.3

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -0
  3. package/package.json +2 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kybernesis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @kybernesis/brain-testkit
2
+
3
+ [![npm](https://img.shields.io/npm/v/@kybernesis/brain-testkit)](https://www.npmjs.com/package/@kybernesis/brain-testkit)
4
+
5
+ Testing tools for the [Cortex](../../README.md) brain library — a parity harness, storage
6
+ conformance cases, an isolated tenant factory, and an LLM stub. This is what you use to
7
+ **prove a provider implementation conforms** to the contracts, and to test code that builds
8
+ on `brain-core`.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pnpm add -D @kybernesis/brain-testkit
14
+ ```
15
+
16
+ ## What's in it
17
+
18
+ ### `runParityHarness` — prove two backends agree
19
+
20
+ ```ts
21
+ import { runParityHarness } from '@kybernesis/brain-testkit/parity';
22
+ ```
23
+
24
+ Drives a sequence of brain operations against two `StorageProvider` implementations and
25
+ asserts their resulting database state matches. The tool that guards "this new backend behaves
26
+ exactly like the canonical one."
27
+
28
+ ### Storage conformance cases
29
+
30
+ ```ts
31
+ import { storageConformanceCases } from '@kybernesis/brain-testkit/conformance';
32
+ ```
33
+
34
+ A reusable suite a `StorageProvider` implementation runs against itself to verify it satisfies
35
+ the [`@kybernesis/brain-contracts`](../brain-contracts) interface. (`brain-storage-sqlite`
36
+ uses these in its own test suite.)
37
+
38
+ ### `createTestTenant` — isolated brain per test
39
+
40
+ ```ts
41
+ import { createTestTenant } from '@kybernesis/brain-testkit/helpers';
42
+
43
+ const { tenant, cleanup } = createTestTenant('my-suite');
44
+ afterEach(cleanup);
45
+ ```
46
+
47
+ Builds a `TenantContext` rooted in a unique tmpdir, so parallel tests never share SQLite files.
48
+
49
+ ### `makeLLMStub` — a deterministic LLM seam
50
+
51
+ ```ts
52
+ import { makeLLMStub } from '@kybernesis/brain-testkit';
53
+ import { setLLMProvider } from '@kybernesis/brain-core';
54
+
55
+ const llm = makeLLMStub({ 'extract entities': '["Ada"]', '*': '[]' });
56
+ setLLMProvider(llm);
57
+ // …run code…
58
+ expect(llm.calls).toHaveLength(1); // every call is recorded (prompt + opts)
59
+ ```
60
+
61
+ Maps prompt-substrings to canned responses (`'*'` is the wildcard fallback) and records every
62
+ invocation on `.calls` so you can assert what the kernel passed through.
63
+
64
+ ## Subpath exports
65
+
66
+ `.` (stub + tenant + re-exports), `./parity`, `./conformance`, `./helpers`.
67
+
68
+ ## Notes
69
+
70
+ - ESM-only, TypeScript strict. Intended as a `devDependency`.
71
+ - Part of [Cortex](../../README.md) — `@kybernesis/brain-*`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kybernesis/brain-testkit",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "In-memory fakes and parity harness for testing brain-* consumers",
5
5
  "license": "MIT",
6
6
  "author": "David Cruwys (AppyDave)",
@@ -39,7 +39,7 @@
39
39
  "README.md"
40
40
  ],
41
41
  "dependencies": {
42
- "@kybernesis/brain-contracts": "0.8.2"
42
+ "@kybernesis/brain-contracts": "0.8.3"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"