@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.
- package/CHANGELOG.md +128 -0
- package/LICENSE +21 -0
- package/OPERATIONS.md +130 -0
- package/README.md +456 -2
- package/ROADMAP.md +179 -0
- package/TESTING.md +896 -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 +94 -4
- package/skills/pi-delegates/SKILL.md +176 -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 +184 -0
- package/src/docs-contract.test.ts +106 -0
- package/src/domain/definitions.test.ts +41 -0
- package/src/domain/definitions.ts +163 -0
- package/src/domain/failure.ts +33 -0
- package/src/domain/ids.ts +13 -0
- package/src/domain/model-source.ts +30 -0
- package/src/domain/names.ts +35 -0
- package/src/domain/orchestration/admission.ts +78 -0
- package/src/domain/orchestration/control.test.ts +1332 -0
- package/src/domain/orchestration/control.ts +457 -0
- package/src/domain/orchestration/fanout.test.ts +524 -0
- package/src/domain/orchestration/fanout.ts +372 -0
- package/src/domain/orchestration/gates.test.ts +685 -0
- package/src/domain/orchestration/gates.ts +360 -0
- package/src/domain/orchestration/launch.test.ts +372 -0
- package/src/domain/orchestration/launch.ts +691 -0
- package/src/domain/orchestration/requests.test.ts +695 -0
- package/src/domain/orchestration/requests.ts +782 -0
- package/src/domain/orchestration/review.test.ts +292 -0
- package/src/domain/orchestration/review.ts +168 -0
- package/src/domain/orchestration/run-wait.test.ts +265 -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 +1566 -0
- package/src/domain/orchestration/workflow.ts +778 -0
- package/src/domain/run-records.test.ts +27 -0
- package/src/domain/run-records.ts +689 -0
- package/src/domain/settlement.test.ts +186 -0
- package/src/domain/settlement.ts +137 -0
- package/src/domain/shapes.test.ts +185 -0
- package/src/domain/skills.test.ts +477 -0
- package/src/domain/skills.ts +114 -0
- package/src/domain/tool-schema.test.ts +46 -0
- package/src/domain/tool-schema.ts +20 -0
- package/src/domain/toolkit.test.ts +215 -0
- package/src/domain/toolkit.ts +374 -0
- package/src/domain/turn-budget.test.ts +37 -0
- package/src/domain/turn-budget.ts +23 -0
- package/src/domain/view.test.ts +803 -0
- package/src/domain/view.ts +491 -0
- package/src/example.test.ts +15 -0
- package/src/extension/commands.test.ts +485 -0
- package/src/extension/commands.ts +230 -0
- package/src/extension/entry.test.ts +1276 -0
- package/src/extension/entry.ts +380 -0
- package/src/extension/gate-alerts.test.ts +237 -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 +1343 -0
- package/src/extension/inspector-command.ts +685 -0
- package/src/extension/prompt.test.ts +108 -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/retry-observer.test.ts +292 -0
- package/src/extension/retry-observer.ts +150 -0
- package/src/extension/revocation.test.ts +81 -0
- package/src/extension/revocation.ts +84 -0
- package/src/extension/settle-alerts.test.ts +579 -0
- package/src/extension/settle-alerts.ts +175 -0
- package/src/extension/shortcut.test.ts +62 -0
- package/src/extension/shortcut.ts +105 -0
- package/src/extension/tools.test.ts +1294 -0
- package/src/extension/tools.ts +553 -0
- package/src/extension/version.test.ts +115 -0
- package/src/extension/version.ts +97 -0
- package/src/goldens.test.ts +294 -0
- package/src/harness-policy.test.ts +76 -0
- package/src/layers.test.ts +309 -0
- package/src/layers.ts +405 -0
- package/src/package-manifest.test.ts +170 -0
- package/src/presentation/actions.test.ts +221 -0
- package/src/presentation/actions.ts +85 -0
- package/src/presentation/activity.test.ts +386 -0
- package/src/presentation/activity.ts +66 -0
- package/src/presentation/close.test.ts +359 -0
- package/src/presentation/inspector.test.ts +682 -0
- package/src/presentation/inspector.ts +442 -0
- package/src/presentation/overlay.test.ts +553 -0
- package/src/presentation/overlay.ts +229 -0
- package/src/presentation/repaint.test.ts +365 -0
- package/src/presentation/shortcut.ts +2 -0
- package/src/presentation/snapshot.test.ts +535 -0
- package/src/presentation/snapshot.ts +306 -0
- package/src/presentation/status.test.ts +43 -0
- package/src/presentation/status.ts +30 -0
- package/src/presentation/strip.test.ts +203 -0
- package/src/presentation/strip.ts +67 -0
- package/src/presentation/wording.test.ts +388 -0
- package/src/presentation/wording.ts +294 -0
- package/src/runtime/bridge.test.ts +131 -0
- package/src/runtime/bridge.ts +128 -0
- package/src/runtime/clock.test.ts +31 -0
- package/src/runtime/clock.ts +31 -0
- package/src/runtime/config.test.ts +63 -0
- package/src/runtime/config.ts +92 -0
- package/src/runtime/context.test.ts +19 -0
- package/src/runtime/context.ts +9 -0
- package/src/runtime/execution-env.test.ts +33 -0
- package/src/runtime/execution-env.ts +15 -0
- package/src/runtime/extensions.test.ts +86 -0
- package/src/runtime/extensions.ts +152 -0
- package/src/runtime/handle.ts +54 -0
- package/src/runtime/log.test.ts +140 -0
- package/src/runtime/log.ts +91 -0
- package/src/runtime/mcp.test.ts +1450 -0
- package/src/runtime/mcp.ts +1005 -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/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 +352 -0
- package/src/runtime/session.ts +263 -0
- package/src/runtime/storage.ts +29 -0
- package/src/test-hygiene.test.ts +97 -0
|
@@ -0,0 +1,803 @@
|
|
|
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 { AgentDoc, type TaskRecord } from "@earendil-works/pi-durable";
|
|
5
|
+
import { PROPERTY_RUNS } from "@ftrdotdev/pi-test-kit";
|
|
6
|
+
import { taskStateArbitrary, type TaskStateSample } from "../../test-support/arbitraries.ts";
|
|
7
|
+
import { stubHostSource } from "../../test-support/stub-model-source.ts";
|
|
8
|
+
import { makeStubPi } from "../../test-support/stub-pi.ts";
|
|
9
|
+
import { createCatalogue } from "./definitions.ts";
|
|
10
|
+
import { launch, type HostDefaults } from "./orchestration/launch.ts";
|
|
11
|
+
import { registerDelegateTools, renderStatusText } from "../extension/tools.ts";
|
|
12
|
+
import { nullLogSink } from "../runtime/log.ts";
|
|
13
|
+
import { HostModelAdapter } from "../runtime/models.ts";
|
|
14
|
+
import { countingRuntime } from "../../test-support/counting-runtime.ts";
|
|
15
|
+
import { type SessionRuntime } from "../runtime/session.ts";
|
|
16
|
+
import type { SessionHandle } from "../runtime/handle.ts";
|
|
17
|
+
import { handleFor } from "../../test-support/session-handle.ts";
|
|
18
|
+
import { Ref } from "effect";
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
laneViews,
|
|
22
|
+
statusOf,
|
|
23
|
+
viewOf,
|
|
24
|
+
viewRun,
|
|
25
|
+
viewSession,
|
|
26
|
+
type RunStatus,
|
|
27
|
+
type RunView,
|
|
28
|
+
type SessionView,
|
|
29
|
+
} from "./view.ts";
|
|
30
|
+
import { RunDoc, RunIndexDoc } from "./run-records.ts";
|
|
31
|
+
import {
|
|
32
|
+
RequestDecided,
|
|
33
|
+
RequestDoc,
|
|
34
|
+
RequestIndexDoc,
|
|
35
|
+
requestState,
|
|
36
|
+
} from "./orchestration/requests.ts";
|
|
37
|
+
import { RunDocV1, RunDocV1WithMode, RunDocV2 } from "../../test-support/run-doc-fixtures.ts";
|
|
38
|
+
import { openTestSession, type TestSession } from "../../test-support/seams.ts";
|
|
39
|
+
|
|
40
|
+
const host: HostDefaults = {
|
|
41
|
+
model: { provider: "stub", modelId: "stub-1" },
|
|
42
|
+
thinkingLevel: "low",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const recordOf = (sample: TaskStateSample): TaskRecord<unknown, unknown, unknown> => {
|
|
46
|
+
const signals =
|
|
47
|
+
sample.signals > 0
|
|
48
|
+
? Array.from({ length: sample.signals }, (_, index) => ({
|
|
49
|
+
signal: "delegates.signal",
|
|
50
|
+
key: `k${index}`,
|
|
51
|
+
}))
|
|
52
|
+
: undefined;
|
|
53
|
+
const outcome =
|
|
54
|
+
sample.outcome === "none"
|
|
55
|
+
? undefined
|
|
56
|
+
: sample.outcome === "completed_answered"
|
|
57
|
+
? { status: "completed", result: { status: "answered", answer: "yes" } }
|
|
58
|
+
: sample.outcome === "completed_failed"
|
|
59
|
+
? { status: "completed", result: { status: "failed", diagnostic: "why" } }
|
|
60
|
+
: sample.outcome === "completed_denied"
|
|
61
|
+
? { status: "completed", result: { status: "denied" } }
|
|
62
|
+
: sample.outcome === "completed_stopped"
|
|
63
|
+
? { status: "completed", result: { status: "stopped" } }
|
|
64
|
+
: sample.outcome === "aborted"
|
|
65
|
+
? { status: "aborted" }
|
|
66
|
+
: sample.outcome === "failed"
|
|
67
|
+
? { status: "failed", error: { message: "failed" } }
|
|
68
|
+
: sample.outcome === "faulted"
|
|
69
|
+
? { status: "faulted", error: { message: "faulted" } }
|
|
70
|
+
: { status: "orphaned", reason: "missing" };
|
|
71
|
+
|
|
72
|
+
const base = { id: 1, input: {}, kind: "delegates.run" };
|
|
73
|
+
const state =
|
|
74
|
+
sample.status === "pending"
|
|
75
|
+
? { status: "pending", checkpoint: { phase: "bind" } }
|
|
76
|
+
: sample.status === "running"
|
|
77
|
+
? { status: "running", checkpoint: { phase: "bind" } }
|
|
78
|
+
: sample.status === "waiting"
|
|
79
|
+
? { status: "waiting", checkpoint: { phase: "settle" }, on: [2], policy: "allSettled" }
|
|
80
|
+
: sample.status === "sleeping"
|
|
81
|
+
? {
|
|
82
|
+
status: "sleeping",
|
|
83
|
+
checkpoint: { phase: "settle" },
|
|
84
|
+
...(signals === undefined ? { until: 10 } : { signals }),
|
|
85
|
+
}
|
|
86
|
+
: sample.status === "completing"
|
|
87
|
+
? { status: "completing", outcome: outcome ?? { status: "aborted" } }
|
|
88
|
+
: { status: "terminal", outcome: outcome ?? { status: "aborted" } };
|
|
89
|
+
return { ...base, state } as unknown as TaskRecord<unknown, unknown, unknown>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
it.prop(
|
|
93
|
+
"the status mapping is total",
|
|
94
|
+
{ sample: taskStateArbitrary },
|
|
95
|
+
({ sample }) => {
|
|
96
|
+
const record = recordOf(sample);
|
|
97
|
+
const status = statusOf(record);
|
|
98
|
+
assert.ok(
|
|
99
|
+
["queued", "running", "waiting", "answered", "failed", "stopped", "denied"].includes(status),
|
|
100
|
+
status,
|
|
101
|
+
);
|
|
102
|
+
if (status === "answered") {
|
|
103
|
+
assert.strictEqual(sample.outcome, "completed_answered");
|
|
104
|
+
}
|
|
105
|
+
if (record.state.status === "terminal" && record.state.outcome.status === "aborted") {
|
|
106
|
+
assert.strictEqual(status, "stopped");
|
|
107
|
+
}
|
|
108
|
+
if (sample.status === "pending") assert.strictEqual(status, "queued");
|
|
109
|
+
if (sample.status === "terminal" && sample.outcome === "faulted") {
|
|
110
|
+
assert.strictEqual(status, "failed");
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
it("a terminal view reports the fixed task duration", () => {
|
|
117
|
+
const task = {
|
|
118
|
+
...recordOf({ status: "terminal", signals: 0, outcome: "completed_answered" }),
|
|
119
|
+
startedAt: 1_000,
|
|
120
|
+
endedAt: 4_000,
|
|
121
|
+
};
|
|
122
|
+
const view = viewOf({
|
|
123
|
+
runId: "run:one",
|
|
124
|
+
definition: "scout",
|
|
125
|
+
mode: "single",
|
|
126
|
+
lane: "default",
|
|
127
|
+
requestedAgent: "scout",
|
|
128
|
+
conversationId: null,
|
|
129
|
+
taskId: 1,
|
|
130
|
+
task,
|
|
131
|
+
missing: [],
|
|
132
|
+
gates: [],
|
|
133
|
+
execution: "wait",
|
|
134
|
+
maxTurns: null,
|
|
135
|
+
failure: null,
|
|
136
|
+
});
|
|
137
|
+
assert.strictEqual(view.durationMs, 3_000);
|
|
138
|
+
assert.strictEqual(view.children[0]?.durationMs, 3_000);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("a live view has no fixed duration", () => {
|
|
142
|
+
const view = viewOf({
|
|
143
|
+
runId: "run:one",
|
|
144
|
+
definition: "scout",
|
|
145
|
+
mode: "single",
|
|
146
|
+
lane: "default",
|
|
147
|
+
requestedAgent: "scout",
|
|
148
|
+
conversationId: null,
|
|
149
|
+
taskId: 1,
|
|
150
|
+
task: recordOf({ status: "running", signals: 0, outcome: "none" }),
|
|
151
|
+
missing: [],
|
|
152
|
+
gates: [],
|
|
153
|
+
execution: "wait",
|
|
154
|
+
maxTurns: null,
|
|
155
|
+
failure: null,
|
|
156
|
+
});
|
|
157
|
+
assert.strictEqual(view.durationMs, null);
|
|
158
|
+
assert.strictEqual(view.children[0]?.durationMs, null);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("status reports one row per child and lane counts", async () => {
|
|
162
|
+
const sessionDir = await makeTempDir("delegates-view-");
|
|
163
|
+
const runtime = await openTestSession({
|
|
164
|
+
identity: { sessionId: "s-1", sessionDir, cwd: sessionDir, agentDir: sessionDir },
|
|
165
|
+
models: new HostModelAdapter(stubHostSource()),
|
|
166
|
+
});
|
|
167
|
+
try {
|
|
168
|
+
const agents = Array.from({ length: 6 }, (_, index) => ({
|
|
169
|
+
agent: "scout",
|
|
170
|
+
task: `task ${index}`,
|
|
171
|
+
}));
|
|
172
|
+
const result = await launch(
|
|
173
|
+
{ kind: "fanout", lane: "review", agents },
|
|
174
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
175
|
+
);
|
|
176
|
+
const run = await viewRun(result.view.runId, runtime);
|
|
177
|
+
assert.deepStrictEqual(
|
|
178
|
+
run.children.map((child) => child.status),
|
|
179
|
+
Array.from({ length: 6 }, () => "answered"),
|
|
180
|
+
);
|
|
181
|
+
assert.ok(
|
|
182
|
+
run.children.every((child) => child.durationMs !== null),
|
|
183
|
+
JSON.stringify(run.children.map((child) => child.durationMs)),
|
|
184
|
+
);
|
|
185
|
+
assert.deepStrictEqual(laneViews([run]), [
|
|
186
|
+
{ name: "review", running: 0, queued: 0, answered: 6 },
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
const stub = makeStubPi({ settings: { packages: [] } });
|
|
190
|
+
registerDelegateTools(stub.api, {
|
|
191
|
+
session: Ref.makeUnsafe<SessionHandle | undefined>(handleFor(runtime)),
|
|
192
|
+
catalogue: createCatalogue(),
|
|
193
|
+
host,
|
|
194
|
+
launchWaitMs: () => 20_000,
|
|
195
|
+
log: () => nullLogSink,
|
|
196
|
+
});
|
|
197
|
+
const status = stub.registrations.toolDefinitions.get("delegate_status") as {
|
|
198
|
+
execute: (
|
|
199
|
+
id: string,
|
|
200
|
+
params: unknown,
|
|
201
|
+
signal: undefined,
|
|
202
|
+
onUpdate: undefined,
|
|
203
|
+
ctx: unknown,
|
|
204
|
+
) => Promise<{ details: { runs: RunView[]; lanes: SessionView["lanes"] } }>;
|
|
205
|
+
};
|
|
206
|
+
const statusResult = await status.execute("", {}, undefined, undefined, stub.context);
|
|
207
|
+
assert.strictEqual(statusResult.details.runs.length, 1);
|
|
208
|
+
assert.strictEqual(statusResult.details.runs[0]?.children.length, 6);
|
|
209
|
+
assert.deepStrictEqual(statusResult.details.lanes, [
|
|
210
|
+
{ name: "review", running: 0, queued: 0, answered: 6 },
|
|
211
|
+
]);
|
|
212
|
+
|
|
213
|
+
const session: SessionView = await viewSession(runtime);
|
|
214
|
+
assert.strictEqual(session.runs.length, 1);
|
|
215
|
+
assert.strictEqual(session.runs[0]?.runId, result.view.runId);
|
|
216
|
+
} finally {
|
|
217
|
+
await runtime.close();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("the status mapping covers every durable state", () => {
|
|
222
|
+
const cases: ReadonlyArray<readonly [Parameters<typeof recordOf>[0], string]> = [
|
|
223
|
+
[{ status: "pending", signals: 0, outcome: "none" }, "queued"],
|
|
224
|
+
[{ status: "running", signals: 0, outcome: "none" }, "running"],
|
|
225
|
+
[{ status: "waiting", signals: 0, outcome: "none" }, "waiting"],
|
|
226
|
+
[{ status: "sleeping", signals: 0, outcome: "none" }, "queued"],
|
|
227
|
+
[{ status: "sleeping", signals: 1, outcome: "none" }, "running"],
|
|
228
|
+
[{ status: "terminal", signals: 0, outcome: "completed_answered" }, "answered"],
|
|
229
|
+
[{ status: "terminal", signals: 0, outcome: "completed_failed" }, "failed"],
|
|
230
|
+
[{ status: "terminal", signals: 0, outcome: "completed_denied" }, "denied"],
|
|
231
|
+
[{ status: "terminal", signals: 0, outcome: "completed_stopped" }, "stopped"],
|
|
232
|
+
[{ status: "terminal", signals: 0, outcome: "aborted" }, "stopped"],
|
|
233
|
+
[{ status: "terminal", signals: 0, outcome: "faulted" }, "failed"],
|
|
234
|
+
];
|
|
235
|
+
for (const [sample, expected] of cases) {
|
|
236
|
+
assert.strictEqual(statusOf(recordOf(sample)), expected);
|
|
237
|
+
}
|
|
238
|
+
const gated = recordOf({ status: "sleeping", signals: 1, outcome: "none" });
|
|
239
|
+
if (gated.state.status === "sleeping") {
|
|
240
|
+
(gated.state.signals as Array<{ signal: string; key: string }>)[0] = {
|
|
241
|
+
signal: "delegates.gate-decision",
|
|
242
|
+
key: "run-1:deploy",
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
assert.strictEqual(statusOf(gated), "waiting");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("a run with a missing toolkit name reports the diagnostic", async () => {
|
|
249
|
+
const sessionDir = await makeTempDir("delegates-view-");
|
|
250
|
+
const runtime = await openTestSession({
|
|
251
|
+
identity: { sessionId: "s-1", sessionDir, cwd: sessionDir, agentDir: sessionDir },
|
|
252
|
+
models: new HostModelAdapter(stubHostSource()),
|
|
253
|
+
});
|
|
254
|
+
try {
|
|
255
|
+
const result = await launch(
|
|
256
|
+
{ kind: "single", agent: "scout", task: "look" },
|
|
257
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 10_000 },
|
|
258
|
+
);
|
|
259
|
+
const doc = await runtime.snapshot(RunDoc, result.view.runId);
|
|
260
|
+
const childId = doc!.childConversationId as never;
|
|
261
|
+
await runtime.harness.commit(async (tx) => {
|
|
262
|
+
const agent = await tx.doc(AgentDoc, childId);
|
|
263
|
+
agent.extensions = ["gone-extension"];
|
|
264
|
+
}, BACKGROUND_CONTEXT);
|
|
265
|
+
|
|
266
|
+
const run = await viewRun(result.view.runId, runtime);
|
|
267
|
+
assert.strictEqual(run.status, "answered");
|
|
268
|
+
assert.deepStrictEqual(run.missing, ["gone-extension"]);
|
|
269
|
+
assert.ok(await runtime.harness.getTask(doc!.taskId as never, BACKGROUND_CONTEXT));
|
|
270
|
+
} finally {
|
|
271
|
+
await runtime.close();
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("status text shows gates, missing names, children and reviews", () => {
|
|
276
|
+
const run: RunView = {
|
|
277
|
+
runId: "run-1",
|
|
278
|
+
definition: "fanout",
|
|
279
|
+
mode: "fanout",
|
|
280
|
+
lane: "review",
|
|
281
|
+
conversationId: null,
|
|
282
|
+
taskId: null,
|
|
283
|
+
status: "waiting",
|
|
284
|
+
answer: null,
|
|
285
|
+
durationMs: null,
|
|
286
|
+
children: [
|
|
287
|
+
{
|
|
288
|
+
child: 0,
|
|
289
|
+
runId: "run-1:child:0",
|
|
290
|
+
conversationId: null,
|
|
291
|
+
taskId: null,
|
|
292
|
+
agent: "scout",
|
|
293
|
+
status: "waiting",
|
|
294
|
+
answer: null,
|
|
295
|
+
durationMs: null,
|
|
296
|
+
maxTurns: null,
|
|
297
|
+
failure: null,
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
missing: ["coding-tools"],
|
|
301
|
+
gates: ["deploy"],
|
|
302
|
+
requests: [],
|
|
303
|
+
diagnostic: null,
|
|
304
|
+
execution: "wait",
|
|
305
|
+
maxTurns: null,
|
|
306
|
+
failure: null,
|
|
307
|
+
};
|
|
308
|
+
const text = renderStatusText({
|
|
309
|
+
runs: [run],
|
|
310
|
+
lanes: [{ name: "review", running: 1, queued: 0, answered: 0 }],
|
|
311
|
+
gates: [
|
|
312
|
+
{
|
|
313
|
+
runId: "run-1",
|
|
314
|
+
gate: "deploy",
|
|
315
|
+
status: "pending",
|
|
316
|
+
tool: "bash",
|
|
317
|
+
taskId: 1,
|
|
318
|
+
taskIds: [1],
|
|
319
|
+
childRunIds: ["run-1:child:0"],
|
|
320
|
+
requestedAt: 0,
|
|
321
|
+
deadline: 1,
|
|
322
|
+
decision: null,
|
|
323
|
+
decidedBy: null,
|
|
324
|
+
reason: null,
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
requests: [],
|
|
328
|
+
reviews: [
|
|
329
|
+
{
|
|
330
|
+
runId: "run-1",
|
|
331
|
+
reviewers: [
|
|
332
|
+
{
|
|
333
|
+
child: 0,
|
|
334
|
+
runId: "run-1:child:0",
|
|
335
|
+
disposition: "changes_requested",
|
|
336
|
+
note: "fix it",
|
|
337
|
+
diagnostic: null,
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
aggregate: "changes_requested",
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
});
|
|
344
|
+
for (const part of [
|
|
345
|
+
"waiting on gate deploy",
|
|
346
|
+
"missing: coding-tools",
|
|
347
|
+
"child 0 run-1:child:0 scout waiting",
|
|
348
|
+
"review run-1 changes_requested",
|
|
349
|
+
"reviewer 0",
|
|
350
|
+
]) {
|
|
351
|
+
assert.ok(text.includes(part), `${part}\n${text}`);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const openView = async (): Promise<TestSession> => {
|
|
356
|
+
const sessionDir = await makeTempDir("delegates-view-");
|
|
357
|
+
return openTestSession({
|
|
358
|
+
identity: { sessionId: "s-1", sessionDir, cwd: sessionDir, agentDir: sessionDir },
|
|
359
|
+
models: new HostModelAdapter(stubHostSource()),
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const snapshotSpy = (runtime: SessionRuntime) => {
|
|
364
|
+
const calls = { count: 0 };
|
|
365
|
+
const proxy = new Proxy(runtime, {
|
|
366
|
+
get(target, property) {
|
|
367
|
+
if (property === "registry") {
|
|
368
|
+
const registry = target.registry;
|
|
369
|
+
return new Proxy(registry, {
|
|
370
|
+
get(reg, regProperty) {
|
|
371
|
+
if (regProperty === "snapshot") {
|
|
372
|
+
return () => {
|
|
373
|
+
calls.count += 1;
|
|
374
|
+
return registry.snapshot();
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
const value = Reflect.get(reg, regProperty, reg) as unknown;
|
|
378
|
+
return typeof value === "function" ? value.bind(reg) : value;
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
const value = Reflect.get(target, property, target) as unknown;
|
|
383
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
384
|
+
},
|
|
385
|
+
}) as SessionRuntime;
|
|
386
|
+
return { runtime: proxy, calls };
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
it("a fanout with six children builds one resolver", async () => {
|
|
390
|
+
const runtime = await openView();
|
|
391
|
+
try {
|
|
392
|
+
const agents = Array.from({ length: 6 }, (_, index) => ({
|
|
393
|
+
agent: "scout",
|
|
394
|
+
task: `task ${index}`,
|
|
395
|
+
}));
|
|
396
|
+
const result = await launch(
|
|
397
|
+
{ kind: "fanout", lane: "review", agents },
|
|
398
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
399
|
+
);
|
|
400
|
+
const spied = snapshotSpy(runtime);
|
|
401
|
+
const session = await viewSession(spied.runtime);
|
|
402
|
+
assert.strictEqual(spied.calls.count, 1);
|
|
403
|
+
const run = session.runs.find((entry) => entry.runId === result.view.runId);
|
|
404
|
+
assert.strictEqual(run?.children.length, 6);
|
|
405
|
+
} finally {
|
|
406
|
+
await runtime.close();
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it("the session view makes one pass over the run index", async () => {
|
|
411
|
+
const runtime = await openView();
|
|
412
|
+
try {
|
|
413
|
+
for (let index = 0; index < 3; index += 1) {
|
|
414
|
+
await launch(
|
|
415
|
+
{ kind: "single", agent: "scout", task: `task ${index}` },
|
|
416
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
for (let index = 0; index < 2; index += 1) {
|
|
420
|
+
await launch(
|
|
421
|
+
{
|
|
422
|
+
kind: "review",
|
|
423
|
+
task: `review ${index}`,
|
|
424
|
+
reviewers: [{ agent: "reviewer" }, { agent: "reviewer" }],
|
|
425
|
+
},
|
|
426
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const counted = countingRuntime(runtime);
|
|
431
|
+
const session = await viewSession(counted.runtime);
|
|
432
|
+
assert.strictEqual(session.runs.length, 5);
|
|
433
|
+
assert.strictEqual(session.reviews.length, 2);
|
|
434
|
+
assert.strictEqual(counted.count("delegates.run-index"), 1);
|
|
435
|
+
} finally {
|
|
436
|
+
await runtime.close();
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it("the session status returns the newest 50 runs and counts the rest", async () => {
|
|
441
|
+
const runtime = await openView();
|
|
442
|
+
try {
|
|
443
|
+
const ids = Array.from({ length: 60 }, (_, index) => `run:seed:${index}`);
|
|
444
|
+
await runtime.harness.commit(async (tx) => {
|
|
445
|
+
const index = await tx.doc(RunIndexDoc);
|
|
446
|
+
for (const id of ids) {
|
|
447
|
+
const doc = await tx.doc(RunDoc, id, { definition: "scout", lane: "default" });
|
|
448
|
+
doc.requestedAgent = "scout";
|
|
449
|
+
index.runIds.push(id);
|
|
450
|
+
}
|
|
451
|
+
}, BACKGROUND_CONTEXT);
|
|
452
|
+
|
|
453
|
+
const counted = countingRuntime(runtime);
|
|
454
|
+
const stub = makeStubPi({ settings: { packages: [] } });
|
|
455
|
+
registerDelegateTools(stub.api, {
|
|
456
|
+
session: Ref.makeUnsafe<SessionHandle | undefined>(handleFor(counted.runtime)),
|
|
457
|
+
catalogue: createCatalogue(),
|
|
458
|
+
host,
|
|
459
|
+
launchWaitMs: () => 5_000,
|
|
460
|
+
log: () => nullLogSink,
|
|
461
|
+
});
|
|
462
|
+
const tool = stub.registrations.toolDefinitions.get("delegate_status") as {
|
|
463
|
+
execute: (
|
|
464
|
+
id: string,
|
|
465
|
+
params: unknown,
|
|
466
|
+
signal: undefined,
|
|
467
|
+
onUpdate: undefined,
|
|
468
|
+
ctx: unknown,
|
|
469
|
+
) => Promise<{
|
|
470
|
+
details?: { readonly runs: readonly RunView[]; readonly omitted?: number };
|
|
471
|
+
}>;
|
|
472
|
+
};
|
|
473
|
+
const result = await tool.execute("", {}, undefined, undefined, stub.context);
|
|
474
|
+
assert.strictEqual(result.details?.runs.length, 50);
|
|
475
|
+
assert.strictEqual(result.details?.omitted, 10);
|
|
476
|
+
assert.strictEqual(counted.count("delegates.run-index"), 1);
|
|
477
|
+
} finally {
|
|
478
|
+
await runtime.close();
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it("an old run document reads with mode single and no parent", async () => {
|
|
483
|
+
const runtime = await openView();
|
|
484
|
+
try {
|
|
485
|
+
await runtime.harness.commit(async (tx) => {
|
|
486
|
+
const doc = await tx.doc(RunDocV1, "run:old", { definition: "scout", lane: "default" });
|
|
487
|
+
doc.requestedAgent = "scout";
|
|
488
|
+
const index = await tx.doc(RunIndexDoc);
|
|
489
|
+
index.runIds.push("run:old");
|
|
490
|
+
}, BACKGROUND_CONTEXT);
|
|
491
|
+
|
|
492
|
+
const view = await viewRun("run:old", runtime);
|
|
493
|
+
assert.strictEqual(view.mode, "single");
|
|
494
|
+
|
|
495
|
+
const doc = await runtime.snapshot(RunDoc, "run:old");
|
|
496
|
+
assert.strictEqual(doc?.mode, "single");
|
|
497
|
+
assert.strictEqual(doc?.parentRunId, null);
|
|
498
|
+
assert.strictEqual(doc?.execution, "wait");
|
|
499
|
+
assert.strictEqual(doc?.maxTurns, null);
|
|
500
|
+
assert.strictEqual(doc?.resolution, null);
|
|
501
|
+
assert.strictEqual(doc?.failure, null);
|
|
502
|
+
assert.strictEqual(doc?.settledTaskId, null);
|
|
503
|
+
assert.strictEqual(doc?.retryCount, 0);
|
|
504
|
+
} finally {
|
|
505
|
+
await runtime.close();
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it("a version 1 workflow run keeps its mode and parent", async () => {
|
|
510
|
+
const runtime = await openView();
|
|
511
|
+
try {
|
|
512
|
+
await runtime.harness.commit(async (tx) => {
|
|
513
|
+
const parent = await tx.doc(RunDocV1WithMode, "run:wf", {
|
|
514
|
+
definition: "composer",
|
|
515
|
+
lane: "workflow",
|
|
516
|
+
mode: "workflow",
|
|
517
|
+
});
|
|
518
|
+
parent.requestedAgent = "composer";
|
|
519
|
+
parent.childRunIds = ["run:wf#1"];
|
|
520
|
+
const child = await tx.doc(RunDocV1WithMode, "run:wf#1", {
|
|
521
|
+
definition: "scout",
|
|
522
|
+
lane: "workflow",
|
|
523
|
+
parentRunId: "run:wf",
|
|
524
|
+
});
|
|
525
|
+
child.requestedAgent = "scout";
|
|
526
|
+
const index = await tx.doc(RunIndexDoc);
|
|
527
|
+
index.runIds.push("run:wf", "run:wf#1");
|
|
528
|
+
}, BACKGROUND_CONTEXT);
|
|
529
|
+
|
|
530
|
+
const view = await viewRun("run:wf", runtime);
|
|
531
|
+
assert.strictEqual(view.mode, "workflow");
|
|
532
|
+
assert.strictEqual(view.children.length, 1);
|
|
533
|
+
const child = await runtime.snapshot(RunDoc, "run:wf#1");
|
|
534
|
+
assert.strictEqual(child?.parentRunId, "run:wf");
|
|
535
|
+
assert.strictEqual(child?.mode, "single");
|
|
536
|
+
assert.strictEqual(child?.execution, "wait");
|
|
537
|
+
assert.strictEqual(child?.resolution, null);
|
|
538
|
+
assert.strictEqual(child?.retryCount, 0);
|
|
539
|
+
const session = await viewSession(runtime);
|
|
540
|
+
assert.deepStrictEqual(
|
|
541
|
+
session.runs.map((run) => run.runId),
|
|
542
|
+
["run:wf"],
|
|
543
|
+
);
|
|
544
|
+
} finally {
|
|
545
|
+
await runtime.close();
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it("an older run document reads with the new facts absent", async () => {
|
|
550
|
+
const runtime = await openView();
|
|
551
|
+
try {
|
|
552
|
+
await runtime.harness.commit(async (tx) => {
|
|
553
|
+
const doc = await tx.doc(RunDocV2, "run:v2", { definition: "scout", lane: "default" });
|
|
554
|
+
doc.requestedAgent = "scout";
|
|
555
|
+
const index = await tx.doc(RunIndexDoc);
|
|
556
|
+
index.runIds.push("run:v2");
|
|
557
|
+
}, BACKGROUND_CONTEXT);
|
|
558
|
+
|
|
559
|
+
const doc = await runtime.snapshot(RunDoc, "run:v2");
|
|
560
|
+
assert.strictEqual(doc?.maxTurns, null);
|
|
561
|
+
assert.strictEqual(doc?.resolution, null);
|
|
562
|
+
assert.strictEqual(doc?.failure, null);
|
|
563
|
+
assert.strictEqual(doc?.settledTaskId, null);
|
|
564
|
+
assert.strictEqual(doc?.retryCount, 0);
|
|
565
|
+
assert.strictEqual(doc?.execution, "wait");
|
|
566
|
+
const view = await viewRun("run:v2", runtime);
|
|
567
|
+
assert.strictEqual(view.status, "queued");
|
|
568
|
+
} finally {
|
|
569
|
+
await runtime.close();
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
const viewRow = (runId: string, status: RunStatus): RunView => ({
|
|
574
|
+
runId,
|
|
575
|
+
definition: "scout",
|
|
576
|
+
mode: "single",
|
|
577
|
+
lane: "default",
|
|
578
|
+
conversationId: null,
|
|
579
|
+
taskId: null,
|
|
580
|
+
status,
|
|
581
|
+
answer: null,
|
|
582
|
+
durationMs: null,
|
|
583
|
+
children: [],
|
|
584
|
+
missing: [],
|
|
585
|
+
gates: [],
|
|
586
|
+
requests: [],
|
|
587
|
+
diagnostic: null,
|
|
588
|
+
execution: "wait",
|
|
589
|
+
maxTurns: null,
|
|
590
|
+
failure: null,
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
it("status lists waiting runs before finished ones", () => {
|
|
594
|
+
const view: SessionView = {
|
|
595
|
+
runs: [
|
|
596
|
+
viewRow("run:answered", "answered"),
|
|
597
|
+
viewRow("run:running", "running"),
|
|
598
|
+
viewRow("run:waiting", "waiting"),
|
|
599
|
+
],
|
|
600
|
+
lanes: [{ name: "default", running: 1, queued: 0, answered: 1 }],
|
|
601
|
+
gates: [],
|
|
602
|
+
reviews: [],
|
|
603
|
+
requests: [],
|
|
604
|
+
};
|
|
605
|
+
const lines = renderStatusText(view).split("\n");
|
|
606
|
+
assert.ok(lines[0]?.startsWith("run:waiting"), lines[0]);
|
|
607
|
+
const answered = lines.findIndex((line) => line.startsWith("run:answered"));
|
|
608
|
+
const lane = lines.findIndex((line) => line.startsWith("default:"));
|
|
609
|
+
assert.ok(answered >= 0 && lane > answered, lines.join("\n"));
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
it("a waiting row names the gate it waits on", () => {
|
|
613
|
+
const view: SessionView = {
|
|
614
|
+
runs: [{ ...viewRow("run:abc", "waiting"), gates: ["approve-deploy"] }],
|
|
615
|
+
lanes: [],
|
|
616
|
+
gates: [],
|
|
617
|
+
reviews: [],
|
|
618
|
+
requests: [],
|
|
619
|
+
};
|
|
620
|
+
const text = renderStatusText(view);
|
|
621
|
+
assert.ok(text.includes("waiting on gate approve-deploy"), text);
|
|
622
|
+
assert.ok(!text.includes("gates:"), text);
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
it("the status text reports omitted runs", () => {
|
|
626
|
+
const view: SessionView = {
|
|
627
|
+
runs: [viewRow("run:one", "answered")],
|
|
628
|
+
lanes: [],
|
|
629
|
+
gates: [],
|
|
630
|
+
reviews: [],
|
|
631
|
+
requests: [],
|
|
632
|
+
omitted: 3,
|
|
633
|
+
};
|
|
634
|
+
const text = renderStatusText(view);
|
|
635
|
+
assert.ok(text.endsWith("3 older runs not shown."), text);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it("the status text shows a run's mode except for single", () => {
|
|
639
|
+
const single = renderStatusText({
|
|
640
|
+
runs: [viewRow("run:one", "answered")],
|
|
641
|
+
lanes: [],
|
|
642
|
+
gates: [],
|
|
643
|
+
reviews: [],
|
|
644
|
+
requests: [],
|
|
645
|
+
});
|
|
646
|
+
assert.ok(single.includes("run:one scout · answered"), single);
|
|
647
|
+
assert.ok(!single.includes("single"), single);
|
|
648
|
+
|
|
649
|
+
const workflow = renderStatusText({
|
|
650
|
+
runs: [{ ...viewRow("run:two", "answered"), definition: "composer", mode: "workflow" }],
|
|
651
|
+
lanes: [],
|
|
652
|
+
gates: [],
|
|
653
|
+
reviews: [],
|
|
654
|
+
requests: [],
|
|
655
|
+
});
|
|
656
|
+
assert.ok(workflow.includes("run:two composer · workflow · answered"), workflow);
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it("a launched run row names its child conversation", async () => {
|
|
660
|
+
const runtime = await openView();
|
|
661
|
+
try {
|
|
662
|
+
const result = await launch(
|
|
663
|
+
{ kind: "single", agent: "scout", task: "look" },
|
|
664
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 10_000 },
|
|
665
|
+
);
|
|
666
|
+
const row = await viewRun(result.view.runId, runtime);
|
|
667
|
+
const doc = await runtime.snapshot(RunDoc, result.view.runId);
|
|
668
|
+
assert.strictEqual(row.conversationId, doc?.childConversationId);
|
|
669
|
+
assert.strictEqual(typeof row.conversationId, "number");
|
|
670
|
+
} finally {
|
|
671
|
+
await runtime.close();
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
it("a fanout child row names its own child conversation", async () => {
|
|
676
|
+
const runtime = await openView();
|
|
677
|
+
try {
|
|
678
|
+
const result = await launch(
|
|
679
|
+
{
|
|
680
|
+
kind: "fanout",
|
|
681
|
+
lane: "review",
|
|
682
|
+
agents: [
|
|
683
|
+
{ agent: "scout", task: "first" },
|
|
684
|
+
{ agent: "scout", task: "second" },
|
|
685
|
+
],
|
|
686
|
+
},
|
|
687
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
688
|
+
);
|
|
689
|
+
const row = await viewRun(result.view.runId, runtime);
|
|
690
|
+
assert.strictEqual(row.children.length, 2);
|
|
691
|
+
for (const child of row.children) assert.strictEqual(typeof child.conversationId, "number");
|
|
692
|
+
assert.notStrictEqual(row.children[0]?.conversationId, row.children[1]?.conversationId);
|
|
693
|
+
} finally {
|
|
694
|
+
await runtime.close();
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
it("a run row names its task and a missing conversation stays nullable", async () => {
|
|
699
|
+
const runtime = await openView();
|
|
700
|
+
try {
|
|
701
|
+
const runId = "run:unsown#1";
|
|
702
|
+
await runtime.harness.commit(async (tx) => {
|
|
703
|
+
const doc = await tx.doc(RunDoc, runId, { definition: "scout", lane: "default" });
|
|
704
|
+
doc.requestedAgent = "scout";
|
|
705
|
+
}, BACKGROUND_CONTEXT);
|
|
706
|
+
|
|
707
|
+
const row = await viewRun(runId, runtime);
|
|
708
|
+
assert.strictEqual(row.conversationId, null);
|
|
709
|
+
assert.strictEqual(row.taskId, null);
|
|
710
|
+
|
|
711
|
+
const result = await launch(
|
|
712
|
+
{ kind: "single", agent: "scout", task: "look" },
|
|
713
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 10_000 },
|
|
714
|
+
);
|
|
715
|
+
const launched = await viewRun(result.view.runId, runtime);
|
|
716
|
+
const doc = await runtime.snapshot(RunDoc, result.view.runId);
|
|
717
|
+
assert.strictEqual(launched.taskId, doc?.taskId);
|
|
718
|
+
assert.strictEqual(typeof launched.taskId, "number");
|
|
719
|
+
assert.strictEqual(launched.children[0]?.taskId, doc?.taskId);
|
|
720
|
+
} finally {
|
|
721
|
+
await runtime.close();
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
it("a request-parked run reads waiting", () => {
|
|
726
|
+
const task = {
|
|
727
|
+
id: 1,
|
|
728
|
+
kind: "delegates.run",
|
|
729
|
+
input: {},
|
|
730
|
+
state: {
|
|
731
|
+
status: "sleeping",
|
|
732
|
+
checkpoint: { phase: "settle" },
|
|
733
|
+
signals: [{ signal: RequestDecided.name, key: "12:c1" }],
|
|
734
|
+
until: 10,
|
|
735
|
+
},
|
|
736
|
+
} as unknown as TaskRecord<unknown, unknown, unknown>;
|
|
737
|
+
assert.strictEqual(statusOf(task), "waiting");
|
|
738
|
+
|
|
739
|
+
const view = viewOf({
|
|
740
|
+
runId: "run:r1",
|
|
741
|
+
definition: "scout",
|
|
742
|
+
mode: "single",
|
|
743
|
+
lane: "default",
|
|
744
|
+
requestedAgent: "scout",
|
|
745
|
+
conversationId: 12,
|
|
746
|
+
taskId: 1,
|
|
747
|
+
task,
|
|
748
|
+
missing: [],
|
|
749
|
+
gates: [],
|
|
750
|
+
requests: ["12:c1"],
|
|
751
|
+
execution: "wait",
|
|
752
|
+
maxTurns: null,
|
|
753
|
+
failure: null,
|
|
754
|
+
});
|
|
755
|
+
assert.strictEqual(view.status, "waiting");
|
|
756
|
+
assert.deepStrictEqual(view.requests, ["12:c1"]);
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
it("the view lists a run's pending requests", async () => {
|
|
760
|
+
const runtime = await openView();
|
|
761
|
+
try {
|
|
762
|
+
const now = runtime.now();
|
|
763
|
+
await runtime.run((context) =>
|
|
764
|
+
runtime.harness.commit(async (tx) => {
|
|
765
|
+
await tx.doc(RunDoc, "run:r1", { definition: "scout", lane: "default" });
|
|
766
|
+
const record = await tx.doc(RequestDoc, "12:c1", { requestId: "12:c1" });
|
|
767
|
+
record.runId = "run:r1";
|
|
768
|
+
record.childRunId = "run:r1";
|
|
769
|
+
record.conversationId = 12;
|
|
770
|
+
record.prompt = "Which environment?";
|
|
771
|
+
record.status = "pending";
|
|
772
|
+
record.requestedAt = now;
|
|
773
|
+
record.deadline = now + 60_000;
|
|
774
|
+
const index = await tx.doc(RequestIndexDoc);
|
|
775
|
+
index.rows.push({
|
|
776
|
+
key: "12:c1",
|
|
777
|
+
runId: "run:r1",
|
|
778
|
+
requestId: "12:c1",
|
|
779
|
+
requestedAt: now,
|
|
780
|
+
deadline: now + 60_000,
|
|
781
|
+
status: "pending",
|
|
782
|
+
});
|
|
783
|
+
}, context),
|
|
784
|
+
);
|
|
785
|
+
|
|
786
|
+
const view = await viewRun("run:r1", runtime);
|
|
787
|
+
assert.deepStrictEqual(view.requests, ["12:c1"]);
|
|
788
|
+
assert.strictEqual(requestState({ status: "pending", deadline: now + 60_000 }, now), "pending");
|
|
789
|
+
} finally {
|
|
790
|
+
await runtime.close();
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
it("statusOf reports failed when a terminal outcome is orphaned", () => {
|
|
795
|
+
assert.strictEqual(
|
|
796
|
+
statusOf(recordOf({ status: "terminal", signals: 0, outcome: "orphaned" })),
|
|
797
|
+
"failed",
|
|
798
|
+
);
|
|
799
|
+
assert.strictEqual(
|
|
800
|
+
statusOf(recordOf({ status: "sleeping", signals: 0, outcome: "none" })),
|
|
801
|
+
"queued",
|
|
802
|
+
);
|
|
803
|
+
});
|