channelstack 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +56 -2
- package/bin/channelstack.mjs +31 -0
- package/dist/integrations/checks/checks.test.d.ts +1 -0
- package/dist/integrations/checks/checks.test.js +31 -0
- package/dist/integrations/checks/index.d.ts +102 -0
- package/dist/integrations/checks/index.js +1034 -0
- package/dist/integrations/matchers-core/index.d.ts +217 -0
- package/dist/integrations/matchers-core/index.js +799 -0
- package/dist/integrations/matchers-core/matchers.test.d.ts +1 -0
- package/dist/integrations/matchers-core/matchers.test.js +407 -0
- package/dist/integrations/vitest/global-setup.d.ts +3 -0
- package/dist/integrations/vitest/global-setup.js +19 -0
- package/dist/integrations/vitest/index.d.ts +82 -0
- package/dist/integrations/vitest/index.js +42 -0
- package/dist/integrations/vitest/plugin.test.d.ts +1 -0
- package/dist/integrations/vitest/plugin.test.js +19 -0
- package/dist/integrations/vitest/refused.d.ts +22 -0
- package/dist/integrations/vitest/refused.js +49 -0
- package/dist/integrations/vitest/setup.d.ts +1 -0
- package/dist/integrations/vitest/setup.js +139 -0
- package/dist/sdks/typescript/client.d.ts +14 -0
- package/dist/sdks/typescript/client.js +11 -0
- package/dist/sdks/typescript/generated/channels.d.ts +32 -0
- package/dist/sdks/typescript/generated/channels.js +4 -0
- package/dist/sdks/typescript/generated/index.d.ts +4178 -0
- package/dist/sdks/typescript/generated/index.js +4608 -0
- 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 +56 -0
- package/dist/sdks/typescript/runtime/client.js +74 -0
- package/dist/sdks/typescript/runtime/credentials.d.ts +7 -0
- package/dist/sdks/typescript/runtime/credentials.js +20 -0
- package/dist/sdks/typescript/runtime/duration.d.ts +4 -0
- package/dist/sdks/typescript/runtime/duration.js +13 -0
- package/dist/sdks/typescript/runtime/files.d.ts +47 -0
- package/dist/sdks/typescript/runtime/files.js +53 -0
- package/dist/sdks/typescript/runtime/launcher.d.ts +27 -0
- package/dist/sdks/typescript/runtime/launcher.js +124 -0
- package/dist/sdks/typescript/runtime/responder.d.ts +26 -0
- package/dist/sdks/typescript/runtime/responder.js +42 -0
- package/dist/sdks/typescript/runtime/transport.d.ts +43 -0
- package/dist/sdks/typescript/runtime/transport.js +95 -0
- package/dist/sdks/typescript/runtime/wait.d.ts +96 -0
- package/dist/sdks/typescript/runtime/wait.js +159 -0
- package/dist/sdks/typescript/types.d.ts +82 -0
- package/dist/sdks/typescript/types.js +1 -0
- package/package.json +82 -4
|
@@ -0,0 +1,1034 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* `channelstack/checks`: the standard behaviour checks. Calling one registers ordinary tests in
|
|
55
|
+
* the suite that is running, on the fixtures and matchers of `channelstack/vitest`:
|
|
56
|
+
*
|
|
57
|
+
* import { slackChecks } from "channelstack/checks";
|
|
58
|
+
* slackChecks({ app: "my-agent" });
|
|
59
|
+
*
|
|
60
|
+
* Each check is something agents commonly get wrong, written against the public API only.
|
|
61
|
+
*/
|
|
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
|
+
};
|
|
138
|
+
/** The ids of the Slack checks, in the order they are registered. */
|
|
139
|
+
export const SLACK_CHECKS = [
|
|
140
|
+
"slack.dm-once",
|
|
141
|
+
"slack.mention-once",
|
|
142
|
+
"slack.in-thread",
|
|
143
|
+
"slack.retry",
|
|
144
|
+
"slack.redelivery",
|
|
145
|
+
"slack.ignores-bots",
|
|
146
|
+
"slack.no-reply-loop",
|
|
147
|
+
"slack.bad-signature",
|
|
148
|
+
"slack.ack",
|
|
149
|
+
"slack.msg-too-long",
|
|
150
|
+
"slack.stream-stop",
|
|
151
|
+
"slack.stop",
|
|
152
|
+
"slack.click-unauthorized",
|
|
153
|
+
"slack.double-click",
|
|
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"]);
|
|
166
|
+
/** The ids of the GitHub checks, in the order they are registered. */
|
|
167
|
+
export const GITHUB_CHECKS = [
|
|
168
|
+
"github.ignores-own-comments",
|
|
169
|
+
"github.one-comment",
|
|
170
|
+
"github.review-thread",
|
|
171
|
+
"github.redelivery",
|
|
172
|
+
"github.check-run",
|
|
173
|
+
"github.bad-signature",
|
|
174
|
+
"github.no-reply-loop",
|
|
175
|
+
];
|
|
176
|
+
/** The ids of the Linear checks, in the order they are registered. */
|
|
177
|
+
export const LINEAR_CHECKS = [
|
|
178
|
+
"linear.first-activity",
|
|
179
|
+
"linear.ends-turn",
|
|
180
|
+
"linear.stop",
|
|
181
|
+
"linear.redelivery",
|
|
182
|
+
"linear.stale",
|
|
183
|
+
"linear.bad-signature",
|
|
184
|
+
"linear.no-reply-loop",
|
|
185
|
+
];
|
|
186
|
+
/** The ids of the Notion checks, in the order they are registered. */
|
|
187
|
+
export const NOTION_CHECKS = [
|
|
188
|
+
"notion.reply-in-discussion",
|
|
189
|
+
"notion.ignores-own-comments",
|
|
190
|
+
"notion.redelivery",
|
|
191
|
+
"notion.bad-signature",
|
|
192
|
+
"notion.no-reply-loop",
|
|
193
|
+
];
|
|
194
|
+
/** The ids of the Resend checks, in the order they are registered. */
|
|
195
|
+
export const RESEND_CHECKS = [
|
|
196
|
+
"resend.reply-in-thread",
|
|
197
|
+
"resend.redelivery",
|
|
198
|
+
"resend.bad-signature",
|
|
199
|
+
"resend.stale",
|
|
200
|
+
"resend.no-reply-loop",
|
|
201
|
+
];
|
|
202
|
+
/** The ids of the Google checks, in the order they are registered. */
|
|
203
|
+
export const GOOGLE_CHECKS = [
|
|
204
|
+
"google.reply-in-thread",
|
|
205
|
+
"google.history",
|
|
206
|
+
"google.redelivery",
|
|
207
|
+
"google.bad-signature",
|
|
208
|
+
"google.wrong-audience",
|
|
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",
|
|
222
|
+
];
|
|
223
|
+
/**
|
|
224
|
+
* The delivery a check retries, redelivers, forges or times: the one thing every delivery check
|
|
225
|
+
* needs, on every channel. Live, the platform delivers to the agent itself and channelstack has no
|
|
226
|
+
* delivery to show (reality-matrix.md), so the check skips with that reason, through the test's own
|
|
227
|
+
* `skip` as every live refusal does, before it waits for anything else.
|
|
228
|
+
*/
|
|
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
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Registers one check as a test, with its id in the name. A check that was skipped, or whose
|
|
244
|
+
* prompt wasn't given, is left out. An id in `skip` that no check has is a mistake worth hearing about.
|
|
245
|
+
*/
|
|
246
|
+
const registrar = (options, ids) => {
|
|
247
|
+
const unknown = (options.skip ?? []).filter((id) => !ids.includes(id));
|
|
248
|
+
if (unknown.length > 0) {
|
|
249
|
+
throw new Error(`No check is called ${unknown.map((id) => `"${id}"`).join(", ")}. The checks are: ${ids.join(", ")}`);
|
|
250
|
+
}
|
|
251
|
+
// `needs` is a rest argument: a default value would turn the `undefined` of a missing option into a value.
|
|
252
|
+
return (id, title, run, ...needs) => {
|
|
253
|
+
if (options.skip?.includes(id) || (needs.length > 0 && needs[0] === undefined))
|
|
254
|
+
return;
|
|
255
|
+
// Vitest reads which fixtures a test uses from how it destructures its context: name them all.
|
|
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
|
+
});
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Registers: replies once to a DM · once to a mention · replies in the thread · survives Slack's
|
|
283
|
+
* 3 s retry · handles redelivery idempotently · ignores other bots' messages · rejects a bad
|
|
284
|
+
* signature · acks within 3 s · handles `msg_too_long` · a stream starts and stops · honours
|
|
285
|
+
* Stop · refuses clicks from people who may not act · a double click acts once.
|
|
286
|
+
*/
|
|
287
|
+
export function slackChecks(options) {
|
|
288
|
+
const { app } = options;
|
|
289
|
+
const prompt = options.prompt ?? `@${app} hello`;
|
|
290
|
+
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
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;
|
|
304
|
+
describe(`slack checks: ${app}`, () => {
|
|
305
|
+
check("slack.dm-once", "replies once to a DM", async ({ slack }) => {
|
|
306
|
+
const agent = await agentOf(slack);
|
|
307
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
308
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
309
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
310
|
+
});
|
|
311
|
+
check("slack.mention-once", "replies once to a mention", async ({ slack }) => {
|
|
312
|
+
const agent = await agentOf(slack);
|
|
313
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
314
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
315
|
+
const msg = await ana.say(prompt, { channel });
|
|
316
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
317
|
+
});
|
|
318
|
+
check("slack.in-thread", "replies in the thread, not in the channel", async ({ slack }) => {
|
|
319
|
+
const agent = await agentOf(slack);
|
|
320
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
321
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
322
|
+
const msg = await ana.say(prompt, { channel });
|
|
323
|
+
await expect(msg.thread).toHaveReplyFrom(app, wait);
|
|
324
|
+
await expect(channel).not.toHaveChannelMessageFrom(app, wait);
|
|
325
|
+
});
|
|
326
|
+
check("slack.retry", "survives Slack's retry after 3 seconds", async (context) => {
|
|
327
|
+
const { slack } = context;
|
|
328
|
+
const agent = await agentOf(slack);
|
|
329
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
330
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
331
|
+
const msg = await ana.say(prompt, { channel });
|
|
332
|
+
// Slack retries what it thinks wasn't acknowledged in time, and says so in the retry headers.
|
|
333
|
+
await (await slackDelivery(msg, agent, context)).retry({ after: "3s", reason: "http_timeout" });
|
|
334
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
335
|
+
});
|
|
336
|
+
check("slack.redelivery", "handles the same event delivered twice", async (context) => {
|
|
337
|
+
const { slack } = context;
|
|
338
|
+
const agent = await agentOf(slack);
|
|
339
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
340
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
341
|
+
const msg = await ana.say(prompt, { channel });
|
|
342
|
+
const delivery = await slackDelivery(msg, agent, context);
|
|
343
|
+
await expect(msg.thread).toHaveReplyFrom(app, wait);
|
|
344
|
+
// The same event again, with nothing that marks it as a retry: only its event_id tells.
|
|
345
|
+
await delivery.resend();
|
|
346
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
347
|
+
});
|
|
348
|
+
check("slack.ignores-bots", "ignores what other bots write", async ({ slack }) => {
|
|
349
|
+
const agent = await agentOf(slack);
|
|
350
|
+
const bot = await slack.createUser({ name: "Deploy Bot", bot: true });
|
|
351
|
+
const channel = await slack.createChannel({ participants: [bot, agent] });
|
|
352
|
+
const msg = await bot.say(prompt, { channel });
|
|
353
|
+
await expect(msg.thread).not.toHaveReplyFrom(app, wait);
|
|
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
|
+
});
|
|
376
|
+
check("slack.bad-signature", "rejects a delivery with a bad signature", async (context) => {
|
|
377
|
+
const { slack } = context;
|
|
378
|
+
const agent = await agentOf(slack);
|
|
379
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
380
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
381
|
+
const delivery = await slackDelivery(msg, agent, context);
|
|
382
|
+
const first = await delivery.settled(wait);
|
|
383
|
+
// Over Socket Mode there is no signature to check: the connection is the app's own.
|
|
384
|
+
if (first.attempts[0]?.transport !== "http")
|
|
385
|
+
return;
|
|
386
|
+
await delivery.resend({ badSignature: true });
|
|
387
|
+
await expect(delivery).toBeRejected(wait);
|
|
388
|
+
});
|
|
389
|
+
check("slack.ack", "acknowledges within 3 seconds", async (context) => {
|
|
390
|
+
const { slack } = context;
|
|
391
|
+
const agent = await agentOf(slack);
|
|
392
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
393
|
+
const msg = await ana.say(prompt, { to: agent });
|
|
394
|
+
await expect(await slackDelivery(msg, agent, context)).toBeAccepted({ within: "3s", ...wait });
|
|
395
|
+
});
|
|
396
|
+
check("slack.msg-too-long", "still answers when Slack refuses its message as too long", async ({ slack }) => {
|
|
397
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
398
|
+
try {
|
|
399
|
+
const agent = await agentOf(slack);
|
|
400
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
401
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
402
|
+
// Slack refuses the agent's next message once; an agent that handles it says something shorter.
|
|
403
|
+
const _fault = __addDisposableResource(env_1, await slack.fault({
|
|
404
|
+
type: "error",
|
|
405
|
+
operation: "chat.postMessage",
|
|
406
|
+
error: "msg_too_long",
|
|
407
|
+
times: 1,
|
|
408
|
+
}), true);
|
|
409
|
+
const msg = await ana.say(prompt, { channel });
|
|
410
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
411
|
+
}
|
|
412
|
+
catch (e_1) {
|
|
413
|
+
env_1.error = e_1;
|
|
414
|
+
env_1.hasError = true;
|
|
415
|
+
}
|
|
416
|
+
finally {
|
|
417
|
+
const result_1 = __disposeResources(env_1);
|
|
418
|
+
if (result_1)
|
|
419
|
+
await result_1;
|
|
420
|
+
}
|
|
421
|
+
});
|
|
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);
|
|
426
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
427
|
+
const msg = await ana.say(streamPrompt ?? "", { to: agent });
|
|
428
|
+
await expect(msg.thread).toHaveStreamingReplyFrom(app, wait);
|
|
429
|
+
const reply = await msg.thread.latestReply({ from: app, ...wait });
|
|
430
|
+
const stream = await reply.stream?.ended(wait);
|
|
431
|
+
expect(stream?.state).toBe("completed");
|
|
432
|
+
await expect(msg.thread).toHaveStatus("idle", wait);
|
|
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);
|
|
438
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
439
|
+
const msg = await ana.say(streamPrompt ?? "", { to: agent });
|
|
440
|
+
await expect(msg.thread).toHaveStreamingReplyFrom(app, wait);
|
|
441
|
+
await ana.stop({ thread: msg });
|
|
442
|
+
await expect(msg.thread).toHaveStatus("stopped", wait);
|
|
443
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
444
|
+
}, streamPrompt);
|
|
445
|
+
check("slack.click-unauthorized", "refuses a click from someone who may not act", async ({ slack }) => {
|
|
446
|
+
const agent = await agentOf(slack);
|
|
447
|
+
const approval = options.approval ?? { prompt: "", button: "" };
|
|
448
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
449
|
+
const channel = await slack.createChannel({ participants: [ana, agent] });
|
|
450
|
+
const msg = await ana.say(approval.prompt, { channel });
|
|
451
|
+
await ana.click(approval.button, { thread: msg.thread });
|
|
452
|
+
// The ask is the only thing everyone sees: whatever the agent tells Ana, it tells her alone.
|
|
453
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
454
|
+
}, options.approval);
|
|
455
|
+
check("slack.double-click", "a double click acts once", async ({ slack }) => {
|
|
456
|
+
const agent = await agentOf(slack);
|
|
457
|
+
const approval = options.approval ?? { prompt: "", button: "" };
|
|
458
|
+
const ana = await slack.createUser({ name: "Ana" });
|
|
459
|
+
const admin = await slack.createUser({ name: "Ben", admin: true });
|
|
460
|
+
const channel = await slack.createChannel({ participants: [ana, admin, agent] });
|
|
461
|
+
const msg = await ana.say(approval.prompt, { channel });
|
|
462
|
+
const ask = await msg.thread.waitForReply({ from: app, ...wait });
|
|
463
|
+
// Both presses are on their way before the agent can answer the first. An agent that takes the
|
|
464
|
+
// button away once it has acted leaves nothing for the later press to find, and that is fine.
|
|
465
|
+
const press = () => admin.click(approval.button, { message: ask }).then(() => true, (error) => {
|
|
466
|
+
if (error.code !== "not_found")
|
|
467
|
+
throw error;
|
|
468
|
+
return false;
|
|
469
|
+
});
|
|
470
|
+
const pressed = await Promise.all([press(), press()]);
|
|
471
|
+
expect(pressed, "the button was there to press at least once").toContain(true);
|
|
472
|
+
// The approval shows up first; then the thread holds the ask and one message for the one approval.
|
|
473
|
+
await msg.thread.waitForReply({ from: app, ...wait });
|
|
474
|
+
await expect(msg.thread).toHaveRepliesFrom(app, { count: 2, ...wait });
|
|
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);
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Registers: ignores its own comments · one comment per trigger · review-thread replies trigger
|
|
534
|
+
* it · redelivery doesn't duplicate · check runs reach a conclusion · rejects a bad webhook
|
|
535
|
+
* signature.
|
|
536
|
+
*/
|
|
537
|
+
export function githubChecks(options) {
|
|
538
|
+
const { app } = options;
|
|
539
|
+
const prompt = options.prompt ?? `@${app} hello`;
|
|
540
|
+
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
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 });
|
|
545
|
+
/** A repository the App is installed on, with Ana as a collaborator and an issue to talk in. */
|
|
546
|
+
const setup = async ({ github }, also = []) => {
|
|
547
|
+
const agent = await agentOf(github);
|
|
548
|
+
const ana = await github.createUser({ login: "ana" });
|
|
549
|
+
const repo = await github.createRepo({ collaborators: [ana], apps: [agent, ...also] });
|
|
550
|
+
return { ana, agent, repo };
|
|
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);
|
|
554
|
+
const pullRequest = async (context) => {
|
|
555
|
+
const { ana, repo } = await setup(context);
|
|
556
|
+
const pr = await ana.openPullRequest({ from: "change", title: "Greet people", changes: { "greeting.txt": "hello\n" } }, { repo });
|
|
557
|
+
return { ana, repo, pr };
|
|
558
|
+
};
|
|
559
|
+
describe(`github checks: ${app}`, () => {
|
|
560
|
+
check("github.ignores-own-comments", "its own comment doesn't set it off again", async (context) => {
|
|
561
|
+
const { ana, repo } = await setup(context);
|
|
562
|
+
const issue = await ana.openIssue({ title: "A question" }, { repo });
|
|
563
|
+
await ana.comment(prompt, { issue });
|
|
564
|
+
await expect(issue).toHaveCommentFrom(app, wait);
|
|
565
|
+
// An agent that answers its own answer keeps going; one that doesn't is quiet with one comment.
|
|
566
|
+
await expect(issue).toHaveCommentsFrom(app, { count: 1, ...wait });
|
|
567
|
+
});
|
|
568
|
+
check("github.one-comment", "one comment per trigger", async (context) => {
|
|
569
|
+
const { ana, repo } = await setup(context);
|
|
570
|
+
const issue = await ana.openIssue({ title: "Two questions" }, { repo });
|
|
571
|
+
await ana.comment(prompt, { issue });
|
|
572
|
+
await issue.waitForComment({ from: app, ...wait });
|
|
573
|
+
await ana.comment(prompt, { issue });
|
|
574
|
+
await issue.waitForComment({ from: app, ...wait });
|
|
575
|
+
await expect(issue).toHaveCommentsFrom(app, { count: 2, ...wait });
|
|
576
|
+
});
|
|
577
|
+
check("github.review-thread", "answers a mention in a thread on the diff, in that thread", async (context) => {
|
|
578
|
+
const { ana, pr } = await pullRequest(context);
|
|
579
|
+
const inline = await ana.reviewComment(prompt, { pr, path: "greeting.txt", line: 1 });
|
|
580
|
+
const replies = await inline.replies();
|
|
581
|
+
expect(replies.map((reply) => reply.author.name)).toEqual([app]);
|
|
582
|
+
});
|
|
583
|
+
check("github.redelivery", "a redelivered webhook doesn't produce a second answer", async (context) => {
|
|
584
|
+
const { ana, agent, repo } = await setup(context);
|
|
585
|
+
const issue = await ana.openIssue({ title: "Delivered twice" }, { repo });
|
|
586
|
+
const comment = await ana.comment(prompt, { issue });
|
|
587
|
+
const delivery = await githubDelivery(comment, agent, context);
|
|
588
|
+
await expect(issue).toHaveCommentFrom(app, wait);
|
|
589
|
+
// GitHub redelivers with the same `X-GitHub-Delivery`, from its UI and its API.
|
|
590
|
+
await delivery.redeliver();
|
|
591
|
+
await expect(issue).toHaveCommentsFrom(app, { count: 1, ...wait });
|
|
592
|
+
});
|
|
593
|
+
check("github.check-run", "every check run it starts reaches a conclusion", async (context) => {
|
|
594
|
+
const { pr } = await pullRequest(context);
|
|
595
|
+
// Quiet means nothing is left open; a check run that never completes is, and the wait says so.
|
|
596
|
+
await context.channelstack.quiet(wait);
|
|
597
|
+
const runs = await pr.checkRuns();
|
|
598
|
+
expect(runs.filter((run) => run.status !== "completed").map((run) => run.name)).toEqual([]);
|
|
599
|
+
});
|
|
600
|
+
check("github.bad-signature", "rejects a webhook with a bad signature", async (context) => {
|
|
601
|
+
const { ana, agent, repo } = await setup(context);
|
|
602
|
+
const issue = await ana.openIssue({ title: "Signed by someone else" }, { repo });
|
|
603
|
+
const delivery = await githubDelivery(await ana.comment(prompt, { issue }), agent, context);
|
|
604
|
+
await delivery.resend({ badSignature: true });
|
|
605
|
+
await expect(delivery).toBeRejected(wait);
|
|
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
|
+
});
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* The Linear checks: an agent delegated an issue. `prompt` is the issue's title (default "Look
|
|
631
|
+
* into this"); the agent should take the issue, work on it and end its turn.
|
|
632
|
+
*/
|
|
633
|
+
export function linearChecks(options) {
|
|
634
|
+
const { app } = options;
|
|
635
|
+
const title = options.prompt ?? "Look into this";
|
|
636
|
+
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
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 });
|
|
641
|
+
/** Ana in a team, an issue, and a session from delegating it to the app. */
|
|
642
|
+
const delegated = async ({ linear }) => {
|
|
643
|
+
const agent = await agentOf(linear);
|
|
644
|
+
const ana = await linear.createUser({ name: "Ana" });
|
|
645
|
+
const team = await linear.createTeam({ members: [ana] });
|
|
646
|
+
const issue = await ana.createIssue({ title }, { team });
|
|
647
|
+
const session = await ana.delegate(agent, { issue });
|
|
648
|
+
return { ana, agent, issue, session };
|
|
649
|
+
};
|
|
650
|
+
const ended = ["complete", "awaitingInput", "error"];
|
|
651
|
+
describe(`linear checks: ${app}`, () => {
|
|
652
|
+
check("linear.first-activity", "acknowledges a new session within 10 seconds", async (context) => {
|
|
653
|
+
const { session } = await delegated(context);
|
|
654
|
+
// Linear shows a session as unresponsive when nothing arrives in that time.
|
|
655
|
+
await expect(session).toHaveActivity({}, { timeout: "10s" });
|
|
656
|
+
});
|
|
657
|
+
check("linear.ends-turn", "ends its turn: the session doesn't stay active", async (context) => {
|
|
658
|
+
const { session } = await delegated(context);
|
|
659
|
+
await session.waitForState([...ended], wait);
|
|
660
|
+
});
|
|
661
|
+
check("linear.stop", "Stop ends the session", async (context) => {
|
|
662
|
+
const { ana, session } = await delegated(context);
|
|
663
|
+
await expect(session).toHaveActivity({}, wait);
|
|
664
|
+
await ana.stop({ session });
|
|
665
|
+
// The agent answers Stop with a response or an error; until then the session is stopping.
|
|
666
|
+
await session.waitForState(["complete", "error"], wait);
|
|
667
|
+
});
|
|
668
|
+
check("linear.redelivery", "a redelivered webhook doesn't start the work again", async (context) => {
|
|
669
|
+
const { session } = await delegated(context);
|
|
670
|
+
const delivery = deliveryOf(session, context, "Linear");
|
|
671
|
+
await session.waitForState([...ended], wait);
|
|
672
|
+
await delivery.redeliver();
|
|
673
|
+
await context.channelstack.quiet(wait);
|
|
674
|
+
const responses = (await session.activities()).filter((activity) => activity.type === "response");
|
|
675
|
+
expect(responses.length).toBeLessThanOrEqual(1);
|
|
676
|
+
});
|
|
677
|
+
check("linear.stale", "rejects a webhook whose timestamp is more than a minute old", async (context) => {
|
|
678
|
+
const { session } = await delegated(context);
|
|
679
|
+
const delivery = deliveryOf(session, context, "Linear");
|
|
680
|
+
await delivery.resend({ stale: true });
|
|
681
|
+
await expect(delivery).toBeRejected(wait);
|
|
682
|
+
});
|
|
683
|
+
check("linear.bad-signature", "rejects a webhook with a bad signature", async (context) => {
|
|
684
|
+
const { session } = await delegated(context);
|
|
685
|
+
const delivery = deliveryOf(session, context, "Linear");
|
|
686
|
+
await delivery.resend({ badSignature: true });
|
|
687
|
+
await expect(delivery).toBeRejected(wait);
|
|
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
|
+
});
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* The Notion checks: an integration mentioned in a page comment. `prompt` is the comment (default
|
|
711
|
+
* `@<app> hello`); the agent should answer once, in that discussion.
|
|
712
|
+
*/
|
|
713
|
+
export function notionChecks(options) {
|
|
714
|
+
const { app } = options;
|
|
715
|
+
const prompt = options.prompt ?? `@${app} hello`;
|
|
716
|
+
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
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 });
|
|
721
|
+
/** Ana, and her comment on a page the integration is connected to. */
|
|
722
|
+
const commented = async ({ notion }, also = []) => {
|
|
723
|
+
const agent = await agentOf(notion);
|
|
724
|
+
const ana = await notion.createUser({ name: "Ana" });
|
|
725
|
+
const page = await notion.createPage({
|
|
726
|
+
title: "Notes",
|
|
727
|
+
content: "- a first note",
|
|
728
|
+
connections: [agent, ...also],
|
|
729
|
+
});
|
|
730
|
+
const comment = await ana.comment(prompt, { page });
|
|
731
|
+
return { ana, agent, page, comment };
|
|
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);
|
|
735
|
+
describe(`notion checks: ${app}`, () => {
|
|
736
|
+
check("notion.reply-in-discussion", "answers a comment in its discussion", async (context) => {
|
|
737
|
+
const { page, comment } = await commented(context);
|
|
738
|
+
await expect(comment.discussion).toHaveCommentFrom(app, wait);
|
|
739
|
+
// An answer in a discussion of its own is one the person doesn't see where they asked.
|
|
740
|
+
const elsewhere = (await page.discussions()).filter((discussion) => discussion.id !== comment.discussion.id);
|
|
741
|
+
expect(elsewhere).toEqual([]);
|
|
742
|
+
});
|
|
743
|
+
check("notion.ignores-own-comments", "its own comment doesn't set it off again", async (context) => {
|
|
744
|
+
const { comment } = await commented(context);
|
|
745
|
+
await expect(comment.discussion).toHaveCommentFrom(app, wait);
|
|
746
|
+
await expect(comment.discussion).toHaveCommentsFrom(app, { count: 1, ...wait });
|
|
747
|
+
});
|
|
748
|
+
check("notion.redelivery", "a webhook sent again doesn't produce a second answer", async (context) => {
|
|
749
|
+
const { agent, comment } = await commented(context);
|
|
750
|
+
const delivery = await notionDelivery(comment, agent, context);
|
|
751
|
+
await expect(comment.discussion).toHaveCommentFrom(app, wait);
|
|
752
|
+
// Notion retries with the same event id.
|
|
753
|
+
await delivery.redeliver();
|
|
754
|
+
await expect(comment.discussion).toHaveCommentsFrom(app, { count: 1, ...wait });
|
|
755
|
+
});
|
|
756
|
+
check("notion.bad-signature", "rejects a webhook with a bad signature", async (context) => {
|
|
757
|
+
const { agent, comment } = await commented(context);
|
|
758
|
+
const delivery = await notionDelivery(comment, agent, context);
|
|
759
|
+
await delivery.resend({ badSignature: true });
|
|
760
|
+
await expect(delivery).toBeRejected(wait);
|
|
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
|
+
});
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* The Resend checks: a person emails the agent. `prompt` is the email's text (default `hello`); the
|
|
790
|
+
* agent should answer once, in the email's thread.
|
|
791
|
+
*/
|
|
792
|
+
export function resendChecks(options) {
|
|
793
|
+
const { app } = options;
|
|
794
|
+
const prompt = options.prompt ?? "hello";
|
|
795
|
+
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
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 });
|
|
800
|
+
/** Ana, and her email to the agent. */
|
|
801
|
+
const emailed = async ({ resend }) => {
|
|
802
|
+
const agent = await agentOf(resend);
|
|
803
|
+
const ana = await resend.createUser({ name: "Ana" });
|
|
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 };
|
|
812
|
+
};
|
|
813
|
+
describe(`resend checks: ${app}`, () => {
|
|
814
|
+
check("resend.reply-in-thread", "answers an email in its thread", async (context) => {
|
|
815
|
+
const { ana, email } = await emailed(context);
|
|
816
|
+
// The answer reaches Ana, and in the thread she started: In-Reply-To and References are set.
|
|
817
|
+
const answer = await ana.waitForEmail({ from: app, ...wait });
|
|
818
|
+
expect(answer.thread.id, "the answer started a thread of its own: set In-Reply-To and References").toBe(email.thread.id);
|
|
819
|
+
});
|
|
820
|
+
check("resend.redelivery", "a webhook sent again doesn't produce a second answer", async (context) => {
|
|
821
|
+
const { email, delivery } = await delivered(context);
|
|
822
|
+
await expect(email.thread).toHaveReplyFrom(app, wait);
|
|
823
|
+
// Resend retries with the same svix-id and the same email_id.
|
|
824
|
+
await delivery.redeliver();
|
|
825
|
+
await expect(email.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
826
|
+
});
|
|
827
|
+
check("resend.bad-signature", "rejects a webhook with a bad signature", async (context) => {
|
|
828
|
+
const { delivery } = await delivered(context);
|
|
829
|
+
await delivery.resend({ badSignature: true });
|
|
830
|
+
await expect(delivery).toBeRejected(wait);
|
|
831
|
+
});
|
|
832
|
+
check("resend.stale", "rejects a webhook signed more than five minutes ago", async (context) => {
|
|
833
|
+
const { delivery } = await delivered(context);
|
|
834
|
+
await delivery.resend({ stale: true });
|
|
835
|
+
await expect(delivery).toBeRejected(wait);
|
|
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
|
+
});
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* The Google checks: a person emails the agent's Gmail address. `prompt` is the email's text
|
|
846
|
+
* (default `hello`); the agent should answer once, in the email's thread, whatever Gmail pushes.
|
|
847
|
+
*/
|
|
848
|
+
export function googleChecks(options) {
|
|
849
|
+
const { app } = options;
|
|
850
|
+
const prompt = options.prompt ?? "hello";
|
|
851
|
+
const wait = options.timeout === undefined ? {} : { timeout: options.timeout };
|
|
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 });
|
|
856
|
+
/** Ana, and her email to the agent. */
|
|
857
|
+
const emailed = async ({ google }) => {
|
|
858
|
+
const agent = await agentOf(google);
|
|
859
|
+
const ana = await google.createUser({ name: "Ana" });
|
|
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 };
|
|
868
|
+
};
|
|
869
|
+
describe(`google checks: ${app}`, () => {
|
|
870
|
+
check("google.reply-in-thread", "answers an email in its thread", async (context) => {
|
|
871
|
+
const { ana, email } = await emailed(context);
|
|
872
|
+
// The answer reaches Ana, and in the thread she started: In-Reply-To and References are set.
|
|
873
|
+
const answer = await ana.waitForEmail({ from: app, ...wait });
|
|
874
|
+
expect(answer.thread.id, "the answer started a thread of its own: set In-Reply-To and References").toBe(email.thread.id);
|
|
875
|
+
});
|
|
876
|
+
check("google.history", "answers each of two emails Gmail told of in one push, once", async ({ google }) => {
|
|
877
|
+
// Gmail pushes at most once a second. A first email is pushed at once; the two after it, within
|
|
878
|
+
// that second, wait for its end and come in one push, so the agent must read its history.
|
|
879
|
+
const ana = await google.createUser({ name: "Ana" });
|
|
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 });
|
|
883
|
+
await expect(opener.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
884
|
+
await expect(first.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
885
|
+
await expect(second.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
886
|
+
});
|
|
887
|
+
check("google.redelivery", "a push sent again doesn't produce a second answer", async (context) => {
|
|
888
|
+
const { email, delivery: push } = await delivered(context);
|
|
889
|
+
await expect(email.thread).toHaveReplyFrom(app, wait);
|
|
890
|
+
// Pub/Sub delivers at least once: the same message id again.
|
|
891
|
+
await push.redeliver();
|
|
892
|
+
await expect(email.thread).toHaveRepliesFrom(app, { count: 1, ...wait });
|
|
893
|
+
});
|
|
894
|
+
check("google.bad-signature", "rejects a push whose token another key signed", async (context) => {
|
|
895
|
+
const { delivery: push } = await delivered(context);
|
|
896
|
+
await push.resend({ badSignature: true });
|
|
897
|
+
await expect(push).toBeRejected(wait);
|
|
898
|
+
});
|
|
899
|
+
check("google.wrong-audience", "rejects a push whose token is for another audience", async (context) => {
|
|
900
|
+
const { delivery: push } = await delivered(context);
|
|
901
|
+
await push.resend({ wrongAudience: true });
|
|
902
|
+
await expect(push).toBeRejected(wait);
|
|
903
|
+
});
|
|
904
|
+
check("google.stale", "rejects a push whose token has expired", async (context) => {
|
|
905
|
+
const { delivery: push } = await delivered(context);
|
|
906
|
+
await push.resend({ stale: true });
|
|
907
|
+
await expect(push).toBeRejected(wait);
|
|
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);
|
|
1033
|
+
});
|
|
1034
|
+
}
|