@kindgi/testing 0.0.0-bootstrap.0 → 0.1.0
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 +201 -0
- package/README.md +55 -1
- package/dist/app-bindings.d.ts +33 -0
- package/dist/app-bindings.d.ts.map +1 -0
- package/dist/app-bindings.js +102 -0
- package/dist/app-bindings.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/stub-binding.d.ts +34 -0
- package/dist/stub-binding.d.ts.map +1 -0
- package/dist/stub-binding.js +42 -0
- package/dist/stub-binding.js.map +1 -0
- package/package.json +53 -4
- package/src/app-bindings.ts +132 -0
- package/src/index.ts +13 -0
- package/src/stub-binding.ts +53 -0
- package/type-manifest.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Kindgi Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
1
|
# @kindgi/testing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Test helpers for Kindgi apps and packages.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
`createApp` from [`@kindgi/api`](../api) requires a set of bindings
|
|
8
|
+
(conversations, run snapshots, kernel, tenant hierarchy, memory,
|
|
9
|
+
provenance) that a production deployment backs with the Kindgi runtime.
|
|
10
|
+
Most API tests exercise one route family and never touch the others.
|
|
11
|
+
`@kindgi/testing` supplies the rest as stubs, so a test can mount the real
|
|
12
|
+
app with no database and no runtime — and any code path that reaches an
|
|
13
|
+
unprovided binding fails loudly instead of silently returning nothing.
|
|
14
|
+
|
|
15
|
+
## Exports
|
|
16
|
+
|
|
17
|
+
| Export | Kind | Description |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| `createStubAppBindings()` | function | Every required `createApp` binding except `resolveToken` / `runHandler`, as stubs. |
|
|
20
|
+
| `createStubKernelBinding()` | function | Stub `KernelBinding` (each sub-binding stubbed; optional `eventBus` absent). |
|
|
21
|
+
| `createStubBinding<T>(name, methods)` | function | Stub any binding interface `T`; every method throws `StubBindingError`. |
|
|
22
|
+
| `StubBindingError` | class | Thrown by stub methods; carries `binding` and `method`. |
|
|
23
|
+
| `StubAppBindings`, `StubMethods<T>` | types | Return type of `createStubAppBindings`; the method map `createStubBinding` requires. |
|
|
24
|
+
|
|
25
|
+
## Example
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { createApp } from '@kindgi/api';
|
|
29
|
+
import { createStubAppBindings, createStubBinding } from '@kindgi/testing';
|
|
30
|
+
|
|
31
|
+
const app = createApp({
|
|
32
|
+
...createStubAppBindings(),
|
|
33
|
+
resolveToken: async () => ({ tenantId }),
|
|
34
|
+
runHandler: createStubBinding<RunHandlerBinding>('runHandler', {
|
|
35
|
+
invokeAgent: true,
|
|
36
|
+
invokeFlow: true,
|
|
37
|
+
resumeRun: true,
|
|
38
|
+
}),
|
|
39
|
+
// The binding this test actually exercises — your in-memory
|
|
40
|
+
// implementation or test double of AgentRegistryBinding:
|
|
41
|
+
agentRegistry: myAgentRegistry,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const res = await app.request('/v1/agents', { headers: { authorization: 'Bearer t' } });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`createStubBinding` requires one `true` entry per interface method — the
|
|
48
|
+
map is type-checked for completeness, so a method added to the interface
|
|
49
|
+
(or a stale entry) fails to compile rather than surfacing at runtime.
|
|
50
|
+
|
|
51
|
+
## Non-goals
|
|
52
|
+
|
|
53
|
+
- **Behavioral fakes.** Stubs never return data. When a test needs a
|
|
54
|
+
binding to behave, pass an in-memory implementation or a hand-written
|
|
55
|
+
double for that binding and keep the stubs for the rest.
|
|
56
|
+
- **Database-backed integration.** Tests that need real persistence run
|
|
57
|
+
against real adapters, not this package.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CreateAppInput } from '@kindgi/api';
|
|
2
|
+
import type { KernelBinding } from '@kindgi/runtime';
|
|
3
|
+
/**
|
|
4
|
+
* The bindings `createApp` requires that tests usually don't exercise —
|
|
5
|
+
* everything in `CreateAppInput` that is mandatory except the
|
|
6
|
+
* caller-specific `resolveToken` and `runHandler`.
|
|
7
|
+
*/
|
|
8
|
+
export type StubAppBindings = Pick<CreateAppInput, 'conversationBinding' | 'runSnapshotBinding' | 'kernelBinding' | 'tenantHierarchyBinding' | 'memoryBinding' | 'provenanceBinding'>;
|
|
9
|
+
/**
|
|
10
|
+
* Stubs for every required `createApp` binding. Mount the API for
|
|
11
|
+
* contract, route-shape, and handler tests without a database or the
|
|
12
|
+
* Kindgi runtime; any route that reaches one of these bindings fails
|
|
13
|
+
* loudly with a `StubBindingError` naming the binding and method.
|
|
14
|
+
*
|
|
15
|
+
* Override the ones a test needs:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const app = createApp({
|
|
19
|
+
* ...createStubAppBindings(),
|
|
20
|
+
* resolveToken,
|
|
21
|
+
* runHandler,
|
|
22
|
+
* agentRegistry: myInMemoryAgentRegistry,
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function createStubAppBindings(): StubAppBindings;
|
|
27
|
+
/**
|
|
28
|
+
* Stub `KernelBinding`: each sub-binding is a stub named
|
|
29
|
+
* `kernelBinding.<sub>`. The optional `eventBus` is omitted (absent), so
|
|
30
|
+
* code that feature-checks it takes the no-event-bus path.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createStubKernelBinding(): KernelBinding;
|
|
33
|
+
//# sourceMappingURL=app-bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-bindings.d.ts","sourceRoot":"","sources":["../src/app-bindings.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,KAAK,EACV,aAAa,EAMd,MAAM,iBAAiB,CAAC;AAIzB;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,cAAc,EACZ,qBAAqB,GACrB,oBAAoB,GACpB,eAAe,GACf,wBAAwB,GACxB,eAAe,GACf,mBAAmB,CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,CAqCvD;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,aAAa,CAqCvD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
import { createStubBinding } from './stub-binding.js';
|
|
4
|
+
/**
|
|
5
|
+
* Stubs for every required `createApp` binding. Mount the API for
|
|
6
|
+
* contract, route-shape, and handler tests without a database or the
|
|
7
|
+
* Kindgi runtime; any route that reaches one of these bindings fails
|
|
8
|
+
* loudly with a `StubBindingError` naming the binding and method.
|
|
9
|
+
*
|
|
10
|
+
* Override the ones a test needs:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const app = createApp({
|
|
14
|
+
* ...createStubAppBindings(),
|
|
15
|
+
* resolveToken,
|
|
16
|
+
* runHandler,
|
|
17
|
+
* agentRegistry: myInMemoryAgentRegistry,
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createStubAppBindings() {
|
|
22
|
+
return {
|
|
23
|
+
conversationBinding: createStubBinding('conversationBinding', {
|
|
24
|
+
openConversation: true,
|
|
25
|
+
getConversation: true,
|
|
26
|
+
listConversations: true,
|
|
27
|
+
listConversationsPage: true,
|
|
28
|
+
closeConversation: true,
|
|
29
|
+
deleteConversation: true,
|
|
30
|
+
appendMessage: true,
|
|
31
|
+
readMessages: true,
|
|
32
|
+
}),
|
|
33
|
+
runSnapshotBinding: createStubBinding('runSnapshotBinding', {
|
|
34
|
+
write: true,
|
|
35
|
+
read: true,
|
|
36
|
+
}),
|
|
37
|
+
kernelBinding: createStubKernelBinding(),
|
|
38
|
+
tenantHierarchyBinding: createStubBinding('tenantHierarchyBinding', {
|
|
39
|
+
createOrg: true,
|
|
40
|
+
createTeam: true,
|
|
41
|
+
createProject: true,
|
|
42
|
+
addTeamMember: true,
|
|
43
|
+
addProjectMember: true,
|
|
44
|
+
getTenant: true,
|
|
45
|
+
}),
|
|
46
|
+
memoryBinding: createStubBinding('memoryBinding', {
|
|
47
|
+
listFacts: true,
|
|
48
|
+
searchByKeyword: true,
|
|
49
|
+
searchBySemantic: true,
|
|
50
|
+
appendLog: true,
|
|
51
|
+
readLog: true,
|
|
52
|
+
}),
|
|
53
|
+
provenanceBinding: createStubBinding('provenanceBinding', {
|
|
54
|
+
listRecords: true,
|
|
55
|
+
getByRunId: true,
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Stub `KernelBinding`: each sub-binding is a stub named
|
|
61
|
+
* `kernelBinding.<sub>`. The optional `eventBus` is omitted (absent), so
|
|
62
|
+
* code that feature-checks it takes the no-event-bus path.
|
|
63
|
+
*/
|
|
64
|
+
export function createStubKernelBinding() {
|
|
65
|
+
return {
|
|
66
|
+
run: createStubBinding('kernelBinding.run', {
|
|
67
|
+
runGraph: true,
|
|
68
|
+
resumeRun: true,
|
|
69
|
+
cancelRun: true,
|
|
70
|
+
cancelToken: true,
|
|
71
|
+
completeToken: true,
|
|
72
|
+
readJournal: true,
|
|
73
|
+
startRun: true,
|
|
74
|
+
deleteRun: true,
|
|
75
|
+
getRun: true,
|
|
76
|
+
listRuns: true,
|
|
77
|
+
}),
|
|
78
|
+
scheduler: createStubBinding('kernelBinding.scheduler', {
|
|
79
|
+
startCronScheduler: true,
|
|
80
|
+
startEventTriggerScheduler: true,
|
|
81
|
+
fireByWebhookId: true,
|
|
82
|
+
initialNextFireAt: true,
|
|
83
|
+
}),
|
|
84
|
+
waitpoint: createStubBinding('kernelBinding.waitpoint', {
|
|
85
|
+
startTimeoutSleeper: true,
|
|
86
|
+
}),
|
|
87
|
+
retention: createStubBinding('kernelBinding.retention', {
|
|
88
|
+
createRetentionAdapter: true,
|
|
89
|
+
}),
|
|
90
|
+
triggers: createStubBinding('kernelBinding.triggers', {
|
|
91
|
+
register: true,
|
|
92
|
+
update: true,
|
|
93
|
+
list: true,
|
|
94
|
+
get: true,
|
|
95
|
+
pause: true,
|
|
96
|
+
resume: true,
|
|
97
|
+
unregister: true,
|
|
98
|
+
fetchActiveByWebhookId: true,
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=app-bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-bindings.js","sourceRoot":"","sources":["../src/app-bindings.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAejC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAiBtD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO;QACL,mBAAmB,EAAE,iBAAiB,CAAsB,qBAAqB,EAAE;YACjF,gBAAgB,EAAE,IAAI;YACtB,eAAe,EAAE,IAAI;YACrB,iBAAiB,EAAE,IAAI;YACvB,qBAAqB,EAAE,IAAI;YAC3B,iBAAiB,EAAE,IAAI;YACvB,kBAAkB,EAAE,IAAI;YACxB,aAAa,EAAE,IAAI;YACnB,YAAY,EAAE,IAAI;SACnB,CAAC;QACF,kBAAkB,EAAE,iBAAiB,CAAqB,oBAAoB,EAAE;YAC9E,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,IAAI;SACX,CAAC;QACF,aAAa,EAAE,uBAAuB,EAAE;QACxC,sBAAsB,EAAE,iBAAiB,CAAyB,wBAAwB,EAAE;YAC1F,SAAS,EAAE,IAAI;YACf,UAAU,EAAE,IAAI;YAChB,aAAa,EAAE,IAAI;YACnB,aAAa,EAAE,IAAI;YACnB,gBAAgB,EAAE,IAAI;YACtB,SAAS,EAAE,IAAI;SAChB,CAAC;QACF,aAAa,EAAE,iBAAiB,CAAqB,eAAe,EAAE;YACpE,SAAS,EAAE,IAAI;YACf,eAAe,EAAE,IAAI;YACrB,gBAAgB,EAAE,IAAI;YACtB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,IAAI;SACd,CAAC;QACF,iBAAiB,EAAE,iBAAiB,CAAsC,mBAAmB,EAAE;YAC7F,WAAW,EAAE,IAAI;YACjB,UAAU,EAAE,IAAI;SACjB,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO;QACL,GAAG,EAAE,iBAAiB,CAAa,mBAAmB,EAAE;YACtD,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;YACf,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,IAAI;YACjB,aAAa,EAAE,IAAI;YACnB,WAAW,EAAE,IAAI;YACjB,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,SAAS,EAAE,iBAAiB,CAAmB,yBAAyB,EAAE;YACxE,kBAAkB,EAAE,IAAI;YACxB,0BAA0B,EAAE,IAAI;YAChC,eAAe,EAAE,IAAI;YACrB,iBAAiB,EAAE,IAAI;SACxB,CAAC;QACF,SAAS,EAAE,iBAAiB,CAAmB,yBAAyB,EAAE;YACxE,mBAAmB,EAAE,IAAI;SAC1B,CAAC;QACF,SAAS,EAAE,iBAAiB,CAAsB,yBAAyB,EAAE;YAC3E,sBAAsB,EAAE,IAAI;SAC7B,CAAC;QACF,QAAQ,EAAE,iBAAiB,CAAyB,wBAAwB,EAAE;YAC5E,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,IAAI;YACT,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,IAAI;YACZ,UAAU,EAAE,IAAI;YAChB,sBAAsB,EAAE,IAAI;SAC7B,CAAC;KACH,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@kindgi/testing` — test helpers for Kindgi apps and packages.
|
|
3
|
+
*/
|
|
4
|
+
export { createStubAppBindings, createStubKernelBinding, type StubAppBindings, } from './app-bindings.js';
|
|
5
|
+
export { StubBindingError, createStubBinding, type StubMethods } from './stub-binding.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AAEH,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
/**
|
|
4
|
+
* `@kindgi/testing` — test helpers for Kindgi apps and packages.
|
|
5
|
+
*/
|
|
6
|
+
export { createStubAppBindings, createStubKernelBinding, } from './app-bindings.js';
|
|
7
|
+
export { StubBindingError, createStubBinding } from './stub-binding.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC;;GAEG;AAEH,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when code under test calls a method on a stub binding. The
|
|
3
|
+
* message names the binding and method so the fix — supply a real
|
|
4
|
+
* implementation or a test double for that binding — is obvious.
|
|
5
|
+
*/
|
|
6
|
+
export declare class StubBindingError extends Error {
|
|
7
|
+
readonly binding: string;
|
|
8
|
+
readonly method: string;
|
|
9
|
+
constructor(binding: string, method: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* One `true` entry per method of `T`. Typed as a complete mapping, so a
|
|
13
|
+
* method added to the interface (or a stale one left behind) fails to
|
|
14
|
+
* compile at the stub definition instead of slipping through at runtime.
|
|
15
|
+
*/
|
|
16
|
+
export type StubMethods<T> = {
|
|
17
|
+
readonly [K in keyof T]-?: true;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Build a stub implementation of the binding interface `T`: every method
|
|
21
|
+
* listed in `methods` throws {@link StubBindingError} when called.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const memory = createStubBinding<MemoryQueryBinding>('memoryBinding', {
|
|
25
|
+
* listFacts: true,
|
|
26
|
+
* searchByKeyword: true,
|
|
27
|
+
* searchBySemantic: true,
|
|
28
|
+
* appendLog: true,
|
|
29
|
+
* readLog: true,
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function createStubBinding<T extends object>(name: string, methods: StubMethods<T>): T;
|
|
34
|
+
//# sourceMappingURL=stub-binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub-binding.d.ts","sourceRoot":"","sources":["../src/stub-binding.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAS5C;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI;CAAE,CAAC;AAEjE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAQ5F"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when code under test calls a method on a stub binding. The
|
|
5
|
+
* message names the binding and method so the fix — supply a real
|
|
6
|
+
* implementation or a test double for that binding — is obvious.
|
|
7
|
+
*/
|
|
8
|
+
export class StubBindingError extends Error {
|
|
9
|
+
binding;
|
|
10
|
+
method;
|
|
11
|
+
constructor(binding, method) {
|
|
12
|
+
super(`${binding}.${method}() was called on a stub binding from @kindgi/testing. ` +
|
|
13
|
+
`Pass a real implementation or a test double for \`${binding}\` to exercise this code path.`);
|
|
14
|
+
this.name = 'StubBindingError';
|
|
15
|
+
this.binding = binding;
|
|
16
|
+
this.method = method;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Build a stub implementation of the binding interface `T`: every method
|
|
21
|
+
* listed in `methods` throws {@link StubBindingError} when called.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const memory = createStubBinding<MemoryQueryBinding>('memoryBinding', {
|
|
25
|
+
* listFacts: true,
|
|
26
|
+
* searchByKeyword: true,
|
|
27
|
+
* searchBySemantic: true,
|
|
28
|
+
* appendLog: true,
|
|
29
|
+
* readLog: true,
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function createStubBinding(name, methods) {
|
|
34
|
+
const stub = {};
|
|
35
|
+
for (const method of Object.keys(methods)) {
|
|
36
|
+
stub[method] = () => {
|
|
37
|
+
throw new StubBindingError(name, method);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return stub;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=stub-binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub-binding.js","sourceRoot":"","sources":["../src/stub-binding.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,OAAO,CAAS;IAChB,MAAM,CAAS;IAExB,YAAY,OAAe,EAAE,MAAc;QACzC,KAAK,CACH,GAAG,OAAO,IAAI,MAAM,wDAAwD;YAC1E,qDAAqD,OAAO,gCAAgC,CAC/F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AASD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAAmB,IAAY,EAAE,OAAuB;IACvF,MAAM,IAAI,GAAgC,EAAE,CAAC;IAC7C,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE;YAClB,MAAM,IAAI,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,IAAS,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kindgi/testing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Test helpers for Kindgi apps and packages. `createStubAppBindings()` supplies every binding `createApp` requires as a typed stub that throws a descriptive `StubBindingError` if called — mount the API for contract / route-shape tests without a database or the Kindgi runtime.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"repository": {
|
|
7
|
-
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/kindgi/kindgi-sdk.git",
|
|
9
|
+
"directory": "packages/testing"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/kindgi/kindgi-sdk/tree/main/packages/testing#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/kindgi/kindgi-sdk/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"src",
|
|
27
|
+
"README.md",
|
|
28
|
+
"type-manifest.json"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@kindgi/agents": "0.1.0",
|
|
32
|
+
"@kindgi/api": "0.1.0",
|
|
33
|
+
"@kindgi/memory": "0.1.0",
|
|
34
|
+
"@kindgi/platform": "0.1.0",
|
|
35
|
+
"@kindgi/runtime": "0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@kindgi/types": "0.1.0",
|
|
39
|
+
"@types/node": "^22.10.5",
|
|
40
|
+
"typescript": "^5.7.3",
|
|
41
|
+
"vitest": "^2.1.8"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22.0.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"provenance": true
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -p tsconfig.build.json",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
|
|
4
|
+
import type { ConversationBinding, RunSnapshotBinding } from '@kindgi/agents';
|
|
5
|
+
import type { CreateAppInput } from '@kindgi/api';
|
|
6
|
+
import type { MemoryQueryBinding } from '@kindgi/memory';
|
|
7
|
+
import type { TenantHierarchyBinding } from '@kindgi/platform';
|
|
8
|
+
import type {
|
|
9
|
+
KernelBinding,
|
|
10
|
+
RunBinding,
|
|
11
|
+
RunRetentionBinding,
|
|
12
|
+
SchedulerBinding,
|
|
13
|
+
TriggerRegistryBinding,
|
|
14
|
+
WaitpointBinding,
|
|
15
|
+
} from '@kindgi/runtime';
|
|
16
|
+
|
|
17
|
+
import { createStubBinding } from './stub-binding.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The bindings `createApp` requires that tests usually don't exercise —
|
|
21
|
+
* everything in `CreateAppInput` that is mandatory except the
|
|
22
|
+
* caller-specific `resolveToken` and `runHandler`.
|
|
23
|
+
*/
|
|
24
|
+
export type StubAppBindings = Pick<
|
|
25
|
+
CreateAppInput,
|
|
26
|
+
| 'conversationBinding'
|
|
27
|
+
| 'runSnapshotBinding'
|
|
28
|
+
| 'kernelBinding'
|
|
29
|
+
| 'tenantHierarchyBinding'
|
|
30
|
+
| 'memoryBinding'
|
|
31
|
+
| 'provenanceBinding'
|
|
32
|
+
>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Stubs for every required `createApp` binding. Mount the API for
|
|
36
|
+
* contract, route-shape, and handler tests without a database or the
|
|
37
|
+
* Kindgi runtime; any route that reaches one of these bindings fails
|
|
38
|
+
* loudly with a `StubBindingError` naming the binding and method.
|
|
39
|
+
*
|
|
40
|
+
* Override the ones a test needs:
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* const app = createApp({
|
|
44
|
+
* ...createStubAppBindings(),
|
|
45
|
+
* resolveToken,
|
|
46
|
+
* runHandler,
|
|
47
|
+
* agentRegistry: myInMemoryAgentRegistry,
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function createStubAppBindings(): StubAppBindings {
|
|
52
|
+
return {
|
|
53
|
+
conversationBinding: createStubBinding<ConversationBinding>('conversationBinding', {
|
|
54
|
+
openConversation: true,
|
|
55
|
+
getConversation: true,
|
|
56
|
+
listConversations: true,
|
|
57
|
+
listConversationsPage: true,
|
|
58
|
+
closeConversation: true,
|
|
59
|
+
deleteConversation: true,
|
|
60
|
+
appendMessage: true,
|
|
61
|
+
readMessages: true,
|
|
62
|
+
}),
|
|
63
|
+
runSnapshotBinding: createStubBinding<RunSnapshotBinding>('runSnapshotBinding', {
|
|
64
|
+
write: true,
|
|
65
|
+
read: true,
|
|
66
|
+
}),
|
|
67
|
+
kernelBinding: createStubKernelBinding(),
|
|
68
|
+
tenantHierarchyBinding: createStubBinding<TenantHierarchyBinding>('tenantHierarchyBinding', {
|
|
69
|
+
createOrg: true,
|
|
70
|
+
createTeam: true,
|
|
71
|
+
createProject: true,
|
|
72
|
+
addTeamMember: true,
|
|
73
|
+
addProjectMember: true,
|
|
74
|
+
getTenant: true,
|
|
75
|
+
}),
|
|
76
|
+
memoryBinding: createStubBinding<MemoryQueryBinding>('memoryBinding', {
|
|
77
|
+
listFacts: true,
|
|
78
|
+
searchByKeyword: true,
|
|
79
|
+
searchBySemantic: true,
|
|
80
|
+
appendLog: true,
|
|
81
|
+
readLog: true,
|
|
82
|
+
}),
|
|
83
|
+
provenanceBinding: createStubBinding<CreateAppInput['provenanceBinding']>('provenanceBinding', {
|
|
84
|
+
listRecords: true,
|
|
85
|
+
getByRunId: true,
|
|
86
|
+
}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Stub `KernelBinding`: each sub-binding is a stub named
|
|
92
|
+
* `kernelBinding.<sub>`. The optional `eventBus` is omitted (absent), so
|
|
93
|
+
* code that feature-checks it takes the no-event-bus path.
|
|
94
|
+
*/
|
|
95
|
+
export function createStubKernelBinding(): KernelBinding {
|
|
96
|
+
return {
|
|
97
|
+
run: createStubBinding<RunBinding>('kernelBinding.run', {
|
|
98
|
+
runGraph: true,
|
|
99
|
+
resumeRun: true,
|
|
100
|
+
cancelRun: true,
|
|
101
|
+
cancelToken: true,
|
|
102
|
+
completeToken: true,
|
|
103
|
+
readJournal: true,
|
|
104
|
+
startRun: true,
|
|
105
|
+
deleteRun: true,
|
|
106
|
+
getRun: true,
|
|
107
|
+
listRuns: true,
|
|
108
|
+
}),
|
|
109
|
+
scheduler: createStubBinding<SchedulerBinding>('kernelBinding.scheduler', {
|
|
110
|
+
startCronScheduler: true,
|
|
111
|
+
startEventTriggerScheduler: true,
|
|
112
|
+
fireByWebhookId: true,
|
|
113
|
+
initialNextFireAt: true,
|
|
114
|
+
}),
|
|
115
|
+
waitpoint: createStubBinding<WaitpointBinding>('kernelBinding.waitpoint', {
|
|
116
|
+
startTimeoutSleeper: true,
|
|
117
|
+
}),
|
|
118
|
+
retention: createStubBinding<RunRetentionBinding>('kernelBinding.retention', {
|
|
119
|
+
createRetentionAdapter: true,
|
|
120
|
+
}),
|
|
121
|
+
triggers: createStubBinding<TriggerRegistryBinding>('kernelBinding.triggers', {
|
|
122
|
+
register: true,
|
|
123
|
+
update: true,
|
|
124
|
+
list: true,
|
|
125
|
+
get: true,
|
|
126
|
+
pause: true,
|
|
127
|
+
resume: true,
|
|
128
|
+
unregister: true,
|
|
129
|
+
fetchActiveByWebhookId: true,
|
|
130
|
+
}),
|
|
131
|
+
};
|
|
132
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `@kindgi/testing` — test helpers for Kindgi apps and packages.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
createStubAppBindings,
|
|
10
|
+
createStubKernelBinding,
|
|
11
|
+
type StubAppBindings,
|
|
12
|
+
} from './app-bindings.js';
|
|
13
|
+
export { StubBindingError, createStubBinding, type StubMethods } from './stub-binding.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when code under test calls a method on a stub binding. The
|
|
6
|
+
* message names the binding and method so the fix — supply a real
|
|
7
|
+
* implementation or a test double for that binding — is obvious.
|
|
8
|
+
*/
|
|
9
|
+
export class StubBindingError extends Error {
|
|
10
|
+
readonly binding: string;
|
|
11
|
+
readonly method: string;
|
|
12
|
+
|
|
13
|
+
constructor(binding: string, method: string) {
|
|
14
|
+
super(
|
|
15
|
+
`${binding}.${method}() was called on a stub binding from @kindgi/testing. ` +
|
|
16
|
+
`Pass a real implementation or a test double for \`${binding}\` to exercise this code path.`,
|
|
17
|
+
);
|
|
18
|
+
this.name = 'StubBindingError';
|
|
19
|
+
this.binding = binding;
|
|
20
|
+
this.method = method;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* One `true` entry per method of `T`. Typed as a complete mapping, so a
|
|
26
|
+
* method added to the interface (or a stale one left behind) fails to
|
|
27
|
+
* compile at the stub definition instead of slipping through at runtime.
|
|
28
|
+
*/
|
|
29
|
+
export type StubMethods<T> = { readonly [K in keyof T]-?: true };
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Build a stub implementation of the binding interface `T`: every method
|
|
33
|
+
* listed in `methods` throws {@link StubBindingError} when called.
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const memory = createStubBinding<MemoryQueryBinding>('memoryBinding', {
|
|
37
|
+
* listFacts: true,
|
|
38
|
+
* searchByKeyword: true,
|
|
39
|
+
* searchBySemantic: true,
|
|
40
|
+
* appendLog: true,
|
|
41
|
+
* readLog: true,
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function createStubBinding<T extends object>(name: string, methods: StubMethods<T>): T {
|
|
46
|
+
const stub: Record<string, () => never> = {};
|
|
47
|
+
for (const method of Object.keys(methods)) {
|
|
48
|
+
stub[method] = () => {
|
|
49
|
+
throw new StubBindingError(name, method);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return stub as T;
|
|
53
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://kindgi.com/schemas/v1/type-manifest.schema.json",
|
|
3
|
+
"package": "@kindgi/testing",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"description": "Test helpers: typed, fail-loud stub bindings for createApp and any binding interface.",
|
|
6
|
+
"exports": {
|
|
7
|
+
"createStubAppBindings": {
|
|
8
|
+
"kind": "function",
|
|
9
|
+
"signature": "() => StubAppBindings",
|
|
10
|
+
"description": "Every required createApp binding except resolveToken / runHandler, as stubs."
|
|
11
|
+
},
|
|
12
|
+
"createStubKernelBinding": {
|
|
13
|
+
"kind": "function",
|
|
14
|
+
"signature": "() => KernelBinding",
|
|
15
|
+
"description": "Stub KernelBinding; sub-bindings stubbed, optional eventBus absent."
|
|
16
|
+
},
|
|
17
|
+
"createStubBinding": {
|
|
18
|
+
"kind": "function",
|
|
19
|
+
"signature": "<T extends object>(name: string, methods: StubMethods<T>) => T",
|
|
20
|
+
"description": "Stub any binding interface; every method throws StubBindingError."
|
|
21
|
+
},
|
|
22
|
+
"StubBindingError": {
|
|
23
|
+
"kind": "class",
|
|
24
|
+
"fields": {
|
|
25
|
+
"binding": "string",
|
|
26
|
+
"method": "string"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"StubAppBindings": {
|
|
30
|
+
"kind": "type",
|
|
31
|
+
"form": "alias",
|
|
32
|
+
"definition": "Pick<CreateAppInput, 'conversationBinding' | 'runSnapshotBinding' | 'kernelBinding' | 'tenantHierarchyBinding' | 'memoryBinding' | 'provenanceBinding'>"
|
|
33
|
+
},
|
|
34
|
+
"StubMethods": {
|
|
35
|
+
"kind": "type",
|
|
36
|
+
"form": "alias",
|
|
37
|
+
"definition": "{ readonly [K in keyof T]-?: true }"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|