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