@ftrdotdev/pi-delegates 0.0.0-stage → 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/CHANGELOG.md +77 -0
- package/LICENSE +21 -0
- package/OPERATIONS.md +57 -0
- package/README.md +448 -2
- package/ROADMAP.md +158 -0
- package/TESTING.md +1061 -0
- package/agents.ts +8 -0
- package/examples/README.md +114 -0
- package/examples/gated.ts +28 -0
- package/index.ts +9 -0
- package/package.json +93 -4
- package/skills/pi-delegates/SKILL.md +147 -0
- package/skills/pi-delegates/references/control.md +159 -0
- package/skills/pi-delegates/references/definitions.md +163 -0
- package/skills/pi-delegates/references/gates.md +175 -0
- package/skills/pi-delegates/references/launch.md +156 -0
- package/src/domain/definitions.test.ts +41 -0
- package/src/domain/definitions.ts +161 -0
- package/src/domain/ids.ts +13 -0
- package/src/domain/names.ts +35 -0
- package/src/domain/orchestration/admission.ts +78 -0
- package/src/domain/orchestration/control.test.ts +1298 -0
- package/src/domain/orchestration/control.ts +436 -0
- package/src/domain/orchestration/fanout.test.ts +419 -0
- package/src/domain/orchestration/fanout.ts +334 -0
- package/src/domain/orchestration/gates.test.ts +686 -0
- package/src/domain/orchestration/gates.ts +360 -0
- package/src/domain/orchestration/launch.test.ts +173 -0
- package/src/domain/orchestration/launch.ts +581 -0
- package/src/domain/orchestration/requests.test.ts +700 -0
- package/src/domain/orchestration/requests.ts +769 -0
- package/src/domain/orchestration/review.test.ts +214 -0
- package/src/domain/orchestration/review.ts +168 -0
- package/src/domain/orchestration/run-wait.test.ts +262 -0
- package/src/domain/orchestration/run-wait.ts +256 -0
- package/src/domain/orchestration/workflow-section.test.ts +62 -0
- package/src/domain/orchestration/workflow-section.ts +99 -0
- package/src/domain/orchestration/workflow.test.ts +1425 -0
- package/src/domain/orchestration/workflow.ts +705 -0
- package/src/domain/run-records.test.ts +27 -0
- package/src/domain/run-records.ts +527 -0
- package/src/domain/shapes.test.ts +165 -0
- package/src/domain/skills.test.ts +466 -0
- package/src/domain/skills.ts +97 -0
- package/src/domain/tool-schema.test.ts +46 -0
- package/src/domain/tool-schema.ts +20 -0
- package/src/domain/toolkit.test.ts +201 -0
- package/src/domain/toolkit.ts +379 -0
- package/src/domain/view.test.ts +739 -0
- package/src/domain/view.ts +459 -0
- package/src/example.test.ts +15 -0
- package/src/extension/commands.test.ts +481 -0
- package/src/extension/commands.ts +227 -0
- package/src/extension/entry.test.ts +1118 -0
- package/src/extension/entry.ts +342 -0
- package/src/extension/gate-alerts.test.ts +235 -0
- package/src/extension/gate-alerts.ts +143 -0
- package/src/extension/guard.test.ts +48 -0
- package/src/extension/guard.ts +31 -0
- package/src/extension/host-signals.test.ts +20 -0
- package/src/extension/host-signals.ts +13 -0
- package/src/extension/inspector-command.test.ts +1191 -0
- package/src/extension/inspector-command.ts +638 -0
- package/src/extension/prompt.test.ts +110 -0
- package/src/extension/prompt.ts +50 -0
- package/src/extension/request-alerts.test.ts +183 -0
- package/src/extension/request-alerts.ts +181 -0
- package/src/extension/revocation.test.ts +81 -0
- package/src/extension/revocation.ts +84 -0
- package/src/extension/shortcut.test.ts +64 -0
- package/src/extension/shortcut.ts +105 -0
- package/src/extension/tools.test.ts +993 -0
- package/src/extension/tools.ts +505 -0
- package/src/extension/version.test.ts +123 -0
- package/src/extension/version.ts +97 -0
- package/src/harness-policy.test.ts +74 -0
- package/src/package-manifest.test.ts +157 -0
- package/src/presentation/actions.test.ts +221 -0
- package/src/presentation/actions.ts +85 -0
- package/src/presentation/activity.test.ts +387 -0
- package/src/presentation/activity.ts +66 -0
- package/src/presentation/close.test.ts +361 -0
- package/src/presentation/inspector.test.ts +679 -0
- package/src/presentation/inspector.ts +440 -0
- package/src/presentation/overlay.test.ts +555 -0
- package/src/presentation/overlay.ts +229 -0
- package/src/presentation/repaint.test.ts +329 -0
- package/src/presentation/shortcut.ts +2 -0
- package/src/presentation/snapshot.test.ts +530 -0
- package/src/presentation/snapshot.ts +306 -0
- package/src/presentation/strip.test.ts +196 -0
- package/src/presentation/strip.ts +74 -0
- package/src/presentation/wording.test.ts +238 -0
- package/src/presentation/wording.ts +222 -0
- package/src/runtime/bridge.test.ts +131 -0
- package/src/runtime/bridge.ts +134 -0
- package/src/runtime/config.test.ts +44 -0
- package/src/runtime/config.ts +87 -0
- package/src/runtime/context.test.ts +19 -0
- package/src/runtime/context.ts +9 -0
- package/src/runtime/execution-env.test.ts +35 -0
- package/src/runtime/execution-env.ts +15 -0
- package/src/runtime/extensions.test.ts +86 -0
- package/src/runtime/extensions.ts +140 -0
- package/src/runtime/log.test.ts +128 -0
- package/src/runtime/log.ts +68 -0
- package/src/runtime/mcp.test.ts +1453 -0
- package/src/runtime/mcp.ts +938 -0
- package/src/runtime/models.test.ts +145 -0
- package/src/runtime/models.ts +259 -0
- package/src/runtime/observe.test.ts +50 -0
- package/src/runtime/observe.ts +150 -0
- package/src/runtime/session.test.ts +359 -0
- package/src/runtime/session.ts +425 -0
- package/src/runtime/timers.test.ts +31 -0
- package/src/runtime/timers.ts +10 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
3
|
+
import { MemoryStorage, type Storage } from "@earendil-works/pi-durable";
|
|
4
|
+
import { Context, Deferred, Effect, Exit, Fiber, Layer, Scope, Stream } from "effect";
|
|
5
|
+
import { mkdtemp } from "node:fs/promises";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { failingStorage } from "../../test-support/failing-storage.ts";
|
|
9
|
+
import { fakeObservations } from "../../test-support/fake-observations.ts";
|
|
10
|
+
import { inspectorClock } from "../../test-support/inspector-clock.ts";
|
|
11
|
+
import { ProbeDoc } from "../../test-support/probe-doc.ts";
|
|
12
|
+
import { stubHostSource } from "../../test-support/stub-model-source.ts";
|
|
13
|
+
import type { ChildView, RunView, SessionView } from "../domain/view.ts";
|
|
14
|
+
import { HostModelAdapter } from "../runtime/models.ts";
|
|
15
|
+
import type { Timers } from "../runtime/timers.ts";
|
|
16
|
+
import { openSessionRuntime, type SessionRuntime } from "../runtime/session.ts";
|
|
17
|
+
import {
|
|
18
|
+
endNotice,
|
|
19
|
+
Inspector,
|
|
20
|
+
RUN_INDEX_ADDRESS,
|
|
21
|
+
type InspectorReadFailed,
|
|
22
|
+
type InspectorService,
|
|
23
|
+
} from "./inspector.ts";
|
|
24
|
+
import type { InspectorDeps } from "./inspector.ts";
|
|
25
|
+
|
|
26
|
+
const runView = (input: Partial<RunView> & { readonly runId: string }): RunView => ({
|
|
27
|
+
definition: "scout",
|
|
28
|
+
mode: "single",
|
|
29
|
+
lane: "default",
|
|
30
|
+
conversationId: null,
|
|
31
|
+
taskId: null,
|
|
32
|
+
status: "running",
|
|
33
|
+
answer: null,
|
|
34
|
+
durationMs: null,
|
|
35
|
+
children: [],
|
|
36
|
+
missing: [],
|
|
37
|
+
gates: [],
|
|
38
|
+
requests: [],
|
|
39
|
+
diagnostic: null,
|
|
40
|
+
...input,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const childView = (
|
|
44
|
+
input: Partial<ChildView> & { readonly child: number; readonly runId: string },
|
|
45
|
+
): ChildView => ({
|
|
46
|
+
conversationId: null,
|
|
47
|
+
taskId: null,
|
|
48
|
+
agent: "scout",
|
|
49
|
+
status: "running",
|
|
50
|
+
answer: null,
|
|
51
|
+
durationMs: null,
|
|
52
|
+
...input,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const oneRunningView = (): SessionView => ({
|
|
56
|
+
runs: [
|
|
57
|
+
runView({
|
|
58
|
+
runId: "run:a",
|
|
59
|
+
conversationId: 10,
|
|
60
|
+
children: [childView({ child: 0, runId: "run:a", conversationId: 10 })],
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
lanes: [],
|
|
64
|
+
gates: [],
|
|
65
|
+
reviews: [],
|
|
66
|
+
requests: [],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const openRuntime = async (storage: Storage = new MemoryStorage()): Promise<SessionRuntime> => {
|
|
70
|
+
const sessionDir = await mkdtemp(join(tmpdir(), "delegates-close-"));
|
|
71
|
+
return openSessionRuntime({
|
|
72
|
+
identity: { sessionId: "s-1", sessionDir, cwd: sessionDir, agentDir: sessionDir },
|
|
73
|
+
models: new HostModelAdapter(stubHostSource()),
|
|
74
|
+
storage,
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
interface Built {
|
|
79
|
+
readonly inspector: InspectorService;
|
|
80
|
+
readonly scope: Scope.Closeable;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const build = Effect.fn("buildInspector")(function* (
|
|
84
|
+
deps: InspectorDeps,
|
|
85
|
+
): Effect.fn.Return<Built, InspectorReadFailed> {
|
|
86
|
+
const scope = yield* Scope.make("sequential");
|
|
87
|
+
const context = yield* Effect.provideService(
|
|
88
|
+
Layer.build(Inspector.layer(deps)),
|
|
89
|
+
Scope.Scope,
|
|
90
|
+
scope,
|
|
91
|
+
);
|
|
92
|
+
return { inspector: Context.get(context, Inspector), scope };
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const close = (built: Built): Effect.Effect<void> => Scope.close(built.scope, Exit.void);
|
|
96
|
+
|
|
97
|
+
const until = Effect.fn("until")(function* (
|
|
98
|
+
predicate: () => boolean,
|
|
99
|
+
label: string,
|
|
100
|
+
): Effect.fn.Return<void> {
|
|
101
|
+
for (let attempt = 0; attempt < 2_000; attempt += 1) {
|
|
102
|
+
if (predicate()) return;
|
|
103
|
+
yield* Effect.promise(() => new Promise((resolve) => setTimeout(resolve, 1)));
|
|
104
|
+
}
|
|
105
|
+
return yield* Effect.die(new Error(`condition not reached: ${label}`));
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it.effect("a closed runtime completes one end event", () =>
|
|
109
|
+
Effect.gen(function* () {
|
|
110
|
+
const runtime = yield* Effect.promise(() => openRuntime());
|
|
111
|
+
const clock = inspectorClock();
|
|
112
|
+
const built = yield* build({
|
|
113
|
+
runtime,
|
|
114
|
+
observe: fakeObservations(),
|
|
115
|
+
view: async () => oneRunningView(),
|
|
116
|
+
timers: clock,
|
|
117
|
+
});
|
|
118
|
+
const ends = yield* Stream.runCollect(built.inspector.end).pipe(Effect.forkChild);
|
|
119
|
+
yield* Effect.promise(() => runtime.close());
|
|
120
|
+
const collected = yield* Fiber.join(ends);
|
|
121
|
+
assert.deepStrictEqual([...collected], [{ kind: "runtime-ended" }]);
|
|
122
|
+
yield* close(built);
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
it.effect("failing then closed still completes one end event", () =>
|
|
127
|
+
Effect.gen(function* () {
|
|
128
|
+
const { storage, failNext } = failingStorage(new MemoryStorage());
|
|
129
|
+
const runtime = yield* Effect.promise(() => openRuntime(storage));
|
|
130
|
+
const built = yield* build({
|
|
131
|
+
runtime,
|
|
132
|
+
observe: fakeObservations(),
|
|
133
|
+
view: async () => oneRunningView(),
|
|
134
|
+
timers: inspectorClock(),
|
|
135
|
+
});
|
|
136
|
+
const ends = yield* Stream.runCollect(built.inspector.end).pipe(Effect.forkChild);
|
|
137
|
+
|
|
138
|
+
failNext();
|
|
139
|
+
yield* Effect.promise(() =>
|
|
140
|
+
runtime.harness
|
|
141
|
+
.commit(async (tx) => {
|
|
142
|
+
await tx.doc(ProbeDoc);
|
|
143
|
+
}, BACKGROUND_CONTEXT)
|
|
144
|
+
.catch(() => undefined),
|
|
145
|
+
);
|
|
146
|
+
yield* Effect.promise(() => runtime.harness.closed);
|
|
147
|
+
const collected = yield* Fiber.join(ends);
|
|
148
|
+
assert.strictEqual(collected.length, 1);
|
|
149
|
+
assert.strictEqual(collected[0]?.kind, "runtime-ended");
|
|
150
|
+
assert.ok(
|
|
151
|
+
collected[0]?.kind === "runtime-ended" &&
|
|
152
|
+
collected[0].reason !== undefined &&
|
|
153
|
+
collected[0].reason.includes("storage failed"),
|
|
154
|
+
JSON.stringify(collected),
|
|
155
|
+
);
|
|
156
|
+
yield* close(built);
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
it.effect("the end interrupts the repaint, then the consumer, then detaches, then completes", () =>
|
|
161
|
+
Effect.gen(function* () {
|
|
162
|
+
const events: string[] = [];
|
|
163
|
+
const clock = inspectorClock();
|
|
164
|
+
const timers: Timers = {
|
|
165
|
+
setTimeout: (callback, ms) => clock.setTimeout(callback, ms),
|
|
166
|
+
clearTimeout: (handle) => {
|
|
167
|
+
events.push("repaint-interrupted");
|
|
168
|
+
clock.clearTimeout(handle);
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
const runtime = yield* Effect.promise(() => openRuntime());
|
|
172
|
+
const fake = fakeObservations({ onDetach: () => events.push("observations-detached") });
|
|
173
|
+
const built = yield* build({
|
|
174
|
+
runtime,
|
|
175
|
+
observe: fake,
|
|
176
|
+
view: async () => oneRunningView(),
|
|
177
|
+
timers,
|
|
178
|
+
onConsumerInterrupted: () => events.push("consumer-interrupted"),
|
|
179
|
+
});
|
|
180
|
+
const ends = yield* Effect.forkChild(
|
|
181
|
+
Stream.runForEach(built.inspector.end, () => Effect.sync(() => events.push("end"))),
|
|
182
|
+
);
|
|
183
|
+
yield* Effect.promise(() => runtime.close());
|
|
184
|
+
yield* until(() => events.includes("end"), "the end event arrived");
|
|
185
|
+
|
|
186
|
+
const repaintAt = events.indexOf("repaint-interrupted");
|
|
187
|
+
const consumerAt = events.indexOf("consumer-interrupted");
|
|
188
|
+
const detachAt = events.indexOf("observations-detached");
|
|
189
|
+
const endAt = events.indexOf("end");
|
|
190
|
+
assert.ok(repaintAt >= 0, events.join(","));
|
|
191
|
+
assert.ok(consumerAt > repaintAt, events.join(","));
|
|
192
|
+
assert.ok(detachAt > consumerAt, events.join(","));
|
|
193
|
+
assert.ok(endAt > detachAt, events.join(","));
|
|
194
|
+
yield* Fiber.interrupt(ends);
|
|
195
|
+
yield* close(built);
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
it.effect("a repaint that fires after the end publishes nothing", () =>
|
|
200
|
+
Effect.gen(function* () {
|
|
201
|
+
const clock = inspectorClock();
|
|
202
|
+
const runtime = yield* Effect.promise(() => openRuntime());
|
|
203
|
+
const built = yield* build({
|
|
204
|
+
runtime,
|
|
205
|
+
observe: fakeObservations(),
|
|
206
|
+
view: async () => oneRunningView(),
|
|
207
|
+
timers: clock,
|
|
208
|
+
});
|
|
209
|
+
const before = yield* built.inspector.snapshot;
|
|
210
|
+
yield* Effect.promise(() => runtime.close());
|
|
211
|
+
yield* until(() => clock.armed === 0, "the age clock stopped");
|
|
212
|
+
yield* clock.fire;
|
|
213
|
+
const after = yield* built.inspector.snapshot;
|
|
214
|
+
assert.strictEqual(after, before);
|
|
215
|
+
assert.strictEqual(after.revision, 1);
|
|
216
|
+
yield* close(built);
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
it.effect("an interruption during the end cannot skip a detach", () =>
|
|
221
|
+
Effect.gen(function* () {
|
|
222
|
+
const runtime = yield* Effect.promise(() => openRuntime());
|
|
223
|
+
const clock = inspectorClock();
|
|
224
|
+
const midFinish = Deferred.makeUnsafe<void>();
|
|
225
|
+
let endFiber: Fiber.Fiber<void> | undefined;
|
|
226
|
+
const fake = fakeObservations();
|
|
227
|
+
const built = yield* build({
|
|
228
|
+
runtime,
|
|
229
|
+
observe: fake,
|
|
230
|
+
view: async () => oneRunningView(),
|
|
231
|
+
timers: {
|
|
232
|
+
setTimeout: (callback, ms) => clock.setTimeout(callback, ms),
|
|
233
|
+
clearTimeout: (handle) => {
|
|
234
|
+
// The end fiber is inside `finish`, between the repaint interrupt and
|
|
235
|
+
// the consumer interrupt: interrupt it exactly there.
|
|
236
|
+
endFiber?.interruptUnsafe();
|
|
237
|
+
Deferred.doneUnsafe(midFinish, Exit.void);
|
|
238
|
+
clock.clearTimeout(handle);
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
onEndFiber: (fiber) => {
|
|
242
|
+
endFiber = fiber;
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
yield* Effect.promise(() => runtime.close());
|
|
246
|
+
yield* Deferred.await(midFinish);
|
|
247
|
+
yield* close(built);
|
|
248
|
+
|
|
249
|
+
assert.strictEqual(fake.detaches.length, fake.attaches.length);
|
|
250
|
+
assert.strictEqual(new Set(fake.detaches).size, fake.detaches.length);
|
|
251
|
+
assert.deepStrictEqual(fake.attached(), []);
|
|
252
|
+
assert.strictEqual(clock.armed, 0);
|
|
253
|
+
}),
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
it.effect("an end stops the consumer before the detaches", () =>
|
|
257
|
+
Effect.gen(function* () {
|
|
258
|
+
const runtime = yield* Effect.promise(() => openRuntime());
|
|
259
|
+
const fake = fakeObservations();
|
|
260
|
+
const readStarted = Deferred.makeUnsafe<void>();
|
|
261
|
+
let reads = 0;
|
|
262
|
+
let resolveRead: ((view: SessionView) => void) | undefined;
|
|
263
|
+
const built = yield* build({
|
|
264
|
+
runtime,
|
|
265
|
+
observe: fake,
|
|
266
|
+
view: () => {
|
|
267
|
+
reads += 1;
|
|
268
|
+
if (reads === 1) return Promise.resolve(oneRunningView());
|
|
269
|
+
Deferred.doneUnsafe(readStarted, Exit.void);
|
|
270
|
+
return new Promise<SessionView>((resolve) => {
|
|
271
|
+
resolveRead = resolve;
|
|
272
|
+
});
|
|
273
|
+
},
|
|
274
|
+
timers: inspectorClock(),
|
|
275
|
+
});
|
|
276
|
+
fake.push(RUN_INDEX_ADDRESS);
|
|
277
|
+
yield* Deferred.await(readStarted);
|
|
278
|
+
yield* Effect.promise(() => runtime.close());
|
|
279
|
+
yield* close(built);
|
|
280
|
+
|
|
281
|
+
// A read still in flight at the end must never reconcile: the consumer was
|
|
282
|
+
// interrupted before the detaches, so the late row attaches nothing.
|
|
283
|
+
resolveRead?.({
|
|
284
|
+
runs: [
|
|
285
|
+
runView({
|
|
286
|
+
runId: "run:a",
|
|
287
|
+
conversationId: 10,
|
|
288
|
+
children: [childView({ child: 0, runId: "run:a", conversationId: 10 })],
|
|
289
|
+
}),
|
|
290
|
+
runView({
|
|
291
|
+
runId: "run:late",
|
|
292
|
+
conversationId: 11,
|
|
293
|
+
children: [childView({ child: 0, runId: "run:late", conversationId: 11 })],
|
|
294
|
+
}),
|
|
295
|
+
],
|
|
296
|
+
lanes: [],
|
|
297
|
+
gates: [],
|
|
298
|
+
reviews: [],
|
|
299
|
+
requests: [],
|
|
300
|
+
});
|
|
301
|
+
yield* Effect.yieldNow;
|
|
302
|
+
|
|
303
|
+
assert.strictEqual(fake.attaches.includes("run:run:late"), false, fake.attaches.join(","));
|
|
304
|
+
assert.deepStrictEqual(fake.attached(), []);
|
|
305
|
+
assert.strictEqual(new Set(fake.detaches).size, fake.detaches.length);
|
|
306
|
+
}),
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
it.effect("teardown is idempotent: closing the scope after a runtime end detaches once", () =>
|
|
310
|
+
Effect.gen(function* () {
|
|
311
|
+
const runtime = yield* Effect.promise(() => openRuntime());
|
|
312
|
+
const fake = fakeObservations();
|
|
313
|
+
const built = yield* build({
|
|
314
|
+
runtime,
|
|
315
|
+
observe: fake,
|
|
316
|
+
view: async () => oneRunningView(),
|
|
317
|
+
timers: inspectorClock(),
|
|
318
|
+
});
|
|
319
|
+
yield* Effect.promise(() => runtime.close());
|
|
320
|
+
yield* until(() => fake.attached().length === 0, "the runtime end detached everything");
|
|
321
|
+
const detaches = fake.detaches.length;
|
|
322
|
+
yield* close(built);
|
|
323
|
+
assert.strictEqual(fake.detaches.length, detaches);
|
|
324
|
+
assert.strictEqual(new Set(fake.detaches).size, fake.detaches.length);
|
|
325
|
+
}),
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
it.effect("a user shutdown completes the end event as stopped and writes no notice", () =>
|
|
329
|
+
Effect.gen(function* () {
|
|
330
|
+
const runtime = yield* Effect.promise(() => openRuntime());
|
|
331
|
+
const built = yield* build({
|
|
332
|
+
runtime,
|
|
333
|
+
observe: fakeObservations(),
|
|
334
|
+
view: async () => oneRunningView(),
|
|
335
|
+
timers: inspectorClock(),
|
|
336
|
+
});
|
|
337
|
+
const ends = yield* Stream.runCollect(built.inspector.end).pipe(Effect.forkChild);
|
|
338
|
+
yield* close(built);
|
|
339
|
+
const collected = yield* Fiber.join(ends);
|
|
340
|
+
assert.deepStrictEqual([...collected], [{ kind: "stopped" }]);
|
|
341
|
+
assert.strictEqual(endNotice({ kind: "stopped" }), undefined);
|
|
342
|
+
yield* Effect.promise(() => runtime.close());
|
|
343
|
+
}),
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
it("a forced close carries one notice line naming the reason", () => {
|
|
347
|
+
const line = endNotice({ kind: "runtime-ended", reason: "storage failed" });
|
|
348
|
+
assert.ok(line !== undefined);
|
|
349
|
+
assert.ok(line.includes("storage failed"));
|
|
350
|
+
assert.ok(!line.includes("\n"));
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("a failed activation writes the same notice shape as a runtime ending", () => {
|
|
354
|
+
assert.deepStrictEqual(
|
|
355
|
+
endNotice({ kind: "runtime-ended", reason: "failed to start: boom" }),
|
|
356
|
+
endNotice({ kind: "runtime-ended", reason: "failed to start: boom" }),
|
|
357
|
+
);
|
|
358
|
+
assert.ok(
|
|
359
|
+
endNotice({ kind: "runtime-ended", reason: "failed to start: boom" })?.includes("boom"),
|
|
360
|
+
);
|
|
361
|
+
});
|