@ftrdotdev/pi-delegates 0.1.0 → 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.
- package/CHANGELOG.md +51 -0
- package/OPERATIONS.md +79 -6
- package/README.md +25 -17
- package/ROADMAP.md +21 -0
- package/TESTING.md +153 -318
- package/package.json +4 -3
- package/skills/pi-delegates/SKILL.md +29 -0
- package/skills/pi-delegates/references/launch.md +28 -0
- package/src/docs-contract.test.ts +106 -0
- package/src/domain/definitions.ts +3 -1
- package/src/domain/failure.ts +33 -0
- package/src/domain/model-source.ts +30 -0
- package/src/domain/orchestration/control.test.ts +69 -35
- package/src/domain/orchestration/control.ts +110 -89
- package/src/domain/orchestration/fanout.test.ts +125 -20
- package/src/domain/orchestration/fanout.ts +60 -22
- package/src/domain/orchestration/gates.test.ts +14 -15
- package/src/domain/orchestration/launch.test.ts +210 -11
- package/src/domain/orchestration/launch.ts +142 -32
- package/src/domain/orchestration/requests.test.ts +11 -16
- package/src/domain/orchestration/requests.ts +14 -1
- package/src/domain/orchestration/review.test.ts +89 -11
- package/src/domain/orchestration/run-wait.test.ts +4 -1
- package/src/domain/orchestration/run-wait.ts +1 -1
- package/src/domain/orchestration/workflow.test.ts +157 -16
- package/src/domain/orchestration/workflow.ts +269 -196
- package/src/domain/run-records.ts +214 -52
- package/src/domain/settlement.test.ts +186 -0
- package/src/domain/settlement.ts +137 -0
- package/src/domain/shapes.test.ts +20 -0
- package/src/domain/skills.test.ts +31 -20
- package/src/domain/skills.ts +36 -19
- package/src/domain/toolkit.test.ts +15 -1
- package/src/domain/toolkit.ts +8 -13
- package/src/domain/turn-budget.test.ts +37 -0
- package/src/domain/turn-budget.ts +23 -0
- package/src/domain/view.test.ts +78 -14
- package/src/domain/view.ts +67 -35
- package/src/extension/commands.test.ts +27 -23
- package/src/extension/commands.ts +10 -7
- package/src/extension/entry.test.ts +214 -56
- package/src/extension/entry.ts +78 -40
- package/src/extension/gate-alerts.test.ts +10 -8
- package/src/extension/inspector-command.test.ts +173 -21
- package/src/extension/inspector-command.ts +100 -53
- package/src/extension/prompt.test.ts +2 -4
- package/src/extension/retry-observer.test.ts +292 -0
- package/src/extension/retry-observer.ts +150 -0
- package/src/extension/settle-alerts.test.ts +579 -0
- package/src/extension/settle-alerts.ts +175 -0
- package/src/extension/shortcut.test.ts +6 -8
- package/src/extension/tools.test.ts +325 -24
- package/src/extension/tools.ts +61 -13
- package/src/extension/version.test.ts +21 -29
- package/src/goldens.test.ts +294 -0
- package/src/harness-policy.test.ts +13 -11
- package/src/layers.test.ts +309 -0
- package/src/layers.ts +405 -0
- package/src/package-manifest.test.ts +32 -19
- package/src/presentation/actions.test.ts +8 -8
- package/src/presentation/activity.test.ts +7 -8
- package/src/presentation/close.test.ts +14 -16
- package/src/presentation/inspector.test.ts +14 -11
- package/src/presentation/inspector.ts +27 -25
- package/src/presentation/overlay.test.ts +1 -3
- package/src/presentation/repaint.test.ts +226 -190
- package/src/presentation/snapshot.test.ts +5 -0
- package/src/presentation/status.test.ts +43 -0
- package/src/presentation/status.ts +30 -0
- package/src/presentation/strip.test.ts +13 -6
- package/src/presentation/strip.ts +7 -14
- package/src/presentation/wording.test.ts +153 -3
- package/src/presentation/wording.ts +78 -6
- package/src/runtime/bridge.ts +38 -44
- package/src/runtime/{timers.test.ts → clock.test.ts} +1 -1
- package/src/runtime/clock.ts +31 -0
- package/src/runtime/config.test.ts +26 -7
- package/src/runtime/config.ts +6 -1
- package/src/runtime/execution-env.test.ts +6 -8
- package/src/runtime/extensions.test.ts +4 -4
- package/src/runtime/extensions.ts +23 -11
- package/src/runtime/handle.ts +54 -0
- package/src/runtime/log.test.ts +19 -7
- package/src/runtime/log.ts +23 -0
- package/src/runtime/mcp.test.ts +29 -32
- package/src/runtime/mcp.ts +70 -3
- package/src/runtime/runtime-state.test.ts +25 -0
- package/src/runtime/runtime-state.ts +36 -0
- package/src/runtime/session-tag.ts +11 -0
- package/src/runtime/session.test.ts +24 -31
- package/src/runtime/session.ts +99 -261
- package/src/runtime/storage.ts +29 -0
- package/src/test-hygiene.test.ts +97 -0
- package/src/runtime/timers.ts +0 -10
|
@@ -1,24 +1,38 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
|
|
3
|
+
import * as NodePath from "@effect/platform-node/NodePath";
|
|
2
4
|
import { MemoryStorage } from "@earendil-works/pi-durable";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
Context,
|
|
7
|
+
Deferred,
|
|
8
|
+
Effect,
|
|
9
|
+
Exit,
|
|
10
|
+
Fiber,
|
|
11
|
+
Layer,
|
|
12
|
+
PlatformError,
|
|
13
|
+
Scope,
|
|
14
|
+
Stream,
|
|
15
|
+
} from "effect";
|
|
16
|
+
import * as FileSystem from "effect/FileSystem";
|
|
17
|
+
import * as Path from "effect/Path";
|
|
7
18
|
import { fakeObservations } from "../../test-support/fake-observations.ts";
|
|
8
19
|
import { inspectorClock } from "../../test-support/inspector-clock.ts";
|
|
9
20
|
import { stubHostSource } from "../../test-support/stub-model-source.ts";
|
|
10
21
|
import type { ChildView, RunStatus, RunView, SessionView } from "../domain/view.ts";
|
|
11
22
|
import type { LogFields, LogLevel, LogSink } from "../runtime/log.ts";
|
|
12
23
|
import { HostModelAdapter } from "../runtime/models.ts";
|
|
13
|
-
|
|
24
|
+
|
|
14
25
|
import {
|
|
15
26
|
Inspector,
|
|
16
27
|
liveAddress,
|
|
17
28
|
REPAINT_INTERVAL_MS,
|
|
18
29
|
type InspectorDeps,
|
|
19
30
|
type InspectorReadFailed,
|
|
20
|
-
type InspectorService,
|
|
21
31
|
} from "./inspector.ts";
|
|
32
|
+
import { openTestSession, type TestSession } from "../../test-support/seams.ts";
|
|
33
|
+
|
|
34
|
+
/** One platform scope for every scenario: teardown is @effect/vitest's internal close. */
|
|
35
|
+
const suite = it.layer(Layer.mergeAll(NodeFileSystem.layer, NodePath.layer));
|
|
22
36
|
|
|
23
37
|
const recordingLog = (): {
|
|
24
38
|
readonly sink: LogSink;
|
|
@@ -35,22 +49,25 @@ const recordingLog = (): {
|
|
|
35
49
|
};
|
|
36
50
|
};
|
|
37
51
|
|
|
38
|
-
const openRuntime = async (log?: LogSink): Promise<
|
|
39
|
-
|
|
40
|
-
return openSessionRuntime({
|
|
52
|
+
const openRuntime = async (sessionDir: string, log?: LogSink): Promise<TestSession> =>
|
|
53
|
+
openTestSession({
|
|
41
54
|
identity: { sessionId: "s-1", sessionDir, cwd: sessionDir, agentDir: sessionDir },
|
|
42
55
|
models: new HostModelAdapter(stubHostSource()),
|
|
43
56
|
storage: new MemoryStorage(),
|
|
44
57
|
...(log === undefined ? {} : { log }),
|
|
45
58
|
});
|
|
46
|
-
};
|
|
47
59
|
|
|
48
60
|
const withRuntime = <A, E, R>(
|
|
49
|
-
use: (runtime:
|
|
61
|
+
use: (runtime: TestSession) => Effect.Effect<A, E, R>,
|
|
50
62
|
log?: LogSink,
|
|
51
|
-
): Effect.Effect<A, E, R> =>
|
|
63
|
+
): Effect.Effect<A, E | PlatformError.PlatformError, R | FileSystem.FileSystem | Scope.Scope> =>
|
|
52
64
|
Effect.acquireUseRelease(
|
|
53
|
-
Effect.
|
|
65
|
+
Effect.gen(function* () {
|
|
66
|
+
const fs = yield* FileSystem.FileSystem;
|
|
67
|
+
// Scoped: the directory is removed when the test's scope closes.
|
|
68
|
+
const sessionDir = yield* fs.makeTempDirectoryScoped({ prefix: "delegates-repaint-" });
|
|
69
|
+
return yield* Effect.promise(() => openRuntime(sessionDir, log));
|
|
70
|
+
}),
|
|
54
71
|
use,
|
|
55
72
|
(runtime) => Effect.promise(() => runtime.close()),
|
|
56
73
|
);
|
|
@@ -70,6 +87,9 @@ const runView = (
|
|
|
70
87
|
gates: [],
|
|
71
88
|
requests: [],
|
|
72
89
|
diagnostic: null,
|
|
90
|
+
execution: "wait",
|
|
91
|
+
maxTurns: null,
|
|
92
|
+
failure: null,
|
|
73
93
|
...input,
|
|
74
94
|
});
|
|
75
95
|
|
|
@@ -82,6 +102,8 @@ const childView = (
|
|
|
82
102
|
status: "running",
|
|
83
103
|
answer: null,
|
|
84
104
|
durationMs: null,
|
|
105
|
+
maxTurns: null,
|
|
106
|
+
failure: null,
|
|
85
107
|
...input,
|
|
86
108
|
});
|
|
87
109
|
|
|
@@ -104,7 +126,7 @@ const oneRunningView = (): SessionView =>
|
|
|
104
126
|
]);
|
|
105
127
|
|
|
106
128
|
interface Built {
|
|
107
|
-
readonly inspector:
|
|
129
|
+
readonly inspector: Inspector["Service"];
|
|
108
130
|
readonly scope: Scope.Closeable;
|
|
109
131
|
}
|
|
110
132
|
|
|
@@ -120,210 +142,224 @@ const build = Effect.fn("buildInspector")(function* (
|
|
|
120
142
|
|
|
121
143
|
const close = (built: Built): Effect.Effect<void> => Scope.close(built.scope, Exit.void);
|
|
122
144
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const views = { reads: 0 };
|
|
126
|
-
const fake = fakeObservations();
|
|
127
|
-
return withRuntime((runtime) =>
|
|
128
|
-
Effect.gen(function* () {
|
|
129
|
-
const built = yield* build({
|
|
130
|
-
runtime,
|
|
131
|
-
observe: fake,
|
|
132
|
-
view: () => {
|
|
133
|
-
views.reads += 1;
|
|
134
|
-
return Promise.resolve(oneRunningView());
|
|
135
|
-
},
|
|
136
|
-
now: () => 4_000,
|
|
137
|
-
timers: clock,
|
|
138
|
-
});
|
|
139
|
-
const snapshot = yield* built.inspector.snapshot;
|
|
140
|
-
assert.strictEqual(snapshot.revision, 1);
|
|
141
|
-
assert.deepStrictEqual(clock.delays, [REPAINT_INTERVAL_MS]);
|
|
142
|
-
assert.strictEqual(views.reads, 1);
|
|
143
|
-
yield* close(built);
|
|
144
|
-
}),
|
|
145
|
-
);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it.effect("a fired repaint reads nothing", () => {
|
|
149
|
-
const clock = inspectorClock();
|
|
150
|
-
let reads = 0;
|
|
151
|
-
const fake = fakeObservations();
|
|
152
|
-
return withRuntime((runtime) =>
|
|
145
|
+
suite((it) => {
|
|
146
|
+
it.effect("the suite resolves the platform services when the platform layer is provided", () =>
|
|
153
147
|
Effect.gen(function* () {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
now: () => 4_000,
|
|
162
|
-
timers: clock,
|
|
163
|
-
});
|
|
164
|
-
const before = reads;
|
|
165
|
-
yield* clock.fire;
|
|
166
|
-
assert.strictEqual(reads, before);
|
|
167
|
-
assert.deepStrictEqual(clock.delays, [REPAINT_INTERVAL_MS, REPAINT_INTERVAL_MS]);
|
|
168
|
-
yield* close(built);
|
|
148
|
+
const fs = yield* FileSystem.FileSystem;
|
|
149
|
+
const path = yield* Path.Path;
|
|
150
|
+
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "delegates-platform-probe-" });
|
|
151
|
+
const file = path.join(directory, "probe.txt");
|
|
152
|
+
yield* fs.writeFileString(file, "probe");
|
|
153
|
+
const entries = yield* fs.readDirectory(directory);
|
|
154
|
+
assert.deepStrictEqual(entries, ["probe.txt"]);
|
|
169
155
|
}),
|
|
170
156
|
);
|
|
171
|
-
});
|
|
172
157
|
|
|
173
|
-
it.effect("
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
assert.strictEqual(afterActivity.rows[0]?.idleMs, 999);
|
|
158
|
+
it.effect("building the owner reads once and arms the repaint interval", () => {
|
|
159
|
+
const clock = inspectorClock();
|
|
160
|
+
const views = { reads: 0 };
|
|
161
|
+
const fake = fakeObservations();
|
|
162
|
+
return withRuntime((runtime) =>
|
|
163
|
+
Effect.gen(function* () {
|
|
164
|
+
const built = yield* build({
|
|
165
|
+
runtime,
|
|
166
|
+
observe: fake,
|
|
167
|
+
view: () => {
|
|
168
|
+
views.reads += 1;
|
|
169
|
+
return Promise.resolve(oneRunningView());
|
|
170
|
+
},
|
|
171
|
+
now: () => 4_000,
|
|
172
|
+
timers: clock,
|
|
173
|
+
});
|
|
174
|
+
const snapshot = yield* built.inspector.snapshot;
|
|
175
|
+
assert.strictEqual(snapshot.revision, 1);
|
|
176
|
+
assert.deepStrictEqual(clock.delays, [REPAINT_INTERVAL_MS]);
|
|
177
|
+
assert.strictEqual(views.reads, 1);
|
|
178
|
+
yield* close(built);
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
});
|
|
198
182
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
183
|
+
it.effect("a fired repaint reads nothing", () => {
|
|
184
|
+
const clock = inspectorClock();
|
|
185
|
+
let reads = 0;
|
|
186
|
+
const fake = fakeObservations();
|
|
187
|
+
return withRuntime((runtime) =>
|
|
188
|
+
Effect.gen(function* () {
|
|
189
|
+
const built = yield* build({
|
|
190
|
+
runtime,
|
|
191
|
+
observe: fake,
|
|
192
|
+
view: () => {
|
|
193
|
+
reads += 1;
|
|
194
|
+
return Promise.resolve(oneRunningView());
|
|
195
|
+
},
|
|
196
|
+
now: () => 4_000,
|
|
197
|
+
timers: clock,
|
|
198
|
+
});
|
|
199
|
+
const before = reads;
|
|
200
|
+
yield* clock.fire;
|
|
201
|
+
assert.strictEqual(reads, before);
|
|
202
|
+
assert.deepStrictEqual(clock.delays, [REPAINT_INTERVAL_MS, REPAINT_INTERVAL_MS]);
|
|
203
|
+
yield* close(built);
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
206
|
+
});
|
|
208
207
|
|
|
209
|
-
it.effect("a fired repaint publishes
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
208
|
+
it.effect("a fired repaint publishes when an age crosses a second", () => {
|
|
209
|
+
const clock = inspectorClock();
|
|
210
|
+
let now = 1_999;
|
|
211
|
+
const fake = fakeObservations();
|
|
212
|
+
return withRuntime((runtime) =>
|
|
213
|
+
Effect.gen(function* () {
|
|
214
|
+
const built = yield* build({
|
|
215
|
+
runtime,
|
|
216
|
+
observe: fake,
|
|
217
|
+
view: async () => oneRunningView(),
|
|
218
|
+
now: () => now,
|
|
219
|
+
timers: clock,
|
|
220
|
+
});
|
|
221
|
+
const subscribed = Deferred.makeUnsafe<void>();
|
|
222
|
+
const changes = yield* Stream.map(built.inspector.changes, (snapshot) => {
|
|
223
|
+
Deferred.doneUnsafe(subscribed, Exit.void);
|
|
224
|
+
return snapshot;
|
|
225
|
+
}).pipe(Stream.take(2), Stream.runCollect, Effect.forkChild);
|
|
226
|
+
yield* Deferred.await(subscribed);
|
|
227
|
+
fake.pushActivity(liveAddress(10), { tool: "bash", slot: "running", turns: 1, at: 1_000 });
|
|
228
|
+
const collected = yield* Fiber.join(changes);
|
|
229
|
+
const afterActivity = [...collected].at(-1);
|
|
230
|
+
assert.ok(afterActivity !== undefined);
|
|
231
|
+
assert.strictEqual(afterActivity.revision, 2);
|
|
232
|
+
assert.strictEqual(afterActivity.rows[0]?.idleMs, 999);
|
|
235
233
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
now: () => 4_000,
|
|
246
|
-
timers: clock,
|
|
247
|
-
});
|
|
248
|
-
const callback = clock.current();
|
|
249
|
-
assert.strictEqual(clock.armed, 1);
|
|
250
|
-
yield* close(built);
|
|
251
|
-
assert.strictEqual(clock.armed, 0);
|
|
252
|
-
callback?.();
|
|
253
|
-
const snapshot = yield* built.inspector.snapshot;
|
|
254
|
-
assert.strictEqual(snapshot.revision, 1);
|
|
255
|
-
assert.strictEqual(clock.armed, 0);
|
|
256
|
-
}),
|
|
257
|
-
);
|
|
258
|
-
});
|
|
234
|
+
now = 2_001;
|
|
235
|
+
yield* clock.fire;
|
|
236
|
+
const afterRepaint = yield* built.inspector.snapshot;
|
|
237
|
+
assert.strictEqual(afterRepaint.revision, 3);
|
|
238
|
+
assert.strictEqual(afterRepaint.rows[0]?.idleMs, 1_001);
|
|
239
|
+
yield* close(built);
|
|
240
|
+
}),
|
|
241
|
+
);
|
|
242
|
+
});
|
|
259
243
|
|
|
260
|
-
it.effect("a repaint
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
(runtime) =>
|
|
244
|
+
it.effect("a fired repaint publishes nothing when no age is rendered", () => {
|
|
245
|
+
const clock = inspectorClock();
|
|
246
|
+
let reads = 0;
|
|
247
|
+
const fake = fakeObservations();
|
|
248
|
+
return withRuntime((runtime) =>
|
|
266
249
|
Effect.gen(function* () {
|
|
267
250
|
const built = yield* build({
|
|
268
251
|
runtime,
|
|
269
252
|
observe: fake,
|
|
270
|
-
view:
|
|
253
|
+
view: () => {
|
|
254
|
+
reads += 1;
|
|
255
|
+
return Promise.resolve(oneRunningView());
|
|
256
|
+
},
|
|
271
257
|
now: () => 4_000,
|
|
272
258
|
timers: clock,
|
|
273
259
|
});
|
|
274
|
-
const
|
|
275
|
-
yield*
|
|
276
|
-
const collected = yield* Fiber.join(ends);
|
|
277
|
-
assert.deepStrictEqual([...collected], [{ kind: "runtime-ended" }]);
|
|
278
|
-
// Slice 10: the runtime end interrupts the age clock, so no timer
|
|
279
|
-
// survives the runtime it would read.
|
|
280
|
-
assert.strictEqual(clock.armed, 0);
|
|
260
|
+
const before = reads;
|
|
261
|
+
yield* clock.fire;
|
|
281
262
|
yield* clock.fire;
|
|
282
263
|
const snapshot = yield* built.inspector.snapshot;
|
|
283
264
|
assert.strictEqual(snapshot.revision, 1);
|
|
284
|
-
|
|
285
|
-
(entry) => entry.code.startsWith("inspector.") && entry.code.endsWith("_failed"),
|
|
286
|
-
);
|
|
287
|
-
assert.deepStrictEqual(failures, []);
|
|
265
|
+
assert.strictEqual(reads, before);
|
|
288
266
|
yield* close(built);
|
|
289
267
|
}),
|
|
290
|
-
|
|
291
|
-
);
|
|
292
|
-
});
|
|
268
|
+
);
|
|
269
|
+
});
|
|
293
270
|
|
|
294
|
-
it.effect("
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
let failing = false;
|
|
299
|
-
return withRuntime(
|
|
300
|
-
(runtime) =>
|
|
271
|
+
it.effect("closing the scope clears the armed timer", () => {
|
|
272
|
+
const clock = inspectorClock();
|
|
273
|
+
const fake = fakeObservations();
|
|
274
|
+
return withRuntime((runtime) =>
|
|
301
275
|
Effect.gen(function* () {
|
|
302
276
|
const built = yield* build({
|
|
303
277
|
runtime,
|
|
304
278
|
observe: fake,
|
|
305
|
-
view: async () =>
|
|
306
|
-
if (failing) throw new Error("boom");
|
|
307
|
-
return oneRunningView();
|
|
308
|
-
},
|
|
279
|
+
view: async () => oneRunningView(),
|
|
309
280
|
now: () => 4_000,
|
|
310
281
|
timers: clock,
|
|
311
282
|
});
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
yield* built.inspector.refresh;
|
|
315
|
-
const after = yield* built.inspector.snapshot;
|
|
316
|
-
assert.strictEqual(after.revision, before.revision);
|
|
317
|
-
// The name is free to change: unwrapping at the log site or giving the
|
|
318
|
-
// error a message both keep the detail, and the detail is the subject.
|
|
319
|
-
const failures = log.entries.filter((entry) => entry.code === "inspector.refresh_failed");
|
|
320
|
-
assert.strictEqual(failures.length, 1);
|
|
321
|
-
assert.strictEqual(failures[0]?.level, "warn");
|
|
322
|
-
assert.strictEqual(failures[0]?.fields.detail, "boom");
|
|
323
|
-
assert.strictEqual(typeof failures[0]?.fields.error, "string");
|
|
324
|
-
assert.notStrictEqual(failures[0]?.fields.error, "");
|
|
283
|
+
const callback = clock.current();
|
|
284
|
+
assert.strictEqual(clock.armed, 1);
|
|
325
285
|
yield* close(built);
|
|
286
|
+
assert.strictEqual(clock.armed, 0);
|
|
287
|
+
callback?.();
|
|
288
|
+
const snapshot = yield* built.inspector.snapshot;
|
|
289
|
+
assert.strictEqual(snapshot.revision, 1);
|
|
290
|
+
assert.strictEqual(clock.armed, 0);
|
|
326
291
|
}),
|
|
327
|
-
|
|
328
|
-
);
|
|
292
|
+
);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it.effect("a repaint after the runtime closed publishes nothing and does not throw", () => {
|
|
296
|
+
const log = recordingLog();
|
|
297
|
+
const clock = inspectorClock();
|
|
298
|
+
const fake = fakeObservations();
|
|
299
|
+
return withRuntime(
|
|
300
|
+
(runtime) =>
|
|
301
|
+
Effect.gen(function* () {
|
|
302
|
+
const built = yield* build({
|
|
303
|
+
runtime,
|
|
304
|
+
observe: fake,
|
|
305
|
+
view: async () => oneRunningView(),
|
|
306
|
+
now: () => 4_000,
|
|
307
|
+
timers: clock,
|
|
308
|
+
});
|
|
309
|
+
const ends = yield* Stream.runCollect(built.inspector.end).pipe(Effect.forkChild);
|
|
310
|
+
yield* Effect.promise(() => runtime.close());
|
|
311
|
+
const collected = yield* Fiber.join(ends);
|
|
312
|
+
assert.deepStrictEqual([...collected], [{ kind: "runtime-ended" }]);
|
|
313
|
+
// Slice 10: the runtime end interrupts the age clock, so no timer
|
|
314
|
+
// survives the runtime it would read.
|
|
315
|
+
assert.strictEqual(clock.armed, 0);
|
|
316
|
+
yield* clock.fire;
|
|
317
|
+
const snapshot = yield* built.inspector.snapshot;
|
|
318
|
+
assert.strictEqual(snapshot.revision, 1);
|
|
319
|
+
const failures = log.entries.filter(
|
|
320
|
+
(entry) => entry.code.startsWith("inspector.") && entry.code.endsWith("_failed"),
|
|
321
|
+
);
|
|
322
|
+
assert.deepStrictEqual(failures, []);
|
|
323
|
+
yield* close(built);
|
|
324
|
+
}),
|
|
325
|
+
log.sink,
|
|
326
|
+
);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it.effect("a failed refresh logs its cause and keeps the published snapshot", () => {
|
|
330
|
+
const log = recordingLog();
|
|
331
|
+
const clock = inspectorClock();
|
|
332
|
+
const fake = fakeObservations();
|
|
333
|
+
let failing = false;
|
|
334
|
+
return withRuntime(
|
|
335
|
+
(runtime) =>
|
|
336
|
+
Effect.gen(function* () {
|
|
337
|
+
const built = yield* build({
|
|
338
|
+
runtime,
|
|
339
|
+
observe: fake,
|
|
340
|
+
view: async () => {
|
|
341
|
+
if (failing) throw new Error("boom");
|
|
342
|
+
return oneRunningView();
|
|
343
|
+
},
|
|
344
|
+
now: () => 4_000,
|
|
345
|
+
timers: clock,
|
|
346
|
+
});
|
|
347
|
+
const before = yield* built.inspector.snapshot;
|
|
348
|
+
failing = true;
|
|
349
|
+
yield* built.inspector.refresh;
|
|
350
|
+
const after = yield* built.inspector.snapshot;
|
|
351
|
+
assert.strictEqual(after.revision, before.revision);
|
|
352
|
+
// The name is free to change: unwrapping at the log site or giving the
|
|
353
|
+
// error a message both keep the detail, and the detail is the subject.
|
|
354
|
+
const failures = log.entries.filter((entry) => entry.code === "inspector.refresh_failed");
|
|
355
|
+
assert.strictEqual(failures.length, 1);
|
|
356
|
+
assert.strictEqual(failures[0]?.level, "warn");
|
|
357
|
+
assert.strictEqual(failures[0]?.fields.detail, "boom");
|
|
358
|
+
assert.strictEqual(typeof failures[0]?.fields.error, "string");
|
|
359
|
+
assert.notStrictEqual(failures[0]?.fields.error, "");
|
|
360
|
+
yield* close(built);
|
|
361
|
+
}),
|
|
362
|
+
log.sink,
|
|
363
|
+
);
|
|
364
|
+
});
|
|
329
365
|
});
|
|
@@ -27,6 +27,9 @@ const runView = (
|
|
|
27
27
|
gates: [],
|
|
28
28
|
requests: [],
|
|
29
29
|
diagnostic: null,
|
|
30
|
+
execution: "wait",
|
|
31
|
+
maxTurns: null,
|
|
32
|
+
failure: null,
|
|
30
33
|
...input,
|
|
31
34
|
});
|
|
32
35
|
|
|
@@ -39,6 +42,8 @@ const childView = (
|
|
|
39
42
|
status: "running",
|
|
40
43
|
answer: null,
|
|
41
44
|
durationMs: null,
|
|
45
|
+
maxTurns: null,
|
|
46
|
+
failure: null,
|
|
42
47
|
...input,
|
|
43
48
|
});
|
|
44
49
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { activeStatus, offStatus, STATUS_KEY } from "./status.ts";
|
|
3
|
+
|
|
4
|
+
const counts = (
|
|
5
|
+
input: Partial<Record<"running" | "queued" | "waiting" | "gates" | "requests", number>>,
|
|
6
|
+
) => ({
|
|
7
|
+
running: 0,
|
|
8
|
+
queued: 0,
|
|
9
|
+
waiting: 0,
|
|
10
|
+
gates: 0,
|
|
11
|
+
requests: 0,
|
|
12
|
+
...input,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("the footer key is one entry", () => {
|
|
16
|
+
assert.strictEqual(STATUS_KEY, "delegates");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("the off line names the command, not the inert shortcut", () => {
|
|
20
|
+
assert.strictEqual(offStatus(), "delegates off · /delegates");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("the idle line names the shortcut and no counter", () => {
|
|
24
|
+
assert.strictEqual(activeStatus(counts({})), "delegates idle · ctrl+space");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("the live line carries every non-zero counter in a fixed order", () => {
|
|
28
|
+
assert.strictEqual(
|
|
29
|
+
activeStatus(counts({ running: 2, waiting: 1, gates: 1, queued: 3, requests: 1 })),
|
|
30
|
+
"delegates running 2 · queued 3 · waiting 1 · gates 1 · requests 1 · ctrl+space",
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("zero counters never print", () => {
|
|
35
|
+
assert.strictEqual(
|
|
36
|
+
activeStatus(counts({ running: 1, queued: 0, waiting: 0, gates: 0, requests: 0 })),
|
|
37
|
+
"delegates running 1 · ctrl+space",
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("a custom shortcut replaces the default in the line", () => {
|
|
42
|
+
assert.strictEqual(activeStatus(counts({}), "f2"), "delegates idle · f2");
|
|
43
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DEFAULT_INSPECT_SHORTCUT } from "./shortcut.ts";
|
|
2
|
+
import type { InspectorSnapshot } from "./snapshot.ts";
|
|
3
|
+
import { counterParts } from "./wording.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The footer status key. Pi shows every extension status on one shared footer
|
|
7
|
+
* line, sorted by key, so this package owns one entry on it, not a row.
|
|
8
|
+
*/
|
|
9
|
+
export const STATUS_KEY = "delegates";
|
|
10
|
+
|
|
11
|
+
/** The panel's footer name, so the line reads the same as the strip's box label. */
|
|
12
|
+
const LABEL = "delegates";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The footer line while the inspector is off. The command is the only working
|
|
16
|
+
* door, so the line names it; the shortcut would be inert.
|
|
17
|
+
*/
|
|
18
|
+
export const offStatus = (): string => `${LABEL} off · /delegates`;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The footer line while the inspector is on. Idle says so instead of printing
|
|
22
|
+
* zero for every counter; live work names the counters the strip may hide.
|
|
23
|
+
*/
|
|
24
|
+
export const activeStatus = (
|
|
25
|
+
counts: InspectorSnapshot["counts"],
|
|
26
|
+
shortcut = DEFAULT_INSPECT_SHORTCUT,
|
|
27
|
+
): string => {
|
|
28
|
+
const parts = counterParts(counts);
|
|
29
|
+
return `${LABEL} ${parts.length === 0 ? "idle" : parts.join(" · ")} · ${shortcut}`;
|
|
30
|
+
};
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type SessionView,
|
|
11
11
|
} from "../domain/view.ts";
|
|
12
12
|
import { projectSnapshot } from "./snapshot.ts";
|
|
13
|
-
import { makeDelegatesStrip, stripLines
|
|
13
|
+
import { makeDelegatesStrip, stripLines } from "./strip.ts";
|
|
14
14
|
import { formatElapsed } from "./wording.ts";
|
|
15
15
|
|
|
16
16
|
const plainTheme = {
|
|
@@ -35,6 +35,9 @@ const runView = (
|
|
|
35
35
|
gates: [],
|
|
36
36
|
requests: [],
|
|
37
37
|
diagnostic: null,
|
|
38
|
+
execution: "wait",
|
|
39
|
+
maxTurns: null,
|
|
40
|
+
failure: null,
|
|
38
41
|
...input,
|
|
39
42
|
});
|
|
40
43
|
|
|
@@ -47,6 +50,8 @@ const childView = (
|
|
|
47
50
|
status: "running",
|
|
48
51
|
answer: null,
|
|
49
52
|
durationMs: null,
|
|
53
|
+
maxTurns: null,
|
|
54
|
+
failure: null,
|
|
50
55
|
...input,
|
|
51
56
|
});
|
|
52
57
|
|
|
@@ -97,7 +102,7 @@ it("the strip renders the house frame around its content lines", () => {
|
|
|
97
102
|
const lines = strip.render(80);
|
|
98
103
|
assert.strictEqual(lines.length, 5);
|
|
99
104
|
assert.ok(lines[0]?.includes("Delegates"));
|
|
100
|
-
assert.ok(lines[1]?.includes("running 2 ·
|
|
105
|
+
assert.ok(lines[1]?.includes("running 2 · gates 1 — ctrl+space"));
|
|
101
106
|
assert.ok(lines[2]?.includes("deployer · bash"));
|
|
102
107
|
assert.ok(lines[3]?.includes("scout · 1m 12s ago"));
|
|
103
108
|
});
|
|
@@ -158,7 +163,6 @@ it("the counter line names queued work only when non-zero", () => {
|
|
|
158
163
|
]);
|
|
159
164
|
const line = stripLines(queued)[0];
|
|
160
165
|
assert.ok(line?.includes("queued 1"), line);
|
|
161
|
-
assert.strictEqual(stripVisible(queued), true);
|
|
162
166
|
});
|
|
163
167
|
|
|
164
168
|
it("elapsed ages are pinned at seconds, minutes and hours", () => {
|
|
@@ -180,11 +184,14 @@ it("more running children than the budget renders the pinned overflow suffix", (
|
|
|
180
184
|
assert.ok(lines.at(-1)?.endsWith("+3 more"), lines.at(-1));
|
|
181
185
|
});
|
|
182
186
|
|
|
183
|
-
it("a snapshot with no live work and no gates renders
|
|
187
|
+
it("a snapshot with no live work and no gates renders the idle line", () => {
|
|
184
188
|
const snapshot = snapshotOf([runView({ runId: "run:answered", status: "answered" })]);
|
|
185
|
-
assert.
|
|
189
|
+
assert.deepStrictEqual(stripLines(snapshot), ["idle — ctrl+space"]);
|
|
186
190
|
const strip = makeDelegatesStrip({ getSnapshot: () => snapshot, theme: plainTheme });
|
|
187
|
-
|
|
191
|
+
const lines = strip.render(80);
|
|
192
|
+
assert.strictEqual(lines.length, 3);
|
|
193
|
+
assert.ok(lines[0]?.includes("Delegates"));
|
|
194
|
+
assert.ok(lines[1]?.includes("idle — ctrl+space"));
|
|
188
195
|
});
|
|
189
196
|
|
|
190
197
|
it("the strip never renders the selection marker", () => {
|