@reinsjs/core 0.1.1 → 0.2.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 +28 -0
- package/README.md +2 -2
- package/dist/{chunk-BOJD54XN.js → chunk-63AJKR7J.js} +34 -22
- package/dist/chunk-63AJKR7J.js.map +1 -0
- package/dist/index.d.ts +33 -7
- package/dist/index.js +109 -40
- package/dist/index.js.map +1 -1
- package/dist/testing/index.d.ts +9 -2
- package/dist/testing/index.js +209 -92
- package/dist/testing/index.js.map +1 -1
- package/dist/{types-BeGSiC1e.d.ts → types-DJB-13o3.d.ts} +58 -5
- package/package.json +1 -1
- package/dist/chunk-BOJD54XN.js.map +0 -1
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BlobStore, E as EventLog, a as Event, M as MemoryStore, f as LoweringCapabilities, o as CoreEventDraft,
|
|
1
|
+
import { B as BlobStore, E as EventLog, a as Event, M as MemoryStore, r as RunLease, f as LoweringCapabilities, o as CoreEventDraft, U as LoweringOutcome, a5 as ToRequestInput, L as Lowering, e as ModelRef, k as LoweredRequest, V as LoweringStreamContext, c as EventDraft } from '../types-DJB-13o3.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 一致性套件对测试框架的最小要求:只要 describe / it 两个函数。
|
|
@@ -37,6 +37,13 @@ declare function eventLogConformance(t: TestHarness, factory: () => EventLog | P
|
|
|
37
37
|
|
|
38
38
|
declare function memoryStoreConformance(t: TestHarness, factory: () => MemoryStore | Promise<MemoryStore>): void;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* RunLease 一致性套件(D4)。过期一项用真时间等(ttl 1 ms、等 30 ms):套件不知道后端的时钟怎么注入,
|
|
42
|
+
* 而 Postgres 实现刻意用数据库时间,测试时钟只能是真时钟。
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
declare function runLeaseConformance(t: TestHarness, factory: () => RunLease | Promise<RunLease>): void;
|
|
46
|
+
|
|
40
47
|
/**
|
|
41
48
|
* 脚本化降级层:按剧本逐轮吐出预设的事件草稿,不联网。
|
|
42
49
|
* 给循环、脑子模块与适配器写单测用 —— 只关心"模型看到了什么、说了什么",不关心线协议。
|
|
@@ -74,4 +81,4 @@ declare const say: (text: string) => CoreEventDraft;
|
|
|
74
81
|
declare const think: (text: string) => CoreEventDraft;
|
|
75
82
|
declare const callTool: (toolCallId: string, name: string, args: unknown) => CoreEventDraft;
|
|
76
83
|
|
|
77
|
-
export { ConformanceError, SCRIPTED_CAPABILITIES, type Script, ScriptedLowering, type ScriptedPayload, type ScriptedTurn, type TestHarness, assert, assertEqual, assertThrowsCode, blobStoreConformance, callTool, collect, eventLogConformance, makeEvents, memoryStoreConformance, say, think };
|
|
84
|
+
export { ConformanceError, SCRIPTED_CAPABILITIES, type Script, ScriptedLowering, type ScriptedPayload, type ScriptedTurn, type TestHarness, assert, assertEqual, assertThrowsCode, blobStoreConformance, callTool, collect, eventLogConformance, makeEvents, memoryStoreConformance, runLeaseConformance, say, think };
|
package/dist/testing/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createCoreEvent,
|
|
3
3
|
createCoreRegistry
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-63AJKR7J.js";
|
|
5
5
|
|
|
6
6
|
// src/testing/harness.ts
|
|
7
7
|
var ConformanceError = class extends Error {
|
|
@@ -17,8 +17,8 @@ function assertEqual(actual, expected, message) {
|
|
|
17
17
|
const a = JSON.stringify(actual);
|
|
18
18
|
const b = JSON.stringify(expected);
|
|
19
19
|
if (a !== b) throw new ConformanceError(`${message}
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
expected: ${b}
|
|
21
|
+
actual: ${a}`);
|
|
22
22
|
}
|
|
23
23
|
async function assertThrowsCode(fn, code, message) {
|
|
24
24
|
try {
|
|
@@ -28,11 +28,11 @@ async function assertThrowsCode(fn, code, message) {
|
|
|
28
28
|
if (got === code) return;
|
|
29
29
|
throw new ConformanceError(
|
|
30
30
|
`${message}
|
|
31
|
-
|
|
31
|
+
expected error code ${code}, got ${String(got)}: ${err.message}`
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
throw new ConformanceError(`${message}
|
|
35
|
-
|
|
35
|
+
expected ${code} to be thrown, but nothing was`);
|
|
36
36
|
}
|
|
37
37
|
async function collect(iter) {
|
|
38
38
|
const out = [];
|
|
@@ -42,51 +42,59 @@ async function collect(iter) {
|
|
|
42
42
|
|
|
43
43
|
// src/testing/blob-store.ts
|
|
44
44
|
function blobStoreConformance(t, factory) {
|
|
45
|
-
t.describe("BlobStore
|
|
46
|
-
t.it("put
|
|
45
|
+
t.describe("BlobStore conformance", () => {
|
|
46
|
+
t.it("put bytes -> get returns them verbatim, with size and mime in meta", async () => {
|
|
47
47
|
const store = await factory();
|
|
48
48
|
const bytes = new Uint8Array([1, 2, 3, 250]);
|
|
49
49
|
const { id } = await store.put(bytes, { mime: "application/octet-stream", sessionId: "s1" });
|
|
50
|
-
assert(typeof id === "string" && id.length > 0, "id
|
|
50
|
+
assert(typeof id === "string" && id.length > 0, "id must be a non-empty string");
|
|
51
51
|
const got = await store.get(id);
|
|
52
|
-
assertEqual(Array.from(got.bytes), [1, 2, 3, 250], "
|
|
52
|
+
assertEqual(Array.from(got.bytes), [1, 2, 3, 250], "byte content");
|
|
53
53
|
assertEqual(got.meta.mime, "application/octet-stream", "mime");
|
|
54
54
|
assertEqual(got.meta.sessionId, "s1", "sessionId");
|
|
55
55
|
assertEqual(got.meta.size, 4, "size");
|
|
56
|
-
assert(typeof got.meta.createdAt === "number", "createdAt
|
|
56
|
+
assert(typeof got.meta.createdAt === "number", "createdAt must be a number");
|
|
57
57
|
});
|
|
58
|
-
t.it("
|
|
58
|
+
t.it("a string is stored as UTF-8", async () => {
|
|
59
59
|
const store = await factory();
|
|
60
60
|
const { id } = await store.put("\u4F60\u597D, world", { mime: "text/plain", sessionId: "s1" });
|
|
61
61
|
const got = await store.get(id);
|
|
62
|
-
assertEqual(new TextDecoder().decode(got.bytes), "\u4F60\u597D, world", "
|
|
63
|
-
assertEqual(
|
|
62
|
+
assertEqual(new TextDecoder().decode(got.bytes), "\u4F60\u597D, world", "decoded text");
|
|
63
|
+
assertEqual(
|
|
64
|
+
got.meta.size,
|
|
65
|
+
new TextEncoder().encode("\u4F60\u597D, world").byteLength,
|
|
66
|
+
"size is the UTF-8 byte length"
|
|
67
|
+
);
|
|
64
68
|
});
|
|
65
|
-
t.it("
|
|
69
|
+
t.it("every put yields a different id", async () => {
|
|
66
70
|
const store = await factory();
|
|
67
71
|
const a = await store.put("x", { mime: "text/plain", sessionId: "s1" });
|
|
68
72
|
const b = await store.put("x", { mime: "text/plain", sessionId: "s1" });
|
|
69
|
-
assert(a.id !== b.id, "
|
|
73
|
+
assert(a.id !== b.id, "putting the same content twice must still yield different ids");
|
|
70
74
|
});
|
|
71
|
-
t.it("get
|
|
75
|
+
t.it("get on an unknown id -> not_found", async () => {
|
|
72
76
|
const store = await factory();
|
|
73
|
-
await assertThrowsCode(() => store.get("no-such-id"), "not_found", "
|
|
77
|
+
await assertThrowsCode(() => store.get("no-such-id"), "not_found", "missing blob");
|
|
74
78
|
});
|
|
75
|
-
t.it("get
|
|
79
|
+
t.it("get returns a copy of the bytes", async () => {
|
|
76
80
|
const store = await factory();
|
|
77
81
|
const { id } = await store.put(new Uint8Array([9, 9]), { mime: "x", sessionId: "s1" });
|
|
78
82
|
const first = await store.get(id);
|
|
79
83
|
first.bytes[0] = 0;
|
|
80
84
|
const again = await store.get(id);
|
|
81
|
-
assertEqual(Array.from(again.bytes), [9, 9], "
|
|
85
|
+
assertEqual(Array.from(again.bytes), [9, 9], "an outside mutation must not affect the store");
|
|
82
86
|
});
|
|
83
|
-
t.it("slice
|
|
87
|
+
t.it("slice (if implemented) returns [start, end) and clamps out-of-range bounds", async () => {
|
|
84
88
|
const store = await factory();
|
|
85
89
|
if (!store.slice) return;
|
|
86
90
|
const { id } = await store.put(new Uint8Array([0, 1, 2, 3, 4]), { mime: "x", sessionId: "s1" });
|
|
87
|
-
assertEqual(Array.from(await store.slice(id, { start: 1, end: 3 })), [1, 2], "
|
|
88
|
-
assertEqual(Array.from(await store.slice(id, { start: 3, end: 99 })), [3, 4], "
|
|
89
|
-
assertEqual(
|
|
91
|
+
assertEqual(Array.from(await store.slice(id, { start: 1, end: 3 })), [1, 2], "middle slice");
|
|
92
|
+
assertEqual(Array.from(await store.slice(id, { start: 3, end: 99 })), [3, 4], "clamped at the end");
|
|
93
|
+
assertEqual(
|
|
94
|
+
Array.from(await store.slice(id, { start: 5, end: 9 })),
|
|
95
|
+
[],
|
|
96
|
+
"a start beyond the end gives nothing"
|
|
97
|
+
);
|
|
90
98
|
});
|
|
91
99
|
});
|
|
92
100
|
}
|
|
@@ -108,76 +116,95 @@ function makeEvents(sessionId, n, startSeq = 1) {
|
|
|
108
116
|
}
|
|
109
117
|
var seqs = (events) => events.map((e) => e.seq);
|
|
110
118
|
function eventLogConformance(t, factory) {
|
|
111
|
-
t.describe("EventLog
|
|
112
|
-
t.it("
|
|
119
|
+
t.describe("EventLog conformance", () => {
|
|
120
|
+
t.it("an empty session reads back an empty stream and an empty tail", async () => {
|
|
113
121
|
const log = await factory();
|
|
114
|
-
assertEqual(await collect(log.read("none")), [], "
|
|
115
|
-
assertEqual(await log.tail("none", 5), [], "
|
|
122
|
+
assertEqual(await collect(log.read("none")), [], "read on an empty session");
|
|
123
|
+
assertEqual(await log.tail("none", 5), [], "tail on an empty session");
|
|
116
124
|
});
|
|
117
|
-
t.it("append
|
|
125
|
+
t.it("after append, events read back in ascending seq order, field for field", async () => {
|
|
118
126
|
const log = await factory();
|
|
119
127
|
const events = makeEvents("s1", 3);
|
|
120
128
|
await log.append(events);
|
|
121
|
-
assertEqual(await collect(log.read("s1")), events, "read
|
|
129
|
+
assertEqual(await collect(log.read("s1")), events, "full read");
|
|
122
130
|
});
|
|
123
|
-
t.it("
|
|
131
|
+
t.it("successive append batches accumulate", async () => {
|
|
124
132
|
const log = await factory();
|
|
125
133
|
await log.append(makeEvents("s1", 2));
|
|
126
134
|
await log.append(makeEvents("s1", 2, 3));
|
|
127
|
-
assertEqual(seqs(await collect(log.read("s1"))), [1, 2, 3, 4], "
|
|
135
|
+
assertEqual(seqs(await collect(log.read("s1"))), [1, 2, 3, 4], "seq after merging two batches");
|
|
128
136
|
});
|
|
129
|
-
t.it("read
|
|
137
|
+
t.it("read supports the closed range fromSeq / toSeq", async () => {
|
|
130
138
|
const log = await factory();
|
|
131
139
|
await log.append(makeEvents("s1", 5));
|
|
132
|
-
assertEqual(seqs(await collect(log.read("s1", { fromSeq: 2, toSeq: 4 }))), [2, 3, 4], "
|
|
133
|
-
assertEqual(seqs(await collect(log.read("s1", { fromSeq: 4 }))), [4, 5], "
|
|
134
|
-
assertEqual(seqs(await collect(log.read("s1", { toSeq: 2 }))), [1, 2], "
|
|
135
|
-
assertEqual(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
assertEqual(seqs(await log.tail("s1", 2)), [4, 5], "tail 2");
|
|
141
|
-
assertEqual(seqs(await log.tail("s1", 10)), [1, 2, 3, 4, 5], "tail \u8D85\u91CF");
|
|
142
|
-
assertEqual(seqs(await log.tail("s1", 0)), [], "tail 0");
|
|
140
|
+
assertEqual(seqs(await collect(log.read("s1", { fromSeq: 2, toSeq: 4 }))), [2, 3, 4], "closed range");
|
|
141
|
+
assertEqual(seqs(await collect(log.read("s1", { fromSeq: 4 }))), [4, 5], "from only");
|
|
142
|
+
assertEqual(seqs(await collect(log.read("s1", { toSeq: 2 }))), [1, 2], "to only");
|
|
143
|
+
assertEqual(
|
|
144
|
+
seqs(await collect(log.read("s1", { fromSeq: 9 }))),
|
|
145
|
+
[],
|
|
146
|
+
"a from beyond the end gives nothing"
|
|
147
|
+
);
|
|
143
148
|
});
|
|
144
|
-
t.it(
|
|
149
|
+
t.it(
|
|
150
|
+
"tail returns the last n events in ascending order; an n above the total returns everything; n=0 returns nothing",
|
|
151
|
+
async () => {
|
|
152
|
+
const log = await factory();
|
|
153
|
+
await log.append(makeEvents("s1", 5));
|
|
154
|
+
assertEqual(seqs(await log.tail("s1", 2)), [4, 5], "tail 2");
|
|
155
|
+
assertEqual(seqs(await log.tail("s1", 10)), [1, 2, 3, 4, 5], "tail beyond the total");
|
|
156
|
+
assertEqual(seqs(await log.tail("s1", 0)), [], "tail 0");
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
t.it("sessions are isolated from each other", async () => {
|
|
145
160
|
const log = await factory();
|
|
146
161
|
await log.append(makeEvents("a", 2));
|
|
147
162
|
await log.append(makeEvents("b", 3));
|
|
148
|
-
assertEqual(seqs(await collect(log.read("a"))), [1, 2], "
|
|
149
|
-
assertEqual(seqs(await collect(log.read("b"))), [1, 2, 3], "
|
|
163
|
+
assertEqual(seqs(await collect(log.read("a"))), [1, 2], "session a");
|
|
164
|
+
assertEqual(seqs(await collect(log.read("b"))), [1, 2, 3], "session b");
|
|
150
165
|
});
|
|
151
|
-
t.it("
|
|
166
|
+
t.it("the first event must have seq 1", async () => {
|
|
152
167
|
const log = await factory();
|
|
153
|
-
await assertThrowsCode(
|
|
154
|
-
|
|
168
|
+
await assertThrowsCode(
|
|
169
|
+
() => log.append(makeEvents("s1", 1, 2)),
|
|
170
|
+
"seq_conflict",
|
|
171
|
+
"a first event with seq=2 must be rejected"
|
|
172
|
+
);
|
|
173
|
+
assertEqual(await collect(log.read("s1")), [], "nothing must be left behind after a rejection");
|
|
155
174
|
});
|
|
156
|
-
t.it("seq
|
|
175
|
+
t.it("a gap in seq -> seq_conflict, and the whole batch is not written (atomic)", async () => {
|
|
157
176
|
const log = await factory();
|
|
158
177
|
await log.append(makeEvents("s1", 2));
|
|
159
178
|
const bad = [...makeEvents("s1", 1, 3), ...makeEvents("s1", 1, 5)];
|
|
160
|
-
await assertThrowsCode(() => log.append(bad), "seq_conflict", "
|
|
161
|
-
assertEqual(
|
|
179
|
+
await assertThrowsCode(() => log.append(bad), "seq_conflict", "a gap must be rejected");
|
|
180
|
+
assertEqual(
|
|
181
|
+
seqs(await collect(log.read("s1"))),
|
|
182
|
+
[1, 2],
|
|
183
|
+
"the whole batch rolls back, so seq=3 must not land either"
|
|
184
|
+
);
|
|
162
185
|
});
|
|
163
|
-
t.it("
|
|
186
|
+
t.it("a duplicate seq (a concurrent writer) -> seq_conflict", async () => {
|
|
164
187
|
const log = await factory();
|
|
165
188
|
await log.append(makeEvents("s1", 2));
|
|
166
|
-
await assertThrowsCode(
|
|
189
|
+
await assertThrowsCode(
|
|
190
|
+
() => log.append(makeEvents("s1", 1, 2)),
|
|
191
|
+
"seq_conflict",
|
|
192
|
+
"a duplicate seq=2 must be rejected"
|
|
193
|
+
);
|
|
167
194
|
});
|
|
168
|
-
t.it("
|
|
195
|
+
t.it("mixing sessions in one batch -> session_mismatch", async () => {
|
|
169
196
|
const log = await factory();
|
|
170
197
|
await assertThrowsCode(
|
|
171
198
|
() => log.append([...makeEvents("a", 1), ...makeEvents("b", 1, 2)]),
|
|
172
199
|
"session_mismatch",
|
|
173
|
-
"
|
|
200
|
+
"a mixed-session batch must be rejected"
|
|
174
201
|
);
|
|
175
202
|
});
|
|
176
|
-
t.it("
|
|
203
|
+
t.it("an empty array -> empty_batch", async () => {
|
|
177
204
|
const log = await factory();
|
|
178
|
-
await assertThrowsCode(() => log.append([]), "empty_batch", "
|
|
205
|
+
await assertThrowsCode(() => log.append([]), "empty_batch", "an empty batch must be rejected");
|
|
179
206
|
});
|
|
180
|
-
t.it("
|
|
207
|
+
t.it("events read back are copies: mutating them does not affect the log", async () => {
|
|
181
208
|
const log = await factory();
|
|
182
209
|
await log.append(makeEvents("s1", 1));
|
|
183
210
|
const [first] = await collect(log.read("s1"));
|
|
@@ -186,10 +213,10 @@ function eventLogConformance(t, factory) {
|
|
|
186
213
|
assertEqual(
|
|
187
214
|
again.payload.content.length,
|
|
188
215
|
1,
|
|
189
|
-
"
|
|
216
|
+
"internal data was tampered with from outside"
|
|
190
217
|
);
|
|
191
218
|
});
|
|
192
|
-
t.it("fork
|
|
219
|
+
t.it("fork: copies [1, atSeq], keeping id and seq, changing only sessionId", async () => {
|
|
193
220
|
const log = await factory();
|
|
194
221
|
const src = makeEvents("s1", 4);
|
|
195
222
|
await log.append(src);
|
|
@@ -198,54 +225,58 @@ function eventLogConformance(t, factory) {
|
|
|
198
225
|
assertEqual(
|
|
199
226
|
forked,
|
|
200
227
|
src.slice(0, 2).map((e) => ({ ...e, sessionId: "s2" })),
|
|
201
|
-
"
|
|
228
|
+
"forked content"
|
|
202
229
|
);
|
|
203
230
|
});
|
|
204
|
-
t.it("fork
|
|
231
|
+
t.it("after a fork the two sessions evolve independently", async () => {
|
|
205
232
|
const log = await factory();
|
|
206
233
|
await log.append(makeEvents("s1", 2));
|
|
207
234
|
await log.fork("s1", 2, "s2");
|
|
208
235
|
await log.append(makeEvents("s1", 1, 3));
|
|
209
236
|
await log.append(makeEvents("s2", 2, 3));
|
|
210
|
-
assertEqual(seqs(await collect(log.read("s1"))), [1, 2, 3], "
|
|
211
|
-
assertEqual(seqs(await collect(log.read("s2"))), [1, 2, 3, 4], "
|
|
237
|
+
assertEqual(seqs(await collect(log.read("s1"))), [1, 2, 3], "source session");
|
|
238
|
+
assertEqual(seqs(await collect(log.read("s2"))), [1, 2, 3, 4], "forked session");
|
|
212
239
|
const s2 = await collect(log.read("s2"));
|
|
213
240
|
assert(
|
|
214
241
|
s2.every((e) => e.sessionId === "s2"),
|
|
215
|
-
"
|
|
242
|
+
"every event in the forked session must carry sessionId s2"
|
|
216
243
|
);
|
|
217
244
|
});
|
|
218
|
-
t.it("fork
|
|
245
|
+
t.it("a fork target that already has events -> target_not_empty", async () => {
|
|
219
246
|
const log = await factory();
|
|
220
247
|
await log.append(makeEvents("s1", 2));
|
|
221
248
|
await log.append(makeEvents("s2", 1));
|
|
222
|
-
await assertThrowsCode(
|
|
249
|
+
await assertThrowsCode(
|
|
250
|
+
() => log.fork("s1", 1, "s2"),
|
|
251
|
+
"target_not_empty",
|
|
252
|
+
"a non-empty target must be rejected"
|
|
253
|
+
);
|
|
223
254
|
});
|
|
224
|
-
t.it("
|
|
255
|
+
t.it("an out-of-range atSeq or an unknown source session -> out_of_range", async () => {
|
|
225
256
|
const log = await factory();
|
|
226
257
|
await log.append(makeEvents("s1", 2));
|
|
227
|
-
await assertThrowsCode(() => log.fork("s1", 3, "s2"), "out_of_range", "atSeq
|
|
258
|
+
await assertThrowsCode(() => log.fork("s1", 3, "s2"), "out_of_range", "atSeq beyond the end");
|
|
228
259
|
await assertThrowsCode(() => log.fork("s1", 0, "s2"), "out_of_range", "atSeq=0");
|
|
229
|
-
await assertThrowsCode(() => log.fork("ghost", 1, "s2"), "out_of_range", "
|
|
260
|
+
await assertThrowsCode(() => log.fork("ghost", 1, "s2"), "out_of_range", "unknown source session");
|
|
230
261
|
});
|
|
231
262
|
});
|
|
232
263
|
}
|
|
233
264
|
|
|
234
265
|
// src/testing/memory-store.ts
|
|
235
266
|
function memoryStoreConformance(t, factory) {
|
|
236
|
-
t.describe("MemoryStore
|
|
237
|
-
t.it("read
|
|
267
|
+
t.describe("MemoryStore conformance", () => {
|
|
268
|
+
t.it("read on an unknown path returns null", async () => {
|
|
238
269
|
const store = await factory();
|
|
239
|
-
assertEqual(await store.read("/memories/none.md"), null, "
|
|
270
|
+
assertEqual(await store.read("/memories/none.md"), null, "missing path");
|
|
240
271
|
});
|
|
241
|
-
t.it("write
|
|
272
|
+
t.it("read returns what write stored; a second write overwrites it", async () => {
|
|
242
273
|
const store = await factory();
|
|
243
274
|
await store.write("/memories/a.md", "v1");
|
|
244
|
-
assertEqual(await store.read("/memories/a.md"), "v1", "
|
|
275
|
+
assertEqual(await store.read("/memories/a.md"), "v1", "first write");
|
|
245
276
|
await store.write("/memories/a.md", "v2");
|
|
246
|
-
assertEqual(await store.read("/memories/a.md"), "v2", "
|
|
277
|
+
assertEqual(await store.read("/memories/a.md"), "v2", "overwriting write");
|
|
247
278
|
});
|
|
248
|
-
t.it("list
|
|
279
|
+
t.it("list filters by prefix and returns paths in lexicographic order", async () => {
|
|
249
280
|
const store = await factory();
|
|
250
281
|
await store.write("/memories/b.md", "");
|
|
251
282
|
await store.write("/memories/a.md", "");
|
|
@@ -254,24 +285,105 @@ function memoryStoreConformance(t, factory) {
|
|
|
254
285
|
assertEqual(
|
|
255
286
|
await store.list("/memories/"),
|
|
256
287
|
["/memories/a.md", "/memories/b.md", "/memories/sub/c.md"],
|
|
257
|
-
"
|
|
288
|
+
"prefix /memories/"
|
|
258
289
|
);
|
|
259
|
-
assertEqual(await store.list("/memories/sub/"), ["/memories/sub/c.md"], "
|
|
260
|
-
assertEqual(await store.list("/nope/"), [], "
|
|
261
|
-
});
|
|
262
|
-
t.it("delete \u540E read \u4E3A null\u3001list \u4E0D\u518D\u51FA\u73B0\uFF1B\u5220\u9664\u4E0D\u5B58\u5728\u7684\u8DEF\u5F84\u4E0D\u62A5\u9519", async () => {
|
|
263
|
-
const store = await factory();
|
|
264
|
-
await store.write("/memories/a.md", "x");
|
|
265
|
-
await store.delete("/memories/a.md");
|
|
266
|
-
assertEqual(await store.read("/memories/a.md"), null, "\u5220\u9664\u540E read");
|
|
267
|
-
assertEqual(await store.list("/memories/"), [], "\u5220\u9664\u540E list");
|
|
268
|
-
await store.delete("/memories/a.md");
|
|
290
|
+
assertEqual(await store.list("/memories/sub/"), ["/memories/sub/c.md"], "subdirectory prefix");
|
|
291
|
+
assertEqual(await store.list("/nope/"), [], "no match");
|
|
269
292
|
});
|
|
270
|
-
t.it(
|
|
293
|
+
t.it(
|
|
294
|
+
"after delete, read is null and list no longer shows it; deleting an unknown path does not throw",
|
|
295
|
+
async () => {
|
|
296
|
+
const store = await factory();
|
|
297
|
+
await store.write("/memories/a.md", "x");
|
|
298
|
+
await store.delete("/memories/a.md");
|
|
299
|
+
assertEqual(await store.read("/memories/a.md"), null, "read after delete");
|
|
300
|
+
assertEqual(await store.list("/memories/"), [], "list after delete");
|
|
301
|
+
await store.delete("/memories/a.md");
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
t.it("an empty string is valid content, distinct from absence", async () => {
|
|
271
305
|
const store = await factory();
|
|
272
306
|
await store.write("/memories/empty.md", "");
|
|
273
|
-
assertEqual(
|
|
307
|
+
assertEqual(
|
|
308
|
+
await store.read("/memories/empty.md"),
|
|
309
|
+
"",
|
|
310
|
+
"empty content must read back as an empty string, not null"
|
|
311
|
+
);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/testing/run-lease.ts
|
|
317
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
318
|
+
function runLeaseConformance(t, factory) {
|
|
319
|
+
t.describe("RunLease conformance", () => {
|
|
320
|
+
t.it(
|
|
321
|
+
"acquire succeeds on a free session, fails while someone else holds an unexpired lease, and sessions do not affect each other",
|
|
322
|
+
async () => {
|
|
323
|
+
const lease = await factory();
|
|
324
|
+
assertEqual(await lease.acquire("s1", "a", 6e4), true, "first acquire");
|
|
325
|
+
assertEqual(await lease.acquire("s1", "b", 6e4), false, "someone else is holding it");
|
|
326
|
+
assertEqual(await lease.acquire("s2", "b", 6e4), true, "another session is unaffected");
|
|
327
|
+
}
|
|
328
|
+
);
|
|
329
|
+
t.it(
|
|
330
|
+
"a repeated acquire by the same owner is idempotent (it renews) and does not change who holds the lease",
|
|
331
|
+
async () => {
|
|
332
|
+
const lease = await factory();
|
|
333
|
+
assertEqual(await lease.acquire("s1", "a", 6e4), true, "first");
|
|
334
|
+
assertEqual(await lease.acquire("s1", "a", 6e4), true, "the same owner acquires again");
|
|
335
|
+
assertEqual(await lease.acquire("s1", "b", 6e4), false, "someone else still cannot acquire");
|
|
336
|
+
assertEqual(await lease.renew("s1", "a", 6e4), true, "the owner can still renew");
|
|
337
|
+
}
|
|
338
|
+
);
|
|
339
|
+
t.it("renew: the holder succeeds; a non-holder fails; a never-acquired session fails", async () => {
|
|
340
|
+
const lease = await factory();
|
|
341
|
+
await lease.acquire("s1", "a", 6e4);
|
|
342
|
+
assertEqual(await lease.renew("s1", "a", 6e4), true, "the holder renews");
|
|
343
|
+
assertEqual(await lease.renew("s1", "b", 6e4), false, "a non-holder");
|
|
344
|
+
assertEqual(await lease.renew("nope", "a", 6e4), false, "an unknown session");
|
|
274
345
|
});
|
|
346
|
+
t.it(
|
|
347
|
+
"release: after the holder releases, someone else can acquire; a release by a non-holder does nothing; releasing an unknown session does not throw",
|
|
348
|
+
async () => {
|
|
349
|
+
const lease = await factory();
|
|
350
|
+
await lease.acquire("s1", "a", 6e4);
|
|
351
|
+
await lease.release("s1", "b");
|
|
352
|
+
assertEqual(
|
|
353
|
+
await lease.acquire("s1", "b", 6e4),
|
|
354
|
+
false,
|
|
355
|
+
"a still holds the lease after a non-holder releases"
|
|
356
|
+
);
|
|
357
|
+
await lease.release("s1", "a");
|
|
358
|
+
assertEqual(
|
|
359
|
+
await lease.acquire("s1", "b", 6e4),
|
|
360
|
+
true,
|
|
361
|
+
"after the holder releases, the lease can be acquired again"
|
|
362
|
+
);
|
|
363
|
+
await lease.release("nope", "a");
|
|
364
|
+
}
|
|
365
|
+
);
|
|
366
|
+
t.it(
|
|
367
|
+
"expiry: once it lapses, someone else can take over, the old holder's renew is false, and the new holder renews normally",
|
|
368
|
+
async () => {
|
|
369
|
+
const lease = await factory();
|
|
370
|
+
assertEqual(await lease.acquire("s1", "a", 1), true, "short lease");
|
|
371
|
+
await sleep(30);
|
|
372
|
+
assertEqual(await lease.acquire("s1", "b", 6e4), true, "taking over after expiry");
|
|
373
|
+
assertEqual(await lease.renew("s1", "a", 6e4), false, "the party that lost the lease cannot renew");
|
|
374
|
+
assertEqual(await lease.renew("s1", "b", 6e4), true, "the new holder renews");
|
|
375
|
+
}
|
|
376
|
+
);
|
|
377
|
+
t.it(
|
|
378
|
+
"expired with no one taking over: the old holder's renew is false, but it can acquire again",
|
|
379
|
+
async () => {
|
|
380
|
+
const lease = await factory();
|
|
381
|
+
await lease.acquire("s1", "a", 1);
|
|
382
|
+
await sleep(30);
|
|
383
|
+
assertEqual(await lease.renew("s1", "a", 6e4), false, "no renew after expiry");
|
|
384
|
+
assert(await lease.acquire("s1", "a", 6e4), "acquiring again after expiry must succeed");
|
|
385
|
+
}
|
|
386
|
+
);
|
|
275
387
|
});
|
|
276
388
|
}
|
|
277
389
|
|
|
@@ -282,6 +394,7 @@ var SCRIPTED_CAPABILITIES = {
|
|
|
282
394
|
thinkingReplay: true,
|
|
283
395
|
parallelTools: true,
|
|
284
396
|
taskBudget: false,
|
|
397
|
+
deferredTools: false,
|
|
285
398
|
images: true,
|
|
286
399
|
contextWindow: 2e5,
|
|
287
400
|
maxOutputTokens: 8192
|
|
@@ -327,7 +440,10 @@ var ScriptedLowering = class {
|
|
|
327
440
|
turnAt(turn, input) {
|
|
328
441
|
if (typeof this.script === "function") return this.script(input, turn);
|
|
329
442
|
const step = this.script[turn];
|
|
330
|
-
if (!step)
|
|
443
|
+
if (!step)
|
|
444
|
+
throw new Error(
|
|
445
|
+
`the script has only ${this.script.length} turn(s); turn ${turn + 1} has no scripted response`
|
|
446
|
+
);
|
|
331
447
|
return step;
|
|
332
448
|
}
|
|
333
449
|
};
|
|
@@ -360,6 +476,7 @@ export {
|
|
|
360
476
|
eventLogConformance,
|
|
361
477
|
makeEvents,
|
|
362
478
|
memoryStoreConformance,
|
|
479
|
+
runLeaseConformance,
|
|
363
480
|
say,
|
|
364
481
|
think
|
|
365
482
|
};
|