@openagentsinc/conformance-kit 0.2.0-rc.2
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 +111 -0
- package/package.json +39 -0
- package/src/adapter-laws.test.ts +36 -0
- package/src/adapter-laws.ts +184 -0
- package/src/event-log-laws.test.ts +10 -0
- package/src/event-log-laws.ts +273 -0
- package/src/fixtures.ts +106 -0
- package/src/index.ts +24 -0
- package/src/recall-laws.test.ts +10 -0
- package/src/recall-laws.ts +270 -0
- package/src/reducer-laws.test.ts +17 -0
- package/src/reducer-laws.ts +277 -0
- package/src/rlm-cap-laws.test.ts +11 -0
- package/src/rlm-cap-laws.ts +207 -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 reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and 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 2025 OpenAgents, 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
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @openagentsinc/conformance-kit
|
|
2
|
+
|
|
3
|
+
Published law suites for the `@openagentsinc/ai` contracts. This package
|
|
4
|
+
promotes the per-package test suites that already encode the SDK's laws into
|
|
5
|
+
one reusable kit. Point a suite at an implementation under test — an adapter, a
|
|
6
|
+
store, a reducer, a recall source, or the RLM engine — and it either passes the
|
|
7
|
+
kit or it is not conformant.
|
|
8
|
+
|
|
9
|
+
This is Phase 1 item 1 of `docs/ROADMAP.md` (issue #15, parent epic #14):
|
|
10
|
+
conformance as product.
|
|
11
|
+
|
|
12
|
+
## The idea
|
|
13
|
+
|
|
14
|
+
Each law suite is one exported function. You call it inside your own test file,
|
|
15
|
+
parameterized over your implementation. The suite registers the `describe` /
|
|
16
|
+
`test` blocks against the same `vite-plus/test` runner your package already
|
|
17
|
+
uses, so a conformance run is just part of your normal test sweep.
|
|
18
|
+
|
|
19
|
+
The kit's own tests run every suite against the in-repo reference
|
|
20
|
+
implementations (the reference adapter, the in-memory event-log store, the
|
|
21
|
+
UI-message reducer, the Tier D recall backend, and the RLM engine), so the kit
|
|
22
|
+
is proven to work before anyone points it at a third-party implementation.
|
|
23
|
+
|
|
24
|
+
## The suites
|
|
25
|
+
|
|
26
|
+
| Import | Runner | Implementation under test | Laws |
|
|
27
|
+
| ------------------------------------------ | ----------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
28
|
+
| `@openagentsinc/conformance-kit/adapter` | `runAdapterLaws` | `AgentHarness` | turn framing, capability refusal is fail-closed and named, suspend/continue cursor exactness (with honest lossy degradation) |
|
|
29
|
+
| `@openagentsinc/conformance-kit/event-log` | `runEventLogLaws` | `HarnessEventLogStore` | append monotonicity / dup-free, gap-free replay from a cursor, durable replay after process death, rerun boundaries, live attach, single-flight attach |
|
|
30
|
+
| `@openagentsinc/conformance-kit/reducer` | `runReducerLaws` | a progressive UI-message reducer | progressive fold, tool state machine, transient bypass, fail-loud-never-corrupt |
|
|
31
|
+
| `@openagentsinc/conformance-kit/recall` | `runRecallLaws` | a `HistoryRecall` Tier D source | correctness anchor, caps truncate + report, `cost.modelCalls === 0`, coverage-note carry-through, typed invalid input |
|
|
32
|
+
| `@openagentsinc/conformance-kit/rlm` | `runRlmCapLaws` | the RLM engine + corpus source | every cap → honest `Partial`, generous → `Completed`, no laundering, deterministic never touches a model |
|
|
33
|
+
|
|
34
|
+
Everything is re-exported from the package root too
|
|
35
|
+
(`@openagentsinc/conformance-kit`).
|
|
36
|
+
|
|
37
|
+
## Run the kit against your adapter
|
|
38
|
+
|
|
39
|
+
Add the kit as a dev dependency, then write a test file that calls the runner:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// my-adapter.conformance.test.ts
|
|
43
|
+
import { Effect } from "effect";
|
|
44
|
+
import { runAdapterLaws } from "@openagentsinc/conformance-kit/adapter";
|
|
45
|
+
|
|
46
|
+
import { makeMyAdapter } from "./my-adapter.ts";
|
|
47
|
+
|
|
48
|
+
runAdapterLaws({
|
|
49
|
+
label: "my-adapter",
|
|
50
|
+
makeHarness: () => Effect.sync(() => makeMyAdapter()),
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
That single call registers the full reference-adapter law suite against your
|
|
55
|
+
adapter. The laws are content-agnostic: the kit starts the session and drives
|
|
56
|
+
the turn itself, so they hold whatever your runtime emits. An adapter that
|
|
57
|
+
cannot suspend a turn still passes — the suite proves the refusal is a typed,
|
|
58
|
+
named `HarnessCapabilityUnsupported`, not a silent success.
|
|
59
|
+
|
|
60
|
+
## Run the kit against your store
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { Effect } from "effect";
|
|
64
|
+
import { runEventLogLaws } from "@openagentsinc/conformance-kit/event-log";
|
|
65
|
+
|
|
66
|
+
import { makeMyStore } from "./my-store.ts";
|
|
67
|
+
|
|
68
|
+
runEventLogLaws({
|
|
69
|
+
label: "my-store",
|
|
70
|
+
makeStore: () => Effect.sync(() => makeMyStore()),
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The kit builds the `HarnessEventLog` runtime over your store, so satisfying the
|
|
75
|
+
`HarnessEventLogStore` port earns both the store-level and the live-attach and
|
|
76
|
+
single-flight laws.
|
|
77
|
+
|
|
78
|
+
## Run the kit against the recall and RLM engines
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { runRecallLaws } from "@openagentsinc/conformance-kit/recall";
|
|
82
|
+
import { runRlmCapLaws } from "@openagentsinc/conformance-kit/rlm";
|
|
83
|
+
import { recallTierD } from "@openagentsinc/history-corpus";
|
|
84
|
+
import { makeRlm, rlmInlineCorpusSourceLayer } from "@openagentsinc/rlm";
|
|
85
|
+
|
|
86
|
+
runRecallLaws({ label: "my-recall", recall: (params) => recallTierD(params) });
|
|
87
|
+
|
|
88
|
+
runRlmCapLaws({
|
|
89
|
+
label: "my-rlm",
|
|
90
|
+
makeEngine: makeRlm,
|
|
91
|
+
corpusSourceLayer: rlmInlineCorpusSourceLayer,
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The kit owns the corpus fixtures (a deep planted-decision corpus for recall, a
|
|
96
|
+
small four-entry corpus for RLM), so a recall or RLM implementation only has to
|
|
97
|
+
answer honestly.
|
|
98
|
+
|
|
99
|
+
## What "conformant" means
|
|
100
|
+
|
|
101
|
+
The laws are the honesty contract, not just the happy path:
|
|
102
|
+
|
|
103
|
+
- An adapter must never present a lossy re-drive as an exact cursor attach.
|
|
104
|
+
- A store must reject a non-increasing sequence so replay stays duplicate-free.
|
|
105
|
+
- A reducer must throw its tagged error on a malformed sequence rather than
|
|
106
|
+
silently corrupt the message.
|
|
107
|
+
- A recall source must report exactly what it scanned, which caps it hit, and
|
|
108
|
+
the corpus coverage bound — and never fabricate a model call behind a
|
|
109
|
+
deterministic answer.
|
|
110
|
+
- The RLM engine must surface every cap that bites as an honest `Partial`,
|
|
111
|
+
never as a `Completed` result that quietly dropped work.
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openagentsinc/conformance-kit",
|
|
3
|
+
"version": "0.2.0-rc.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.ts",
|
|
13
|
+
"./adapter": "./src/adapter-laws.ts",
|
|
14
|
+
"./event-log": "./src/event-log-laws.ts",
|
|
15
|
+
"./reducer": "./src/reducer-laws.ts",
|
|
16
|
+
"./recall": "./src/recall-laws.ts",
|
|
17
|
+
"./rlm": "./src/rlm-cap-laws.ts",
|
|
18
|
+
"./fixtures": "./src/fixtures.ts"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"effect": "4.0.0-beta.94",
|
|
25
|
+
"@openagentsinc/agent-runtime-schema": "0.2.0-rc.2",
|
|
26
|
+
"@openagentsinc/rlm": "0.2.0-rc.2",
|
|
27
|
+
"@openagentsinc/history-corpus": "0.2.0-rc.2",
|
|
28
|
+
"@openagentsinc/agent-harness-contract": "0.2.0-rc.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "24.13.1",
|
|
32
|
+
"typescript": "^6.0.3",
|
|
33
|
+
"@types/vite-plus-matchers": "0.0.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "vp test --run packages/conformance-kit/src",
|
|
37
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { makeReferenceAdapter } from "@openagentsinc/agent-harness-contract";
|
|
3
|
+
|
|
4
|
+
import { runAdapterLaws } from "./adapter-laws.ts";
|
|
5
|
+
|
|
6
|
+
// The kit run against the in-repo reference adapter proves the kit itself
|
|
7
|
+
// works — a lossless suspend/continue adapter that supports every verb.
|
|
8
|
+
runAdapterLaws({
|
|
9
|
+
label: "reference-adapter",
|
|
10
|
+
makeHarness: () => Effect.sync(() => makeReferenceAdapter({ scriptWords: ["a", "b", "c"] })),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// A lossy-continue variant exercises the honest-degradation branch of the
|
|
14
|
+
// suspend/continue law.
|
|
15
|
+
runAdapterLaws({
|
|
16
|
+
label: "reference-adapter (lossy continue)",
|
|
17
|
+
makeHarness: () =>
|
|
18
|
+
Effect.sync(() =>
|
|
19
|
+
makeReferenceAdapter({ scriptWords: ["a", "b", "c"], continueIsLossy: true }),
|
|
20
|
+
),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// A verb-refusing variant exercises the fail-closed capability branch: compact,
|
|
24
|
+
// detach, and suspend must each fail with a named CapabilityUnsupported error.
|
|
25
|
+
runAdapterLaws({
|
|
26
|
+
label: "reference-adapter (refuses compact/detach/suspend)",
|
|
27
|
+
makeHarness: () =>
|
|
28
|
+
Effect.sync(() =>
|
|
29
|
+
makeReferenceAdapter({
|
|
30
|
+
scriptWords: ["a", "b", "c"],
|
|
31
|
+
supportsCompact: false,
|
|
32
|
+
supportsDetach: false,
|
|
33
|
+
supportsSuspend: false,
|
|
34
|
+
}),
|
|
35
|
+
),
|
|
36
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Effect, Stream } from "effect";
|
|
2
|
+
import {
|
|
3
|
+
type AgentHarness,
|
|
4
|
+
HarnessCapabilityUnsupported,
|
|
5
|
+
type HarnessSession,
|
|
6
|
+
} from "@openagentsinc/agent-harness-contract";
|
|
7
|
+
import type { KhalaRuntimeSource } from "@openagentsinc/agent-runtime-schema";
|
|
8
|
+
import { describe, expect, test } from "vite-plus/test";
|
|
9
|
+
|
|
10
|
+
import { attempt, collect, sequencesOf, TEST_SOURCE } from "./fixtures.ts";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for {@link runAdapterLaws}. The implementation under test is a
|
|
14
|
+
* factory that produces a fresh {@link AgentHarness}; the kit starts the
|
|
15
|
+
* sessions and drives the turns itself, so the laws are content-agnostic and
|
|
16
|
+
* hold for any conforming adapter (the in-repo reference adapter, Codex,
|
|
17
|
+
* Claude Code, an ACP peer, a third-party runtime).
|
|
18
|
+
*/
|
|
19
|
+
export interface AdapterLawsConfig {
|
|
20
|
+
/** A short label naming the implementation under test, used in test titles. */
|
|
21
|
+
readonly label: string;
|
|
22
|
+
/** Produce a fresh harness. Called once per law so laws never share state. */
|
|
23
|
+
readonly makeHarness: () => Effect.Effect<AgentHarness>;
|
|
24
|
+
/** The prompt driven through each turn. Defaults to a neutral fixture prompt. */
|
|
25
|
+
readonly prompt?: string;
|
|
26
|
+
/** The event source label. Defaults to the shared `test_fixture` source. */
|
|
27
|
+
readonly source?: KhalaRuntimeSource;
|
|
28
|
+
/**
|
|
29
|
+
* How many events to pull before the suspend/continue law suspends the turn.
|
|
30
|
+
* Defaults to 2, enough to prove a mid-turn cursor is exact.
|
|
31
|
+
*/
|
|
32
|
+
readonly prefixTake?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The reference-adapter session-verb laws, parameterized over any adapter.
|
|
37
|
+
*
|
|
38
|
+
* These are the promoted, published form of
|
|
39
|
+
* `agent-harness-contract/src/reference-adapter.test.ts`. A third-party adapter
|
|
40
|
+
* either passes these or it is not conformant:
|
|
41
|
+
*
|
|
42
|
+
* 1. **Turn framing.** A full turn streams `turn.started` first and
|
|
43
|
+
* `turn.finished` last, with session-global sequences contiguous from 0 and
|
|
44
|
+
* no duplicate; the turn result's `lastCursor` is exactly the last event's
|
|
45
|
+
* sequence.
|
|
46
|
+
* 2. **Capability refusal is fail-closed and named.** An optional verb an
|
|
47
|
+
* adapter cannot satisfy fails with a typed
|
|
48
|
+
* {@link HarnessCapabilityUnsupported} naming the exact missing capability —
|
|
49
|
+
* never a silent success and never an untyped defect.
|
|
50
|
+
* 3. **Suspend/continue cursor exactness.** When an adapter supports
|
|
51
|
+
* suspend+continue losslessly, the continuation cursor is exactly the last
|
|
52
|
+
* event delivered before the suspend, and the continued slice attaches at
|
|
53
|
+
* `cursor + 1` with no gap and no duplicate. When the adapter reports the
|
|
54
|
+
* continuation as lossy, the degradation is honestly flagged rather than
|
|
55
|
+
* presented as an exact attach.
|
|
56
|
+
*/
|
|
57
|
+
export const runAdapterLaws = (config: AdapterLawsConfig): void => {
|
|
58
|
+
const { label, makeHarness } = config;
|
|
59
|
+
const prompt = config.prompt ?? "hello";
|
|
60
|
+
const source = config.source ?? TEST_SOURCE;
|
|
61
|
+
const prefixTake = config.prefixTake ?? 2;
|
|
62
|
+
|
|
63
|
+
describe(`[${label}] adapter — turn framing`, () => {
|
|
64
|
+
test("a full turn streams turn.started -> ... -> turn.finished with contiguous sequences from 0", async () => {
|
|
65
|
+
const result = await Effect.runPromise(
|
|
66
|
+
Effect.gen(function* () {
|
|
67
|
+
const harness = yield* makeHarness();
|
|
68
|
+
const session = yield* harness.start({ sessionId: "s1", source });
|
|
69
|
+
const control = yield* session.promptTurn({ turnId: "t1", prompt });
|
|
70
|
+
const events = yield* collect(control.events);
|
|
71
|
+
const done = yield* control.done;
|
|
72
|
+
return { events, done };
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const { events, done } = result;
|
|
77
|
+
expect(events.length).toBeGreaterThanOrEqual(2);
|
|
78
|
+
expect(events[0]?.kind).toBe("turn.started");
|
|
79
|
+
expect(events.at(-1)?.kind).toBe("turn.finished");
|
|
80
|
+
|
|
81
|
+
const seqs = sequencesOf(events);
|
|
82
|
+
// Session-global sequences: fresh session starts at 0 so a replay from
|
|
83
|
+
// cursor -1 recovers the whole turn.
|
|
84
|
+
expect(seqs[0]).toBe(0);
|
|
85
|
+
expect(seqs).toEqual(seqs.map((_, index) => index));
|
|
86
|
+
expect(new Set(seqs).size).toBe(seqs.length);
|
|
87
|
+
|
|
88
|
+
expect(done.lastCursor).toBe(events.at(-1)?.sequence);
|
|
89
|
+
expect(typeof done.finishReason).toBe("string");
|
|
90
|
+
expect(done.finishReason.length).toBeGreaterThan(0);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe(`[${label}] adapter — capability refusal is fail-closed`, () => {
|
|
95
|
+
// The verbs whose refusal must be a named, typed capability error. Each
|
|
96
|
+
// returns a value on support, or fails with CapabilityUnsupported.
|
|
97
|
+
const verbs: ReadonlyArray<{
|
|
98
|
+
readonly capability: "compact" | "detach" | "suspend_turn";
|
|
99
|
+
readonly attemptVerb: (session: HarnessSession) => Effect.Effect<unknown, unknown>;
|
|
100
|
+
}> = [
|
|
101
|
+
{ capability: "compact", attemptVerb: (session) => session.compact() },
|
|
102
|
+
{ capability: "detach", attemptVerb: (session) => session.detach() },
|
|
103
|
+
{ capability: "suspend_turn", attemptVerb: (session) => session.suspendTurn() },
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
const startSession = (harness: AgentHarness) => harness.start({ sessionId: "s1", source });
|
|
107
|
+
|
|
108
|
+
for (const verb of verbs) {
|
|
109
|
+
test(`${verb.capability}: either succeeds or fails with a named CapabilityUnsupported error`, async () => {
|
|
110
|
+
const outcome = await Effect.runPromise(
|
|
111
|
+
Effect.gen(function* () {
|
|
112
|
+
const harness = yield* makeHarness();
|
|
113
|
+
const session = yield* startSession(harness);
|
|
114
|
+
return yield* attempt(verb.attemptVerb(session));
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
if (outcome._tag === "failed") {
|
|
119
|
+
expect(outcome.error).toBeInstanceOf(HarnessCapabilityUnsupported);
|
|
120
|
+
expect((outcome.error as HarnessCapabilityUnsupported).capability).toBe(verb.capability);
|
|
121
|
+
}
|
|
122
|
+
// An `ok` outcome is a conformant adapter that supports the verb.
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe(`[${label}] adapter — suspend/continue cursor exactness`, () => {
|
|
128
|
+
test("continuation cursor is exact and a lossless continue attaches at cursor + 1", async () => {
|
|
129
|
+
const outcome = await Effect.runPromise(
|
|
130
|
+
Effect.gen(function* () {
|
|
131
|
+
const harness = yield* makeHarness();
|
|
132
|
+
const session = yield* harness.start({ sessionId: "s1", source });
|
|
133
|
+
const control = yield* session.promptTurn({ turnId: "t1", prompt });
|
|
134
|
+
|
|
135
|
+
// Pull a prefix, then attempt to suspend.
|
|
136
|
+
const phase1 = yield* collect(control.events.pipe(Stream.take(prefixTake)));
|
|
137
|
+
const suspend = yield* attempt(session.suspendTurn());
|
|
138
|
+
if (suspend._tag === "failed") {
|
|
139
|
+
return { supported: false as const, error: suspend.error };
|
|
140
|
+
}
|
|
141
|
+
const continuation = suspend.value;
|
|
142
|
+
|
|
143
|
+
// A FRESH session (different process) resumes from the cursor.
|
|
144
|
+
const session2 = yield* harness.start({
|
|
145
|
+
sessionId: "s1",
|
|
146
|
+
source,
|
|
147
|
+
continueFrom: continuation,
|
|
148
|
+
});
|
|
149
|
+
const continued = yield* attempt(session2.continueTurn({}));
|
|
150
|
+
if (continued._tag === "failed") {
|
|
151
|
+
return { supported: false as const, error: continued.error, continuation };
|
|
152
|
+
}
|
|
153
|
+
const phase2 = yield* collect(continued.value.events);
|
|
154
|
+
return { supported: true as const, phase1, continuation, phase2 };
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
if (outcome.supported === false) {
|
|
159
|
+
// A refusal must be the named, typed capability error — never a defect.
|
|
160
|
+
expect(outcome.error).toBeInstanceOf(HarnessCapabilityUnsupported);
|
|
161
|
+
const capability = (outcome.error as HarnessCapabilityUnsupported).capability;
|
|
162
|
+
expect(["suspend_turn", "continue_turn"]).toContain(capability);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const { phase1, continuation, phase2 } = outcome;
|
|
167
|
+
// The cursor is exactly the last event delivered in phase 1.
|
|
168
|
+
expect(continuation.cursor).toBe(phase1.at(-1)?.sequence);
|
|
169
|
+
expect(typeof continuation.lossy).toBe("boolean");
|
|
170
|
+
|
|
171
|
+
if (continuation.lossy === false) {
|
|
172
|
+
// No gap, no duplicate at the seam.
|
|
173
|
+
expect(phase2[0]?.sequence).toBe(continuation.cursor + 1);
|
|
174
|
+
const merged = sequencesOf([...phase1, ...phase2]);
|
|
175
|
+
expect(merged).toEqual(merged.map((_, index) => index));
|
|
176
|
+
expect(new Set(merged).size).toBe(merged.length);
|
|
177
|
+
} else {
|
|
178
|
+
// Honest degradation: a lossy continue re-drives the tail. The adapter
|
|
179
|
+
// must flag it rather than present a recomputed tail as an exact attach.
|
|
180
|
+
expect(continuation.lossy).toBe(true);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { makeInMemoryEventLogStore } from "@openagentsinc/agent-harness-contract";
|
|
3
|
+
|
|
4
|
+
import { runEventLogLaws } from "./event-log-laws.ts";
|
|
5
|
+
|
|
6
|
+
// The kit run against the in-repo reference store proves the kit itself works.
|
|
7
|
+
runEventLogLaws({
|
|
8
|
+
label: "in-memory-store",
|
|
9
|
+
makeStore: () => Effect.sync(() => makeInMemoryEventLogStore()),
|
|
10
|
+
});
|