-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathorchestrator-plan.spec.ts
More file actions
369 lines (343 loc) · 14.7 KB
/
Copy pathorchestrator-plan.spec.ts
File metadata and controls
369 lines (343 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import { describe, expect, it } from "vitest"
import {
ORCHESTRATOR_FAN_OUT_CHILD_STEPS,
ORCHESTRATOR_FAN_OUT_FINAL_RESULT,
ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP,
ORCHESTRATOR_CANCELLATION_RECOVERY_FINAL_RESULT,
ORCHESTRATOR_CANCELLATION_RECOVERY_FOLLOWUP_ANSWER,
ORCHESTRATOR_CANCELLATION_RECOVERY_FOLLOWUP_TOOL_CALL_ID,
ORCHESTRATOR_CANCELLATION_RECOVERY_MARKER,
ORCHESTRATOR_CANCELLATION_RECOVERY_PARENT_PROMPT,
ORCHESTRATOR_FAN_OUT_PARENT_PROMPT,
ORCHESTRATOR_NESTED_DELEGATION_CHILD_FINAL_RESULT,
ORCHESTRATOR_NESTED_DELEGATION_CHILD_ORCHESTRATOR_STEP,
ORCHESTRATOR_NESTED_DELEGATION_FINAL_RESULT,
ORCHESTRATOR_NESTED_DELEGATION_GRANDCHILD_STEPS,
ORCHESTRATOR_NESTED_DELEGATION_MARKER,
ORCHESTRATOR_NESTED_DELEGATION_PARENT_PROMPT,
ORCHESTRATOR_REPEATED_DELEGATION_CHILD_STEPS,
ORCHESTRATOR_REPEATED_DELEGATION_FINAL_RESULT,
ORCHESTRATOR_REPEATED_DELEGATION_MARKER,
ORCHESTRATOR_REPEATED_DELEGATION_PARENT_PROMPT,
buildOrchestratorCancellationRecoveryResumeExpectations,
buildOrchestratorNestedChildResumeExpectations,
buildOrchestratorNestedParentResumeExpectations,
buildOrchestratorRepeatedResumeExpectations,
buildOrchestratorResumeExpectations,
shouldMatchOrchestratorCancellationChildCompletionRequest,
shouldMatchOrchestratorCancellationChildRequest,
shouldMatchOrchestratorCancellationRecoveryResumeRequest,
shouldMatchOrchestratorChildRequest,
shouldMatchOrchestratorNestedChildResumeRequest,
shouldMatchOrchestratorNestedParentResumeRequest,
shouldMatchOrchestratorRepeatedResumeRequest,
shouldMatchOrchestratorResumeRequest,
} from "./orchestrator-plan"
describe("orchestrator delegation plans", () => {
it("defines the first commit single-round ask/architect/code child sequence", () => {
expect(ORCHESTRATOR_FAN_OUT_PARENT_PROMPT).toContain("ORCHESTRATOR_SINGLE_ROUND_FAN_OUT")
expect(ORCHESTRATOR_FAN_OUT_CHILD_STEPS).toEqual([
expect.objectContaining({
mode: "ask",
summary: "Requirement summary: gather requirements for the reporting workflow.",
}),
expect.objectContaining({
mode: "architect",
summary: "Design summary: outline a minimal fan-in architecture.",
}),
expect.objectContaining({
mode: "code",
summary: "Implementation summary: implement the delegated workflow skeleton.",
}),
])
})
it("builds cumulative parent resume expectations for fan-in matching", () => {
expect(buildOrchestratorResumeExpectations()).toEqual([
{
stepIndex: 1,
requiredSummaries: ["Requirement summary: gather requirements for the reporting workflow."],
nextMode: "architect",
},
{
stepIndex: 2,
requiredSummaries: [
"Requirement summary: gather requirements for the reporting workflow.",
"Design summary: outline a minimal fan-in architecture.",
],
nextMode: "code",
},
{
stepIndex: 3,
requiredSummaries: [
"Requirement summary: gather requirements for the reporting workflow.",
"Design summary: outline a minimal fan-in architecture.",
"Implementation summary: implement the delegated workflow skeleton.",
],
nextMode: undefined,
},
])
})
it("matches child requests without matching the parent prompt that embeds child markers", () => {
expect(
shouldMatchOrchestratorChildRequest(
"child ORCHESTRATOR_SINGLE_ROUND_REQUIREMENTS_CHILD",
"ORCHESTRATOR_SINGLE_ROUND_REQUIREMENTS_CHILD",
),
).toBe(true)
expect(
shouldMatchOrchestratorChildRequest(
"ORCHESTRATOR_SINGLE_ROUND_FAN_OUT embeds ORCHESTRATOR_SINGLE_ROUND_REQUIREMENTS_CHILD",
"ORCHESTRATOR_SINGLE_ROUND_REQUIREMENTS_CHILD",
),
).toBe(false)
})
it("matches parent resume requests only after cumulative child result injection", () => {
const firstExpectation = buildOrchestratorResumeExpectations()[0]!
const resumeRequest = `ORCHESTRATOR_SINGLE_ROUND_FAN_OUT completed.\\n\\nResult:\\n${firstExpectation.requiredSummaries[0]}`
expect(shouldMatchOrchestratorResumeRequest(resumeRequest, firstExpectation.requiredSummaries)).toBe(true)
expect(
shouldMatchOrchestratorResumeRequest(
`ORCHESTRATOR_SINGLE_ROUND_FAN_OUT completed.\\n\\nResult:\\nmissing ${firstExpectation.requiredSummaries[0]}`,
firstExpectation.requiredSummaries,
),
).toBe(false)
expect(
shouldMatchOrchestratorResumeRequest(
"ORCHESTRATOR_SINGLE_ROUND_FAN_OUT without result",
firstExpectation.requiredSummaries,
),
).toBe(false)
})
it("keeps the final parent result fan-in explicit and reviewable", () => {
expect(ORCHESTRATOR_FAN_OUT_FINAL_RESULT).toContain(
"Requirement summary: gather requirements for the reporting workflow.",
)
expect(ORCHESTRATOR_FAN_OUT_FINAL_RESULT).toContain("Design summary: outline a minimal fan-in architecture.")
expect(ORCHESTRATOR_FAN_OUT_FINAL_RESULT).toContain(
"Implementation summary: implement the delegated workflow skeleton.",
)
})
it("defines a three-round repeated delegation sequence with ask/architect/code children per round", () => {
expect(ORCHESTRATOR_REPEATED_DELEGATION_PARENT_PROMPT).toContain(ORCHESTRATOR_REPEATED_DELEGATION_MARKER)
expect(ORCHESTRATOR_REPEATED_DELEGATION_CHILD_STEPS).toHaveLength(9)
expect(
ORCHESTRATOR_REPEATED_DELEGATION_CHILD_STEPS.map(({ round, role, mode }) => ({ round, role, mode })),
).toEqual([
{ round: 1, role: "requirements", mode: "ask" },
{ round: 1, role: "design", mode: "architect" },
{ round: 1, role: "implementation", mode: "code" },
{ round: 2, role: "requirements", mode: "ask" },
{ round: 2, role: "design", mode: "architect" },
{ round: 2, role: "implementation", mode: "code" },
{ round: 3, role: "requirements", mode: "ask" },
{ round: 3, role: "design", mode: "architect" },
{ round: 3, role: "implementation", mode: "code" },
])
expect(ORCHESTRATOR_REPEATED_DELEGATION_CHILD_STEPS[0]?.summary).toBe(
"Round 1 requirements summary: capture reporting workflow constraints.",
)
expect(ORCHESTRATOR_REPEATED_DELEGATION_CHILD_STEPS[8]?.summary).toBe(
"Round 3 implementation summary: validate repeated delegation convergence.",
)
})
it("builds cumulative repeated delegation resume expectations across all rounds", () => {
const expectations = buildOrchestratorRepeatedResumeExpectations()
expect(expectations).toHaveLength(9)
expect(expectations[0]).toEqual({
stepIndex: 1,
requiredSummaries: ["Round 1 requirements summary: capture reporting workflow constraints."],
nextMode: "architect",
})
expect(expectations[2]).toEqual({
stepIndex: 3,
requiredSummaries: ORCHESTRATOR_REPEATED_DELEGATION_CHILD_STEPS.slice(0, 3).map(({ summary }) => summary),
nextMode: "ask",
})
expect(expectations[8]).toEqual({
stepIndex: 9,
requiredSummaries: ORCHESTRATOR_REPEATED_DELEGATION_CHILD_STEPS.map(({ summary }) => summary),
nextMode: undefined,
})
})
it("matches repeated delegation parent resumes only for cumulative child result injection", () => {
const expectations = buildOrchestratorRepeatedResumeExpectations()
const thirdExpectation = expectations[2]!
const resumeRequest = `${ORCHESTRATOR_REPEATED_DELEGATION_MARKER} completed.\\n\\nResult:\\n${thirdExpectation.requiredSummaries.join(" completed.\\n\\nResult:\\n")}`
expect(shouldMatchOrchestratorRepeatedResumeRequest(resumeRequest, thirdExpectation.requiredSummaries)).toBe(
true,
)
expect(
shouldMatchOrchestratorRepeatedResumeRequest(
`${ORCHESTRATOR_REPEATED_DELEGATION_MARKER} completed.\\n\\nResult:\\nmissing ${thirdExpectation.requiredSummaries[2]}`,
thirdExpectation.requiredSummaries,
),
).toBe(false)
expect(
shouldMatchOrchestratorRepeatedResumeRequest(
"ORCHESTRATOR_SINGLE_ROUND_FAN_OUT completed.\\n\\nResult:\\nRound 1 requirements summary: capture reporting workflow constraints.",
["Round 1 requirements summary: capture reporting workflow constraints."],
),
).toBe(false)
})
it("composes a repeated delegation final result with every round and child summary", () => {
for (const { round, role, summary } of ORCHESTRATOR_REPEATED_DELEGATION_CHILD_STEPS) {
expect(ORCHESTRATOR_REPEATED_DELEGATION_FINAL_RESULT).toContain(`Round ${round} ${role}: ${summary}`)
}
})
it("defines a nested parent/child orchestrator plan with A/B/C/D roles, modes, and summaries", () => {
expect(ORCHESTRATOR_NESTED_DELEGATION_PARENT_PROMPT).toContain(ORCHESTRATOR_NESTED_DELEGATION_MARKER)
expect(ORCHESTRATOR_NESTED_DELEGATION_CHILD_ORCHESTRATOR_STEP).toEqual(
expect.objectContaining({
role: "child-orchestrator",
mode: "orchestrator",
summary: ORCHESTRATOR_NESTED_DELEGATION_CHILD_FINAL_RESULT,
}),
)
expect(ORCHESTRATOR_NESTED_DELEGATION_GRANDCHILD_STEPS).toEqual([
expect.objectContaining({
role: "requirements",
mode: "ask",
summary: "Nested requirement summary: capture child orchestrator requirements.",
}),
expect.objectContaining({
role: "implementation",
mode: "code",
summary: "Nested implementation summary: produce child orchestrator implementation notes.",
}),
])
})
it("matches nested child orchestrator resumes only after cumulative C/D result injection", () => {
const expectations = buildOrchestratorNestedChildResumeExpectations()
expect(expectations).toEqual([
{
stepIndex: 1,
requiredSummaries: ["Nested requirement summary: capture child orchestrator requirements."],
nextMode: "code",
},
{
stepIndex: 2,
requiredSummaries: ORCHESTRATOR_NESTED_DELEGATION_GRANDCHILD_STEPS.map(({ summary }) => summary),
nextMode: undefined,
},
])
const secondExpectation = expectations[1]!
const childResumeRequest = `${ORCHESTRATOR_NESTED_DELEGATION_CHILD_ORCHESTRATOR_STEP.marker} completed.\\n\\nResult:\\n${secondExpectation.requiredSummaries.join(" completed.\\n\\nResult:\\n")}`
expect(
shouldMatchOrchestratorNestedChildResumeRequest(childResumeRequest, secondExpectation.requiredSummaries),
).toBe(true)
expect(
shouldMatchOrchestratorNestedChildResumeRequest(
`${ORCHESTRATOR_NESTED_DELEGATION_CHILD_ORCHESTRATOR_STEP.marker} completed.\\n\\nResult:\\nmissing ${secondExpectation.requiredSummaries[1]}`,
secondExpectation.requiredSummaries,
),
).toBe(false)
expect(
shouldMatchOrchestratorNestedChildResumeRequest(
`${ORCHESTRATOR_NESTED_DELEGATION_MARKER} completed.\\n\\nResult:\\n${secondExpectation.requiredSummaries[0]}`,
[secondExpectation.requiredSummaries[0]!],
),
).toBe(false)
})
it("matches top-level nested parent resumes only after the B nested result", () => {
const expectations = buildOrchestratorNestedParentResumeExpectations()
expect(expectations).toEqual([
{
stepIndex: 1,
requiredSummaries: [ORCHESTRATOR_NESTED_DELEGATION_CHILD_FINAL_RESULT],
nextMode: undefined,
},
])
const parentResumeRequest = `${ORCHESTRATOR_NESTED_DELEGATION_MARKER} completed.\\n\\nResult:\\n${ORCHESTRATOR_NESTED_DELEGATION_CHILD_FINAL_RESULT}`
expect(
shouldMatchOrchestratorNestedParentResumeRequest(parentResumeRequest, [
ORCHESTRATOR_NESTED_DELEGATION_CHILD_FINAL_RESULT,
]),
).toBe(true)
expect(
shouldMatchOrchestratorNestedParentResumeRequest(
`${ORCHESTRATOR_NESTED_DELEGATION_MARKER} completed.\\n\\nResult:\\n${ORCHESTRATOR_NESTED_DELEGATION_GRANDCHILD_STEPS[0]!.summary}`,
[ORCHESTRATOR_NESTED_DELEGATION_CHILD_FINAL_RESULT],
),
).toBe(false)
})
it("composes nested child and final parent results with the nested summaries", () => {
for (const { summary } of ORCHESTRATOR_NESTED_DELEGATION_GRANDCHILD_STEPS) {
expect(ORCHESTRATOR_NESTED_DELEGATION_CHILD_FINAL_RESULT).toContain(summary)
}
expect(ORCHESTRATOR_NESTED_DELEGATION_FINAL_RESULT).toContain(ORCHESTRATOR_NESTED_DELEGATION_CHILD_FINAL_RESULT)
})
it("defines a cancellation recovery parent/child plan with a pending ask child", () => {
expect(ORCHESTRATOR_CANCELLATION_RECOVERY_PARENT_PROMPT).toContain(ORCHESTRATOR_CANCELLATION_RECOVERY_MARKER)
expect(ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP).toEqual(
expect.objectContaining({
mode: "ask",
role: "cancellation-child",
summary: "Cancellation recovery child summary: resumed after interruption.",
}),
)
expect(ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.prompt).toContain("Ask the user exactly")
expect(ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.prompt).toContain(
ORCHESTRATOR_CANCELLATION_RECOVERY_FOLLOWUP_ANSWER,
)
})
it("matches cancellation child requests without colliding with other orchestrator scenarios", () => {
expect(
shouldMatchOrchestratorCancellationChildRequest(
`child ${ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.marker}`,
),
).toBe(true)
expect(shouldMatchOrchestratorCancellationChildRequest(ORCHESTRATOR_CANCELLATION_RECOVERY_PARENT_PROMPT)).toBe(
false,
)
expect(
shouldMatchOrchestratorCancellationChildRequest(
`${ORCHESTRATOR_NESTED_DELEGATION_MARKER} embeds ${ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.marker}`,
),
).toBe(false)
})
it("matches cancellation child completion only after the recovery answer", () => {
expect(
shouldMatchOrchestratorCancellationChildCompletionRequest(
`${ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.marker} ${ORCHESTRATOR_CANCELLATION_RECOVERY_FOLLOWUP_TOOL_CALL_ID} ${ORCHESTRATOR_CANCELLATION_RECOVERY_FOLLOWUP_ANSWER}`,
),
).toBe(true)
expect(
shouldMatchOrchestratorCancellationChildCompletionRequest(
`${ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.marker} without the answer`,
),
).toBe(false)
expect(
shouldMatchOrchestratorCancellationChildCompletionRequest(
`${ORCHESTRATOR_CANCELLATION_RECOVERY_MARKER} call_cancellation_child_followup_001 ${ORCHESTRATOR_CANCELLATION_RECOVERY_FOLLOWUP_ANSWER}`,
),
).toBe(false)
})
it("matches cancellation recovery parent resumes only after child result injection", () => {
const expectations = buildOrchestratorCancellationRecoveryResumeExpectations()
expect(expectations).toEqual([
{
stepIndex: 1,
requiredSummaries: [ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.summary],
nextMode: undefined,
},
])
const parentResumeRequest = `${ORCHESTRATOR_CANCELLATION_RECOVERY_MARKER} completed.\\n\\nResult:\\n${ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.summary}`
expect(
shouldMatchOrchestratorCancellationRecoveryResumeRequest(parentResumeRequest, [
ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.summary,
]),
).toBe(true)
expect(
shouldMatchOrchestratorCancellationRecoveryResumeRequest(
`${ORCHESTRATOR_CANCELLATION_RECOVERY_MARKER} completed.\\n\\nResult:\\nmissing`,
[ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.summary],
),
).toBe(false)
})
it("composes cancellation recovery final result with an explicit cancellation marker", () => {
expect(ORCHESTRATOR_CANCELLATION_RECOVERY_FINAL_RESULT).toContain("cancellation recovery")
expect(ORCHESTRATOR_CANCELLATION_RECOVERY_FINAL_RESULT).toContain(
ORCHESTRATOR_CANCELLATION_RECOVERY_CHILD_STEP.summary,
)
})
})