@kybernesis/brain-testkit 0.8.1 → 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.
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/llm-stub.d.ts +13 -1
- package/dist/llm-stub.d.ts.map +1 -1
- package/dist/llm-stub.js +7 -1
- package/dist/llm-stub.js.map +1 -1
- 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
|
+
[](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/dist/llm-stub.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
interface LLMProvider {
|
|
2
2
|
call(prompt: string, opts?: unknown): Promise<string | null>;
|
|
3
3
|
}
|
|
4
|
+
/** One recorded invocation of the stub. */
|
|
5
|
+
export interface RecordedCall {
|
|
6
|
+
prompt: string;
|
|
7
|
+
opts?: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** The stub plus the recorded-calls log, so tests can assert on prompt AND opts. */
|
|
10
|
+
export interface LLMStub extends LLMProvider {
|
|
11
|
+
readonly calls: RecordedCall[];
|
|
12
|
+
}
|
|
4
13
|
/**
|
|
5
14
|
* Test double for LLMProvider. `responses` is a map from prompt substring to
|
|
6
15
|
* the string the stub should return. '*' is a special wildcard fallback — it
|
|
7
16
|
* only fires when no other key matches (regardless of insertion order).
|
|
17
|
+
*
|
|
18
|
+
* Every invocation is recorded on `.calls` (prompt + opts) so tests can assert
|
|
19
|
+
* that callers pass through model / system / etc.
|
|
8
20
|
*/
|
|
9
|
-
export declare function makeLLMStub(responses?: Record<string, string>):
|
|
21
|
+
export declare function makeLLMStub(responses?: Record<string, string>): LLMStub;
|
|
10
22
|
export {};
|
|
11
23
|
//# sourceMappingURL=llm-stub.d.ts.map
|
package/dist/llm-stub.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm-stub.d.ts","sourceRoot":"","sources":["../src/llm-stub.ts"],"names":[],"mappings":"AAEA,UAAU,WAAW;IACnB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9D;AAED
|
|
1
|
+
{"version":3,"file":"llm-stub.d.ts","sourceRoot":"","sources":["../src/llm-stub.ts"],"names":[],"mappings":"AAEA,UAAU,WAAW;IACnB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9D;AAED,2CAA2C;AAC3C,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,oFAAoF;AACpF,MAAM,WAAW,OAAQ,SAAQ,WAAW;IAC1C,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,OAAO,CAY3E"}
|
package/dist/llm-stub.js
CHANGED
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
* Test double for LLMProvider. `responses` is a map from prompt substring to
|
|
3
3
|
* the string the stub should return. '*' is a special wildcard fallback — it
|
|
4
4
|
* only fires when no other key matches (regardless of insertion order).
|
|
5
|
+
*
|
|
6
|
+
* Every invocation is recorded on `.calls` (prompt + opts) so tests can assert
|
|
7
|
+
* that callers pass through model / system / etc.
|
|
5
8
|
*/
|
|
6
9
|
export function makeLLMStub(responses = {}) {
|
|
10
|
+
const calls = [];
|
|
7
11
|
return {
|
|
8
|
-
|
|
12
|
+
calls,
|
|
13
|
+
async call(prompt, opts) {
|
|
14
|
+
calls.push({ prompt, opts });
|
|
9
15
|
for (const [key, value] of Object.entries(responses)) {
|
|
10
16
|
if (key !== '*' && prompt.includes(key))
|
|
11
17
|
return value;
|
package/dist/llm-stub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm-stub.js","sourceRoot":"","sources":["../src/llm-stub.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"llm-stub.js","sourceRoot":"","sources":["../src/llm-stub.ts"],"names":[],"mappings":"AAiBA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,YAAoC,EAAE;IAChE,MAAM,KAAK,GAAmB,EAAE,CAAC;IACjC,OAAO;QACL,KAAK;QACL,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,IAAc;YACvC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;gBACrD,IAAI,GAAG,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;oBAAE,OAAO,KAAK,CAAC;YACxD,CAAC;YACD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;QAChC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kybernesis/brain-testkit",
|
|
3
|
-
"version": "0.8.
|
|
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.
|
|
42
|
+
"@kybernesis/brain-contracts": "0.8.3"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|