@cursor/july 0.1.23 → 0.1.24

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.
Files changed (174) hide show
  1. package/dist/bin/agent-serve.js +0 -0
  2. package/dist/docs/404.html +1 -1
  3. package/dist/docs/ab.html +2 -2
  4. package/dist/docs/assets/{app.DYcC9FY-.js → app.CvSGaAxk.js} +1 -1
  5. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
  6. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
  7. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.C7vfzr7h.js} +2 -2
  8. package/dist/docs/building-with-agents.html +2 -2
  9. package/dist/docs/concepts.html +2 -2
  10. package/dist/docs/deployment.html +2 -2
  11. package/dist/docs/evals.html +2 -2
  12. package/dist/docs/example-agents/approval-buddy.html +2 -2
  13. package/dist/docs/example-agents/benny.html +2 -2
  14. package/dist/docs/example-agents/bugbot.html +2 -2
  15. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  16. package/dist/docs/example-agents/codeowners-review.html +2 -2
  17. package/dist/docs/example-agents/concierge.html +2 -2
  18. package/dist/docs/example-agents/fsd.html +2 -2
  19. package/dist/docs/example-agents/index.html +2 -2
  20. package/dist/docs/example-agents/knowledge-base.html +2 -2
  21. package/dist/docs/example-agents/oncall.html +2 -2
  22. package/dist/docs/example-agents/security-reviewer.html +2 -2
  23. package/dist/docs/example-agents/slack-agent.html +2 -2
  24. package/dist/docs/example-agents/weather-agent.html +2 -2
  25. package/dist/docs/guides/agent-to-agent.html +2 -2
  26. package/dist/docs/guides/cloud-runtime.html +2 -2
  27. package/dist/docs/guides/github.html +2 -2
  28. package/dist/docs/guides/human-in-the-loop.html +2 -2
  29. package/dist/docs/guides/mcp-oauth.html +2 -2
  30. package/dist/docs/guides/slack.html +2 -2
  31. package/dist/docs/guides/webhooks.html +2 -2
  32. package/dist/docs/hillclimbing.html +2 -2
  33. package/dist/docs/index.html +2 -2
  34. package/dist/docs/quickstart.html +2 -2
  35. package/dist/docs/reference/agent-config.html +2 -2
  36. package/dist/docs/reference/channels.html +2 -2
  37. package/dist/docs/reference/cli.html +2 -2
  38. package/dist/docs/reference/connections.html +2 -2
  39. package/dist/docs/reference/hooks.html +2 -2
  40. package/dist/docs/reference/http-api.html +2 -2
  41. package/dist/docs/reference/instructions.html +2 -2
  42. package/dist/docs/reference/playground.html +2 -2
  43. package/dist/docs/reference/project-layout.html +2 -2
  44. package/dist/docs/reference/prompt.html +2 -2
  45. package/dist/docs/reference/schedules.html +2 -2
  46. package/dist/docs/reference/sessions.html +2 -2
  47. package/dist/docs/reference/skills.html +2 -2
  48. package/dist/docs/reference/subagents.html +2 -2
  49. package/dist/docs/reference/tools.html +2 -2
  50. package/dist/docs/scaffolding-agents.html +2 -2
  51. package/dist/docs/storage.html +2 -2
  52. package/dist/docs/troubleshooting.html +2 -2
  53. package/dist/playground/assets/index-CidizGZv.css +1 -0
  54. package/dist/playground/assets/{index-DqXdAFGa.js → index-DTG9OsPV.js} +41 -41
  55. package/dist/playground/index.html +2 -2
  56. package/package.json +24 -24
  57. package/dist/channels/github/instrument.d.ts +0 -20
  58. package/dist/channels/github/instrument.d.ts.map +0 -1
  59. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  60. package/dist/internal/json-dir-store.d.ts +0 -32
  61. package/dist/internal/json-dir-store.d.ts.map +0 -1
  62. package/dist/internal/json-dir-store.js +0 -100
  63. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  64. package/src/bin/agent-serve.version.test.ts +0 -64
  65. package/src/channels/github/api.test.ts +0 -64
  66. package/src/channels/github/auth.test.ts +0 -105
  67. package/src/channels/github/cursor-account.test.ts +0 -204
  68. package/src/channels/github/forward.test.ts +0 -457
  69. package/src/channels/github/github.test.ts +0 -937
  70. package/src/channels/github/replay.test.ts +0 -179
  71. package/src/channels/slack/api.post-message.test.ts +0 -148
  72. package/src/channels/slack/approvals.test.ts +0 -328
  73. package/src/channels/slack/block-actions.test.ts +0 -452
  74. package/src/channels/slack/bot-mentions.test.ts +0 -267
  75. package/src/channels/slack/channel-watch.test.ts +0 -363
  76. package/src/channels/slack/cursor-account.test.ts +0 -253
  77. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  78. package/src/channels/slack/dispatch.test.ts +0 -795
  79. package/src/channels/slack/eval-directive.test.ts +0 -273
  80. package/src/channels/slack/message-body.test.ts +0 -54
  81. package/src/channels/slack/nudge-store.test.ts +0 -143
  82. package/src/channels/slack/slack.test.ts +0 -391
  83. package/src/channels/slack/stop.test.ts +0 -23
  84. package/src/channels/slack/thread-context.test.ts +0 -202
  85. package/src/evals/assertions.test.ts +0 -580
  86. package/src/evals/expect.test.ts +0 -144
  87. package/src/evals/judge.test.ts +0 -181
  88. package/src/evals/loaders.test.ts +0 -132
  89. package/src/evals/matchers.test.ts +0 -95
  90. package/src/evals/reporters.test.ts +0 -303
  91. package/src/evals/run-facts.test.ts +0 -259
  92. package/src/internal/ab-snapshot.test.ts +0 -325
  93. package/src/internal/approval-gate.test.ts +0 -49
  94. package/src/internal/approvals.integration.test.ts +0 -383
  95. package/src/internal/authored-loaders.test.ts +0 -31
  96. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  97. package/src/internal/channel-route-schema.test.ts +0 -294
  98. package/src/internal/chat-attach.test.ts +0 -262
  99. package/src/internal/cli-deploy.test.ts +0 -1991
  100. package/src/internal/cli-docs.test.ts +0 -161
  101. package/src/internal/cli-mcp.test.ts +0 -789
  102. package/src/internal/cli-skills.test.ts +0 -133
  103. package/src/internal/cli-slack.test.ts +0 -1647
  104. package/src/internal/cloud-merge.test.ts +0 -74
  105. package/src/internal/cron.test.ts +0 -22
  106. package/src/internal/cursor/account-mcp.test.ts +0 -807
  107. package/src/internal/cursor/backend-client.test.ts +0 -591
  108. package/src/internal/cursor/credentials.test.ts +0 -351
  109. package/src/internal/cursor/github-credentials.test.ts +0 -136
  110. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  111. package/src/internal/cursor-account.integration.test.ts +0 -441
  112. package/src/internal/cursor-event-relay.test.ts +0 -746
  113. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  114. package/src/internal/cursor-slack-relay.test.ts +0 -525
  115. package/src/internal/deploy-source.test.ts +0 -111
  116. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  117. package/src/internal/discovery.concurrency.test.ts +0 -60
  118. package/src/internal/discovery.cursor-account.test.ts +0 -133
  119. package/src/internal/discovery.cwd.test.ts +0 -83
  120. package/src/internal/discovery.hosting.test.ts +0 -80
  121. package/src/internal/discovery.identity.test.ts +0 -44
  122. package/src/internal/docs-site.test.ts +0 -66
  123. package/src/internal/duration.test.ts +0 -29
  124. package/src/internal/eval-judge-model.test.ts +0 -187
  125. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  126. package/src/internal/eval-run-store.storage.test.ts +0 -211
  127. package/src/internal/eval-runner.http.test.ts +0 -403
  128. package/src/internal/eval-runner.run.test.ts +0 -928
  129. package/src/internal/evals-client.test.ts +0 -307
  130. package/src/internal/event-mapper.test.ts +0 -243
  131. package/src/internal/github-fanout.test.ts +0 -213
  132. package/src/internal/handleAgentServeTrigger.test.ts +0 -179
  133. package/src/internal/host-kv.test.ts +0 -82
  134. package/src/internal/host-platforms.test.ts +0 -126
  135. package/src/internal/http-channel.test.ts +0 -402
  136. package/src/internal/init-project.test.ts +0 -270
  137. package/src/internal/install-cursor-skills.test.ts +0 -262
  138. package/src/internal/local-env.test.ts +0 -120
  139. package/src/internal/log-ring.test.ts +0 -31
  140. package/src/internal/logs-client.test.ts +0 -350
  141. package/src/internal/mcp-endpoint.test.ts +0 -436
  142. package/src/internal/mcp-host.test.ts +0 -298
  143. package/src/internal/mcp-oauth.test.ts +0 -148
  144. package/src/internal/net.test.ts +0 -17
  145. package/src/internal/peer-connections.test.ts +0 -128
  146. package/src/internal/peer-mcp.integration.test.ts +0 -289
  147. package/src/internal/playground/toolchain.test.ts +0 -53
  148. package/src/internal/playground-cli.test.ts +0 -187
  149. package/src/internal/playground-proxy.test.ts +0 -376
  150. package/src/internal/prompt-context.integration.test.ts +0 -232
  151. package/src/internal/prompt-context.test.ts +0 -127
  152. package/src/internal/reminder-runner.test.ts +0 -390
  153. package/src/internal/reminder-store.test.ts +0 -53
  154. package/src/internal/request-headers.test.ts +0 -27
  155. package/src/internal/resolve-prod-target.test.ts +0 -787
  156. package/src/internal/resolved-connections.test.ts +0 -295
  157. package/src/internal/router.test.ts +0 -57
  158. package/src/internal/sdk-runner.test.ts +0 -290
  159. package/src/internal/session-engine.coalesce.test.ts +0 -169
  160. package/src/internal/session-engine.concurrency.test.ts +0 -250
  161. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  162. package/src/internal/session-engine.interrupt.test.ts +0 -577
  163. package/src/internal/session-engine.storage.test.ts +0 -547
  164. package/src/internal/session-urls.test.ts +0 -28
  165. package/src/internal/sessions-client.test.ts +0 -518
  166. package/src/internal/storage-coordinator.test.ts +0 -517
  167. package/src/internal/tool-call.test.ts +0 -458
  168. package/src/internal/tool-result.test.ts +0 -52
  169. package/src/internal/trajectory.approvals.test.ts +0 -83
  170. package/src/internal/trajectory.subagents.test.ts +0 -198
  171. package/src/internal/turn-governor.test.ts +0 -137
  172. package/src/internal/update-check.test.ts +0 -485
  173. package/src/internal/workspace.test.ts +0 -207
  174. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,795 +0,0 @@
1
- import { mkdtemp, rm } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, describe, expect, it, vi } from "vitest";
5
- import type {
6
- ChannelSession,
7
- HostContext,
8
- SendMessageFn,
9
- } from "../../types.js";
10
- import * as slackApi from "./api.js";
11
- import {
12
- createEventIdDedupe,
13
- createSlackLogger,
14
- dispatchInboundFromEventBody,
15
- dispatchInboundMessage,
16
- SlackAskDedupeStore,
17
- SlackNudgeStore,
18
- } from "./index.js";
19
- import type { SlackMessageHandler } from "./types.js";
20
-
21
- const testAuth = {
22
- authenticator: "test",
23
- principalId: "U1",
24
- principalType: "user" as const,
25
- };
26
-
27
- function mockSession(
28
- id = "ses_test",
29
- extras?: { coalesced?: boolean; isNew?: boolean }
30
- ): ChannelSession {
31
- return {
32
- id,
33
- continuationToken: null,
34
- isNew: extras?.isNew ?? true,
35
- ...(extras?.coalesced === true ? { coalesced: true as const } : {}),
36
- info: {
37
- id,
38
- channelId: "slack",
39
- mode: "chat",
40
- auth: testAuth,
41
- },
42
- getEventStream: async () => new ReadableStream(),
43
- waitForCompletion: async () => ({ status: "finished" }),
44
- setContinuationToken: async () => undefined,
45
- };
46
- }
47
-
48
- function createSendRecorder(options?: { coalesced?: boolean }): {
49
- send: SendMessageFn;
50
- calls: Array<{ message: string; options: Parameters<SendMessageFn>[1] }>;
51
- } {
52
- const calls: Array<{
53
- message: string;
54
- options: Parameters<SendMessageFn>[1];
55
- }> = [];
56
- const send: SendMessageFn = async (message, sendOptions) => {
57
- calls.push({ message, options: sendOptions });
58
- return mockSession("ses_1", {
59
- coalesced: options?.coalesced,
60
- isNew: false,
61
- });
62
- };
63
- return { send, calls };
64
- }
65
-
66
- function acceptHandler(): SlackMessageHandler {
67
- return async () => ({ auth: testAuth });
68
- }
69
-
70
- function testHost(options?: {
71
- nudgeRoot?: string;
72
- askRoot?: string;
73
- evals?: HostContext["evals"];
74
- }) {
75
- const nudgeStore =
76
- options?.nudgeRoot === undefined
77
- ? undefined
78
- : new SlackNudgeStore(options.nudgeRoot);
79
- const askStore =
80
- options?.askRoot === undefined
81
- ? undefined
82
- : new SlackAskDedupeStore(options.askRoot);
83
- return {
84
- mcp: {
85
- names: () => [] as string[],
86
- listTools: async () => [],
87
- callTool: async () => ({ content: [] }),
88
- },
89
- github: {
90
- getOctokit: async () => {
91
- throw new Error("github client not configured in test");
92
- },
93
- },
94
- slack: {
95
- getClient: async () => {
96
- throw new Error("slack client not configured in test");
97
- },
98
- },
99
- kv: {
100
- get: async () => undefined,
101
- put: async () => {},
102
- delete: async () => {},
103
- },
104
- evals: options?.evals,
105
- slackNudges:
106
- nudgeStore === undefined || askStore === undefined
107
- ? undefined
108
- : {
109
- append: (input: Parameters<SlackNudgeStore["append"]>[0]) =>
110
- nudgeStore.append(input),
111
- drainFormatted: (key: string) => nudgeStore.drainFormatted(key),
112
- clear: (key: string) => nudgeStore.clear(key),
113
- hasUndelivered: (key: string) => nudgeStore.hasUndelivered(key),
114
- isDelivered: (key: string, ts: string) =>
115
- nudgeStore.isDelivered(key, ts),
116
- tryClaimAsk: (channelId: string, ts: string) =>
117
- askStore.tryClaim(channelId, ts),
118
- releaseAsk: (channelId: string, ts: string) =>
119
- askStore.release(channelId, ts),
120
- },
121
- };
122
- }
123
-
124
- function mentionBody(
125
- args: {
126
- eventId?: string;
127
- text?: string;
128
- ts?: string;
129
- threadTs?: string;
130
- channel?: string;
131
- } = {}
132
- ): Record<string, unknown> {
133
- return {
134
- type: "event_callback",
135
- team_id: "T1",
136
- ...(args.eventId === undefined ? {} : { event_id: args.eventId }),
137
- event: {
138
- type: "app_mention",
139
- user: "U1",
140
- text: args.text ?? "<@Ubot> weather?",
141
- ts: args.ts ?? "10.0",
142
- // Different from ts so setTitle is skipped (no network).
143
- thread_ts: args.threadTs ?? "9.0",
144
- channel: args.channel ?? "C9",
145
- },
146
- };
147
- }
148
-
149
- const cleanups: Array<() => Promise<void>> = [];
150
-
151
- afterEach(async () => {
152
- vi.unstubAllGlobals();
153
- vi.restoreAllMocks();
154
- while (cleanups.length > 0) {
155
- await cleanups.pop()?.();
156
- }
157
- });
158
-
159
- describe("dispatchInboundFromEventBody", () => {
160
- it("dispatches app_mention to send with continuation token", async () => {
161
- const { send, calls } = createSendRecorder();
162
- const background: Promise<unknown>[] = [];
163
- const lines: string[] = [];
164
-
165
- const scheduled = dispatchInboundFromEventBody(mentionBody(), {
166
- send,
167
- waitUntil: (p) => {
168
- background.push(p);
169
- },
170
- onAppMention: acceptHandler(),
171
- onDirectMessage: async () => null,
172
- credentials: undefined,
173
- eventIds: createEventIdDedupe(),
174
- host: testHost(),
175
- log: createSlackLogger((line) => lines.push(line)),
176
- });
177
-
178
- expect(scheduled).toBe(true);
179
- await Promise.all(background);
180
- expect(calls).toHaveLength(1);
181
- expect(calls[0]?.options?.continuationToken).toBe("C9:9.0");
182
- expect(calls[0]?.message).toContain("weather?");
183
- expect(calls[0]?.message).toContain("<slack_context>");
184
- expect(lines.some((l) => l.includes("session start"))).toBe(true);
185
- });
186
-
187
- it("dedupes by event_id", async () => {
188
- const { send, calls } = createSendRecorder();
189
- const background: Promise<unknown>[] = [];
190
- const eventIds = createEventIdDedupe();
191
- const deps = {
192
- send,
193
- waitUntil: (p: Promise<unknown>) => {
194
- background.push(p);
195
- },
196
- onAppMention: acceptHandler(),
197
- onDirectMessage: async () => null,
198
- credentials: undefined as undefined,
199
- host: testHost(),
200
- eventIds,
201
- log: createSlackLogger(() => undefined),
202
- };
203
-
204
- const body = mentionBody({ eventId: "Ev1" });
205
- expect(dispatchInboundFromEventBody(body, deps)).toBe(true);
206
- expect(dispatchInboundFromEventBody(body, deps)).toBe(false);
207
- await Promise.all(background);
208
- expect(calls).toHaveLength(1);
209
- });
210
-
211
- it("skips send when handler returns null", async () => {
212
- const { send, calls } = createSendRecorder();
213
- const background: Promise<unknown>[] = [];
214
- dispatchInboundFromEventBody(mentionBody(), {
215
- send,
216
- waitUntil: (p) => {
217
- background.push(p);
218
- },
219
- onAppMention: async () => null,
220
- onDirectMessage: async () => null,
221
- credentials: undefined,
222
- eventIds: createEventIdDedupe(),
223
- host: testHost(),
224
- });
225
- await Promise.all(background);
226
- expect(calls).toHaveLength(0);
227
- });
228
-
229
- it("does not send when handler throws", async () => {
230
- const { send, calls } = createSendRecorder();
231
- const background: Promise<unknown>[] = [];
232
- dispatchInboundFromEventBody(mentionBody(), {
233
- send,
234
- waitUntil: (p) => {
235
- background.push(p);
236
- },
237
- onAppMention: async () => {
238
- throw new Error("boom");
239
- },
240
- onDirectMessage: async () => null,
241
- credentials: undefined,
242
- eventIds: createEventIdDedupe(),
243
- host: testHost(),
244
- log: createSlackLogger(() => undefined),
245
- });
246
- await Promise.all(background);
247
- expect(calls).toHaveLength(0);
248
- });
249
-
250
- it("dispatches direct messages", async () => {
251
- const { send, calls } = createSendRecorder();
252
- const background: Promise<unknown>[] = [];
253
- dispatchInboundFromEventBody(
254
- {
255
- type: "event_callback",
256
- team_id: "T1",
257
- event_id: "EvDM",
258
- event: {
259
- type: "message",
260
- channel_type: "im",
261
- user: "U1",
262
- text: "hi from dm",
263
- ts: "2.0",
264
- thread_ts: "1.0",
265
- channel: "D1",
266
- },
267
- },
268
- {
269
- send,
270
- waitUntil: (p) => {
271
- background.push(p);
272
- },
273
- onAppMention: async () => null,
274
- onDirectMessage: acceptHandler(),
275
- credentials: undefined,
276
- eventIds: createEventIdDedupe(),
277
- host: testHost(),
278
- }
279
- );
280
- await Promise.all(background);
281
- expect(calls).toHaveLength(1);
282
- expect(calls[0]?.options?.continuationToken).toBe("D1:1.0");
283
- });
284
-
285
- it("returns false for unhandled shapes", () => {
286
- expect(
287
- dispatchInboundFromEventBody(
288
- { type: "event_callback", event: { type: "reaction_added" } },
289
- {
290
- send: async () => mockSession(),
291
- waitUntil: () => undefined,
292
- onAppMention: async () => null,
293
- onDirectMessage: async () => null,
294
- credentials: undefined,
295
- eventIds: createEventIdDedupe(),
296
- host: testHost(),
297
- }
298
- )
299
- ).toBe(false);
300
- });
301
-
302
- it("forwards message override, workspaceFiles, and cloud options from the handler", async () => {
303
- const { send, calls } = createSendRecorder();
304
- const background: Promise<unknown>[] = [];
305
-
306
- dispatchInboundFromEventBody(mentionBody(), {
307
- send,
308
- waitUntil: (p) => {
309
- background.push(p);
310
- },
311
- onAppMention: async () => ({
312
- auth: testAuth,
313
- title: "Bugbot acme/widget#1",
314
- message: "Read pr.txt and review",
315
- workspaceFiles: { "pr.txt": "evidence" },
316
- cloud: {
317
- repos: [
318
- {
319
- url: "https://github.com/acme/widget",
320
- prUrl: "https://github.com/acme/widget/pull/1",
321
- },
322
- ],
323
- },
324
- }),
325
- onDirectMessage: async () => null,
326
- credentials: undefined,
327
- eventIds: createEventIdDedupe(),
328
- host: testHost(),
329
- });
330
- await Promise.all(background);
331
- expect(calls).toHaveLength(1);
332
- expect(calls[0]?.options?.title).toBe("Bugbot acme/widget#1");
333
- expect(calls[0]?.message).toContain("Read pr.txt");
334
- expect(calls[0]?.options?.workspaceFiles).toEqual({
335
- "pr.txt": "evidence",
336
- });
337
- expect(calls[0]?.options?.cloud).toEqual({
338
- repos: [
339
- {
340
- url: "https://github.com/acme/widget",
341
- prUrl: "https://github.com/acme/widget/pull/1",
342
- },
343
- ],
344
- });
345
- });
346
- });
347
-
348
- describe("engagement routing", () => {
349
- it("ignores mentions when mentionsEnabled is false", async () => {
350
- const { send, calls } = createSendRecorder();
351
- const background: Promise<unknown>[] = [];
352
- const scheduled = dispatchInboundFromEventBody(mentionBody(), {
353
- send,
354
- waitUntil: (p) => {
355
- background.push(p);
356
- },
357
- onAppMention: acceptHandler(),
358
- onDirectMessage: async () => null,
359
- credentials: undefined,
360
- eventIds: createEventIdDedupe(),
361
- host: testHost(),
362
- log: createSlackLogger(() => undefined),
363
- mentionsEnabled: false,
364
- });
365
- expect(scheduled).toBe(false);
366
- await Promise.all(background);
367
- expect(calls).toHaveLength(0);
368
- });
369
-
370
- it("routes channel posts to the watcher when configured", async () => {
371
- const { send, calls } = createSendRecorder();
372
- const background: Promise<unknown>[] = [];
373
- const handled: string[] = [];
374
- const deps = {
375
- send,
376
- waitUntil: (p: Promise<unknown>) => {
377
- background.push(p);
378
- },
379
- onAppMention: acceptHandler(),
380
- onDirectMessage: async () => null,
381
- credentials: undefined as undefined,
382
- eventIds: createEventIdDedupe(),
383
- host: testHost(),
384
- log: createSlackLogger(() => undefined),
385
- channelWatch: {
386
- handle: (event: { kind: string }, eventId?: string) => {
387
- handled.push(`${event.kind}:${eventId ?? ""}`);
388
- return true;
389
- },
390
- stop: () => undefined,
391
- },
392
- };
393
- const scheduled = dispatchInboundFromEventBody(
394
- {
395
- type: "event_callback",
396
- team_id: "T1",
397
- event_id: "Ev9",
398
- event: {
399
- type: "message",
400
- channel: "C9",
401
- channel_type: "channel",
402
- ts: "20.0",
403
- text: "fresh report",
404
- user: "U1",
405
- },
406
- },
407
- deps
408
- );
409
- expect(scheduled).toBe(true);
410
- await Promise.all(background);
411
- expect(handled).toEqual(["post:Ev9"]);
412
- // Watcher decides whether to dispatch; nothing sent by default here.
413
- expect(calls).toHaveLength(0);
414
- });
415
-
416
- it("ignores channel posts without a watcher", () => {
417
- const { send } = createSendRecorder();
418
- const scheduled = dispatchInboundFromEventBody(
419
- {
420
- type: "event_callback",
421
- event: {
422
- type: "message",
423
- channel: "C9",
424
- channel_type: "channel",
425
- ts: "20.0",
426
- text: "fresh report",
427
- user: "U1",
428
- },
429
- },
430
- {
431
- send,
432
- waitUntil: () => undefined,
433
- onAppMention: acceptHandler(),
434
- onDirectMessage: async () => null,
435
- credentials: undefined,
436
- eventIds: createEventIdDedupe(),
437
- host: testHost(),
438
- log: createSlackLogger(() => undefined),
439
- }
440
- );
441
- expect(scheduled).toBe(false);
442
- });
443
- });
444
-
445
- describe("dispatchInboundMessage", () => {
446
- it("logs delivery failure when send throws", async () => {
447
- const lines: string[] = [];
448
- await dispatchInboundMessage({
449
- kind: "app_mention",
450
- message: {
451
- text: "hi",
452
- body: "hi",
453
- markdown: "hi",
454
- ts: "2.0",
455
- threadTs: "1.0",
456
- channelId: "C1",
457
- teamId: "T1",
458
- author: { userId: "U1", isBot: false },
459
- },
460
- handler: acceptHandler(),
461
- send: async () => {
462
- throw new Error("engine down");
463
- },
464
- credentials: undefined,
465
- host: testHost(),
466
- log: createSlackLogger((line) => lines.push(line)),
467
- });
468
- expect(lines.some((line) => line.includes("delivery failed"))).toBe(true);
469
- });
470
-
471
- it("coalesces busy follow-ups with admission + nudge (no preempt retry)", async () => {
472
- const root = await mkdtemp(join(tmpdir(), "dispatch-coalesce-"));
473
- cleanups.push(() => rm(root, { recursive: true, force: true }));
474
- const apiSoft = vi.spyOn(slackApi, "callSlackApiSoft").mockResolvedValue({
475
- ok: true,
476
- messages: [
477
- { ts: "1.0", bot_id: "B1", text: "parent" },
478
- { ts: "2.0", user: "U1", text: "follow-up" },
479
- ],
480
- has_more: false,
481
- });
482
- const lines: string[] = [];
483
- const { send, calls } = createSendRecorder({ coalesced: true });
484
- const host = testHost({
485
- nudgeRoot: join(root, "nudges"),
486
- askRoot: join(root, "asks"),
487
- });
488
- await dispatchInboundMessage({
489
- kind: "app_mention",
490
- message: {
491
- text: "follow-up",
492
- body: "follow-up",
493
- markdown: "follow-up",
494
- ts: "2.0",
495
- threadTs: "1.0",
496
- channelId: "C1",
497
- teamId: "T1",
498
- author: { userId: "U1", isBot: false },
499
- },
500
- handler: acceptHandler(),
501
- send,
502
- credentials: { botToken: "xoxb-test" },
503
- host,
504
- hasContinuationSession: async () => true,
505
- log: createSlackLogger((line) => lines.push(line)),
506
- });
507
- expect(calls).toHaveLength(1);
508
- expect(calls[0]?.options?.admission).toBe("coalesce");
509
- expect(calls[0]?.options?.coalesceSourceTs).toBe("2.0");
510
- expect(
511
- lines.some((line) => line.includes("session busy; coalescing follow-up"))
512
- ).toBe(true);
513
- expect(await host.slackNudges?.hasUndelivered("C1:1.0")).toBe(false);
514
- // Follow-up typing uses same-module setThreadStatus → callSlackApiSoft;
515
- // vitest cannot spy that path. Coalesce admission + log is the contract.
516
- expect(apiSoft).toHaveBeenCalled();
517
- vi.restoreAllMocks();
518
- });
519
-
520
- it("handles whole-message stop without send", async () => {
521
- const root = await mkdtemp(join(tmpdir(), "dispatch-stop-"));
522
- cleanups.push(() => rm(root, { recursive: true, force: true }));
523
- vi.spyOn(slackApi, "setThreadStatus").mockResolvedValue({ ok: true });
524
- const { send, calls } = createSendRecorder();
525
- let interrupted = false;
526
- await dispatchInboundMessage({
527
- kind: "app_mention",
528
- message: {
529
- text: "<@Ubot> stop",
530
- body: "<@Ubot> stop",
531
- markdown: "@Ubot stop",
532
- ts: "2.0",
533
- threadTs: "1.0",
534
- channelId: "C1",
535
- teamId: "T1",
536
- author: { userId: "U1", isBot: false },
537
- },
538
- handler: acceptHandler(),
539
- send,
540
- credentials: { botToken: "xoxb-test" },
541
- host: testHost({
542
- nudgeRoot: join(root, "nudges"),
543
- askRoot: join(root, "asks"),
544
- }),
545
- interruptContinuation: async () => {
546
- interrupted = true;
547
- return true;
548
- },
549
- });
550
- expect(calls).toHaveLength(0);
551
- expect(interrupted).toBe(true);
552
- vi.restoreAllMocks();
553
- });
554
-
555
- it("handles eval list directive without send", async () => {
556
- // Assert host.evals.list ran and no agent turn was started. Slack
557
- // postMessage is same-module (not spyable via the export).
558
- const { send, calls } = createSendRecorder();
559
- let listed = false;
560
- await dispatchInboundMessage({
561
- kind: "app_mention",
562
- message: {
563
- text: "<@Ubot> eval list",
564
- body: "<@Ubot> eval list",
565
- markdown: "@Ubot eval list",
566
- ts: "2.0",
567
- threadTs: "1.0",
568
- channelId: "C1",
569
- teamId: "T1",
570
- author: { userId: "U1", isBot: false },
571
- },
572
- handler: acceptHandler(),
573
- send,
574
- credentials: { botToken: "xoxb-test" },
575
- host: testHost({
576
- evals: {
577
- list: async () => {
578
- listed = true;
579
- return {
580
- evals: [{ id: "smoke", fileId: "smoke" }],
581
- config: { maxPlaygroundRuns: 20, durableRuns: false },
582
- };
583
- },
584
- get: async () => undefined,
585
- listRunsWithActive: async () => ({ runs: [] }),
586
- start: async () => {
587
- throw new Error("should not start");
588
- },
589
- cancel: async () => {
590
- throw new Error("should not cancel");
591
- },
592
- },
593
- }),
594
- });
595
- expect(calls).toHaveLength(0);
596
- expect(listed).toBe(true);
597
- });
598
-
599
- it("skips eval directive when evalCommandsEnabled is false", async () => {
600
- const { send, calls } = createSendRecorder();
601
- await dispatchInboundMessage({
602
- kind: "app_mention",
603
- message: {
604
- text: "<@Ubot> eval list",
605
- body: "<@Ubot> eval list",
606
- markdown: "@Ubot eval list",
607
- ts: "2.0",
608
- threadTs: "1.0",
609
- channelId: "C1",
610
- teamId: "T1",
611
- author: { userId: "U1", isBot: false },
612
- },
613
- handler: acceptHandler(),
614
- send,
615
- credentials: undefined,
616
- host: testHost({
617
- evals: {
618
- list: async () => {
619
- throw new Error("should not list");
620
- },
621
- get: async () => undefined,
622
- listRunsWithActive: async () => ({ runs: [] }),
623
- start: async () => {
624
- throw new Error("should not start");
625
- },
626
- cancel: async () => {
627
- throw new Error("should not cancel");
628
- },
629
- },
630
- }),
631
- evalCommandsEnabled: false,
632
- });
633
- expect(calls).toHaveLength(1);
634
- });
635
-
636
- it("dedupes asks by channel:ts", async () => {
637
- const root = await mkdtemp(join(tmpdir(), "dispatch-dedupe-"));
638
- cleanups.push(() => rm(root, { recursive: true, force: true }));
639
- const host = testHost({
640
- nudgeRoot: join(root, "nudges"),
641
- askRoot: join(root, "asks"),
642
- });
643
- const { send, calls } = createSendRecorder();
644
- const message = {
645
- text: "hello",
646
- body: "hello",
647
- markdown: "hello",
648
- ts: "2.0",
649
- threadTs: "1.0",
650
- channelId: "C1",
651
- teamId: "T1",
652
- author: { userId: "U1", isBot: false },
653
- };
654
- await dispatchInboundMessage({
655
- kind: "app_mention",
656
- message,
657
- handler: acceptHandler(),
658
- send,
659
- credentials: undefined,
660
- host,
661
- });
662
- await dispatchInboundMessage({
663
- kind: "app_mention",
664
- message,
665
- handler: acceptHandler(),
666
- send,
667
- credentials: undefined,
668
- host,
669
- });
670
- expect(calls).toHaveLength(1);
671
- });
672
-
673
- it("hydrates prior thread messages into the prompt", async () => {
674
- vi.spyOn(slackApi, "callSlackApiSoft").mockResolvedValue({
675
- ok: true,
676
- messages: [
677
- {
678
- ts: "1.0",
679
- bot_id: "BDD",
680
- username: "Datadog",
681
- text: "Monitor alert: rate limited",
682
- },
683
- {
684
- ts: "2.0",
685
- user: "U1",
686
- text: "@jenny what happened here?",
687
- },
688
- ],
689
- has_more: false,
690
- });
691
- const { send, calls } = createSendRecorder();
692
- const lines: string[] = [];
693
- await dispatchInboundMessage({
694
- kind: "app_mention",
695
- message: {
696
- text: "<@BJENNY> what happened here?",
697
- body: "<@BJENNY> what happened here?",
698
- markdown: "@BJENNY what happened here?",
699
- ts: "2.0",
700
- threadTs: "1.0",
701
- channelId: "C1",
702
- teamId: "T1",
703
- author: { userId: "U1", isBot: false },
704
- },
705
- handler: acceptHandler(),
706
- send,
707
- credentials: { botToken: "xoxb-test" },
708
- host: testHost(),
709
- log: createSlackLogger((line) => lines.push(line)),
710
- });
711
- expect(calls).toHaveLength(1);
712
- expect(calls[0]!.message).toContain("<slack_thread>");
713
- expect(calls[0]!.message).toContain("Monitor alert: rate limited");
714
- expect(calls[0]!.message).toContain("@BJENNY what happened here?");
715
- expect(calls[0]!.message).not.toMatch(/\[reply\].*what happened here\?/);
716
- expect(lines.some((line) => line.includes("thread context loaded"))).toBe(
717
- true
718
- );
719
- vi.restoreAllMocks();
720
- });
721
-
722
- it("loads slack_thread_delta on warm continuations", async () => {
723
- const spy = vi.spyOn(slackApi, "callSlackApiSoft").mockResolvedValue({
724
- ok: true,
725
- messages: [
726
- { ts: "1.0", bot_id: "BDD", text: "parent alert" },
727
- { ts: "1.5", bot_id: "BJENNY", text: "first reply" },
728
- // Non-trigger reply after our last post — appears in the delta.
729
- // The triggering ask (3.0) is excluded from the block and appended
730
- // as user text at the end of the prompt.
731
- { ts: "2.0", user: "U2", text: "also looking" },
732
- { ts: "3.0", user: "U1", text: "any leads?" },
733
- ],
734
- has_more: false,
735
- });
736
- const { send, calls } = createSendRecorder();
737
- await dispatchInboundMessage({
738
- kind: "app_mention",
739
- message: {
740
- text: "any leads?",
741
- body: "any leads?",
742
- markdown: "any leads?",
743
- ts: "3.0",
744
- threadTs: "1.0",
745
- channelId: "C1",
746
- teamId: "T1",
747
- author: { userId: "U1", isBot: false },
748
- },
749
- handler: acceptHandler(),
750
- send,
751
- credentials: { botToken: "xoxb-test" },
752
- host: testHost(),
753
- hasContinuationSession: async () => true,
754
- // Agent watermark (not Datadog's parent) — human reply at 2.0 is in delta.
755
- getContinuationLastBotMessageTs: async () => "1.5",
756
- });
757
- expect(spy).toHaveBeenCalled();
758
- expect(calls[0]?.message).toContain("<slack_thread_delta>");
759
- expect(calls[0]?.message).toContain("also looking");
760
- expect(calls[0]?.message).not.toContain("<slack_thread>");
761
- expect(calls[0]?.options?.admission).toBe("coalesce");
762
- spy.mockRestore();
763
- });
764
-
765
- it("releases ask claim when send fails", async () => {
766
- const root = await mkdtemp(join(tmpdir(), "dispatch-claim-release-"));
767
- cleanups.push(() => rm(root, { recursive: true, force: true }));
768
- const host = testHost({
769
- nudgeRoot: join(root, "nudges"),
770
- askRoot: join(root, "asks"),
771
- });
772
- const send: SendMessageFn = async () => {
773
- throw new Error("boom");
774
- };
775
- await dispatchInboundMessage({
776
- kind: "app_mention",
777
- message: {
778
- text: "hello",
779
- body: "hello",
780
- markdown: "hello",
781
- ts: "2.0",
782
- threadTs: "1.0",
783
- channelId: "C1",
784
- teamId: "T1",
785
- author: { userId: "U1", isBot: false },
786
- },
787
- handler: acceptHandler(),
788
- send,
789
- credentials: undefined,
790
- host,
791
- log: createSlackLogger(() => undefined),
792
- });
793
- expect(await host.slackNudges?.tryClaimAsk("C1", "2.0")).toBe(true);
794
- });
795
- });