@agentwonderland/mcp 0.1.53 → 0.1.54
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/dist/core/__tests__/api-client.test.js +40 -0
- package/dist/core/api-client.js +18 -0
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +1 -1
- package/dist/index.js +8 -5
- package/dist/tools/__tests__/playbooks.test.d.ts +1 -0
- package/dist/tools/__tests__/playbooks.test.js +2043 -0
- package/dist/tools/__tests__/wallet.test.js +5 -4
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/passes.js +4 -21
- package/dist/tools/playbooks.d.ts +2 -0
- package/dist/tools/playbooks.js +880 -0
- package/dist/tools/run.js +4 -18
- package/dist/tools/solve.js +4 -18
- package/dist/tools/wallet.js +9 -12
- package/package.json +1 -1
- package/src/core/__tests__/api-client.test.ts +44 -0
- package/src/core/api-client.ts +18 -0
- package/src/core/version.ts +1 -1
- package/src/index.ts +8 -5
- package/src/tools/__tests__/playbooks.test.ts +2285 -0
- package/src/tools/__tests__/wallet.test.ts +5 -4
- package/src/tools/index.ts +1 -0
- package/src/tools/passes.ts +3 -21
- package/src/tools/playbooks.ts +1100 -0
- package/src/tools/run.ts +3 -17
- package/src/tools/solve.ts +3 -17
- package/src/tools/wallet.ts +9 -12
|
@@ -0,0 +1,2043 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
const mockApiGet = vi.fn();
|
|
3
|
+
const mockApiPost = vi.fn();
|
|
4
|
+
const mockApiPostWithPayment = vi.fn();
|
|
5
|
+
const mockUploadLocalFiles = vi.fn();
|
|
6
|
+
const mockHasWalletConfigured = vi.fn();
|
|
7
|
+
const mockGetConfiguredMethods = vi.fn();
|
|
8
|
+
const mockGetWalletAddress = vi.fn();
|
|
9
|
+
const mockRequiresSpendConfirmation = vi.fn();
|
|
10
|
+
const mockCanSpend = vi.fn();
|
|
11
|
+
const mockRecordSpend = vi.fn();
|
|
12
|
+
const mockRequiresPolicyConfirmation = vi.fn();
|
|
13
|
+
const mockStoreFeedbackToken = vi.fn();
|
|
14
|
+
vi.mock("../../core/api-client.js", () => ({
|
|
15
|
+
apiGet: mockApiGet,
|
|
16
|
+
apiPost: mockApiPost,
|
|
17
|
+
apiPostWithPayment: mockApiPostWithPayment,
|
|
18
|
+
}));
|
|
19
|
+
vi.mock("../../core/file-upload.js", () => ({
|
|
20
|
+
uploadLocalFiles: mockUploadLocalFiles,
|
|
21
|
+
}));
|
|
22
|
+
vi.mock("../../core/payments.js", () => ({
|
|
23
|
+
hasWalletConfigured: mockHasWalletConfigured,
|
|
24
|
+
getConfiguredMethods: mockGetConfiguredMethods,
|
|
25
|
+
getWalletAddress: mockGetWalletAddress,
|
|
26
|
+
}));
|
|
27
|
+
vi.mock("../../core/config.js", () => ({
|
|
28
|
+
requiresSpendConfirmation: mockRequiresSpendConfirmation,
|
|
29
|
+
}));
|
|
30
|
+
vi.mock("../../core/spend-policy.js", () => ({
|
|
31
|
+
canSpend: mockCanSpend,
|
|
32
|
+
recordSpend: mockRecordSpend,
|
|
33
|
+
requiresPolicyConfirmation: mockRequiresPolicyConfirmation,
|
|
34
|
+
}));
|
|
35
|
+
vi.mock("../_token-cache.js", () => ({
|
|
36
|
+
storeFeedbackToken: mockStoreFeedbackToken,
|
|
37
|
+
}));
|
|
38
|
+
function flattenToolText(result) {
|
|
39
|
+
const content = result?.content ?? [];
|
|
40
|
+
return content
|
|
41
|
+
.filter((item) => item?.type === "text")
|
|
42
|
+
.map((item) => item.text ?? "")
|
|
43
|
+
.join("\n\n");
|
|
44
|
+
}
|
|
45
|
+
function makeServerHarness() {
|
|
46
|
+
const handlers = new Map();
|
|
47
|
+
return {
|
|
48
|
+
handlers,
|
|
49
|
+
server: {
|
|
50
|
+
tool(name, _description, _schema, handler) {
|
|
51
|
+
handlers.set(name, handler);
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const playbook = {
|
|
57
|
+
id: "pb_competitor_ads_v1",
|
|
58
|
+
slug: "competitor-ads",
|
|
59
|
+
version: 1,
|
|
60
|
+
name: "Competitor Ads",
|
|
61
|
+
persona: "gtm",
|
|
62
|
+
tags: ["gtm"],
|
|
63
|
+
description: "Competitor ad workflow",
|
|
64
|
+
outcome: "Ad intel",
|
|
65
|
+
support_status: "supported",
|
|
66
|
+
input_schema: {
|
|
67
|
+
type: "object",
|
|
68
|
+
properties: { domain: { type: "string", description: "Competitor domain" } },
|
|
69
|
+
required: ["domain"],
|
|
70
|
+
},
|
|
71
|
+
sample_input: { domain: "notion.so" },
|
|
72
|
+
budget_notes: ["Low fanout"],
|
|
73
|
+
risks: [],
|
|
74
|
+
stats: {
|
|
75
|
+
favorite_count: 3,
|
|
76
|
+
rating_count: 2,
|
|
77
|
+
average_rating: 4.5,
|
|
78
|
+
},
|
|
79
|
+
current_quote: {
|
|
80
|
+
estimated_cost_usd: 1.25,
|
|
81
|
+
step_count: 1,
|
|
82
|
+
blocking_issues: [],
|
|
83
|
+
steps: [
|
|
84
|
+
{
|
|
85
|
+
id: "ads",
|
|
86
|
+
index: 0,
|
|
87
|
+
node_type: "aw_agent",
|
|
88
|
+
agent_slug: "ad-strategy-intel",
|
|
89
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
90
|
+
provider_id: null,
|
|
91
|
+
agent_name: "AdStrategyIntel",
|
|
92
|
+
description: "Ad intelligence",
|
|
93
|
+
quantity: 1,
|
|
94
|
+
unit_price_usd: 1.25,
|
|
95
|
+
quoted_cost_usd: 1.25,
|
|
96
|
+
support_status: "ready",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
describe("playbook MCP tools", () => {
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
vi.resetModules();
|
|
104
|
+
vi.clearAllMocks();
|
|
105
|
+
mockHasWalletConfigured.mockReturnValue(true);
|
|
106
|
+
mockGetConfiguredMethods.mockReturnValue(["card"]);
|
|
107
|
+
mockGetWalletAddress.mockResolvedValue("0xabc");
|
|
108
|
+
mockRequiresSpendConfirmation.mockReturnValue(true);
|
|
109
|
+
mockRequiresPolicyConfirmation.mockReturnValue(false);
|
|
110
|
+
mockCanSpend.mockReturnValue({ ok: true, message: "" });
|
|
111
|
+
mockUploadLocalFiles.mockResolvedValue({ input: { domain: "notion.so" }, uploads: [] });
|
|
112
|
+
});
|
|
113
|
+
it("searches playbooks through the gateway", async () => {
|
|
114
|
+
mockApiGet.mockResolvedValueOnce({ playbooks: [playbook] });
|
|
115
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
116
|
+
const harness = makeServerHarness();
|
|
117
|
+
registerPlaybookTools(harness.server);
|
|
118
|
+
const result = await harness.handlers.get("search_playbooks")({ query: "competitor ads", limit: 5 });
|
|
119
|
+
const text = flattenToolText(result);
|
|
120
|
+
expect(mockApiGet).toHaveBeenCalledWith("/playbooks?q=competitor+ads&limit=5");
|
|
121
|
+
expect(text).toContain("Competitor Ads (competitor-ads)");
|
|
122
|
+
expect(text).toContain("Favorites: 3");
|
|
123
|
+
expect(text).toContain("Rating: 4.5/5 (2)");
|
|
124
|
+
expect(text).toContain("get_playbook");
|
|
125
|
+
});
|
|
126
|
+
it("passes playbook search filters and sorting to the gateway", async () => {
|
|
127
|
+
mockApiGet.mockResolvedValueOnce({ playbooks: [playbook] });
|
|
128
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
129
|
+
const harness = makeServerHarness();
|
|
130
|
+
registerPlaybookTools(harness.server);
|
|
131
|
+
await harness.handlers.get("search_playbooks")({
|
|
132
|
+
query: "lead gen",
|
|
133
|
+
persona: "gtm",
|
|
134
|
+
tag: "prospecting",
|
|
135
|
+
max_budget: 5,
|
|
136
|
+
sort: "popularity",
|
|
137
|
+
limit: 3,
|
|
138
|
+
});
|
|
139
|
+
expect(mockApiGet).toHaveBeenCalledWith("/playbooks?q=lead+gen&persona=gtm&tag=prospecting&limit=3&max_budget=5&sort=popularity");
|
|
140
|
+
});
|
|
141
|
+
it("returns a useful search empty state", async () => {
|
|
142
|
+
mockApiGet.mockResolvedValueOnce({ playbooks: [] });
|
|
143
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
144
|
+
const harness = makeServerHarness();
|
|
145
|
+
registerPlaybookTools(harness.server);
|
|
146
|
+
const result = await harness.handlers.get("search_playbooks")({ query: "quantum waffles", limit: 5 });
|
|
147
|
+
const text = flattenToolText(result);
|
|
148
|
+
expect(text).toContain('No playbooks found matching "quantum waffles"');
|
|
149
|
+
expect(text).toContain('search_playbooks({ persona: "gtm" })');
|
|
150
|
+
expect(text).toContain('search_playbooks({ tag: "research" })');
|
|
151
|
+
});
|
|
152
|
+
it("labels catalog-only playbooks clearly in search results", async () => {
|
|
153
|
+
mockApiGet.mockResolvedValueOnce({
|
|
154
|
+
playbooks: [{
|
|
155
|
+
...playbook,
|
|
156
|
+
slug: "trend-radar",
|
|
157
|
+
name: "Trend Radar",
|
|
158
|
+
support_status: "catalog_only",
|
|
159
|
+
support_note: "Best as a future scheduling demo.",
|
|
160
|
+
}],
|
|
161
|
+
});
|
|
162
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
163
|
+
const harness = makeServerHarness();
|
|
164
|
+
registerPlaybookTools(harness.server);
|
|
165
|
+
const result = await harness.handlers.get("search_playbooks")({ query: "trend", limit: 5 });
|
|
166
|
+
const text = flattenToolText(result);
|
|
167
|
+
expect(text).toContain("Trend Radar (trend-radar)");
|
|
168
|
+
expect(text).toContain("catalog-only: Best as a future scheduling demo.");
|
|
169
|
+
});
|
|
170
|
+
it("gets a playbook with live quote, graph, risks, and run suggestion", async () => {
|
|
171
|
+
mockApiGet.mockResolvedValueOnce({
|
|
172
|
+
...playbook,
|
|
173
|
+
budget_notes: ["Low fanout", "Stops before exceeding the approved budget cap."],
|
|
174
|
+
risks: ["SERP step may need a derived query."],
|
|
175
|
+
});
|
|
176
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
177
|
+
const harness = makeServerHarness();
|
|
178
|
+
registerPlaybookTools(harness.server);
|
|
179
|
+
const result = await harness.handlers.get("get_playbook")({ slug: "competitor-ads" });
|
|
180
|
+
const text = flattenToolText(result);
|
|
181
|
+
expect(mockApiGet).toHaveBeenCalledWith("/playbooks/competitor-ads");
|
|
182
|
+
expect(text).toContain("Competitor Ads (competitor-ads)");
|
|
183
|
+
expect(text).toContain("Support: supported");
|
|
184
|
+
expect(text).toContain("Estimated cost: $1.25 across 1 paid step");
|
|
185
|
+
expect(text).toContain("Inputs:");
|
|
186
|
+
expect(text).toContain("domain: string (required)");
|
|
187
|
+
expect(text).toContain("Execution plan:");
|
|
188
|
+
expect(text).toContain("1. AdStrategyIntel (ad-strategy-intel) — $1.25");
|
|
189
|
+
expect(text).toContain("Budget notes:");
|
|
190
|
+
expect(text).toContain("Stops before exceeding the approved budget cap.");
|
|
191
|
+
expect(text).toContain("Risks:");
|
|
192
|
+
expect(text).toContain("SERP step may need a derived query.");
|
|
193
|
+
expect(text).toContain("Sample input:");
|
|
194
|
+
expect(text).toContain('Run quote: run_playbook({ slug: "competitor-ads"');
|
|
195
|
+
});
|
|
196
|
+
it("shows blocking child-agent issues in get_playbook output", async () => {
|
|
197
|
+
mockApiGet.mockResolvedValueOnce({
|
|
198
|
+
...playbook,
|
|
199
|
+
current_quote: {
|
|
200
|
+
...playbook.current_quote,
|
|
201
|
+
blocking_issues: ["Inactive child agent: ad-strategy-intel"],
|
|
202
|
+
steps: [{
|
|
203
|
+
...playbook.current_quote.steps[0],
|
|
204
|
+
support_status: "blocking",
|
|
205
|
+
agent_id: null,
|
|
206
|
+
}],
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
210
|
+
const harness = makeServerHarness();
|
|
211
|
+
registerPlaybookTools(harness.server);
|
|
212
|
+
const result = await harness.handlers.get("get_playbook")({ playbook_id: "pb_competitor_ads_v1" });
|
|
213
|
+
const text = flattenToolText(result);
|
|
214
|
+
expect(mockApiGet).toHaveBeenCalledWith("/playbooks/pb_competitor_ads_v1");
|
|
215
|
+
expect(text).toContain("Blocking issues: Inactive child agent: ad-strategy-intel");
|
|
216
|
+
expect(text).toContain("[blocking]");
|
|
217
|
+
});
|
|
218
|
+
it("favorites a playbook with consumer principal headers", async () => {
|
|
219
|
+
mockApiPost.mockResolvedValueOnce({
|
|
220
|
+
ok: true,
|
|
221
|
+
favorite_id: "favorite-row-1",
|
|
222
|
+
playbook_slug: "competitor-ads",
|
|
223
|
+
});
|
|
224
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
225
|
+
const harness = makeServerHarness();
|
|
226
|
+
registerPlaybookTools(harness.server);
|
|
227
|
+
const result = await harness.handlers.get("favorite_playbook")({ slug: "competitor-ads" });
|
|
228
|
+
const text = flattenToolText(result);
|
|
229
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbooks/competitor-ads/favorite", {}, { ensureConsumerPrincipal: true });
|
|
230
|
+
expect(text).toContain("Saved competitor-ads to favorites");
|
|
231
|
+
});
|
|
232
|
+
it("records playbook feedback with consumer principal headers", async () => {
|
|
233
|
+
mockApiPost.mockResolvedValueOnce({
|
|
234
|
+
ok: true,
|
|
235
|
+
feedback_id: "feedback-row-1",
|
|
236
|
+
playbook_slug: "competitor-ads",
|
|
237
|
+
});
|
|
238
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
239
|
+
const harness = makeServerHarness();
|
|
240
|
+
registerPlaybookTools(harness.server);
|
|
241
|
+
const result = await harness.handlers.get("rate_playbook")({
|
|
242
|
+
slug: "competitor-ads",
|
|
243
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
244
|
+
rating: 5,
|
|
245
|
+
useful: true,
|
|
246
|
+
comment: "Useful.",
|
|
247
|
+
});
|
|
248
|
+
const text = flattenToolText(result);
|
|
249
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbooks/competitor-ads/feedback", {
|
|
250
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
251
|
+
rating: 5,
|
|
252
|
+
useful: true,
|
|
253
|
+
comment: "Useful.",
|
|
254
|
+
}, { ensureConsumerPrincipal: true });
|
|
255
|
+
expect(text).toContain("Recorded feedback for competitor-ads");
|
|
256
|
+
});
|
|
257
|
+
it("validates favorite and feedback inputs before calling the gateway", async () => {
|
|
258
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
259
|
+
const harness = makeServerHarness();
|
|
260
|
+
registerPlaybookTools(harness.server);
|
|
261
|
+
const favoriteResult = await harness.handlers.get("favorite_playbook")({});
|
|
262
|
+
const emptyFeedbackResult = await harness.handlers.get("rate_playbook")({ slug: "competitor-ads" });
|
|
263
|
+
const missingIdFeedbackResult = await harness.handlers.get("rate_playbook")({ rating: 5 });
|
|
264
|
+
expect(flattenToolText(favoriteResult)).toContain("Provide slug or playbook_id.");
|
|
265
|
+
expect(flattenToolText(emptyFeedbackResult)).toContain("Provide rating, useful, or comment.");
|
|
266
|
+
expect(flattenToolText(missingIdFeedbackResult)).toContain("Provide slug or playbook_id.");
|
|
267
|
+
expect(mockApiPost).not.toHaveBeenCalled();
|
|
268
|
+
});
|
|
269
|
+
it("quotes before confirmed execution", async () => {
|
|
270
|
+
mockApiGet.mockResolvedValueOnce({
|
|
271
|
+
...playbook,
|
|
272
|
+
risks: ["SERP step may need a derived query."],
|
|
273
|
+
});
|
|
274
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
275
|
+
const harness = makeServerHarness();
|
|
276
|
+
registerPlaybookTools(harness.server);
|
|
277
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
278
|
+
slug: "competitor-ads",
|
|
279
|
+
input: { domain: "notion.so" },
|
|
280
|
+
budget: 5,
|
|
281
|
+
pay_with: "card",
|
|
282
|
+
});
|
|
283
|
+
const text = flattenToolText(result);
|
|
284
|
+
expect(text).toContain("Ready to run Competitor Ads");
|
|
285
|
+
expect(text).toContain("Budget and fanout notes:");
|
|
286
|
+
expect(text).toContain("Low fanout");
|
|
287
|
+
expect(text).toContain("Risks and limitations:");
|
|
288
|
+
expect(text).toContain("SERP step may need a derived query.");
|
|
289
|
+
expect(text).toContain('run_playbook({ slug: "competitor-ads", input: <same>, budget: 5, pay_with: "card", confirmed: true })');
|
|
290
|
+
expect(mockApiPostWithPayment).not.toHaveBeenCalled();
|
|
291
|
+
});
|
|
292
|
+
it("keeps reduced fanout limits in the confirmation command", async () => {
|
|
293
|
+
mockApiGet.mockResolvedValueOnce(playbook);
|
|
294
|
+
mockApiPost.mockResolvedValueOnce({
|
|
295
|
+
playbook,
|
|
296
|
+
budget_usd: 5,
|
|
297
|
+
budget_sufficient: true,
|
|
298
|
+
remaining_budget_usd: 3.75,
|
|
299
|
+
});
|
|
300
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
301
|
+
const harness = makeServerHarness();
|
|
302
|
+
registerPlaybookTools(harness.server);
|
|
303
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
304
|
+
slug: "competitor-ads",
|
|
305
|
+
input: { domain: "notion.so" },
|
|
306
|
+
budget: 5,
|
|
307
|
+
pay_with: "card",
|
|
308
|
+
limits: { prospects: 2 },
|
|
309
|
+
});
|
|
310
|
+
const text = flattenToolText(result);
|
|
311
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-quotes", expect.objectContaining({
|
|
312
|
+
limits: { prospects: 2 },
|
|
313
|
+
}));
|
|
314
|
+
expect(text).toContain('run_playbook({ slug: "competitor-ads", input: <same>, budget: 5, limits: {"prospects":2}, pay_with: "card", confirmed: true })');
|
|
315
|
+
expect(mockApiPostWithPayment).not.toHaveBeenCalled();
|
|
316
|
+
});
|
|
317
|
+
it("returns the first quote before wallet setup is complete", async () => {
|
|
318
|
+
mockHasWalletConfigured.mockReturnValue(false);
|
|
319
|
+
mockApiGet.mockResolvedValueOnce(playbook);
|
|
320
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
321
|
+
const harness = makeServerHarness();
|
|
322
|
+
registerPlaybookTools(harness.server);
|
|
323
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
324
|
+
slug: "competitor-ads",
|
|
325
|
+
input: { domain: "notion.so" },
|
|
326
|
+
budget: 5,
|
|
327
|
+
pay_with: "tempo",
|
|
328
|
+
});
|
|
329
|
+
const text = flattenToolText(result);
|
|
330
|
+
expect(text).toContain("Ready to run Competitor Ads");
|
|
331
|
+
expect(text).toContain("Estimated child-agent charges: $1.25");
|
|
332
|
+
expect(text).toContain('run_playbook({ slug: "competitor-ads", input: <same>, budget: 5, pay_with: "tempo", confirmed: true })');
|
|
333
|
+
expect(text).not.toContain("No payment method configured");
|
|
334
|
+
expect(mockApiPost).not.toHaveBeenCalledWith("/playbook-runs", expect.anything());
|
|
335
|
+
expect(mockApiPostWithPayment).not.toHaveBeenCalled();
|
|
336
|
+
});
|
|
337
|
+
it("requires a configured wallet before confirmed playbook execution", async () => {
|
|
338
|
+
mockHasWalletConfigured.mockReturnValue(false);
|
|
339
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
340
|
+
mockApiGet.mockResolvedValueOnce(playbook);
|
|
341
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
342
|
+
const harness = makeServerHarness();
|
|
343
|
+
registerPlaybookTools(harness.server);
|
|
344
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
345
|
+
slug: "competitor-ads",
|
|
346
|
+
input: { domain: "notion.so" },
|
|
347
|
+
budget: 5,
|
|
348
|
+
pay_with: "tempo",
|
|
349
|
+
confirmed: true,
|
|
350
|
+
});
|
|
351
|
+
const text = flattenToolText(result);
|
|
352
|
+
expect(text).toContain("No payment method configured");
|
|
353
|
+
expect(text).toContain('wallet_setup({ action: "start" })');
|
|
354
|
+
expect(mockApiPost).not.toHaveBeenCalledWith("/playbook-runs", expect.anything());
|
|
355
|
+
expect(mockApiPostWithPayment).not.toHaveBeenCalled();
|
|
356
|
+
});
|
|
357
|
+
it("quotes the direct IPO brief run before any paid execution", async () => {
|
|
358
|
+
const ipoBrief = {
|
|
359
|
+
...playbook,
|
|
360
|
+
id: "pb_ipo_brief_v1",
|
|
361
|
+
slug: "ipo-brief",
|
|
362
|
+
name: "IPO Brief",
|
|
363
|
+
persona: "investor",
|
|
364
|
+
input_schema: {
|
|
365
|
+
type: "object",
|
|
366
|
+
properties: { ticker: { type: "string", description: "IPO ticker" } },
|
|
367
|
+
required: ["ticker"],
|
|
368
|
+
},
|
|
369
|
+
sample_input: { ticker: "CRCL" },
|
|
370
|
+
current_quote: {
|
|
371
|
+
...playbook.current_quote,
|
|
372
|
+
estimated_cost_usd: 2.5,
|
|
373
|
+
step_count: 3,
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
mockApiGet.mockResolvedValueOnce(ipoBrief);
|
|
377
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
378
|
+
const harness = makeServerHarness();
|
|
379
|
+
registerPlaybookTools(harness.server);
|
|
380
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
381
|
+
slug: "ipo-brief",
|
|
382
|
+
input: { ticker: "CRCL" },
|
|
383
|
+
budget: 3,
|
|
384
|
+
pay_with: "card",
|
|
385
|
+
});
|
|
386
|
+
const text = flattenToolText(result);
|
|
387
|
+
expect(mockApiGet).toHaveBeenCalledWith("/playbooks/ipo-brief");
|
|
388
|
+
expect(text).toContain("Ready to run IPO Brief");
|
|
389
|
+
expect(text).toContain("Estimated child-agent charges: $2.50");
|
|
390
|
+
expect(text).toContain('run_playbook({ slug: "ipo-brief", input: <same>, budget: 3, pay_with: "card", confirmed: true })');
|
|
391
|
+
expect(mockApiPost).not.toHaveBeenCalledWith("/playbook-runs", expect.anything());
|
|
392
|
+
expect(mockApiPostWithPayment).not.toHaveBeenCalled();
|
|
393
|
+
});
|
|
394
|
+
it("returns no paid execution when the budget is below the live quote", async () => {
|
|
395
|
+
const cheaperPlaybook = {
|
|
396
|
+
...playbook,
|
|
397
|
+
id: "pb_quick_ads_v1",
|
|
398
|
+
slug: "quick-ads-check",
|
|
399
|
+
name: "Quick Ads Check",
|
|
400
|
+
current_quote: {
|
|
401
|
+
...playbook.current_quote,
|
|
402
|
+
estimated_cost_usd: 0.25,
|
|
403
|
+
step_count: 1,
|
|
404
|
+
blocking_issues: [],
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
mockApiGet
|
|
408
|
+
.mockResolvedValueOnce(playbook)
|
|
409
|
+
.mockResolvedValueOnce({ playbooks: [cheaperPlaybook] });
|
|
410
|
+
mockApiPost.mockResolvedValueOnce({
|
|
411
|
+
playbook,
|
|
412
|
+
budget_usd: 0.5,
|
|
413
|
+
budget_sufficient: false,
|
|
414
|
+
remaining_budget_usd: 0,
|
|
415
|
+
});
|
|
416
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
417
|
+
const harness = makeServerHarness();
|
|
418
|
+
registerPlaybookTools(harness.server);
|
|
419
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
420
|
+
slug: "competitor-ads",
|
|
421
|
+
input: { domain: "notion.so" },
|
|
422
|
+
budget: 0.5,
|
|
423
|
+
pay_with: "card",
|
|
424
|
+
});
|
|
425
|
+
const text = flattenToolText(result);
|
|
426
|
+
expect(text).toContain("quote exceeds the budget");
|
|
427
|
+
expect(text).toContain("Estimated cost: $1.25");
|
|
428
|
+
expect(text).toContain("Cheaper supported alternatives under this budget");
|
|
429
|
+
expect(text).toContain("Quick Ads Check (quick-ads-check) — $0.2500 est.");
|
|
430
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-quotes", expect.objectContaining({
|
|
431
|
+
slug: "competitor-ads",
|
|
432
|
+
budget: 0.5,
|
|
433
|
+
}));
|
|
434
|
+
expect(mockApiGet).toHaveBeenCalledWith("/playbooks?max_budget=0.5&limit=4&sort=price");
|
|
435
|
+
expect(mockApiPost).not.toHaveBeenCalledWith("/playbook-runs", expect.anything());
|
|
436
|
+
expect(mockApiPostWithPayment).not.toHaveBeenCalled();
|
|
437
|
+
});
|
|
438
|
+
it("creates a run, executes child agent, records step receipt, and completes", async () => {
|
|
439
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
440
|
+
mockApiGet
|
|
441
|
+
.mockResolvedValueOnce(playbook)
|
|
442
|
+
.mockResolvedValueOnce({
|
|
443
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
444
|
+
status: "completed",
|
|
445
|
+
playbook_id: playbook.id,
|
|
446
|
+
playbook_slug: playbook.slug,
|
|
447
|
+
playbook_version: 1,
|
|
448
|
+
budget_usd: 5,
|
|
449
|
+
quoted_cost_usd: 1.25,
|
|
450
|
+
charged_usd: 1.25,
|
|
451
|
+
refunded_usd: 0,
|
|
452
|
+
remaining_budget_usd: 3.75,
|
|
453
|
+
steps: [
|
|
454
|
+
{
|
|
455
|
+
playbook_step_id: "ads",
|
|
456
|
+
step_index: 0,
|
|
457
|
+
node_type: "aw_agent",
|
|
458
|
+
agent_slug: "ad-strategy-intel",
|
|
459
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
460
|
+
provider_id: null,
|
|
461
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
462
|
+
status: "succeeded",
|
|
463
|
+
quoted_cost_usd: 1.25,
|
|
464
|
+
charged_usd: 1.25,
|
|
465
|
+
refunded_usd: 0,
|
|
466
|
+
},
|
|
467
|
+
],
|
|
468
|
+
});
|
|
469
|
+
mockApiPost
|
|
470
|
+
.mockResolvedValueOnce({
|
|
471
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
472
|
+
steps: playbook.current_quote.steps,
|
|
473
|
+
})
|
|
474
|
+
.mockResolvedValueOnce({ ok: true })
|
|
475
|
+
.mockRejectedValueOnce(new Error("temporary receipt write failure"))
|
|
476
|
+
.mockResolvedValueOnce({ ok: true })
|
|
477
|
+
.mockRejectedValueOnce({ status: 402, message: "payment required" })
|
|
478
|
+
.mockResolvedValueOnce({ ok: true })
|
|
479
|
+
.mockResolvedValueOnce({ ok: true });
|
|
480
|
+
mockApiPostWithPayment.mockResolvedValueOnce({
|
|
481
|
+
status: "success",
|
|
482
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
483
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
484
|
+
output: { rows: 3 },
|
|
485
|
+
cost: 1.25,
|
|
486
|
+
feedback_token: "token",
|
|
487
|
+
});
|
|
488
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
489
|
+
const harness = makeServerHarness();
|
|
490
|
+
registerPlaybookTools(harness.server);
|
|
491
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
492
|
+
slug: "competitor-ads",
|
|
493
|
+
input: { domain: "notion.so" },
|
|
494
|
+
budget: 5,
|
|
495
|
+
pay_with: "card",
|
|
496
|
+
confirmed: true,
|
|
497
|
+
});
|
|
498
|
+
const text = flattenToolText(result);
|
|
499
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs", expect.objectContaining({
|
|
500
|
+
slug: "competitor-ads",
|
|
501
|
+
budget: 5,
|
|
502
|
+
}));
|
|
503
|
+
expect(mockApiPostWithPayment).toHaveBeenCalledWith("/agents/11111111-1111-4111-8111-111111111111/run", expect.objectContaining({
|
|
504
|
+
input: expect.objectContaining({
|
|
505
|
+
startUrls: [{
|
|
506
|
+
url: "https://notion.so",
|
|
507
|
+
}],
|
|
508
|
+
maxAds: 1,
|
|
509
|
+
}),
|
|
510
|
+
playbook_context: {
|
|
511
|
+
playbook_run_id: "22222222-2222-4222-8222-222222222222",
|
|
512
|
+
playbook_id: "pb_competitor_ads_v1",
|
|
513
|
+
playbook_slug: "competitor-ads",
|
|
514
|
+
playbook_step_id: "ads",
|
|
515
|
+
playbook_step_index: 0,
|
|
516
|
+
},
|
|
517
|
+
}), "card");
|
|
518
|
+
expect(mockRecordSpend).toHaveBeenCalledWith("card", 1.25);
|
|
519
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads", expect.objectContaining({
|
|
520
|
+
status: "succeeded",
|
|
521
|
+
error_code: null,
|
|
522
|
+
failure_message: null,
|
|
523
|
+
}));
|
|
524
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/status", expect.objectContaining({
|
|
525
|
+
status: "completed",
|
|
526
|
+
error_code: null,
|
|
527
|
+
failure_message: null,
|
|
528
|
+
}));
|
|
529
|
+
expect(mockStoreFeedbackToken).toHaveBeenCalledWith("33333333-3333-4333-8333-333333333333", "token", "11111111-1111-4111-8111-111111111111");
|
|
530
|
+
expect(text).toContain("Playbook run 22222222-2222-4222-8222-222222222222");
|
|
531
|
+
expect(text).toContain("Charged: $1.25");
|
|
532
|
+
expect(text).toContain("Was this playbook useful?");
|
|
533
|
+
expect(text).toContain("favorite_playbook({ slug: \"competitor-ads\" })");
|
|
534
|
+
expect(text).toContain("rate_playbook({ slug: \"competitor-ads\", run_id: \"22222222-2222-4222-8222-222222222222\"");
|
|
535
|
+
});
|
|
536
|
+
it("uploads local file inputs before run creation and child execution", async () => {
|
|
537
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
538
|
+
mockUploadLocalFiles.mockResolvedValueOnce({
|
|
539
|
+
input: { domain: "https://files.example/notion.txt" },
|
|
540
|
+
uploads: [{
|
|
541
|
+
field: "domain",
|
|
542
|
+
originalPath: "/tmp/notion.txt",
|
|
543
|
+
url: "https://files.example/notion.txt",
|
|
544
|
+
}],
|
|
545
|
+
});
|
|
546
|
+
mockApiGet
|
|
547
|
+
.mockResolvedValueOnce(playbook)
|
|
548
|
+
.mockResolvedValueOnce({
|
|
549
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
550
|
+
status: "completed",
|
|
551
|
+
playbook_id: playbook.id,
|
|
552
|
+
playbook_slug: playbook.slug,
|
|
553
|
+
playbook_version: 1,
|
|
554
|
+
budget_usd: 5,
|
|
555
|
+
quoted_cost_usd: 1.25,
|
|
556
|
+
charged_usd: 1.25,
|
|
557
|
+
refunded_usd: 0,
|
|
558
|
+
remaining_budget_usd: 3.75,
|
|
559
|
+
steps: [{
|
|
560
|
+
playbook_step_id: "ads",
|
|
561
|
+
step_index: 0,
|
|
562
|
+
node_type: "aw_agent",
|
|
563
|
+
agent_slug: "ad-strategy-intel",
|
|
564
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
565
|
+
provider_id: null,
|
|
566
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
567
|
+
status: "succeeded",
|
|
568
|
+
quoted_cost_usd: 1.25,
|
|
569
|
+
charged_usd: 1.25,
|
|
570
|
+
refunded_usd: 0,
|
|
571
|
+
}],
|
|
572
|
+
});
|
|
573
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
574
|
+
if (path === "/playbook-runs") {
|
|
575
|
+
return {
|
|
576
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
577
|
+
steps: playbook.current_quote.steps,
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
581
|
+
throw { status: 402, message: "payment required" };
|
|
582
|
+
}
|
|
583
|
+
return { ok: true };
|
|
584
|
+
});
|
|
585
|
+
mockApiPostWithPayment.mockResolvedValueOnce({
|
|
586
|
+
status: "success",
|
|
587
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
588
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
589
|
+
output: { rows: 3 },
|
|
590
|
+
cost: 1.25,
|
|
591
|
+
});
|
|
592
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
593
|
+
const harness = makeServerHarness();
|
|
594
|
+
registerPlaybookTools(harness.server);
|
|
595
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
596
|
+
slug: "competitor-ads",
|
|
597
|
+
input: { domain: "/tmp/notion.txt" },
|
|
598
|
+
budget: 5,
|
|
599
|
+
pay_with: "base",
|
|
600
|
+
confirmed: true,
|
|
601
|
+
});
|
|
602
|
+
const text = flattenToolText(result);
|
|
603
|
+
expect(mockUploadLocalFiles).toHaveBeenCalledWith({ domain: "/tmp/notion.txt" });
|
|
604
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs", expect.objectContaining({
|
|
605
|
+
input: { domain: "https://files.example/notion.txt" },
|
|
606
|
+
}));
|
|
607
|
+
expect(mockApiPostWithPayment).toHaveBeenCalledWith("/agents/11111111-1111-4111-8111-111111111111/run", expect.objectContaining({
|
|
608
|
+
input: expect.objectContaining({
|
|
609
|
+
domain: "https://files.example/notion.txt",
|
|
610
|
+
}),
|
|
611
|
+
}), "base");
|
|
612
|
+
expect(text).toContain("Uploaded domain: /tmp/notion.txt -> https://files.example/notion.txt");
|
|
613
|
+
});
|
|
614
|
+
it("records credit-pack child consumption distinctly from direct charges", async () => {
|
|
615
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
616
|
+
mockApiGet
|
|
617
|
+
.mockResolvedValueOnce(playbook)
|
|
618
|
+
.mockResolvedValueOnce({
|
|
619
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
620
|
+
status: "completed",
|
|
621
|
+
playbook_id: playbook.id,
|
|
622
|
+
playbook_slug: playbook.slug,
|
|
623
|
+
playbook_version: 1,
|
|
624
|
+
budget_usd: 5,
|
|
625
|
+
quoted_cost_usd: 1.25,
|
|
626
|
+
charged_usd: 0,
|
|
627
|
+
refunded_usd: 0,
|
|
628
|
+
remaining_budget_usd: 5,
|
|
629
|
+
steps: [
|
|
630
|
+
{
|
|
631
|
+
playbook_step_id: "ads",
|
|
632
|
+
step_index: 0,
|
|
633
|
+
node_type: "aw_agent",
|
|
634
|
+
agent_slug: "ad-strategy-intel",
|
|
635
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
636
|
+
provider_id: null,
|
|
637
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
638
|
+
consumption_mode: "credit_pack",
|
|
639
|
+
status: "succeeded",
|
|
640
|
+
quoted_cost_usd: 1.25,
|
|
641
|
+
charged_usd: 0,
|
|
642
|
+
refunded_usd: 0,
|
|
643
|
+
},
|
|
644
|
+
],
|
|
645
|
+
});
|
|
646
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
647
|
+
if (path === "/playbook-runs") {
|
|
648
|
+
return {
|
|
649
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
650
|
+
steps: playbook.current_quote.steps,
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
654
|
+
return {
|
|
655
|
+
status: "success",
|
|
656
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
657
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
658
|
+
output: { rows: 3 },
|
|
659
|
+
cost: 1.25,
|
|
660
|
+
consumption_mode: "credit_pack",
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
return { ok: true };
|
|
664
|
+
});
|
|
665
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
666
|
+
const harness = makeServerHarness();
|
|
667
|
+
registerPlaybookTools(harness.server);
|
|
668
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
669
|
+
slug: "competitor-ads",
|
|
670
|
+
input: { domain: "notion.so" },
|
|
671
|
+
budget: 5,
|
|
672
|
+
pay_with: "card",
|
|
673
|
+
confirmed: true,
|
|
674
|
+
});
|
|
675
|
+
const text = flattenToolText(result);
|
|
676
|
+
expect(mockApiPostWithPayment).not.toHaveBeenCalled();
|
|
677
|
+
expect(mockRecordSpend).not.toHaveBeenCalled();
|
|
678
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads", expect.objectContaining({
|
|
679
|
+
status: "succeeded",
|
|
680
|
+
consumption_mode: "credit_pack",
|
|
681
|
+
charged_usd: 0,
|
|
682
|
+
}));
|
|
683
|
+
expect(text).toContain("Charged: $0.00");
|
|
684
|
+
expect(text).toContain("credit pack");
|
|
685
|
+
});
|
|
686
|
+
it("URL-encodes fanout step ids when recording receipts", async () => {
|
|
687
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
688
|
+
const fanoutPlaybook = {
|
|
689
|
+
...playbook,
|
|
690
|
+
current_quote: {
|
|
691
|
+
...playbook.current_quote,
|
|
692
|
+
steps: [{
|
|
693
|
+
...playbook.current_quote.steps[0],
|
|
694
|
+
id: "people:1",
|
|
695
|
+
}],
|
|
696
|
+
},
|
|
697
|
+
};
|
|
698
|
+
mockApiGet
|
|
699
|
+
.mockResolvedValueOnce(fanoutPlaybook)
|
|
700
|
+
.mockResolvedValueOnce({
|
|
701
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
702
|
+
status: "completed",
|
|
703
|
+
playbook_id: playbook.id,
|
|
704
|
+
playbook_slug: playbook.slug,
|
|
705
|
+
playbook_version: 1,
|
|
706
|
+
budget_usd: 5,
|
|
707
|
+
quoted_cost_usd: 1.25,
|
|
708
|
+
charged_usd: 1.25,
|
|
709
|
+
refunded_usd: 0,
|
|
710
|
+
remaining_budget_usd: 3.75,
|
|
711
|
+
steps: [{
|
|
712
|
+
playbook_step_id: "people:1",
|
|
713
|
+
step_index: 0,
|
|
714
|
+
node_type: "aw_agent",
|
|
715
|
+
agent_slug: "ad-strategy-intel",
|
|
716
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
717
|
+
provider_id: null,
|
|
718
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
719
|
+
consumption_mode: "direct_charge",
|
|
720
|
+
status: "succeeded",
|
|
721
|
+
quoted_cost_usd: 1.25,
|
|
722
|
+
charged_usd: 1.25,
|
|
723
|
+
refunded_usd: 0,
|
|
724
|
+
}],
|
|
725
|
+
});
|
|
726
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
727
|
+
if (path === "/playbook-runs") {
|
|
728
|
+
return {
|
|
729
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
730
|
+
steps: fanoutPlaybook.current_quote.steps,
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
734
|
+
return {
|
|
735
|
+
status: "success",
|
|
736
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
737
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
738
|
+
output: { rows: 3 },
|
|
739
|
+
cost: 1.25,
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
return { ok: true };
|
|
743
|
+
});
|
|
744
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
745
|
+
const harness = makeServerHarness();
|
|
746
|
+
registerPlaybookTools(harness.server);
|
|
747
|
+
await harness.handlers.get("run_playbook")({
|
|
748
|
+
slug: "competitor-ads",
|
|
749
|
+
input: { domain: "notion.so" },
|
|
750
|
+
budget: 5,
|
|
751
|
+
pay_with: "base",
|
|
752
|
+
confirmed: true,
|
|
753
|
+
});
|
|
754
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/people%3A1", expect.objectContaining({ status: "running" }));
|
|
755
|
+
expect(mockApiPost).toHaveBeenCalledWith("/agents/11111111-1111-4111-8111-111111111111/run", expect.objectContaining({
|
|
756
|
+
playbook_context: expect.objectContaining({ playbook_step_id: "people:1" }),
|
|
757
|
+
}), expect.objectContaining({ ensureConsumerPrincipal: true }));
|
|
758
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/people%3A1", expect.objectContaining({ status: "succeeded" }));
|
|
759
|
+
});
|
|
760
|
+
it("resumes an existing run without creating a new run or rerunning completed steps", async () => {
|
|
761
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
762
|
+
const twoStepPlaybook = {
|
|
763
|
+
...playbook,
|
|
764
|
+
current_quote: {
|
|
765
|
+
...playbook.current_quote,
|
|
766
|
+
estimated_cost_usd: 2,
|
|
767
|
+
step_count: 2,
|
|
768
|
+
steps: [
|
|
769
|
+
playbook.current_quote.steps[0],
|
|
770
|
+
{
|
|
771
|
+
...playbook.current_quote.steps[0],
|
|
772
|
+
id: "traffic",
|
|
773
|
+
index: 1,
|
|
774
|
+
agent_slug: "traffic-estimator",
|
|
775
|
+
agent_id: "44444444-4444-4444-8444-444444444444",
|
|
776
|
+
agent_name: "Traffic Estimator",
|
|
777
|
+
quoted_cost_usd: 0.75,
|
|
778
|
+
unit_price_usd: 0.75,
|
|
779
|
+
},
|
|
780
|
+
],
|
|
781
|
+
},
|
|
782
|
+
};
|
|
783
|
+
mockApiGet
|
|
784
|
+
.mockResolvedValueOnce({
|
|
785
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
786
|
+
status: "paused",
|
|
787
|
+
playbook_id: playbook.id,
|
|
788
|
+
playbook_slug: playbook.slug,
|
|
789
|
+
playbook_version: 1,
|
|
790
|
+
input: { domain: "notion.so" },
|
|
791
|
+
budget_usd: 5,
|
|
792
|
+
quoted_cost_usd: 2,
|
|
793
|
+
charged_usd: 1.25,
|
|
794
|
+
refunded_usd: 0,
|
|
795
|
+
remaining_budget_usd: 3.75,
|
|
796
|
+
steps: [
|
|
797
|
+
{
|
|
798
|
+
playbook_step_id: "ads",
|
|
799
|
+
step_index: 0,
|
|
800
|
+
node_type: "aw_agent",
|
|
801
|
+
agent_slug: "ad-strategy-intel",
|
|
802
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
803
|
+
provider_id: null,
|
|
804
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
805
|
+
status: "succeeded",
|
|
806
|
+
quoted_cost_usd: 1.25,
|
|
807
|
+
charged_usd: 1.25,
|
|
808
|
+
refunded_usd: 0,
|
|
809
|
+
output: { ads: 3 },
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
playbook_step_id: "traffic",
|
|
813
|
+
step_index: 1,
|
|
814
|
+
node_type: "aw_agent",
|
|
815
|
+
agent_slug: "traffic-estimator",
|
|
816
|
+
agent_id: "44444444-4444-4444-8444-444444444444",
|
|
817
|
+
provider_id: null,
|
|
818
|
+
job_id: null,
|
|
819
|
+
status: "pending",
|
|
820
|
+
quoted_cost_usd: 0.75,
|
|
821
|
+
charged_usd: 0,
|
|
822
|
+
refunded_usd: 0,
|
|
823
|
+
},
|
|
824
|
+
],
|
|
825
|
+
})
|
|
826
|
+
.mockResolvedValueOnce(twoStepPlaybook)
|
|
827
|
+
.mockResolvedValueOnce({
|
|
828
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
829
|
+
status: "completed",
|
|
830
|
+
playbook_id: playbook.id,
|
|
831
|
+
playbook_slug: playbook.slug,
|
|
832
|
+
playbook_version: 1,
|
|
833
|
+
budget_usd: 5,
|
|
834
|
+
quoted_cost_usd: 2,
|
|
835
|
+
charged_usd: 2,
|
|
836
|
+
refunded_usd: 0,
|
|
837
|
+
remaining_budget_usd: 3,
|
|
838
|
+
steps: [
|
|
839
|
+
{
|
|
840
|
+
playbook_step_id: "ads",
|
|
841
|
+
step_index: 0,
|
|
842
|
+
node_type: "aw_agent",
|
|
843
|
+
agent_slug: "ad-strategy-intel",
|
|
844
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
845
|
+
provider_id: null,
|
|
846
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
847
|
+
status: "succeeded",
|
|
848
|
+
quoted_cost_usd: 1.25,
|
|
849
|
+
charged_usd: 1.25,
|
|
850
|
+
refunded_usd: 0,
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
playbook_step_id: "traffic",
|
|
854
|
+
step_index: 1,
|
|
855
|
+
node_type: "aw_agent",
|
|
856
|
+
agent_slug: "traffic-estimator",
|
|
857
|
+
agent_id: "44444444-4444-4444-8444-444444444444",
|
|
858
|
+
provider_id: null,
|
|
859
|
+
job_id: "55555555-5555-4555-8555-555555555555",
|
|
860
|
+
status: "succeeded",
|
|
861
|
+
quoted_cost_usd: 0.75,
|
|
862
|
+
charged_usd: 0.75,
|
|
863
|
+
refunded_usd: 0,
|
|
864
|
+
},
|
|
865
|
+
],
|
|
866
|
+
});
|
|
867
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
868
|
+
if (path === "/playbook-runs") {
|
|
869
|
+
throw new Error("resume should not create a new run");
|
|
870
|
+
}
|
|
871
|
+
if (path === "/agents/44444444-4444-4444-8444-444444444444/run") {
|
|
872
|
+
throw { status: 402, message: "payment required" };
|
|
873
|
+
}
|
|
874
|
+
return { ok: true };
|
|
875
|
+
});
|
|
876
|
+
mockApiPostWithPayment.mockResolvedValueOnce({
|
|
877
|
+
status: "success",
|
|
878
|
+
job_id: "55555555-5555-4555-8555-555555555555",
|
|
879
|
+
agent_id: "44444444-4444-4444-8444-444444444444",
|
|
880
|
+
output: { traffic: "ok" },
|
|
881
|
+
cost: 0.75,
|
|
882
|
+
});
|
|
883
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
884
|
+
const harness = makeServerHarness();
|
|
885
|
+
registerPlaybookTools(harness.server);
|
|
886
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
887
|
+
resume_run_id: "22222222-2222-4222-8222-222222222222",
|
|
888
|
+
budget: 5,
|
|
889
|
+
pay_with: "card",
|
|
890
|
+
confirmed: true,
|
|
891
|
+
});
|
|
892
|
+
const text = flattenToolText(result);
|
|
893
|
+
expect(mockApiPost).not.toHaveBeenCalledWith("/playbook-runs", expect.anything());
|
|
894
|
+
expect(mockApiPost).not.toHaveBeenCalledWith("/agents/11111111-1111-4111-8111-111111111111/run", expect.anything(), expect.anything());
|
|
895
|
+
expect(mockApiPostWithPayment).toHaveBeenCalledTimes(1);
|
|
896
|
+
expect(mockApiPostWithPayment).toHaveBeenCalledWith("/agents/44444444-4444-4444-8444-444444444444/run", expect.objectContaining({
|
|
897
|
+
playbook_context: expect.objectContaining({
|
|
898
|
+
playbook_run_id: "22222222-2222-4222-8222-222222222222",
|
|
899
|
+
playbook_step_id: "traffic",
|
|
900
|
+
}),
|
|
901
|
+
}), "card");
|
|
902
|
+
expect(text).toContain("completed");
|
|
903
|
+
expect(text).toContain("traffic-estimator");
|
|
904
|
+
});
|
|
905
|
+
it("uses net charged amount after refunds when enforcing resume budget", async () => {
|
|
906
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
907
|
+
mockApiGet
|
|
908
|
+
.mockResolvedValueOnce({
|
|
909
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
910
|
+
status: "paused",
|
|
911
|
+
playbook_id: playbook.id,
|
|
912
|
+
playbook_slug: playbook.slug,
|
|
913
|
+
playbook_version: 1,
|
|
914
|
+
input: { domain: "notion.so" },
|
|
915
|
+
budget_usd: 1.25,
|
|
916
|
+
quoted_cost_usd: 1.25,
|
|
917
|
+
charged_usd: 1.25,
|
|
918
|
+
refunded_usd: 1.25,
|
|
919
|
+
remaining_budget_usd: 1.25,
|
|
920
|
+
error_code: "UPSTREAM_FAILED",
|
|
921
|
+
steps: [{
|
|
922
|
+
playbook_step_id: "ads",
|
|
923
|
+
step_index: 0,
|
|
924
|
+
node_type: "aw_agent",
|
|
925
|
+
agent_slug: "ad-strategy-intel",
|
|
926
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
927
|
+
provider_id: null,
|
|
928
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
929
|
+
status: "failed",
|
|
930
|
+
quoted_cost_usd: 1.25,
|
|
931
|
+
charged_usd: 1.25,
|
|
932
|
+
refunded_usd: 1.25,
|
|
933
|
+
error_code: "UPSTREAM_FAILED",
|
|
934
|
+
}],
|
|
935
|
+
})
|
|
936
|
+
.mockResolvedValueOnce(playbook)
|
|
937
|
+
.mockResolvedValueOnce({
|
|
938
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
939
|
+
status: "completed",
|
|
940
|
+
playbook_id: playbook.id,
|
|
941
|
+
playbook_slug: playbook.slug,
|
|
942
|
+
playbook_version: 1,
|
|
943
|
+
budget_usd: 1.25,
|
|
944
|
+
quoted_cost_usd: 1.25,
|
|
945
|
+
charged_usd: 2.5,
|
|
946
|
+
refunded_usd: 1.25,
|
|
947
|
+
remaining_budget_usd: 0,
|
|
948
|
+
steps: [{
|
|
949
|
+
playbook_step_id: "ads",
|
|
950
|
+
step_index: 0,
|
|
951
|
+
node_type: "aw_agent",
|
|
952
|
+
agent_slug: "ad-strategy-intel",
|
|
953
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
954
|
+
provider_id: null,
|
|
955
|
+
job_id: "55555555-5555-4555-8555-555555555555",
|
|
956
|
+
status: "succeeded",
|
|
957
|
+
quoted_cost_usd: 1.25,
|
|
958
|
+
charged_usd: 1.25,
|
|
959
|
+
refunded_usd: 0,
|
|
960
|
+
}],
|
|
961
|
+
});
|
|
962
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
963
|
+
if (path === "/playbook-runs") {
|
|
964
|
+
throw new Error("resume should not create a new run");
|
|
965
|
+
}
|
|
966
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
967
|
+
throw { status: 402, message: "payment required" };
|
|
968
|
+
}
|
|
969
|
+
return { ok: true };
|
|
970
|
+
});
|
|
971
|
+
mockApiPostWithPayment.mockResolvedValueOnce({
|
|
972
|
+
status: "success",
|
|
973
|
+
job_id: "55555555-5555-4555-8555-555555555555",
|
|
974
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
975
|
+
output: { retry: "ok" },
|
|
976
|
+
cost: 1.25,
|
|
977
|
+
});
|
|
978
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
979
|
+
const harness = makeServerHarness();
|
|
980
|
+
registerPlaybookTools(harness.server);
|
|
981
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
982
|
+
resume_run_id: "22222222-2222-4222-8222-222222222222",
|
|
983
|
+
budget: 1.25,
|
|
984
|
+
pay_with: "card",
|
|
985
|
+
confirmed: true,
|
|
986
|
+
});
|
|
987
|
+
const text = flattenToolText(result);
|
|
988
|
+
expect(mockApiPostWithPayment).toHaveBeenCalledWith("/agents/11111111-1111-4111-8111-111111111111/run", expect.anything(), "card");
|
|
989
|
+
expect(mockApiPost).not.toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads", expect.objectContaining({
|
|
990
|
+
status: "skipped",
|
|
991
|
+
error_code: "BUDGET_EXHAUSTED",
|
|
992
|
+
}));
|
|
993
|
+
expect(text).toContain("completed");
|
|
994
|
+
});
|
|
995
|
+
it("pauses without another payment when the next step would exceed the budget", async () => {
|
|
996
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
997
|
+
const twoStepPlaybook = {
|
|
998
|
+
...playbook,
|
|
999
|
+
current_quote: {
|
|
1000
|
+
...playbook.current_quote,
|
|
1001
|
+
estimated_cost_usd: 2,
|
|
1002
|
+
step_count: 2,
|
|
1003
|
+
steps: [
|
|
1004
|
+
playbook.current_quote.steps[0],
|
|
1005
|
+
{
|
|
1006
|
+
...playbook.current_quote.steps[0],
|
|
1007
|
+
id: "traffic",
|
|
1008
|
+
index: 1,
|
|
1009
|
+
agent_slug: "traffic-estimator",
|
|
1010
|
+
agent_id: "44444444-4444-4444-8444-444444444444",
|
|
1011
|
+
agent_name: "Traffic Estimator",
|
|
1012
|
+
quoted_cost_usd: 1,
|
|
1013
|
+
unit_price_usd: 1,
|
|
1014
|
+
},
|
|
1015
|
+
],
|
|
1016
|
+
},
|
|
1017
|
+
};
|
|
1018
|
+
mockApiGet
|
|
1019
|
+
.mockResolvedValueOnce(twoStepPlaybook)
|
|
1020
|
+
.mockResolvedValueOnce({
|
|
1021
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1022
|
+
status: "paused",
|
|
1023
|
+
playbook_id: playbook.id,
|
|
1024
|
+
playbook_slug: playbook.slug,
|
|
1025
|
+
playbook_version: 1,
|
|
1026
|
+
budget_usd: 2.1,
|
|
1027
|
+
quoted_cost_usd: 2,
|
|
1028
|
+
charged_usd: 1.5,
|
|
1029
|
+
refunded_usd: 0,
|
|
1030
|
+
remaining_budget_usd: 0.6,
|
|
1031
|
+
error_code: "BUDGET_EXHAUSTED",
|
|
1032
|
+
steps: [
|
|
1033
|
+
{
|
|
1034
|
+
playbook_step_id: "ads",
|
|
1035
|
+
step_index: 0,
|
|
1036
|
+
node_type: "aw_agent",
|
|
1037
|
+
agent_slug: "ad-strategy-intel",
|
|
1038
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1039
|
+
provider_id: null,
|
|
1040
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1041
|
+
status: "succeeded",
|
|
1042
|
+
quoted_cost_usd: 1,
|
|
1043
|
+
charged_usd: 1.5,
|
|
1044
|
+
refunded_usd: 0,
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
playbook_step_id: "traffic",
|
|
1048
|
+
step_index: 1,
|
|
1049
|
+
node_type: "aw_agent",
|
|
1050
|
+
agent_slug: "traffic-estimator",
|
|
1051
|
+
agent_id: "44444444-4444-4444-8444-444444444444",
|
|
1052
|
+
provider_id: null,
|
|
1053
|
+
job_id: null,
|
|
1054
|
+
status: "skipped",
|
|
1055
|
+
quoted_cost_usd: 1,
|
|
1056
|
+
charged_usd: 0,
|
|
1057
|
+
refunded_usd: 0,
|
|
1058
|
+
error_code: "BUDGET_EXHAUSTED",
|
|
1059
|
+
},
|
|
1060
|
+
],
|
|
1061
|
+
});
|
|
1062
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
1063
|
+
if (path === "/playbook-runs") {
|
|
1064
|
+
return {
|
|
1065
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1066
|
+
steps: twoStepPlaybook.current_quote.steps,
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1070
|
+
throw { status: 402, message: "payment required" };
|
|
1071
|
+
}
|
|
1072
|
+
return { ok: true };
|
|
1073
|
+
});
|
|
1074
|
+
mockApiPostWithPayment.mockResolvedValueOnce({
|
|
1075
|
+
status: "success",
|
|
1076
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1077
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1078
|
+
output: { ads: 3 },
|
|
1079
|
+
cost: 1.5,
|
|
1080
|
+
});
|
|
1081
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1082
|
+
const harness = makeServerHarness();
|
|
1083
|
+
registerPlaybookTools(harness.server);
|
|
1084
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1085
|
+
slug: "competitor-ads",
|
|
1086
|
+
input: { domain: "notion.so" },
|
|
1087
|
+
budget: 2.1,
|
|
1088
|
+
pay_with: "card",
|
|
1089
|
+
confirmed: true,
|
|
1090
|
+
});
|
|
1091
|
+
const text = flattenToolText(result);
|
|
1092
|
+
expect(mockApiPostWithPayment).toHaveBeenCalledTimes(1);
|
|
1093
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/traffic", expect.objectContaining({
|
|
1094
|
+
status: "skipped",
|
|
1095
|
+
consumption_mode: "not_charged",
|
|
1096
|
+
error_code: "BUDGET_EXHAUSTED",
|
|
1097
|
+
}));
|
|
1098
|
+
expect(text).toContain("BUDGET_EXHAUSTED");
|
|
1099
|
+
expect(text).toContain("Resume:");
|
|
1100
|
+
});
|
|
1101
|
+
it("records payment rejection as an uncharged skipped step", async () => {
|
|
1102
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1103
|
+
mockApiGet
|
|
1104
|
+
.mockResolvedValueOnce(playbook)
|
|
1105
|
+
.mockResolvedValueOnce({
|
|
1106
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1107
|
+
status: "paused",
|
|
1108
|
+
playbook_id: playbook.id,
|
|
1109
|
+
playbook_slug: playbook.slug,
|
|
1110
|
+
playbook_version: 1,
|
|
1111
|
+
budget_usd: 5,
|
|
1112
|
+
quoted_cost_usd: 1.25,
|
|
1113
|
+
charged_usd: 0,
|
|
1114
|
+
refunded_usd: 0,
|
|
1115
|
+
remaining_budget_usd: 5,
|
|
1116
|
+
error_code: "PAYMENT_REJECTED",
|
|
1117
|
+
steps: [{
|
|
1118
|
+
playbook_step_id: "ads",
|
|
1119
|
+
step_index: 0,
|
|
1120
|
+
node_type: "aw_agent",
|
|
1121
|
+
agent_slug: "ad-strategy-intel",
|
|
1122
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1123
|
+
provider_id: null,
|
|
1124
|
+
job_id: null,
|
|
1125
|
+
status: "skipped",
|
|
1126
|
+
quoted_cost_usd: 1.25,
|
|
1127
|
+
charged_usd: 0,
|
|
1128
|
+
refunded_usd: 0,
|
|
1129
|
+
error_code: "PAYMENT_REJECTED",
|
|
1130
|
+
}],
|
|
1131
|
+
});
|
|
1132
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
1133
|
+
if (path === "/playbook-runs") {
|
|
1134
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: playbook.current_quote.steps };
|
|
1135
|
+
}
|
|
1136
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1137
|
+
throw { status: 402, message: "payment required" };
|
|
1138
|
+
}
|
|
1139
|
+
return { ok: true };
|
|
1140
|
+
});
|
|
1141
|
+
mockApiPostWithPayment.mockRejectedValueOnce({ status: 402, message: "wallet declined" });
|
|
1142
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1143
|
+
const harness = makeServerHarness();
|
|
1144
|
+
registerPlaybookTools(harness.server);
|
|
1145
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1146
|
+
slug: "competitor-ads",
|
|
1147
|
+
input: { domain: "notion.so" },
|
|
1148
|
+
budget: 5,
|
|
1149
|
+
pay_with: "card",
|
|
1150
|
+
confirmed: true,
|
|
1151
|
+
});
|
|
1152
|
+
const text = flattenToolText(result);
|
|
1153
|
+
expect(mockRecordSpend).not.toHaveBeenCalled();
|
|
1154
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads", expect.objectContaining({
|
|
1155
|
+
status: "skipped",
|
|
1156
|
+
consumption_mode: "not_charged",
|
|
1157
|
+
error_code: "PAYMENT_REJECTED",
|
|
1158
|
+
}));
|
|
1159
|
+
expect(text).toContain("wallet_status");
|
|
1160
|
+
});
|
|
1161
|
+
it("records schema mismatch before payment as an uncharged skipped step", async () => {
|
|
1162
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1163
|
+
mockApiGet
|
|
1164
|
+
.mockResolvedValueOnce(playbook)
|
|
1165
|
+
.mockResolvedValueOnce({
|
|
1166
|
+
id: "11111111-1111-4111-8111-111111111111",
|
|
1167
|
+
schema: {
|
|
1168
|
+
input: {
|
|
1169
|
+
inputSchema: {
|
|
1170
|
+
type: "object",
|
|
1171
|
+
properties: { prompt: { type: "string" } },
|
|
1172
|
+
required: ["prompt"],
|
|
1173
|
+
},
|
|
1174
|
+
},
|
|
1175
|
+
},
|
|
1176
|
+
})
|
|
1177
|
+
.mockResolvedValueOnce({
|
|
1178
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1179
|
+
status: "paused",
|
|
1180
|
+
playbook_id: playbook.id,
|
|
1181
|
+
playbook_slug: playbook.slug,
|
|
1182
|
+
playbook_version: 1,
|
|
1183
|
+
budget_usd: 5,
|
|
1184
|
+
quoted_cost_usd: 1.25,
|
|
1185
|
+
charged_usd: 0,
|
|
1186
|
+
refunded_usd: 0,
|
|
1187
|
+
remaining_budget_usd: 5,
|
|
1188
|
+
error_code: "SCHEMA_MISMATCH",
|
|
1189
|
+
steps: [{
|
|
1190
|
+
playbook_step_id: "ads",
|
|
1191
|
+
step_index: 0,
|
|
1192
|
+
node_type: "aw_agent",
|
|
1193
|
+
agent_slug: "ad-strategy-intel",
|
|
1194
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1195
|
+
provider_id: null,
|
|
1196
|
+
job_id: null,
|
|
1197
|
+
status: "skipped",
|
|
1198
|
+
quoted_cost_usd: 1.25,
|
|
1199
|
+
charged_usd: 0,
|
|
1200
|
+
refunded_usd: 0,
|
|
1201
|
+
error_code: "SCHEMA_MISMATCH",
|
|
1202
|
+
}],
|
|
1203
|
+
});
|
|
1204
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
1205
|
+
if (path === "/playbook-runs") {
|
|
1206
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: playbook.current_quote.steps };
|
|
1207
|
+
}
|
|
1208
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1209
|
+
throw { status: 400, message: "validation failed: missing required field prompt" };
|
|
1210
|
+
}
|
|
1211
|
+
return { ok: true };
|
|
1212
|
+
});
|
|
1213
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1214
|
+
const harness = makeServerHarness();
|
|
1215
|
+
registerPlaybookTools(harness.server);
|
|
1216
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1217
|
+
slug: "competitor-ads",
|
|
1218
|
+
input: { domain: "notion.so" },
|
|
1219
|
+
budget: 5,
|
|
1220
|
+
pay_with: "card",
|
|
1221
|
+
confirmed: true,
|
|
1222
|
+
});
|
|
1223
|
+
const text = flattenToolText(result);
|
|
1224
|
+
expect(mockApiPostWithPayment).not.toHaveBeenCalled();
|
|
1225
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads", expect.objectContaining({
|
|
1226
|
+
status: "skipped",
|
|
1227
|
+
consumption_mode: "not_charged",
|
|
1228
|
+
error_code: "SCHEMA_MISMATCH",
|
|
1229
|
+
}));
|
|
1230
|
+
expect(text).toContain("get_agent");
|
|
1231
|
+
});
|
|
1232
|
+
it("uses live child schema metadata to safely repair a field name before payment", async () => {
|
|
1233
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1234
|
+
mockApiGet
|
|
1235
|
+
.mockResolvedValueOnce(playbook)
|
|
1236
|
+
.mockResolvedValueOnce({
|
|
1237
|
+
id: "11111111-1111-4111-8111-111111111111",
|
|
1238
|
+
schema: {
|
|
1239
|
+
input: {
|
|
1240
|
+
inputSchema: {
|
|
1241
|
+
type: "object",
|
|
1242
|
+
properties: { q: { type: "string", description: "Search query" } },
|
|
1243
|
+
required: ["q"],
|
|
1244
|
+
},
|
|
1245
|
+
},
|
|
1246
|
+
},
|
|
1247
|
+
})
|
|
1248
|
+
.mockResolvedValueOnce({
|
|
1249
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1250
|
+
status: "completed",
|
|
1251
|
+
playbook_id: playbook.id,
|
|
1252
|
+
playbook_slug: playbook.slug,
|
|
1253
|
+
playbook_version: 1,
|
|
1254
|
+
budget_usd: 5,
|
|
1255
|
+
quoted_cost_usd: 1.25,
|
|
1256
|
+
charged_usd: 1.25,
|
|
1257
|
+
refunded_usd: 0,
|
|
1258
|
+
remaining_budget_usd: 3.75,
|
|
1259
|
+
steps: [{
|
|
1260
|
+
playbook_step_id: "ads",
|
|
1261
|
+
step_index: 0,
|
|
1262
|
+
node_type: "aw_agent",
|
|
1263
|
+
agent_slug: "ad-strategy-intel",
|
|
1264
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1265
|
+
provider_id: null,
|
|
1266
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1267
|
+
status: "succeeded",
|
|
1268
|
+
quoted_cost_usd: 1.25,
|
|
1269
|
+
charged_usd: 1.25,
|
|
1270
|
+
refunded_usd: 0,
|
|
1271
|
+
}],
|
|
1272
|
+
});
|
|
1273
|
+
let agentRunAttempts = 0;
|
|
1274
|
+
mockApiPost.mockImplementation(async (path, body) => {
|
|
1275
|
+
if (path === "/playbook-runs") {
|
|
1276
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: playbook.current_quote.steps };
|
|
1277
|
+
}
|
|
1278
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1279
|
+
agentRunAttempts += 1;
|
|
1280
|
+
if (agentRunAttempts === 1) {
|
|
1281
|
+
throw { status: 400, message: "validation failed: missing required field q" };
|
|
1282
|
+
}
|
|
1283
|
+
expect(body).toMatchObject({
|
|
1284
|
+
input: {
|
|
1285
|
+
q: "notion.so",
|
|
1286
|
+
},
|
|
1287
|
+
});
|
|
1288
|
+
expect(body.input).not.toHaveProperty("domain");
|
|
1289
|
+
return {
|
|
1290
|
+
status: "success",
|
|
1291
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1292
|
+
output: { repaired: true },
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
return { ok: true };
|
|
1296
|
+
});
|
|
1297
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1298
|
+
const harness = makeServerHarness();
|
|
1299
|
+
registerPlaybookTools(harness.server);
|
|
1300
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1301
|
+
slug: "competitor-ads",
|
|
1302
|
+
input: { domain: "notion.so" },
|
|
1303
|
+
budget: 5,
|
|
1304
|
+
pay_with: "card",
|
|
1305
|
+
confirmed: true,
|
|
1306
|
+
});
|
|
1307
|
+
const text = flattenToolText(result);
|
|
1308
|
+
expect(mockApiGet).toHaveBeenCalledWith("/agents/11111111-1111-4111-8111-111111111111");
|
|
1309
|
+
expect(agentRunAttempts).toBe(2);
|
|
1310
|
+
expect(mockApiPostWithPayment).not.toHaveBeenCalled();
|
|
1311
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads", expect.objectContaining({
|
|
1312
|
+
status: "succeeded",
|
|
1313
|
+
charged_usd: 1.25,
|
|
1314
|
+
}));
|
|
1315
|
+
expect(text).toContain("completed");
|
|
1316
|
+
});
|
|
1317
|
+
it("uses live child schema metadata to derive startUrls from a domain before payment", async () => {
|
|
1318
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1319
|
+
mockApiGet
|
|
1320
|
+
.mockResolvedValueOnce(playbook)
|
|
1321
|
+
.mockResolvedValueOnce({
|
|
1322
|
+
id: "11111111-1111-4111-8111-111111111111",
|
|
1323
|
+
schema: {
|
|
1324
|
+
input: {
|
|
1325
|
+
inputSchema: {
|
|
1326
|
+
type: "object",
|
|
1327
|
+
properties: {
|
|
1328
|
+
startUrls: { type: "array", items: { type: "object" } },
|
|
1329
|
+
maxAds: { type: "number", default: 10 },
|
|
1330
|
+
},
|
|
1331
|
+
required: ["startUrls"],
|
|
1332
|
+
},
|
|
1333
|
+
},
|
|
1334
|
+
},
|
|
1335
|
+
})
|
|
1336
|
+
.mockResolvedValueOnce({
|
|
1337
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1338
|
+
status: "completed",
|
|
1339
|
+
playbook_id: playbook.id,
|
|
1340
|
+
playbook_slug: playbook.slug,
|
|
1341
|
+
playbook_version: 1,
|
|
1342
|
+
budget_usd: 5,
|
|
1343
|
+
quoted_cost_usd: 1.25,
|
|
1344
|
+
charged_usd: 1.25,
|
|
1345
|
+
refunded_usd: 0,
|
|
1346
|
+
remaining_budget_usd: 3.75,
|
|
1347
|
+
steps: [{
|
|
1348
|
+
playbook_step_id: "ads",
|
|
1349
|
+
step_index: 0,
|
|
1350
|
+
node_type: "aw_agent",
|
|
1351
|
+
agent_slug: "ad-strategy-intel",
|
|
1352
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1353
|
+
provider_id: null,
|
|
1354
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1355
|
+
status: "succeeded",
|
|
1356
|
+
quoted_cost_usd: 1.25,
|
|
1357
|
+
charged_usd: 1.25,
|
|
1358
|
+
refunded_usd: 0,
|
|
1359
|
+
}],
|
|
1360
|
+
});
|
|
1361
|
+
let agentRunAttempts = 0;
|
|
1362
|
+
mockApiPost.mockImplementation(async (path, body) => {
|
|
1363
|
+
if (path === "/playbook-runs") {
|
|
1364
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: playbook.current_quote.steps };
|
|
1365
|
+
}
|
|
1366
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1367
|
+
agentRunAttempts += 1;
|
|
1368
|
+
if (agentRunAttempts === 1) {
|
|
1369
|
+
throw { status: 400, message: "validation failed: missing required field startUrls; unknown field domain" };
|
|
1370
|
+
}
|
|
1371
|
+
expect(body).toMatchObject({
|
|
1372
|
+
input: {
|
|
1373
|
+
startUrls: [{ url: "https://notion.so" }],
|
|
1374
|
+
maxAds: 10,
|
|
1375
|
+
},
|
|
1376
|
+
});
|
|
1377
|
+
expect(body.input).not.toHaveProperty("domain");
|
|
1378
|
+
expect(body.input).not.toHaveProperty("platforms");
|
|
1379
|
+
return {
|
|
1380
|
+
status: "success",
|
|
1381
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1382
|
+
output: { repaired: true },
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
return { ok: true };
|
|
1386
|
+
});
|
|
1387
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1388
|
+
const harness = makeServerHarness();
|
|
1389
|
+
registerPlaybookTools(harness.server);
|
|
1390
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1391
|
+
slug: "competitor-ads",
|
|
1392
|
+
input: { domain: "notion.so" },
|
|
1393
|
+
budget: 5,
|
|
1394
|
+
pay_with: "card",
|
|
1395
|
+
confirmed: true,
|
|
1396
|
+
});
|
|
1397
|
+
const text = flattenToolText(result);
|
|
1398
|
+
expect(agentRunAttempts).toBe(2);
|
|
1399
|
+
expect(text).toContain("completed");
|
|
1400
|
+
});
|
|
1401
|
+
it("uses live child schema metadata to derive urls from a domain before payment", async () => {
|
|
1402
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1403
|
+
mockApiGet
|
|
1404
|
+
.mockResolvedValueOnce(playbook)
|
|
1405
|
+
.mockResolvedValueOnce({
|
|
1406
|
+
id: "11111111-1111-4111-8111-111111111111",
|
|
1407
|
+
schema: {
|
|
1408
|
+
input: {
|
|
1409
|
+
inputSchema: {
|
|
1410
|
+
type: "object",
|
|
1411
|
+
properties: {
|
|
1412
|
+
urls: { type: "array", items: { type: "string" } },
|
|
1413
|
+
},
|
|
1414
|
+
required: ["urls"],
|
|
1415
|
+
},
|
|
1416
|
+
},
|
|
1417
|
+
},
|
|
1418
|
+
})
|
|
1419
|
+
.mockResolvedValueOnce({
|
|
1420
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1421
|
+
status: "completed",
|
|
1422
|
+
playbook_id: playbook.id,
|
|
1423
|
+
playbook_slug: playbook.slug,
|
|
1424
|
+
playbook_version: 1,
|
|
1425
|
+
budget_usd: 5,
|
|
1426
|
+
quoted_cost_usd: 1.25,
|
|
1427
|
+
charged_usd: 1.25,
|
|
1428
|
+
refunded_usd: 0,
|
|
1429
|
+
remaining_budget_usd: 3.75,
|
|
1430
|
+
steps: [{
|
|
1431
|
+
playbook_step_id: "ads",
|
|
1432
|
+
step_index: 0,
|
|
1433
|
+
node_type: "aw_agent",
|
|
1434
|
+
agent_slug: "ad-strategy-intel",
|
|
1435
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1436
|
+
provider_id: null,
|
|
1437
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1438
|
+
status: "succeeded",
|
|
1439
|
+
quoted_cost_usd: 1.25,
|
|
1440
|
+
charged_usd: 1.25,
|
|
1441
|
+
refunded_usd: 0,
|
|
1442
|
+
}],
|
|
1443
|
+
});
|
|
1444
|
+
let agentRunAttempts = 0;
|
|
1445
|
+
mockApiPost.mockImplementation(async (path, body) => {
|
|
1446
|
+
if (path === "/playbook-runs") {
|
|
1447
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: playbook.current_quote.steps };
|
|
1448
|
+
}
|
|
1449
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1450
|
+
agentRunAttempts += 1;
|
|
1451
|
+
if (agentRunAttempts === 1) {
|
|
1452
|
+
throw { status: 400, message: "validation failed: missing required field urls; unknown field domain" };
|
|
1453
|
+
}
|
|
1454
|
+
expect(body).toMatchObject({
|
|
1455
|
+
input: {
|
|
1456
|
+
urls: ["https://notion.so"],
|
|
1457
|
+
},
|
|
1458
|
+
});
|
|
1459
|
+
expect(body.input).not.toHaveProperty("domain");
|
|
1460
|
+
return {
|
|
1461
|
+
status: "success",
|
|
1462
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1463
|
+
output: { repaired: true },
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
return { ok: true };
|
|
1467
|
+
});
|
|
1468
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1469
|
+
const harness = makeServerHarness();
|
|
1470
|
+
registerPlaybookTools(harness.server);
|
|
1471
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1472
|
+
slug: "competitor-ads",
|
|
1473
|
+
input: { domain: "notion.so" },
|
|
1474
|
+
budget: 5,
|
|
1475
|
+
pay_with: "card",
|
|
1476
|
+
confirmed: true,
|
|
1477
|
+
});
|
|
1478
|
+
const text = flattenToolText(result);
|
|
1479
|
+
expect(agentRunAttempts).toBe(2);
|
|
1480
|
+
expect(text).toContain("completed");
|
|
1481
|
+
});
|
|
1482
|
+
it("uses live child schema metadata to coerce array fields into strings before payment", async () => {
|
|
1483
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1484
|
+
const playbookWithArrayDefault = {
|
|
1485
|
+
...playbook,
|
|
1486
|
+
current_quote: {
|
|
1487
|
+
...playbook.current_quote,
|
|
1488
|
+
steps: playbook.current_quote.steps.map((step) => ({
|
|
1489
|
+
...step,
|
|
1490
|
+
default_input: { queries: ["notion.so alternatives", "notion.so pricing"] },
|
|
1491
|
+
})),
|
|
1492
|
+
},
|
|
1493
|
+
};
|
|
1494
|
+
mockApiGet
|
|
1495
|
+
.mockResolvedValueOnce(playbookWithArrayDefault)
|
|
1496
|
+
.mockResolvedValueOnce({
|
|
1497
|
+
id: "11111111-1111-4111-8111-111111111111",
|
|
1498
|
+
schema: {
|
|
1499
|
+
input: {
|
|
1500
|
+
inputSchema: {
|
|
1501
|
+
type: "object",
|
|
1502
|
+
properties: {
|
|
1503
|
+
queries: { type: "string" },
|
|
1504
|
+
countryCode: { type: "string", default: "us" },
|
|
1505
|
+
},
|
|
1506
|
+
required: ["queries"],
|
|
1507
|
+
},
|
|
1508
|
+
},
|
|
1509
|
+
},
|
|
1510
|
+
})
|
|
1511
|
+
.mockResolvedValueOnce({
|
|
1512
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1513
|
+
status: "completed",
|
|
1514
|
+
playbook_id: playbook.id,
|
|
1515
|
+
playbook_slug: playbook.slug,
|
|
1516
|
+
playbook_version: 1,
|
|
1517
|
+
budget_usd: 5,
|
|
1518
|
+
quoted_cost_usd: 1.25,
|
|
1519
|
+
charged_usd: 1.25,
|
|
1520
|
+
refunded_usd: 0,
|
|
1521
|
+
remaining_budget_usd: 3.75,
|
|
1522
|
+
steps: [{
|
|
1523
|
+
playbook_step_id: "ads",
|
|
1524
|
+
step_index: 0,
|
|
1525
|
+
node_type: "aw_agent",
|
|
1526
|
+
agent_slug: "ad-strategy-intel",
|
|
1527
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1528
|
+
provider_id: null,
|
|
1529
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1530
|
+
status: "succeeded",
|
|
1531
|
+
quoted_cost_usd: 1.25,
|
|
1532
|
+
charged_usd: 1.25,
|
|
1533
|
+
refunded_usd: 0,
|
|
1534
|
+
}],
|
|
1535
|
+
});
|
|
1536
|
+
let agentRunAttempts = 0;
|
|
1537
|
+
mockApiPost.mockImplementation(async (path, body) => {
|
|
1538
|
+
if (path === "/playbook-runs") {
|
|
1539
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: playbookWithArrayDefault.current_quote.steps };
|
|
1540
|
+
}
|
|
1541
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1542
|
+
agentRunAttempts += 1;
|
|
1543
|
+
if (agentRunAttempts === 1) {
|
|
1544
|
+
throw { status: 400, message: "validation failed: queries expected string, got object" };
|
|
1545
|
+
}
|
|
1546
|
+
expect(body).toMatchObject({
|
|
1547
|
+
input: {
|
|
1548
|
+
queries: "notion.so alternatives; notion.so pricing",
|
|
1549
|
+
countryCode: "us",
|
|
1550
|
+
},
|
|
1551
|
+
});
|
|
1552
|
+
expect(body.input).not.toHaveProperty("domain");
|
|
1553
|
+
return {
|
|
1554
|
+
status: "success",
|
|
1555
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1556
|
+
output: { repaired: true },
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
return { ok: true };
|
|
1560
|
+
});
|
|
1561
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1562
|
+
const harness = makeServerHarness();
|
|
1563
|
+
registerPlaybookTools(harness.server);
|
|
1564
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1565
|
+
slug: "competitor-ads",
|
|
1566
|
+
input: { domain: "notion.so" },
|
|
1567
|
+
budget: 5,
|
|
1568
|
+
pay_with: "card",
|
|
1569
|
+
confirmed: true,
|
|
1570
|
+
});
|
|
1571
|
+
const text = flattenToolText(result);
|
|
1572
|
+
expect(agentRunAttempts).toBe(2);
|
|
1573
|
+
expect(text).toContain("completed");
|
|
1574
|
+
});
|
|
1575
|
+
it("uses company_name for company enrichment children", async () => {
|
|
1576
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1577
|
+
mockUploadLocalFiles.mockResolvedValueOnce({ input: { leads: [{ company: "Kelvin" }] }, uploads: [] });
|
|
1578
|
+
const companyPlaybook = {
|
|
1579
|
+
...playbook,
|
|
1580
|
+
input_schema: {
|
|
1581
|
+
type: "object",
|
|
1582
|
+
properties: { leads: { type: "array" } },
|
|
1583
|
+
required: ["leads"],
|
|
1584
|
+
},
|
|
1585
|
+
current_quote: {
|
|
1586
|
+
...playbook.current_quote,
|
|
1587
|
+
steps: playbook.current_quote.steps.map((step) => ({
|
|
1588
|
+
...step,
|
|
1589
|
+
agent_slug: "company-enrichment-deep",
|
|
1590
|
+
agent_name: "Company Enrichment",
|
|
1591
|
+
})),
|
|
1592
|
+
},
|
|
1593
|
+
};
|
|
1594
|
+
mockApiGet
|
|
1595
|
+
.mockResolvedValueOnce(companyPlaybook)
|
|
1596
|
+
.mockResolvedValueOnce({
|
|
1597
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1598
|
+
status: "completed",
|
|
1599
|
+
playbook_id: playbook.id,
|
|
1600
|
+
playbook_slug: playbook.slug,
|
|
1601
|
+
playbook_version: 1,
|
|
1602
|
+
budget_usd: 5,
|
|
1603
|
+
quoted_cost_usd: 1.25,
|
|
1604
|
+
charged_usd: 1.25,
|
|
1605
|
+
refunded_usd: 0,
|
|
1606
|
+
remaining_budget_usd: 3.75,
|
|
1607
|
+
steps: [{
|
|
1608
|
+
playbook_step_id: "ads",
|
|
1609
|
+
step_index: 0,
|
|
1610
|
+
node_type: "aw_agent",
|
|
1611
|
+
agent_slug: "company-enrichment-deep",
|
|
1612
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1613
|
+
provider_id: null,
|
|
1614
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1615
|
+
status: "succeeded",
|
|
1616
|
+
quoted_cost_usd: 1.25,
|
|
1617
|
+
charged_usd: 1.25,
|
|
1618
|
+
refunded_usd: 0,
|
|
1619
|
+
}],
|
|
1620
|
+
});
|
|
1621
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
1622
|
+
if (path === "/playbook-runs") {
|
|
1623
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: companyPlaybook.current_quote.steps };
|
|
1624
|
+
}
|
|
1625
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1626
|
+
throw { status: 402, message: "payment required" };
|
|
1627
|
+
}
|
|
1628
|
+
return { ok: true };
|
|
1629
|
+
});
|
|
1630
|
+
mockApiPostWithPayment.mockResolvedValueOnce({
|
|
1631
|
+
status: "success",
|
|
1632
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1633
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1634
|
+
output: { enriched: true },
|
|
1635
|
+
cost: 1.25,
|
|
1636
|
+
});
|
|
1637
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1638
|
+
const harness = makeServerHarness();
|
|
1639
|
+
registerPlaybookTools(harness.server);
|
|
1640
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1641
|
+
slug: "competitor-ads",
|
|
1642
|
+
input: { leads: [{ company: "Kelvin" }] },
|
|
1643
|
+
budget: 5,
|
|
1644
|
+
pay_with: "card",
|
|
1645
|
+
confirmed: true,
|
|
1646
|
+
});
|
|
1647
|
+
const text = flattenToolText(result);
|
|
1648
|
+
expect(mockApiPostWithPayment).toHaveBeenCalledWith("/agents/11111111-1111-4111-8111-111111111111/run", expect.objectContaining({
|
|
1649
|
+
input: expect.objectContaining({
|
|
1650
|
+
company: "Kelvin",
|
|
1651
|
+
company_name: "Kelvin",
|
|
1652
|
+
}),
|
|
1653
|
+
}), "card");
|
|
1654
|
+
expect(text).toContain("completed");
|
|
1655
|
+
});
|
|
1656
|
+
it("builds cold email council brief and email verification inputs from a lead", async () => {
|
|
1657
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1658
|
+
mockUploadLocalFiles.mockResolvedValueOnce({ input: { leads: [{ name: "Dana Ko", company: "Kelvin", email: "dana@example.com" }] }, uploads: [] });
|
|
1659
|
+
const steps = [
|
|
1660
|
+
{
|
|
1661
|
+
...playbook.current_quote.steps[0],
|
|
1662
|
+
id: "copy",
|
|
1663
|
+
index: 0,
|
|
1664
|
+
agent_slug: "cold-email-council",
|
|
1665
|
+
agent_name: "Cold Email Council",
|
|
1666
|
+
},
|
|
1667
|
+
{
|
|
1668
|
+
...playbook.current_quote.steps[0],
|
|
1669
|
+
id: "verify",
|
|
1670
|
+
index: 1,
|
|
1671
|
+
agent_slug: "email-verification",
|
|
1672
|
+
agent_name: "Email Verification",
|
|
1673
|
+
},
|
|
1674
|
+
];
|
|
1675
|
+
const coldPlaybook = {
|
|
1676
|
+
...playbook,
|
|
1677
|
+
input_schema: {
|
|
1678
|
+
type: "object",
|
|
1679
|
+
properties: { leads: { type: "array" } },
|
|
1680
|
+
required: ["leads"],
|
|
1681
|
+
},
|
|
1682
|
+
current_quote: {
|
|
1683
|
+
...playbook.current_quote,
|
|
1684
|
+
estimated_cost_usd: 2.5,
|
|
1685
|
+
step_count: 2,
|
|
1686
|
+
steps,
|
|
1687
|
+
},
|
|
1688
|
+
};
|
|
1689
|
+
mockApiGet
|
|
1690
|
+
.mockResolvedValueOnce(coldPlaybook)
|
|
1691
|
+
.mockResolvedValueOnce({
|
|
1692
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1693
|
+
status: "completed",
|
|
1694
|
+
playbook_id: playbook.id,
|
|
1695
|
+
playbook_slug: playbook.slug,
|
|
1696
|
+
playbook_version: 1,
|
|
1697
|
+
budget_usd: 5,
|
|
1698
|
+
quoted_cost_usd: 2.5,
|
|
1699
|
+
charged_usd: 2.5,
|
|
1700
|
+
refunded_usd: 0,
|
|
1701
|
+
remaining_budget_usd: 2.5,
|
|
1702
|
+
steps: steps.map((step) => ({
|
|
1703
|
+
playbook_step_id: step.id,
|
|
1704
|
+
step_index: step.index,
|
|
1705
|
+
node_type: "aw_agent",
|
|
1706
|
+
agent_slug: step.agent_slug,
|
|
1707
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1708
|
+
provider_id: null,
|
|
1709
|
+
job_id: `33333333-3333-4333-8333-33333333333${step.index}`,
|
|
1710
|
+
status: "succeeded",
|
|
1711
|
+
quoted_cost_usd: 1.25,
|
|
1712
|
+
charged_usd: 1.25,
|
|
1713
|
+
refunded_usd: 0,
|
|
1714
|
+
})),
|
|
1715
|
+
});
|
|
1716
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
1717
|
+
if (path === "/playbook-runs") {
|
|
1718
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps };
|
|
1719
|
+
}
|
|
1720
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1721
|
+
throw { status: 402, message: "payment required" };
|
|
1722
|
+
}
|
|
1723
|
+
return { ok: true };
|
|
1724
|
+
});
|
|
1725
|
+
mockApiPostWithPayment
|
|
1726
|
+
.mockResolvedValueOnce({
|
|
1727
|
+
status: "success",
|
|
1728
|
+
job_id: "33333333-3333-4333-8333-333333333330",
|
|
1729
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1730
|
+
output: { email: "hello" },
|
|
1731
|
+
cost: 1.25,
|
|
1732
|
+
})
|
|
1733
|
+
.mockResolvedValueOnce({
|
|
1734
|
+
status: "success",
|
|
1735
|
+
job_id: "33333333-3333-4333-8333-333333333331",
|
|
1736
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1737
|
+
output: { valid: true },
|
|
1738
|
+
cost: 1.25,
|
|
1739
|
+
});
|
|
1740
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1741
|
+
const harness = makeServerHarness();
|
|
1742
|
+
registerPlaybookTools(harness.server);
|
|
1743
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1744
|
+
slug: "competitor-ads",
|
|
1745
|
+
input: { leads: [{ name: "Dana Ko", company: "Kelvin", email: "dana@example.com" }] },
|
|
1746
|
+
budget: 5,
|
|
1747
|
+
pay_with: "card",
|
|
1748
|
+
confirmed: true,
|
|
1749
|
+
});
|
|
1750
|
+
const text = flattenToolText(result);
|
|
1751
|
+
expect(mockApiPostWithPayment).toHaveBeenNthCalledWith(1, "/agents/11111111-1111-4111-8111-111111111111/run", expect.objectContaining({
|
|
1752
|
+
input: expect.objectContaining({
|
|
1753
|
+
brief: expect.stringContaining("Dana Ko"),
|
|
1754
|
+
context: expect.objectContaining({
|
|
1755
|
+
company: "Kelvin",
|
|
1756
|
+
email: "dana@example.com",
|
|
1757
|
+
}),
|
|
1758
|
+
num_outputs: 1,
|
|
1759
|
+
}),
|
|
1760
|
+
}), "card");
|
|
1761
|
+
expect(mockApiPostWithPayment).toHaveBeenNthCalledWith(2, "/agents/11111111-1111-4111-8111-111111111111/run", expect.objectContaining({
|
|
1762
|
+
input: expect.objectContaining({
|
|
1763
|
+
emails: ["dana@example.com"],
|
|
1764
|
+
}),
|
|
1765
|
+
}), "card");
|
|
1766
|
+
expect(text).toContain("completed");
|
|
1767
|
+
});
|
|
1768
|
+
it("marks still-processing child jobs as needs reconciliation on poll timeout", async () => {
|
|
1769
|
+
vi.useFakeTimers();
|
|
1770
|
+
try {
|
|
1771
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1772
|
+
mockApiGet.mockImplementation(async (path) => {
|
|
1773
|
+
if (path === "/playbooks/competitor-ads")
|
|
1774
|
+
return playbook;
|
|
1775
|
+
if (path.startsWith("/jobs/33333333-3333-4333-8333-333333333333")) {
|
|
1776
|
+
return { status: "processing" };
|
|
1777
|
+
}
|
|
1778
|
+
if (path === "/playbook-runs/22222222-2222-4222-8222-222222222222") {
|
|
1779
|
+
return {
|
|
1780
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1781
|
+
status: "needs_reconciliation",
|
|
1782
|
+
playbook_id: playbook.id,
|
|
1783
|
+
playbook_slug: playbook.slug,
|
|
1784
|
+
playbook_version: 1,
|
|
1785
|
+
budget_usd: 5,
|
|
1786
|
+
quoted_cost_usd: 1.25,
|
|
1787
|
+
charged_usd: 0,
|
|
1788
|
+
refunded_usd: 0,
|
|
1789
|
+
remaining_budget_usd: 5,
|
|
1790
|
+
error_code: "POLL_TIMEOUT",
|
|
1791
|
+
steps: [{
|
|
1792
|
+
playbook_step_id: "ads",
|
|
1793
|
+
step_index: 0,
|
|
1794
|
+
node_type: "aw_agent",
|
|
1795
|
+
agent_slug: "ad-strategy-intel",
|
|
1796
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1797
|
+
provider_id: null,
|
|
1798
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1799
|
+
status: "running",
|
|
1800
|
+
quoted_cost_usd: 1.25,
|
|
1801
|
+
charged_usd: 0,
|
|
1802
|
+
refunded_usd: 0,
|
|
1803
|
+
error_code: "POLL_TIMEOUT",
|
|
1804
|
+
}],
|
|
1805
|
+
};
|
|
1806
|
+
}
|
|
1807
|
+
throw new Error(`Unexpected GET ${path}`);
|
|
1808
|
+
});
|
|
1809
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
1810
|
+
if (path === "/playbook-runs") {
|
|
1811
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: playbook.current_quote.steps };
|
|
1812
|
+
}
|
|
1813
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1814
|
+
throw { status: 402, message: "payment required" };
|
|
1815
|
+
}
|
|
1816
|
+
return { ok: true };
|
|
1817
|
+
});
|
|
1818
|
+
mockApiPostWithPayment.mockResolvedValueOnce({
|
|
1819
|
+
status: "processing",
|
|
1820
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1821
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1822
|
+
});
|
|
1823
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1824
|
+
const harness = makeServerHarness();
|
|
1825
|
+
registerPlaybookTools(harness.server);
|
|
1826
|
+
const resultPromise = harness.handlers.get("run_playbook")({
|
|
1827
|
+
slug: "competitor-ads",
|
|
1828
|
+
input: { domain: "notion.so" },
|
|
1829
|
+
budget: 5,
|
|
1830
|
+
pay_with: "card",
|
|
1831
|
+
confirmed: true,
|
|
1832
|
+
});
|
|
1833
|
+
await vi.advanceTimersByTimeAsync(305_000);
|
|
1834
|
+
const result = await resultPromise;
|
|
1835
|
+
const text = flattenToolText(result);
|
|
1836
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads", expect.objectContaining({
|
|
1837
|
+
status: "running",
|
|
1838
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1839
|
+
error_code: "POLL_TIMEOUT",
|
|
1840
|
+
}));
|
|
1841
|
+
expect(mockApiPost).not.toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads", expect.objectContaining({
|
|
1842
|
+
status: "refunded",
|
|
1843
|
+
}));
|
|
1844
|
+
expect(text).toContain("needs_reconciliation");
|
|
1845
|
+
expect(text).toContain("still processing");
|
|
1846
|
+
}
|
|
1847
|
+
finally {
|
|
1848
|
+
vi.useRealTimers();
|
|
1849
|
+
}
|
|
1850
|
+
});
|
|
1851
|
+
it("records child failure and explains the per-agent refund behavior", async () => {
|
|
1852
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1853
|
+
mockApiGet
|
|
1854
|
+
.mockResolvedValueOnce(playbook)
|
|
1855
|
+
.mockResolvedValueOnce({
|
|
1856
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1857
|
+
status: "paused",
|
|
1858
|
+
playbook_id: playbook.id,
|
|
1859
|
+
playbook_slug: playbook.slug,
|
|
1860
|
+
playbook_version: 1,
|
|
1861
|
+
budget_usd: 5,
|
|
1862
|
+
quoted_cost_usd: 1.25,
|
|
1863
|
+
charged_usd: 1.25,
|
|
1864
|
+
refunded_usd: 1.25,
|
|
1865
|
+
remaining_budget_usd: 5,
|
|
1866
|
+
error_code: "CHILD_AGENT_FAILED",
|
|
1867
|
+
steps: [{
|
|
1868
|
+
playbook_step_id: "ads",
|
|
1869
|
+
step_index: 0,
|
|
1870
|
+
node_type: "aw_agent",
|
|
1871
|
+
agent_slug: "ad-strategy-intel",
|
|
1872
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1873
|
+
provider_id: null,
|
|
1874
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1875
|
+
status: "failed",
|
|
1876
|
+
quoted_cost_usd: 1.25,
|
|
1877
|
+
charged_usd: 1.25,
|
|
1878
|
+
refunded_usd: 1.25,
|
|
1879
|
+
error_code: "UPSTREAM_FAILED",
|
|
1880
|
+
}],
|
|
1881
|
+
});
|
|
1882
|
+
mockApiPost.mockImplementation(async (path) => {
|
|
1883
|
+
if (path === "/playbook-runs") {
|
|
1884
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: playbook.current_quote.steps };
|
|
1885
|
+
}
|
|
1886
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1887
|
+
throw { status: 402, message: "payment required" };
|
|
1888
|
+
}
|
|
1889
|
+
return { ok: true };
|
|
1890
|
+
});
|
|
1891
|
+
mockApiPostWithPayment.mockResolvedValueOnce({
|
|
1892
|
+
status: "failed",
|
|
1893
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1894
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1895
|
+
output: { error: "upstream failed" },
|
|
1896
|
+
error_code: "UPSTREAM_FAILED",
|
|
1897
|
+
});
|
|
1898
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1899
|
+
const harness = makeServerHarness();
|
|
1900
|
+
registerPlaybookTools(harness.server);
|
|
1901
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1902
|
+
slug: "competitor-ads",
|
|
1903
|
+
input: { domain: "notion.so" },
|
|
1904
|
+
budget: 5,
|
|
1905
|
+
pay_with: "card",
|
|
1906
|
+
confirmed: true,
|
|
1907
|
+
});
|
|
1908
|
+
const text = flattenToolText(result);
|
|
1909
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads", expect.objectContaining({
|
|
1910
|
+
status: "refunded",
|
|
1911
|
+
consumption_mode: "direct_charge",
|
|
1912
|
+
charged_usd: 1.25,
|
|
1913
|
+
refunded_usd: 1.25,
|
|
1914
|
+
error_code: "UPSTREAM_FAILED",
|
|
1915
|
+
}));
|
|
1916
|
+
expect(text).toContain("Existing per-agent refund behavior applies");
|
|
1917
|
+
});
|
|
1918
|
+
it("returns paid child output and marks the run for reconciliation when receipt writes keep failing", async () => {
|
|
1919
|
+
mockRequiresSpendConfirmation.mockReturnValue(false);
|
|
1920
|
+
mockApiGet.mockResolvedValueOnce(playbook);
|
|
1921
|
+
let successfulStepReceiptAttempts = 0;
|
|
1922
|
+
mockApiPost.mockImplementation(async (path, body) => {
|
|
1923
|
+
if (path === "/playbook-runs") {
|
|
1924
|
+
return { run_id: "22222222-2222-4222-8222-222222222222", steps: playbook.current_quote.steps };
|
|
1925
|
+
}
|
|
1926
|
+
if (path === "/agents/11111111-1111-4111-8111-111111111111/run") {
|
|
1927
|
+
throw { status: 402, message: "payment required" };
|
|
1928
|
+
}
|
|
1929
|
+
if (path === "/playbook-runs/22222222-2222-4222-8222-222222222222/steps/ads" && body?.status === "succeeded") {
|
|
1930
|
+
successfulStepReceiptAttempts += 1;
|
|
1931
|
+
throw new Error("receipt store unavailable");
|
|
1932
|
+
}
|
|
1933
|
+
return { ok: true };
|
|
1934
|
+
});
|
|
1935
|
+
mockApiPostWithPayment.mockResolvedValueOnce({
|
|
1936
|
+
status: "success",
|
|
1937
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1938
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1939
|
+
output: { rows: 3 },
|
|
1940
|
+
cost: 1.25,
|
|
1941
|
+
});
|
|
1942
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
1943
|
+
const harness = makeServerHarness();
|
|
1944
|
+
registerPlaybookTools(harness.server);
|
|
1945
|
+
const result = await harness.handlers.get("run_playbook")({
|
|
1946
|
+
slug: "competitor-ads",
|
|
1947
|
+
input: { domain: "notion.so" },
|
|
1948
|
+
budget: 5,
|
|
1949
|
+
pay_with: "card",
|
|
1950
|
+
confirmed: true,
|
|
1951
|
+
});
|
|
1952
|
+
const text = flattenToolText(result);
|
|
1953
|
+
expect(successfulStepReceiptAttempts).toBe(3);
|
|
1954
|
+
expect(mockApiPost).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222/status", expect.objectContaining({
|
|
1955
|
+
status: "needs_reconciliation",
|
|
1956
|
+
error_code: "RECEIPT_WRITE_FAILED",
|
|
1957
|
+
}));
|
|
1958
|
+
expect(text).toContain("needs reconciliation");
|
|
1959
|
+
expect(text).toContain("rows");
|
|
1960
|
+
});
|
|
1961
|
+
it("gets a paused playbook run receipt with completed, refunded, skipped, and resume details", async () => {
|
|
1962
|
+
mockApiGet.mockResolvedValueOnce({
|
|
1963
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
1964
|
+
status: "paused",
|
|
1965
|
+
playbook_id: playbook.id,
|
|
1966
|
+
playbook_slug: playbook.slug,
|
|
1967
|
+
playbook_version: 1,
|
|
1968
|
+
input: { domain: "notion.so" },
|
|
1969
|
+
limits: { prospects: 2 },
|
|
1970
|
+
budget_usd: 5,
|
|
1971
|
+
quoted_cost_usd: 3,
|
|
1972
|
+
charged_usd: 2,
|
|
1973
|
+
refunded_usd: 0.75,
|
|
1974
|
+
remaining_budget_usd: 3.75,
|
|
1975
|
+
error_code: "BUDGET_EXHAUSTED",
|
|
1976
|
+
steps: [
|
|
1977
|
+
{
|
|
1978
|
+
playbook_step_id: "ads",
|
|
1979
|
+
step_index: 0,
|
|
1980
|
+
node_type: "aw_agent",
|
|
1981
|
+
agent_slug: "ad-strategy-intel",
|
|
1982
|
+
agent_id: "11111111-1111-4111-8111-111111111111",
|
|
1983
|
+
provider_id: null,
|
|
1984
|
+
job_id: "33333333-3333-4333-8333-333333333333",
|
|
1985
|
+
consumption_mode: "direct_charge",
|
|
1986
|
+
status: "succeeded",
|
|
1987
|
+
quoted_cost_usd: 1.25,
|
|
1988
|
+
charged_usd: 1.25,
|
|
1989
|
+
refunded_usd: 0,
|
|
1990
|
+
},
|
|
1991
|
+
{
|
|
1992
|
+
playbook_step_id: "traffic",
|
|
1993
|
+
step_index: 1,
|
|
1994
|
+
node_type: "aw_agent",
|
|
1995
|
+
agent_slug: "traffic-estimator",
|
|
1996
|
+
agent_id: "44444444-4444-4444-8444-444444444444",
|
|
1997
|
+
provider_id: null,
|
|
1998
|
+
job_id: "55555555-5555-4555-8555-555555555555",
|
|
1999
|
+
consumption_mode: "direct_charge",
|
|
2000
|
+
status: "failed",
|
|
2001
|
+
quoted_cost_usd: 0.75,
|
|
2002
|
+
charged_usd: 0.75,
|
|
2003
|
+
refunded_usd: 0.75,
|
|
2004
|
+
error_code: "UPSTREAM_FAILED",
|
|
2005
|
+
},
|
|
2006
|
+
{
|
|
2007
|
+
playbook_step_id: "serp",
|
|
2008
|
+
step_index: 2,
|
|
2009
|
+
node_type: "external_x402",
|
|
2010
|
+
agent_slug: null,
|
|
2011
|
+
agent_id: null,
|
|
2012
|
+
provider_id: null,
|
|
2013
|
+
job_id: null,
|
|
2014
|
+
consumption_mode: "not_charged",
|
|
2015
|
+
status: "skipped",
|
|
2016
|
+
quoted_cost_usd: 1,
|
|
2017
|
+
charged_usd: 0,
|
|
2018
|
+
refunded_usd: 0,
|
|
2019
|
+
error_code: "BUDGET_EXHAUSTED",
|
|
2020
|
+
},
|
|
2021
|
+
],
|
|
2022
|
+
});
|
|
2023
|
+
const { registerPlaybookTools } = await import("../playbooks.js");
|
|
2024
|
+
const harness = makeServerHarness();
|
|
2025
|
+
registerPlaybookTools(harness.server);
|
|
2026
|
+
const result = await harness.handlers.get("get_playbook_run")({
|
|
2027
|
+
run_id: "22222222-2222-4222-8222-222222222222",
|
|
2028
|
+
});
|
|
2029
|
+
const text = flattenToolText(result);
|
|
2030
|
+
expect(mockApiGet).toHaveBeenCalledWith("/playbook-runs/22222222-2222-4222-8222-222222222222");
|
|
2031
|
+
expect(text).toContain("competitor-ads v1 — paused");
|
|
2032
|
+
expect(text).toContain("Charged: $2.00");
|
|
2033
|
+
expect(text).toContain("Refunded: $0.7500");
|
|
2034
|
+
expect(text).toContain("Remaining unspent budget: $3.75");
|
|
2035
|
+
expect(text).toContain("ad-strategy-intel: succeeded");
|
|
2036
|
+
expect(text).toContain("traffic-estimator: failed");
|
|
2037
|
+
expect(text).toContain("refunded $0.7500");
|
|
2038
|
+
expect(text).toContain("serp: skipped · not charged");
|
|
2039
|
+
expect(text).not.toContain("null: skipped");
|
|
2040
|
+
expect(text).toContain("error: BUDGET_EXHAUSTED");
|
|
2041
|
+
expect(text).toContain('Resume: run_playbook({ resume_run_id: "22222222-2222-4222-8222-222222222222", confirmed: true, budget: 5, limits: {"prospects":2} })');
|
|
2042
|
+
});
|
|
2043
|
+
});
|