channelstack 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/integrations/checks/index.d.ts +40 -7
- package/dist/integrations/checks/index.js +525 -69
- package/dist/integrations/matchers-core/index.d.ts +90 -11
- package/dist/integrations/matchers-core/index.js +356 -15
- package/dist/integrations/matchers-core/matchers.test.js +251 -3
- package/dist/integrations/vitest/index.d.ts +4 -2
- package/dist/integrations/vitest/setup.js +33 -3
- package/dist/sdks/typescript/client.d.ts +5 -4
- package/dist/sdks/typescript/client.js +4 -4
- package/dist/sdks/typescript/generated/channels.d.ts +17 -9
- package/dist/sdks/typescript/generated/channels.js +3 -1
- package/dist/sdks/typescript/generated/index.d.ts +1744 -313
- package/dist/sdks/typescript/generated/index.js +1991 -422
- package/dist/sdks/typescript/generated/normalisation.d.ts +18 -0
- package/dist/sdks/typescript/generated/normalisation.js +14 -0
- package/dist/sdks/typescript/runtime/client.d.ts +9 -0
- package/dist/sdks/typescript/runtime/client.js +5 -0
- package/dist/sdks/typescript/runtime/files.d.ts +17 -2
- package/dist/sdks/typescript/runtime/files.js +11 -3
- package/dist/sdks/typescript/runtime/launcher.d.ts +5 -2
- package/dist/sdks/typescript/runtime/launcher.js +6 -3
- package/dist/sdks/typescript/runtime/responder.d.ts +26 -0
- package/dist/sdks/typescript/runtime/responder.js +42 -0
- package/dist/sdks/typescript/runtime/wait.d.ts +14 -0
- package/dist/sdks/typescript/runtime/wait.js +23 -0
- package/dist/sdks/typescript/types.d.ts +16 -6
- package/package.json +9 -7
|
@@ -60,6 +60,81 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
60
60
|
* Each check is something agents commonly get wrong, written against the public API only.
|
|
61
61
|
*/
|
|
62
62
|
import { describe, expect, test } from "vitest";
|
|
63
|
+
import { waitFor, WaitTimeoutError, } from "../../sdks/typescript/client.js";
|
|
64
|
+
import { appTurns } from "../matchers-core/index.js";
|
|
65
|
+
/**
|
|
66
|
+
* How every `<channel>.no-reply-loop` ends. The conversation goes quiet with at most what a correct
|
|
67
|
+
* agent leaves (the `start` app messages there were when the peer began, then at most `turns`
|
|
68
|
+
* answers, each followed by the peer's): `toGoQuiet` fails otherwise. And the agent answered the
|
|
69
|
+
* other app at most `turns` times. Either failure names the authors in turn since a person last
|
|
70
|
+
* wrote (decision 0027).
|
|
71
|
+
*/
|
|
72
|
+
async function answeredAtMost(conversation, loop) {
|
|
73
|
+
const { start, answered, turns, what, wait } = loop;
|
|
74
|
+
await expect(conversation).toGoQuiet({
|
|
75
|
+
maxReplies: start + 2 * turns + 1,
|
|
76
|
+
...(wait.timeout === undefined ? {} : { within: wait.timeout }),
|
|
77
|
+
});
|
|
78
|
+
const since = await appTurns(conversation);
|
|
79
|
+
expect(answered, `times it answered ${what}: ${since.count} app messages and no person between them: ${since.turns}`).toBeLessThanOrEqual(turns);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* `<channel>.no-reply-loop` for email: another app mails the agent, marked as sent by a program
|
|
83
|
+
* (RFC 3834), and answers each answer the same way. The agent may answer it at most `turns` times.
|
|
84
|
+
*/
|
|
85
|
+
async function autoMailLoop(agent, peer, turns, wait) {
|
|
86
|
+
const auto = { "Auto-Submitted": "auto-replied" };
|
|
87
|
+
const first = await peer.send({ to: [agent], subject: "Build report", text: "The build passed.", headers: auto });
|
|
88
|
+
const answers = async () => (await first.thread.replies()).filter((one) => one.author.id === agent.id);
|
|
89
|
+
let seen = 0;
|
|
90
|
+
for (let turn = 0; turn <= turns; turn++) {
|
|
91
|
+
const now = await answersAgain(async () => (await answers()).length, seen, wait);
|
|
92
|
+
if (now === seen)
|
|
93
|
+
break;
|
|
94
|
+
seen = now;
|
|
95
|
+
// The peer answers the agent's latest answer, so the agent gets it, marked as sent by a program again.
|
|
96
|
+
const latest = (await answers()).at(-1) ?? first;
|
|
97
|
+
await peer.reply(latest, { text: "Noted, thanks.", headers: auto });
|
|
98
|
+
}
|
|
99
|
+
// The peer's first email starts the loop: no app message was there before it.
|
|
100
|
+
await answeredAtMost(first.thread, {
|
|
101
|
+
start: 0,
|
|
102
|
+
answered: seen,
|
|
103
|
+
turns,
|
|
104
|
+
what: "mail another program sent on its own",
|
|
105
|
+
wait,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Whether `app` names the fixture's own app: `my-agent`, or, live, its real name. Any other name is
|
|
110
|
+
* an app the suite makes (decision 0027).
|
|
111
|
+
*/
|
|
112
|
+
const builtIn = (app, fixtureApp) => app === "my-agent" || app === fixtureApp.name;
|
|
113
|
+
/**
|
|
114
|
+
* How many answers the agent has given once it gives another, or as many as before when none comes
|
|
115
|
+
* within the check's timeout (5 s by default). An agent may answer after it acknowledged a
|
|
116
|
+
* delivery, so quiet alone doesn't say it is done.
|
|
117
|
+
*/
|
|
118
|
+
async function answersAgain(count, seen, wait) {
|
|
119
|
+
try {
|
|
120
|
+
return await waitFor("another answer", async () => {
|
|
121
|
+
const now = await count();
|
|
122
|
+
return now > seen ? now : undefined;
|
|
123
|
+
}, { timeout: wait.timeout ?? "5s" });
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (error instanceof WaitTimeoutError)
|
|
127
|
+
return seen;
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** What a check's model answers when the check scripts nothing of its own. */
|
|
132
|
+
const FALLBACK_ANSWER = "Here's what I found.";
|
|
133
|
+
/** A long answer, streamed slowly: what the stream and Stop checks script. */
|
|
134
|
+
const LONG_ANSWER = {
|
|
135
|
+
text: Array.from({ length: 40 }, (_, at) => `Part ${at + 1} of the report. `),
|
|
136
|
+
timing: { betweenChunks: "100ms" },
|
|
137
|
+
};
|
|
63
138
|
/** The ids of the Slack checks, in the order they are registered. */
|
|
64
139
|
export const SLACK_CHECKS = [
|
|
65
140
|
"slack.dm-once",
|
|
@@ -68,6 +143,7 @@ export const SLACK_CHECKS = [
|
|
|
68
143
|
"slack.retry",
|
|
69
144
|
"slack.redelivery",
|
|
70
145
|
"slack.ignores-bots",
|
|
146
|
+
"slack.no-reply-loop",
|
|
71
147
|
"slack.bad-signature",
|
|
72
148
|
"slack.ack",
|
|
73
149
|
"slack.msg-too-long",
|
|
@@ -76,6 +152,17 @@ export const SLACK_CHECKS = [
|
|
|
76
152
|
"slack.click-unauthorized",
|
|
77
153
|
"slack.double-click",
|
|
78
154
|
];
|
|
155
|
+
/** The ids of the Slack checks of an agent on the fake OpenAI (`model: "openai"`), in the order they are registered. */
|
|
156
|
+
export const SLACK_MODEL_CHECKS = [
|
|
157
|
+
"slack.slow-model",
|
|
158
|
+
"slack.model-error",
|
|
159
|
+
"slack.model-retry",
|
|
160
|
+
"slack.stream-breaks",
|
|
161
|
+
"slack.stop-cancels-model",
|
|
162
|
+
"slack.no-secrets-to-model",
|
|
163
|
+
];
|
|
164
|
+
/** The checks that script the model themselves: no fallback answer goes in front of theirs. */
|
|
165
|
+
const SCRIPTS_THE_MODEL = new Set([...SLACK_MODEL_CHECKS, "slack.stream-stop", "slack.stop"]);
|
|
79
166
|
/** The ids of the GitHub checks, in the order they are registered. */
|
|
80
167
|
export const GITHUB_CHECKS = [
|
|
81
168
|
"github.ignores-own-comments",
|
|
@@ -84,6 +171,7 @@ export const GITHUB_CHECKS = [
|
|
|
84
171
|
"github.redelivery",
|
|
85
172
|
"github.check-run",
|
|
86
173
|
"github.bad-signature",
|
|
174
|
+
"github.no-reply-loop",
|
|
87
175
|
];
|
|
88
176
|
/** The ids of the Linear checks, in the order they are registered. */
|
|
89
177
|
export const LINEAR_CHECKS = [
|
|
@@ -93,6 +181,7 @@ export const LINEAR_CHECKS = [
|
|
|
93
181
|
"linear.redelivery",
|
|
94
182
|
"linear.stale",
|
|
95
183
|
"linear.bad-signature",
|
|
184
|
+
"linear.no-reply-loop",
|
|
96
185
|
];
|
|
97
186
|
/** The ids of the Notion checks, in the order they are registered. */
|
|
98
187
|
export const NOTION_CHECKS = [
|
|
@@ -100,6 +189,7 @@ export const NOTION_CHECKS = [
|
|
|
100
189
|
"notion.ignores-own-comments",
|
|
101
190
|
"notion.redelivery",
|
|
102
191
|
"notion.bad-signature",
|
|
192
|
+
"notion.no-reply-loop",
|
|
103
193
|
];
|
|
104
194
|
/** The ids of the Resend checks, in the order they are registered. */
|
|
105
195
|
export const RESEND_CHECKS = [
|
|
@@ -107,6 +197,7 @@ export const RESEND_CHECKS = [
|
|
|
107
197
|
"resend.redelivery",
|
|
108
198
|
"resend.bad-signature",
|
|
109
199
|
"resend.stale",
|
|
200
|
+
"resend.no-reply-loop",
|
|
110
201
|
];
|
|
111
202
|
/** The ids of the Google checks, in the order they are registered. */
|
|
112
203
|
export const GOOGLE_CHECKS = [
|
|
@@ -116,6 +207,18 @@ export const GOOGLE_CHECKS = [
|
|
|
116
207
|
"google.bad-signature",
|
|
117
208
|
"google.wrong-audience",
|
|
118
209
|
"google.stale",
|
|
210
|
+
"google.no-reply-loop",
|
|
211
|
+
];
|
|
212
|
+
/** The ids of the Discord checks, in the order they are registered. */
|
|
213
|
+
export const DISCORD_CHECKS = [
|
|
214
|
+
"discord.mention-once",
|
|
215
|
+
"discord.dm-once",
|
|
216
|
+
"discord.ignores-bots",
|
|
217
|
+
"discord.no-reply-loop",
|
|
218
|
+
"discord.resume",
|
|
219
|
+
"discord.long-answer",
|
|
220
|
+
"discord.interaction-3s",
|
|
221
|
+
"discord.bad-signature",
|
|
119
222
|
];
|
|
120
223
|
/**
|
|
121
224
|
* The delivery a check retries, redelivers, forges or times: the one thing every delivery check
|
|
@@ -124,6 +227,18 @@ export const GOOGLE_CHECKS = [
|
|
|
124
227
|
* `skip` as every live refusal does, before it waits for anything else.
|
|
125
228
|
*/
|
|
126
229
|
const deliveryOf = (subject, { skip }, platform) => subject.delivery ?? skip(`live: ${platform} delivers to the agent itself, so delivery checks are fake-only`);
|
|
230
|
+
/**
|
|
231
|
+
* The delivery an event caused to the app under test: the built-in app's `delivery`, or another
|
|
232
|
+
* app's `deliveryFor(app)` (decision 0027), waited for as a push may come a moment later. An app
|
|
233
|
+
* that was never sent it fails the check: that is the bug the delivery checks are there to find.
|
|
234
|
+
*/
|
|
235
|
+
async function deliveryTo(subject, agent, fixtureApp, context, platform, wait) {
|
|
236
|
+
if (agent.id === fixtureApp.id)
|
|
237
|
+
return deliveryOf(subject, context, platform);
|
|
238
|
+
return waitFor(`${platform}'s delivery of this event to ${agent.name}`, () => subject.deliveryFor(agent), {
|
|
239
|
+
timeout: wait.timeout ?? "5s",
|
|
240
|
+
});
|
|
241
|
+
}
|
|
127
242
|
/**
|
|
128
243
|
* Registers one check as a test, with its id in the name. A check that was skipped, or whose
|
|
129
244
|
* prompt wasn't given, is left out. An id in `skip` that no check has is a mistake worth hearing about.
|
|
@@ -138,22 +253,29 @@ const registrar = (options, ids) => {
|
|
|
138
253
|
if (options.skip?.includes(id) || (needs.length > 0 && needs[0] === undefined))
|
|
139
254
|
return;
|
|
140
255
|
// Vitest reads which fixtures a test uses from how it destructures its context: name them all.
|
|
141
|
-
test(`${title} [${id}]`, ({ channelstack, slack, github, linear, notion, resend, google, task, expect, skip, signal, onTestFailed, onTestFinished, annotate, }) =>
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
256
|
+
test(`${title} [${id}]`, async ({ channelstack, openai, slack, github, linear, notion, resend, google, discord, task, expect, skip, signal, onTestFailed, onTestFinished, annotate, }) => {
|
|
257
|
+
// On the fake OpenAI, a check that scripts nothing itself gets a plain answer for every call.
|
|
258
|
+
if (options.model === "openai" && !SCRIPTS_THE_MODEL.has(id))
|
|
259
|
+
await openai.respond(FALLBACK_ANSWER, { times: -1 });
|
|
260
|
+
return run({
|
|
261
|
+
channelstack,
|
|
262
|
+
openai,
|
|
263
|
+
slack,
|
|
264
|
+
github,
|
|
265
|
+
linear,
|
|
266
|
+
notion,
|
|
267
|
+
resend,
|
|
268
|
+
google,
|
|
269
|
+
discord,
|
|
270
|
+
task,
|
|
271
|
+
expect,
|
|
272
|
+
skip,
|
|
273
|
+
signal,
|
|
274
|
+
onTestFailed,
|
|
275
|
+
onTestFinished,
|
|
276
|
+
annotate,
|
|
277
|
+
});
|
|
278
|
+
});
|
|
157
279
|
};
|
|
158
280
|
};
|
|
159
281
|
/**
|
|
@@ -166,57 +288,97 @@ export function slackChecks(options) {
|
|
|
166
288
|
const { app } = options;
|
|
167
289
|
const prompt = options.prompt ?? `@${app} hello`;
|
|
168
290
|
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
169
|
-
const check = registrar(options, SLACK_CHECKS);
|
|
291
|
+
const check = registrar(options, [...SLACK_CHECKS, ...SLACK_MODEL_CHECKS]);
|
|
292
|
+
const turns = options.loopTurns ?? 3;
|
|
293
|
+
/** The app under test: the built-in one, or the app of that name (decision 0027), whose agent runs as it. */
|
|
294
|
+
const agentOf = async (slack) => builtIn(app, slack.app) ? slack.app : slack.createApp({ name: app });
|
|
295
|
+
/** The delivery a message caused to the app under test. */
|
|
296
|
+
const slackDelivery = (msg, agent, context) => deliveryTo(msg, agent, context.slack.app, context, "Slack", wait);
|
|
297
|
+
/** On the fake OpenAI, the stream checks script a long, slow stream, and need no prompt of their own. */
|
|
298
|
+
const streamPrompt = options.model === "openai" ? (options.streamPrompt ?? prompt) : options.streamPrompt;
|
|
299
|
+
const streams = async ({ openai }) => {
|
|
300
|
+
if (options.model === "openai")
|
|
301
|
+
await openai.respond(LONG_ANSWER);
|
|
302
|
+
};
|
|
303
|
+
const withModel = options.model === "openai" ? true : undefined;
|
|
170
304
|
describe(`slack checks: ${app}`, () => {
|
|
171
305
|
check("slack.dm-once", "replies once to a DM", async ({ slack }) => {
|
|
306
|
+
const agent = await agentOf(slack);
|
|
172
307
|
const ana = await slack.createUser({ name: "Ana" });
|
|
173
|
-
const msg = await ana.say(prompt, { to:
|
|
308
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
174
309
|
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
175
310
|
});
|
|
176
311
|
check("slack.mention-once", "replies once to a mention", async ({ slack }) => {
|
|
312
|
+
const agent = await agentOf(slack);
|
|
177
313
|
const ana = await slack.createUser({ name: "Ana" });
|
|
178
|
-
const channel = await slack.createChannel({ participants: [ana,
|
|
314
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
179
315
|
const msg = await ana.say(prompt, { channel });
|
|
180
316
|
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
181
317
|
});
|
|
182
318
|
check("slack.in-thread", "replies in the thread, not in the channel", async ({ slack }) => {
|
|
319
|
+
const agent = await agentOf(slack);
|
|
183
320
|
const ana = await slack.createUser({ name: "Ana" });
|
|
184
|
-
const channel = await slack.createChannel({ participants: [ana,
|
|
321
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
185
322
|
const msg = await ana.say(prompt, { channel });
|
|
186
323
|
await expect(msg.thread).toHaveReplyFrom(app, wait);
|
|
187
324
|
await expect(channel).not.toHaveChannelMessageFrom(app, wait);
|
|
188
325
|
});
|
|
189
326
|
check("slack.retry", "survives Slack's retry after 3 seconds", async (context) => {
|
|
190
327
|
const { slack } = context;
|
|
328
|
+
const agent = await agentOf(slack);
|
|
191
329
|
const ana = await slack.createUser({ name: "Ana" });
|
|
192
|
-
const channel = await slack.createChannel({ participants: [ana,
|
|
330
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
193
331
|
const msg = await ana.say(prompt, { channel });
|
|
194
332
|
// Slack retries what it thinks wasn't acknowledged in time, and says so in the retry headers.
|
|
195
|
-
await
|
|
333
|
+
await (await slackDelivery(msg, agent, context)).retry({ after: "3s", reason: "http_timeout" });
|
|
196
334
|
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
197
335
|
});
|
|
198
336
|
check("slack.redelivery", "handles the same event delivered twice", async (context) => {
|
|
199
337
|
const { slack } = context;
|
|
338
|
+
const agent = await agentOf(slack);
|
|
200
339
|
const ana = await slack.createUser({ name: "Ana" });
|
|
201
|
-
const channel = await slack.createChannel({ participants: [ana,
|
|
340
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
202
341
|
const msg = await ana.say(prompt, { channel });
|
|
203
|
-
const delivery =
|
|
342
|
+
const delivery = await slackDelivery(msg, agent, context);
|
|
204
343
|
await expect(msg.thread).toHaveReplyFrom(app, wait);
|
|
205
344
|
// The same event again, with nothing that marks it as a retry: only its event_id tells.
|
|
206
345
|
await delivery.resend();
|
|
207
346
|
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
208
347
|
});
|
|
209
348
|
check("slack.ignores-bots", "ignores what other bots write", async ({ slack }) => {
|
|
349
|
+
const agent = await agentOf(slack);
|
|
210
350
|
const bot = await slack.createUser({ name: "Deploy Bot", bot: true });
|
|
211
|
-
const channel = await slack.createChannel({ participants: [bot,
|
|
351
|
+
const channel = await slack.createChannel({ participants: [bot, agent] });
|
|
212
352
|
const msg = await bot.say(prompt, { channel });
|
|
213
353
|
await expect(msg.thread).not.toHaveReplyFrom(app, wait);
|
|
214
354
|
});
|
|
355
|
+
check("slack.no-reply-loop", "stops answering another app that answers everything it says", async ({ slack }) => {
|
|
356
|
+
const agent = await agentOf(slack);
|
|
357
|
+
const peer = await slack.createApp({ name: app === "loop-peer" ? "loop-peer-2" : "loop-peer" });
|
|
358
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
359
|
+
const channel = await slack.createChannel({ participants: [ana, agent, peer] });
|
|
360
|
+
const msg = await ana.say(prompt, { channel });
|
|
361
|
+
const replies = async () => (await msg.thread.replies()).filter((reply) => reply.author.id === agent.id).length;
|
|
362
|
+
// The agent's answer to Ana; then the peer answers each of its answers, mentioning it, as a
|
|
363
|
+
// second agent without a loop guard would.
|
|
364
|
+
const first = await answersAgain(replies, 0, wait);
|
|
365
|
+
const start = (await appTurns(msg.thread)).count;
|
|
366
|
+
let seen = first;
|
|
367
|
+
for (let turn = 0; turn <= turns; turn++) {
|
|
368
|
+
await peer.reply(`@${agent.name} thanks! Anything else?`, { thread: msg.thread });
|
|
369
|
+
const now = await answersAgain(replies, seen, wait);
|
|
370
|
+
if (now === seen)
|
|
371
|
+
break;
|
|
372
|
+
seen = now;
|
|
373
|
+
}
|
|
374
|
+
await answeredAtMost(msg.thread, { start, answered: seen - first, turns, what: "the other app", wait });
|
|
375
|
+
});
|
|
215
376
|
check("slack.bad-signature", "rejects a delivery with a bad signature", async (context) => {
|
|
216
377
|
const { slack } = context;
|
|
378
|
+
const agent = await agentOf(slack);
|
|
217
379
|
const ana = await slack.createUser({ name: "Ana" });
|
|
218
|
-
const msg = await ana.say(prompt, { to:
|
|
219
|
-
const delivery =
|
|
380
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
381
|
+
const delivery = await slackDelivery(msg, agent, context);
|
|
220
382
|
const first = await delivery.settled(wait);
|
|
221
383
|
// Over Socket Mode there is no signature to check: the connection is the app's own.
|
|
222
384
|
if (first.attempts[0]?.transport !== "http")
|
|
@@ -226,15 +388,17 @@ export function slackChecks(options) {
|
|
|
226
388
|
});
|
|
227
389
|
check("slack.ack", "acknowledges within 3 seconds", async (context) => {
|
|
228
390
|
const { slack } = context;
|
|
391
|
+
const agent = await agentOf(slack);
|
|
229
392
|
const ana = await slack.createUser({ name: "Ana" });
|
|
230
|
-
const msg = await ana.say(prompt, { to:
|
|
231
|
-
await expect(
|
|
393
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
394
|
+
await expect(await slackDelivery(msg, agent, context)).toBeAccepted({ within: "3s", ...wait });
|
|
232
395
|
});
|
|
233
396
|
check("slack.msg-too-long", "still answers when Slack refuses its message as too long", async ({ slack }) => {
|
|
234
397
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
235
398
|
try {
|
|
399
|
+
const agent = await agentOf(slack);
|
|
236
400
|
const ana = await slack.createUser({ name: "Ana" });
|
|
237
|
-
const channel = await slack.createChannel({ participants: [ana,
|
|
401
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
238
402
|
// Slack refuses the agent's next message once; an agent that handles it says something shorter.
|
|
239
403
|
const _fault = __addDisposableResource(env_1, await slack.fault({
|
|
240
404
|
type: "error",
|
|
@@ -255,37 +419,45 @@ export function slackChecks(options) {
|
|
|
255
419
|
await result_1;
|
|
256
420
|
}
|
|
257
421
|
});
|
|
258
|
-
check("slack.stream-stop", "a stream it starts, it also stops", async (
|
|
422
|
+
check("slack.stream-stop", "a stream it starts, it also stops", async (context) => {
|
|
423
|
+
const { slack } = context;
|
|
424
|
+
await streams(context);
|
|
425
|
+
const agent = await agentOf(slack);
|
|
259
426
|
const ana = await slack.createUser({ name: "Ana" });
|
|
260
|
-
const msg = await ana.say(
|
|
427
|
+
const msg = await ana.say(streamPrompt ?? "", { to: agent });
|
|
261
428
|
await expect(msg.thread).toHaveStreamingReplyFrom(app, wait);
|
|
262
429
|
const reply = await msg.thread.latestReply({ from: app, ...wait });
|
|
263
430
|
const stream = await reply.stream?.ended(wait);
|
|
264
431
|
expect(stream?.state).toBe("completed");
|
|
265
432
|
await expect(msg.thread).toHaveStatus("idle", wait);
|
|
266
|
-
},
|
|
267
|
-
check("slack.stop", "honours Stop: nothing more is written after it", async (
|
|
433
|
+
}, streamPrompt);
|
|
434
|
+
check("slack.stop", "honours Stop: nothing more is written after it", async (context) => {
|
|
435
|
+
const { slack } = context;
|
|
436
|
+
await streams(context);
|
|
437
|
+
const agent = await agentOf(slack);
|
|
268
438
|
const ana = await slack.createUser({ name: "Ana" });
|
|
269
|
-
const msg = await ana.say(
|
|
439
|
+
const msg = await ana.say(streamPrompt ?? "", { to: agent });
|
|
270
440
|
await expect(msg.thread).toHaveStreamingReplyFrom(app, wait);
|
|
271
441
|
await ana.stop({ thread: msg });
|
|
272
442
|
await expect(msg.thread).toHaveStatus("stopped", wait);
|
|
273
443
|
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
274
|
-
},
|
|
444
|
+
}, streamPrompt);
|
|
275
445
|
check("slack.click-unauthorized", "refuses a click from someone who may not act", async ({ slack }) => {
|
|
446
|
+
const agent = await agentOf(slack);
|
|
276
447
|
const approval = options.approval ?? { prompt: "", button: "" };
|
|
277
448
|
const ana = await slack.createUser({ name: "Ana" });
|
|
278
|
-
const channel = await slack.createChannel({ participants: [ana,
|
|
449
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
279
450
|
const msg = await ana.say(approval.prompt, { channel });
|
|
280
451
|
await ana.click(approval.button, { thread: msg.thread });
|
|
281
452
|
// The ask is the only thing everyone sees: whatever the agent tells Ana, it tells her alone.
|
|
282
453
|
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
283
454
|
}, options.approval);
|
|
284
455
|
check("slack.double-click", "a double click acts once", async ({ slack }) => {
|
|
456
|
+
const agent = await agentOf(slack);
|
|
285
457
|
const approval = options.approval ?? { prompt: "", button: "" };
|
|
286
458
|
const ana = await slack.createUser({ name: "Ana" });
|
|
287
459
|
const admin = await slack.createUser({ name: "Ben", admin: true });
|
|
288
|
-
const channel = await slack.createChannel({ participants: [ana, admin,
|
|
460
|
+
const channel = await slack.createChannel({ participants: [ana, admin, agent] });
|
|
289
461
|
const msg = await ana.say(approval.prompt, { channel });
|
|
290
462
|
const ask = await msg.thread.waitForReply({ from: app, ...wait });
|
|
291
463
|
// Both presses are on their way before the agent can answer the first. An agent that takes the
|
|
@@ -301,6 +473,60 @@ export function slackChecks(options) {
|
|
|
301
473
|
await msg.thread.waitForReply({ from: app, ...wait });
|
|
302
474
|
await expect(msg.thread).toHaveRepliesFrom(app, { count: 2, ...wait });
|
|
303
475
|
}, options.approval);
|
|
476
|
+
// --- On the fake OpenAI (decision 0029): one check per bug class the model's timing and failures cause.
|
|
477
|
+
check("slack.slow-model", "a slow model and Slack's 3s retry still give one reply", async (context) => {
|
|
478
|
+
const { slack, openai } = context;
|
|
479
|
+
await openai.respond(FALLBACK_ANSWER, { timing: { firstToken: "5s" }, times: -1 });
|
|
480
|
+
const agent = await agentOf(slack);
|
|
481
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
482
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
483
|
+
await (await slackDelivery(msg, agent, context)).retry({ after: "3s", reason: "http_timeout" });
|
|
484
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, timeout: "20s" });
|
|
485
|
+
}, withModel);
|
|
486
|
+
check("slack.model-error", "when the model fails, the person hears so and nothing is left working", async ({ slack, openai }) => {
|
|
487
|
+
await openai.respond({ error: "overloaded" }, { times: -1 });
|
|
488
|
+
const agent = await agentOf(slack);
|
|
489
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
490
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
491
|
+
await expect(msg.thread).toHaveReplyFrom(app, { timeout: "20s" });
|
|
492
|
+
await expect(msg.thread).not.toHaveStreamingReplyFrom(app, wait);
|
|
493
|
+
await expect(msg.thread).toHaveStatus("idle", wait);
|
|
494
|
+
}, withModel);
|
|
495
|
+
check("slack.model-retry", "a model call that is retried still gives one reply", async ({ slack, openai }) => {
|
|
496
|
+
await openai.respond([{ error: "overloaded" }, { error: "overloaded" }, FALLBACK_ANSWER]);
|
|
497
|
+
const agent = await agentOf(slack);
|
|
498
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
499
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
500
|
+
await expect(msg.thread).toHaveReplyFrom(app, { text: FALLBACK_ANSWER, timeout: "20s" });
|
|
501
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
502
|
+
}, withModel);
|
|
503
|
+
check("slack.stream-breaks", "a stream that breaks halfway is stopped, and the status clears", async ({ slack, openai }) => {
|
|
504
|
+
await openai.respond({ ...LONG_ANSWER, failAfter: { chunks: 3, how: "drop" } });
|
|
505
|
+
const agent = await agentOf(slack);
|
|
506
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
507
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
508
|
+
await expect(msg.thread).toHaveReplyFrom(app, wait);
|
|
509
|
+
await expect(msg.thread).not.toHaveStreamingReplyFrom(app, wait);
|
|
510
|
+
await expect(msg.thread).toHaveStatus("idle", wait);
|
|
511
|
+
}, withModel);
|
|
512
|
+
check("slack.stop-cancels-model", "Stop cancels the model request", async ({ slack, openai }) => {
|
|
513
|
+
const ai = await openai.respond({ ...LONG_ANSWER, pauseAfter: 3 });
|
|
514
|
+
const agent = await agentOf(slack);
|
|
515
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
516
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
517
|
+
const call = await ai.waitForPause(wait);
|
|
518
|
+
await ana.stop({ thread: msg });
|
|
519
|
+
await expect(msg.thread).toHaveStatus("stopped", wait);
|
|
520
|
+
await expect(call).toBeAborted(wait);
|
|
521
|
+
}, withModel);
|
|
522
|
+
check("slack.no-secrets-to-model", "sends the model no token, signing secret or key", async ({ slack, openai }) => {
|
|
523
|
+
await openai.respond(FALLBACK_ANSWER, { times: -1 });
|
|
524
|
+
const agent = await agentOf(slack);
|
|
525
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
526
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
527
|
+
await expect(msg.thread).toHaveReplyFrom(app, wait);
|
|
528
|
+
await expect(openai).not.toHaveSentSecrets(wait);
|
|
529
|
+
}, withModel);
|
|
304
530
|
});
|
|
305
531
|
}
|
|
306
532
|
/**
|
|
@@ -313,12 +539,18 @@ export function githubChecks(options) {
|
|
|
313
539
|
const prompt = options.prompt ?? `@${app} hello`;
|
|
314
540
|
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
315
541
|
const check = registrar(options, GITHUB_CHECKS);
|
|
542
|
+
const turns = options.loopTurns ?? 3;
|
|
543
|
+
/** The App under test: the built-in one, or the App of that name (decision 0027). */
|
|
544
|
+
const agentOf = async (github) => builtIn(app, github.app) ? github.app : github.createApp({ name: app });
|
|
316
545
|
/** A repository the App is installed on, with Ana as a collaborator and an issue to talk in. */
|
|
317
|
-
const setup = async ({ github }) => {
|
|
546
|
+
const setup = async ({ github }, also = []) => {
|
|
547
|
+
const agent = await agentOf(github);
|
|
318
548
|
const ana = await github.createUser({ login: "ana" });
|
|
319
|
-
const repo = await github.createRepo({ collaborators: [ana], apps: [
|
|
320
|
-
return { ana, repo };
|
|
549
|
+
const repo = await github.createRepo({ collaborators: [ana], apps: [agent, ...also] });
|
|
550
|
+
return { ana, agent, repo };
|
|
321
551
|
};
|
|
552
|
+
/** The delivery a comment caused to the App under test. */
|
|
553
|
+
const githubDelivery = (comment, agent, context) => deliveryTo(comment, agent, context.github.app, context, "GitHub", wait);
|
|
322
554
|
const pullRequest = async (context) => {
|
|
323
555
|
const { ana, repo } = await setup(context);
|
|
324
556
|
const pr = await ana.openPullRequest({ from: "change", title: "Greet people", changes: { "greeting.txt": "hello\n" } }, { repo });
|
|
@@ -349,10 +581,10 @@ export function githubChecks(options) {
|
|
|
349
581
|
expect(replies.map((reply) => reply.author.name)).toEqual([app]);
|
|
350
582
|
});
|
|
351
583
|
check("github.redelivery", "a redelivered webhook doesn't produce a second answer", async (context) => {
|
|
352
|
-
const { ana, repo } = await setup(context);
|
|
584
|
+
const { ana, agent, repo } = await setup(context);
|
|
353
585
|
const issue = await ana.openIssue({ title: "Delivered twice" }, { repo });
|
|
354
586
|
const comment = await ana.comment(prompt, { issue });
|
|
355
|
-
const delivery =
|
|
587
|
+
const delivery = await githubDelivery(comment, agent, context);
|
|
356
588
|
await expect(issue).toHaveCommentFrom(app, wait);
|
|
357
589
|
// GitHub redelivers with the same `X-GitHub-Delivery`, from its UI and its API.
|
|
358
590
|
await delivery.redeliver();
|
|
@@ -366,12 +598,32 @@ export function githubChecks(options) {
|
|
|
366
598
|
expect(runs.filter((run) => run.status !== "completed").map((run) => run.name)).toEqual([]);
|
|
367
599
|
});
|
|
368
600
|
check("github.bad-signature", "rejects a webhook with a bad signature", async (context) => {
|
|
369
|
-
const { ana, repo } = await setup(context);
|
|
601
|
+
const { ana, agent, repo } = await setup(context);
|
|
370
602
|
const issue = await ana.openIssue({ title: "Signed by someone else" }, { repo });
|
|
371
|
-
const delivery =
|
|
603
|
+
const delivery = await githubDelivery(await ana.comment(prompt, { issue }), agent, context);
|
|
372
604
|
await delivery.resend({ badSignature: true });
|
|
373
605
|
await expect(delivery).toBeRejected(wait);
|
|
374
606
|
});
|
|
607
|
+
check("github.no-reply-loop", "stops answering another App that mentions it after every answer", async (context) => {
|
|
608
|
+
const peer = await context.github.createApp({ name: app === "loop-peer" ? "loop-peer-2" : "loop-peer" });
|
|
609
|
+
const { ana, agent, repo } = await setup(context, [peer]);
|
|
610
|
+
const issue = await ana.openIssue({ title: "A question" }, { repo });
|
|
611
|
+
await ana.comment(prompt, { issue });
|
|
612
|
+
await expect(issue).toHaveCommentFrom(agent, wait);
|
|
613
|
+
const agentComments = async () => (await issue.comments()).filter((one) => one.author.id === agent.id).length;
|
|
614
|
+
// The peer answers each comment of the agent's, mentioning it, as a second agent without a loop guard would.
|
|
615
|
+
const before = await agentComments();
|
|
616
|
+
const start = (await appTurns(issue)).count;
|
|
617
|
+
let seen = before;
|
|
618
|
+
for (let turn = 0; turn <= turns; turn++) {
|
|
619
|
+
await peer.comment(`@${agent.name} thanks! Anything else?`, { issue });
|
|
620
|
+
const now = await answersAgain(agentComments, seen, wait);
|
|
621
|
+
if (now === seen)
|
|
622
|
+
break;
|
|
623
|
+
seen = now;
|
|
624
|
+
}
|
|
625
|
+
await answeredAtMost(issue, { start, answered: seen - before, turns, what: "the other App", wait });
|
|
626
|
+
});
|
|
375
627
|
});
|
|
376
628
|
}
|
|
377
629
|
/**
|
|
@@ -383,13 +635,17 @@ export function linearChecks(options) {
|
|
|
383
635
|
const title = options.prompt ?? "Look into this";
|
|
384
636
|
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
385
637
|
const check = registrar(options, LINEAR_CHECKS);
|
|
638
|
+
const turns = options.loopTurns ?? 3;
|
|
639
|
+
/** The app under test: the built-in one, or the app of that name (decision 0027). A session's delivery is its own. */
|
|
640
|
+
const agentOf = async (linear) => builtIn(app, linear.app) ? linear.app : linear.createApp({ name: app });
|
|
386
641
|
/** Ana in a team, an issue, and a session from delegating it to the app. */
|
|
387
642
|
const delegated = async ({ linear }) => {
|
|
643
|
+
const agent = await agentOf(linear);
|
|
388
644
|
const ana = await linear.createUser({ name: "Ana" });
|
|
389
645
|
const team = await linear.createTeam({ members: [ana] });
|
|
390
646
|
const issue = await ana.createIssue({ title }, { team });
|
|
391
|
-
const session = await ana.delegate(
|
|
392
|
-
return { ana, issue, session };
|
|
647
|
+
const session = await ana.delegate(agent, { issue });
|
|
648
|
+
return { ana, agent, issue, session };
|
|
393
649
|
};
|
|
394
650
|
const ended = ["complete", "awaitingInput", "error"];
|
|
395
651
|
describe(`linear checks: ${app}`, () => {
|
|
@@ -430,6 +686,24 @@ export function linearChecks(options) {
|
|
|
430
686
|
await delivery.resend({ badSignature: true });
|
|
431
687
|
await expect(delivery).toBeRejected(wait);
|
|
432
688
|
});
|
|
689
|
+
check("linear.no-reply-loop", "stops answering another app that comments on everything", async (context) => {
|
|
690
|
+
const { agent, issue, session } = await delegated(context);
|
|
691
|
+
const peer = await context.linear.createApp({ name: app === "loop-peer" ? "loop-peer-2" : "loop-peer" });
|
|
692
|
+
await session.waitForState([...ended], wait);
|
|
693
|
+
const agentComments = async () => (await issue.comments()).filter((one) => one.author.id === agent.id).length;
|
|
694
|
+
// The peer comments after each comment of the agent's, as a second agent without a loop guard would.
|
|
695
|
+
const before = await agentComments();
|
|
696
|
+
const start = (await appTurns(issue)).count;
|
|
697
|
+
let seen = before;
|
|
698
|
+
for (let turn = 0; turn <= turns; turn++) {
|
|
699
|
+
await peer.comment("Thanks! Anything else?", { issue });
|
|
700
|
+
const now = await answersAgain(agentComments, seen, wait);
|
|
701
|
+
if (now === seen)
|
|
702
|
+
break;
|
|
703
|
+
seen = now;
|
|
704
|
+
}
|
|
705
|
+
await answeredAtMost(issue, { start, answered: seen - before, turns, what: "the other app", wait });
|
|
706
|
+
});
|
|
433
707
|
});
|
|
434
708
|
}
|
|
435
709
|
/**
|
|
@@ -441,13 +715,23 @@ export function notionChecks(options) {
|
|
|
441
715
|
const prompt = options.prompt ?? `@${app} hello`;
|
|
442
716
|
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
443
717
|
const check = registrar(options, NOTION_CHECKS);
|
|
718
|
+
const turns = options.loopTurns ?? 3;
|
|
719
|
+
/** The integration under test: the built-in one, or the integration of that name (decision 0027). */
|
|
720
|
+
const agentOf = async (notion) => builtIn(app, notion.app) ? notion.app : notion.createApp({ name: app });
|
|
444
721
|
/** Ana, and her comment on a page the integration is connected to. */
|
|
445
|
-
const commented = async ({ notion }) => {
|
|
722
|
+
const commented = async ({ notion }, also = []) => {
|
|
723
|
+
const agent = await agentOf(notion);
|
|
446
724
|
const ana = await notion.createUser({ name: "Ana" });
|
|
447
|
-
const page = await notion.createPage({
|
|
725
|
+
const page = await notion.createPage({
|
|
726
|
+
title: "Notes",
|
|
727
|
+
content: "- a first note",
|
|
728
|
+
connections: [agent, ...also],
|
|
729
|
+
});
|
|
448
730
|
const comment = await ana.comment(prompt, { page });
|
|
449
|
-
return { ana, page, comment };
|
|
731
|
+
return { ana, agent, page, comment };
|
|
450
732
|
};
|
|
733
|
+
/** The delivery a comment caused to the integration under test. */
|
|
734
|
+
const notionDelivery = (comment, agent, context) => deliveryTo(comment, agent, context.notion.app, context, "Notion", wait);
|
|
451
735
|
describe(`notion checks: ${app}`, () => {
|
|
452
736
|
check("notion.reply-in-discussion", "answers a comment in its discussion", async (context) => {
|
|
453
737
|
const { page, comment } = await commented(context);
|
|
@@ -462,18 +746,43 @@ export function notionChecks(options) {
|
|
|
462
746
|
await expect(comment.discussion).toHaveCommentsFrom(app, { count: 1, ...wait });
|
|
463
747
|
});
|
|
464
748
|
check("notion.redelivery", "a webhook sent again doesn't produce a second answer", async (context) => {
|
|
465
|
-
const { comment } = await commented(context);
|
|
466
|
-
const delivery =
|
|
749
|
+
const { agent, comment } = await commented(context);
|
|
750
|
+
const delivery = await notionDelivery(comment, agent, context);
|
|
467
751
|
await expect(comment.discussion).toHaveCommentFrom(app, wait);
|
|
468
752
|
// Notion retries with the same event id.
|
|
469
753
|
await delivery.redeliver();
|
|
470
754
|
await expect(comment.discussion).toHaveCommentsFrom(app, { count: 1, ...wait });
|
|
471
755
|
});
|
|
472
756
|
check("notion.bad-signature", "rejects a webhook with a bad signature", async (context) => {
|
|
473
|
-
const
|
|
757
|
+
const { agent, comment } = await commented(context);
|
|
758
|
+
const delivery = await notionDelivery(comment, agent, context);
|
|
474
759
|
await delivery.resend({ badSignature: true });
|
|
475
760
|
await expect(delivery).toBeRejected(wait);
|
|
476
761
|
});
|
|
762
|
+
check("notion.no-reply-loop", "stops answering another integration that answers everything", async (context) => {
|
|
763
|
+
const peer = await context.notion.createApp({ name: app === "loop-peer" ? "loop-peer-2" : "loop-peer" });
|
|
764
|
+
const { agent, comment } = await commented(context, [peer]);
|
|
765
|
+
await expect(comment.discussion).toHaveCommentFrom(agent, wait);
|
|
766
|
+
const agentComments = async () => (await comment.discussion.comments()).filter((one) => one.author.id === agent.id).length;
|
|
767
|
+
// The peer answers each comment of the agent's in the discussion, as a second agent without a loop guard would.
|
|
768
|
+
const before = await agentComments();
|
|
769
|
+
const start = (await appTurns(comment.discussion)).count;
|
|
770
|
+
let seen = before;
|
|
771
|
+
for (let turn = 0; turn <= turns; turn++) {
|
|
772
|
+
await peer.reply("Thanks! Anything else?", { discussion: comment.discussion });
|
|
773
|
+
const now = await answersAgain(agentComments, seen, wait);
|
|
774
|
+
if (now === seen)
|
|
775
|
+
break;
|
|
776
|
+
seen = now;
|
|
777
|
+
}
|
|
778
|
+
await answeredAtMost(comment.discussion, {
|
|
779
|
+
start,
|
|
780
|
+
answered: seen - before,
|
|
781
|
+
turns,
|
|
782
|
+
what: "the other integration",
|
|
783
|
+
wait,
|
|
784
|
+
});
|
|
785
|
+
});
|
|
477
786
|
});
|
|
478
787
|
}
|
|
479
788
|
/**
|
|
@@ -485,11 +794,21 @@ export function resendChecks(options) {
|
|
|
485
794
|
const prompt = options.prompt ?? "hello";
|
|
486
795
|
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
487
796
|
const check = registrar(options, RESEND_CHECKS);
|
|
797
|
+
const turns = options.loopTurns ?? 3;
|
|
798
|
+
/** The app under test: the built-in one, or the app of that name (decision 0027). */
|
|
799
|
+
const agentOf = async (resend) => builtIn(app, resend.app) ? resend.app : resend.createApp({ name: app });
|
|
488
800
|
/** Ana, and her email to the agent. */
|
|
489
801
|
const emailed = async ({ resend }) => {
|
|
802
|
+
const agent = await agentOf(resend);
|
|
490
803
|
const ana = await resend.createUser({ name: "Ana" });
|
|
491
|
-
const email = await ana.send({ to: [
|
|
492
|
-
return { ana, email };
|
|
804
|
+
const email = await ana.send({ to: [agent], subject: "A question", text: prompt });
|
|
805
|
+
return { ana, agent, email };
|
|
806
|
+
};
|
|
807
|
+
/** The delivery an email caused to the app under test. */
|
|
808
|
+
const delivered = async (context) => {
|
|
809
|
+
const { agent, email } = await emailed(context);
|
|
810
|
+
const delivery = await deliveryTo(email, agent, context.resend.app, context, "Resend", wait);
|
|
811
|
+
return { email, delivery };
|
|
493
812
|
};
|
|
494
813
|
describe(`resend checks: ${app}`, () => {
|
|
495
814
|
check("resend.reply-in-thread", "answers an email in its thread", async (context) => {
|
|
@@ -499,23 +818,27 @@ export function resendChecks(options) {
|
|
|
499
818
|
expect(answer.thread.id, "the answer started a thread of its own: set In-Reply-To and References").toBe(email.thread.id);
|
|
500
819
|
});
|
|
501
820
|
check("resend.redelivery", "a webhook sent again doesn't produce a second answer", async (context) => {
|
|
502
|
-
const { email } = await
|
|
503
|
-
const delivery = deliveryOf(email, context, "Resend");
|
|
821
|
+
const { email, delivery } = await delivered(context);
|
|
504
822
|
await expect(email.thread).toHaveReplyFrom(app, wait);
|
|
505
823
|
// Resend retries with the same svix-id and the same email_id.
|
|
506
824
|
await delivery.redeliver();
|
|
507
825
|
await expect(email.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
508
826
|
});
|
|
509
827
|
check("resend.bad-signature", "rejects a webhook with a bad signature", async (context) => {
|
|
510
|
-
const delivery =
|
|
828
|
+
const { delivery } = await delivered(context);
|
|
511
829
|
await delivery.resend({ badSignature: true });
|
|
512
830
|
await expect(delivery).toBeRejected(wait);
|
|
513
831
|
});
|
|
514
832
|
check("resend.stale", "rejects a webhook signed more than five minutes ago", async (context) => {
|
|
515
|
-
const delivery =
|
|
833
|
+
const { delivery } = await delivered(context);
|
|
516
834
|
await delivery.resend({ stale: true });
|
|
517
835
|
await expect(delivery).toBeRejected(wait);
|
|
518
836
|
});
|
|
837
|
+
check("resend.no-reply-loop", "leaves mail another program sent on its own unanswered", async (context) => {
|
|
838
|
+
const agent = await agentOf(context.resend);
|
|
839
|
+
const peer = await context.resend.createApp({ name: app === "loop-peer" ? "loop-peer-2" : "loop-peer" });
|
|
840
|
+
await autoMailLoop(agent, peer, turns, wait);
|
|
841
|
+
});
|
|
519
842
|
});
|
|
520
843
|
}
|
|
521
844
|
/**
|
|
@@ -527,11 +850,21 @@ export function googleChecks(options) {
|
|
|
527
850
|
const prompt = options.prompt ?? "hello";
|
|
528
851
|
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
529
852
|
const check = registrar(options, GOOGLE_CHECKS);
|
|
853
|
+
const turns = options.loopTurns ?? 3;
|
|
854
|
+
/** The app under test: the built-in one, or the app of that name (decision 0027). */
|
|
855
|
+
const agentOf = async (google) => builtIn(app, google.app) ? google.app : google.createApp({ name: app });
|
|
530
856
|
/** Ana, and her email to the agent. */
|
|
531
857
|
const emailed = async ({ google }) => {
|
|
858
|
+
const agent = await agentOf(google);
|
|
532
859
|
const ana = await google.createUser({ name: "Ana" });
|
|
533
|
-
const email = await ana.send({ to: [
|
|
534
|
-
return { ana, email };
|
|
860
|
+
const email = await ana.send({ to: [agent], subject: "A question", text: prompt });
|
|
861
|
+
return { ana, agent, email };
|
|
862
|
+
};
|
|
863
|
+
/** The delivery an email caused to the app under test. */
|
|
864
|
+
const delivered = async (context) => {
|
|
865
|
+
const { agent, email } = await emailed(context);
|
|
866
|
+
const delivery = await deliveryTo(email, agent, context.google.app, context, "Gmail", wait);
|
|
867
|
+
return { email, delivery };
|
|
535
868
|
};
|
|
536
869
|
describe(`google checks: ${app}`, () => {
|
|
537
870
|
check("google.reply-in-thread", "answers an email in its thread", async (context) => {
|
|
@@ -544,35 +877,158 @@ export function googleChecks(options) {
|
|
|
544
877
|
// Gmail pushes at most once a second. A first email is pushed at once; the two after it, within
|
|
545
878
|
// that second, wait for its end and come in one push, so the agent must read its history.
|
|
546
879
|
const ana = await google.createUser({ name: "Ana" });
|
|
547
|
-
const opener = await ana.send({ to: [google
|
|
548
|
-
const first = await ana.send({ to: [google
|
|
549
|
-
const second = await ana.send({ to: [google
|
|
880
|
+
const opener = await ana.send({ to: [await agentOf(google)], subject: "Hello", text: prompt });
|
|
881
|
+
const first = await ana.send({ to: [await agentOf(google)], subject: "First", text: prompt });
|
|
882
|
+
const second = await ana.send({ to: [await agentOf(google)], subject: "Second", text: prompt });
|
|
550
883
|
await expect(opener.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
551
884
|
await expect(first.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
552
885
|
await expect(second.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
553
886
|
});
|
|
554
887
|
check("google.redelivery", "a push sent again doesn't produce a second answer", async (context) => {
|
|
555
|
-
const { email } = await
|
|
556
|
-
const push = deliveryOf(email, context, "Gmail");
|
|
888
|
+
const { email, delivery: push } = await delivered(context);
|
|
557
889
|
await expect(email.thread).toHaveReplyFrom(app, wait);
|
|
558
890
|
// Pub/Sub delivers at least once: the same message id again.
|
|
559
891
|
await push.redeliver();
|
|
560
892
|
await expect(email.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
561
893
|
});
|
|
562
894
|
check("google.bad-signature", "rejects a push whose token another key signed", async (context) => {
|
|
563
|
-
const push =
|
|
895
|
+
const { delivery: push } = await delivered(context);
|
|
564
896
|
await push.resend({ badSignature: true });
|
|
565
897
|
await expect(push).toBeRejected(wait);
|
|
566
898
|
});
|
|
567
899
|
check("google.wrong-audience", "rejects a push whose token is for another audience", async (context) => {
|
|
568
|
-
const push =
|
|
900
|
+
const { delivery: push } = await delivered(context);
|
|
569
901
|
await push.resend({ wrongAudience: true });
|
|
570
902
|
await expect(push).toBeRejected(wait);
|
|
571
903
|
});
|
|
572
904
|
check("google.stale", "rejects a push whose token has expired", async (context) => {
|
|
573
|
-
const push =
|
|
905
|
+
const { delivery: push } = await delivered(context);
|
|
574
906
|
await push.resend({ stale: true });
|
|
575
907
|
await expect(push).toBeRejected(wait);
|
|
576
908
|
});
|
|
909
|
+
check("google.no-reply-loop", "leaves mail another program sent on its own unanswered", async (context) => {
|
|
910
|
+
const agent = await agentOf(context.google);
|
|
911
|
+
const peer = await context.google.createApp({ name: app === "loop-peer" ? "loop-peer-2" : "loop-peer" });
|
|
912
|
+
await autoMailLoop(agent, peer, turns, wait);
|
|
913
|
+
});
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Registers: answers a mention once · answers a DM once · ignores other bots · stops answering
|
|
918
|
+
* another app that answers everything · after a dropped Gateway connection, answers what it
|
|
919
|
+
* missed once · writes a long answer in messages Discord takes · answers an interaction within
|
|
920
|
+
* 3 s · rejects an interaction with a bad signature.
|
|
921
|
+
*/
|
|
922
|
+
export function discordChecks(options) {
|
|
923
|
+
const { app } = options;
|
|
924
|
+
const prompt = options.prompt ?? `@${app} hello`;
|
|
925
|
+
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
926
|
+
const check = registrar(options, DISCORD_CHECKS);
|
|
927
|
+
const turns = options.loopTurns ?? 3;
|
|
928
|
+
/** The app under test: the built-in one, or the app of that name (decision 0027), whose agent runs as it. */
|
|
929
|
+
const agentOf = async (discord) => builtIn(app, discord.app) ? discord.app : discord.createApp({ name: app });
|
|
930
|
+
/** A channel with Ana and the bot under test. */
|
|
931
|
+
const inChannel = async ({ discord }) => {
|
|
932
|
+
const agent = await agentOf(discord);
|
|
933
|
+
const ana = await discord.createUser({ name: "Ana" });
|
|
934
|
+
const channel = await discord.createChannel({ participants: [ana, agent] });
|
|
935
|
+
return { agent, ana, channel };
|
|
936
|
+
};
|
|
937
|
+
describe(`discord checks: ${app}`, () => {
|
|
938
|
+
check("discord.mention-once", "answers a mention once", async (context) => {
|
|
939
|
+
const { ana, channel } = await inChannel(context);
|
|
940
|
+
const msg = await ana.say(prompt, { channel });
|
|
941
|
+
await expect(msg).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
942
|
+
});
|
|
943
|
+
check("discord.dm-once", "answers a DM once", async ({ discord }) => {
|
|
944
|
+
const agent = await agentOf(discord);
|
|
945
|
+
const ana = await discord.createUser({ name: "Ana" });
|
|
946
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
947
|
+
await expect(msg.channel).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
948
|
+
});
|
|
949
|
+
check("discord.ignores-bots", "ignores what other bots write", async ({ discord }) => {
|
|
950
|
+
const agent = await agentOf(discord);
|
|
951
|
+
const bot = await discord.createUser({ name: "Deploy Bot", bot: true });
|
|
952
|
+
const channel = await discord.createChannel({ participants: [bot, agent] });
|
|
953
|
+
const msg = await bot.say(prompt, { channel });
|
|
954
|
+
await expect(msg).not.toHaveReplyFrom(app, wait);
|
|
955
|
+
});
|
|
956
|
+
check("discord.no-reply-loop", "stops answering another app that answers everything it says", async ({ discord }) => {
|
|
957
|
+
const agent = await agentOf(discord);
|
|
958
|
+
const peer = await discord.createApp({ name: app === "loop-peer" ? "loop-peer-2" : "loop-peer" });
|
|
959
|
+
const ana = await discord.createUser({ name: "Ana" });
|
|
960
|
+
const channel = await discord.createChannel({ participants: [ana, agent, peer] });
|
|
961
|
+
await ana.say(prompt, { channel });
|
|
962
|
+
const answers = async () => (await channel.messages()).filter((message) => message.author.id === agent.id);
|
|
963
|
+
const count = async () => (await answers()).length;
|
|
964
|
+
// The agent's answer to Ana; then the peer answers each of its answers, mentioning it, as a
|
|
965
|
+
// second agent without a loop guard would.
|
|
966
|
+
const first = await answersAgain(count, 0, wait);
|
|
967
|
+
const start = (await appTurns(channel)).count;
|
|
968
|
+
let seen = first;
|
|
969
|
+
for (let turn = 0; turn <= turns; turn++) {
|
|
970
|
+
const latest = (await answers()).at(-1);
|
|
971
|
+
if (!latest)
|
|
972
|
+
break;
|
|
973
|
+
await peer.reply(`@${agent.name} thanks! Anything else?`, { message: latest });
|
|
974
|
+
const now = await answersAgain(count, seen, wait);
|
|
975
|
+
if (now === seen)
|
|
976
|
+
break;
|
|
977
|
+
seen = now;
|
|
978
|
+
}
|
|
979
|
+
await answeredAtMost(channel, { start, answered: seen - first, turns, what: "the other app", wait });
|
|
980
|
+
});
|
|
981
|
+
check("discord.resume", "after a dropped connection, answers what it missed once", async (context) => {
|
|
982
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
983
|
+
try {
|
|
984
|
+
const { discord } = context;
|
|
985
|
+
const agent = await agentOf(discord);
|
|
986
|
+
const ana = await discord.createUser({ name: "Ana" });
|
|
987
|
+
// Live, Discord drops connections itself: the fault is fake-only, and the test skips there.
|
|
988
|
+
const _drop = __addDisposableResource(env_2, await discord.fault({ type: "drop_gateway" }), true);
|
|
989
|
+
// The connection drops just before Ana's message reaches the bot: a bot that resumes gets it then.
|
|
990
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
991
|
+
await expect(msg.channel).toHaveRepliesFrom(app, { count: 1, timeout: "20s", ...wait });
|
|
992
|
+
}
|
|
993
|
+
catch (e_2) {
|
|
994
|
+
env_2.error = e_2;
|
|
995
|
+
env_2.hasError = true;
|
|
996
|
+
}
|
|
997
|
+
finally {
|
|
998
|
+
const result_2 = __disposeResources(env_2);
|
|
999
|
+
if (result_2)
|
|
1000
|
+
await result_2;
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
check("discord.long-answer", "writes a long answer in messages of at most 2000 characters", async ({ discord }) => {
|
|
1004
|
+
const agent = await agentOf(discord);
|
|
1005
|
+
const ana = await discord.createUser({ name: "Ana" });
|
|
1006
|
+
const msg = await ana.say(options.longPrompt ?? "", { to: agent });
|
|
1007
|
+
await expect(msg.channel).toHaveReplyFrom(app, wait);
|
|
1008
|
+
// Discord refuses a longer message (50035, Invalid Form Body): the agent must split it. This waits for quiet.
|
|
1009
|
+
await expect(discord).not.toHaveReceivedCall(/.*/, { error: "50035", ...wait });
|
|
1010
|
+
// Split, not cut: the whole answer takes more than one message.
|
|
1011
|
+
const answers = (await msg.channel.messages()).filter((message) => message.author.name === app);
|
|
1012
|
+
expect(answers.length, "the long answer came in one message: it was cut, not split").toBeGreaterThan(1);
|
|
1013
|
+
}, options.longPrompt);
|
|
1014
|
+
check("discord.interaction-3s", "answers an interaction within 3 seconds", async (context) => {
|
|
1015
|
+
const { agent, ana, channel } = await inChannel(context);
|
|
1016
|
+
// The agent's own command: another app may have one of that name too.
|
|
1017
|
+
const delivery = await ana.runCommand(options.command ?? "/", { channel, app: agent });
|
|
1018
|
+
// Late, Discord shows the person "This interaction failed", and takes no answer any more.
|
|
1019
|
+
await expect(channel).not.toContainText("This interaction failed", { as: ana, ...wait });
|
|
1020
|
+
if (delivery)
|
|
1021
|
+
await expect(delivery).toBeAccepted({ within: "3s", ...wait });
|
|
1022
|
+
}, options.command);
|
|
1023
|
+
check("discord.bad-signature", "rejects an interaction with a bad signature", async (context) => {
|
|
1024
|
+
const { agent, ana, channel } = await inChannel(context);
|
|
1025
|
+
const delivery = deliveryOf({ delivery: await ana.runCommand(options.command ?? "/", { channel, app: agent }) }, context, "Discord");
|
|
1026
|
+
const first = await delivery.settled(wait);
|
|
1027
|
+
// Over the Gateway there is no signature to check: the connection is the bot's own.
|
|
1028
|
+
if (first.attempts[0]?.transport !== "http")
|
|
1029
|
+
return;
|
|
1030
|
+
await delivery.resend({ badSignature: true });
|
|
1031
|
+
await expect(delivery).toBeRejected(wait);
|
|
1032
|
+
}, options.command);
|
|
577
1033
|
});
|
|
578
1034
|
}
|