@cursor/july 0.1.22 → 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.
- package/README.md +5 -5
- package/dist/bin/agent-serve.d.ts +1 -0
- package/dist/bin/agent-serve.d.ts.map +1 -1
- package/dist/bin/agent-serve.js +21 -3
- package/dist/docs/404.html +2 -2
- package/dist/docs/ab.html +3 -3
- package/dist/docs/assets/{app.BKNKMLp4.js → app.CvSGaAxk.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.sOSfEZR6.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
- package/dist/docs/assets/chunks/{theme.BvCHT5lj.js → theme.C7vfzr7h.js} +2 -2
- package/dist/docs/assets/index.md.Dfv5ic9t.js +20 -0
- package/dist/docs/assets/{index.md.t0TM2Qzz.lean.js → index.md.Dfv5ic9t.lean.js} +1 -1
- package/dist/docs/assets/{reference_cli.md.DnYfr5V2.js → reference_cli.md.ccoKOoXt.js} +4 -3
- package/dist/docs/assets/{reference_cli.md.DnYfr5V2.lean.js → reference_cli.md.ccoKOoXt.lean.js} +1 -1
- package/dist/docs/building-with-agents.html +3 -3
- package/dist/docs/concepts.html +3 -3
- package/dist/docs/deployment.html +3 -3
- package/dist/docs/evals.html +3 -3
- package/dist/docs/example-agents/approval-buddy.html +3 -3
- package/dist/docs/example-agents/benny.html +3 -3
- package/dist/docs/example-agents/bugbot.html +3 -3
- package/dist/docs/example-agents/codebase-wiki.html +3 -3
- package/dist/docs/example-agents/codeowners-review.html +3 -3
- package/dist/docs/example-agents/concierge.html +3 -3
- package/dist/docs/example-agents/fsd.html +3 -3
- package/dist/docs/example-agents/index.html +3 -3
- package/dist/docs/example-agents/knowledge-base.html +3 -3
- package/dist/docs/example-agents/oncall.html +3 -3
- package/dist/docs/example-agents/security-reviewer.html +3 -3
- package/dist/docs/example-agents/slack-agent.html +3 -3
- package/dist/docs/example-agents/weather-agent.html +3 -3
- package/dist/docs/guides/agent-to-agent.html +3 -3
- package/dist/docs/guides/cloud-runtime.html +3 -3
- package/dist/docs/guides/github.html +3 -3
- package/dist/docs/guides/human-in-the-loop.html +3 -3
- package/dist/docs/guides/mcp-oauth.html +3 -3
- package/dist/docs/guides/slack.html +3 -3
- package/dist/docs/guides/webhooks.html +3 -3
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +3 -3
- package/dist/docs/index.html +6 -6
- package/dist/docs/quickstart.html +3 -3
- package/dist/docs/reference/agent-config.html +3 -3
- package/dist/docs/reference/channels.html +3 -3
- package/dist/docs/reference/cli.html +7 -6
- package/dist/docs/reference/connections.html +3 -3
- package/dist/docs/reference/hooks.html +3 -3
- package/dist/docs/reference/http-api.html +3 -3
- package/dist/docs/reference/instructions.html +3 -3
- package/dist/docs/reference/playground.html +3 -3
- package/dist/docs/reference/project-layout.html +3 -3
- package/dist/docs/reference/prompt.html +3 -3
- package/dist/docs/reference/schedules.html +3 -3
- package/dist/docs/reference/sessions.html +3 -3
- package/dist/docs/reference/skills.html +3 -3
- package/dist/docs/reference/subagents.html +3 -3
- package/dist/docs/reference/tools.html +3 -3
- package/dist/docs/scaffolding-agents.html +3 -3
- package/dist/docs/storage.html +3 -3
- package/dist/docs/troubleshooting.html +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/internal/cli-docs.d.ts +34 -0
- package/dist/internal/cli-docs.d.ts.map +1 -0
- package/dist/internal/cli-docs.js +162 -0
- package/dist/internal/distribution.d.ts +2 -1
- package/dist/internal/distribution.d.ts.map +1 -1
- package/dist/internal/distribution.js +3 -1
- package/dist/internal/docs-site.d.ts +4 -2
- package/dist/internal/docs-site.d.ts.map +1 -1
- package/dist/internal/docs-site.js +15 -11
- package/dist/internal/init-project.d.ts.map +1 -1
- package/dist/internal/init-project.js +19 -0
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +5 -0
- package/dist/internal/workspace.d.ts +9 -0
- package/dist/internal/workspace.d.ts.map +1 -1
- package/dist/internal/workspace.js +52 -5
- package/dist/memory.d.ts +79 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +164 -0
- package/dist/playground/assets/index-CidizGZv.css +1 -0
- package/dist/playground/assets/index-DTG9OsPV.js +85 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/README.md +8 -1
- package/docs/reference/cli.md +20 -4
- package/package.json +32 -24
- package/src/bin/agent-serve.ts +23 -3
- package/src/index.ts +2 -0
- package/src/internal/cli-docs.ts +191 -0
- package/src/internal/distribution.ts +3 -1
- package/src/internal/docs-site.ts +19 -11
- package/src/internal/init-project.ts +22 -0
- package/src/internal/session-engine.ts +5 -0
- package/src/internal/workspace.ts +81 -5
- package/src/memory.ts +215 -0
- package/src/types.ts +11 -0
- package/dist/channels/github/instrument.d.ts +0 -20
- package/dist/channels/github/instrument.d.ts.map +0 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.YFE6WoMB.js +0 -1
- package/dist/docs/assets/index.md.t0TM2Qzz.js +0 -20
- package/dist/internal/json-dir-store.d.ts +0 -32
- package/dist/internal/json-dir-store.d.ts.map +0 -1
- package/dist/internal/json-dir-store.js +0 -100
- package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
- package/dist/playground/assets/index-dshZQJCp.js +0 -85
- package/src/bin/agent-serve.version.test.ts +0 -62
- package/src/channels/github/api.test.ts +0 -64
- package/src/channels/github/auth.test.ts +0 -105
- package/src/channels/github/cursor-account.test.ts +0 -204
- package/src/channels/github/forward.test.ts +0 -457
- package/src/channels/github/github.test.ts +0 -937
- package/src/channels/github/replay.test.ts +0 -179
- package/src/channels/slack/api.post-message.test.ts +0 -148
- package/src/channels/slack/approvals.test.ts +0 -328
- package/src/channels/slack/block-actions.test.ts +0 -452
- package/src/channels/slack/bot-mentions.test.ts +0 -267
- package/src/channels/slack/channel-watch.test.ts +0 -363
- package/src/channels/slack/cursor-account.test.ts +0 -253
- package/src/channels/slack/defaults.final-post.test.ts +0 -182
- package/src/channels/slack/dispatch.test.ts +0 -795
- package/src/channels/slack/eval-directive.test.ts +0 -273
- package/src/channels/slack/message-body.test.ts +0 -54
- package/src/channels/slack/nudge-store.test.ts +0 -143
- package/src/channels/slack/slack.test.ts +0 -391
- package/src/channels/slack/stop.test.ts +0 -23
- package/src/channels/slack/thread-context.test.ts +0 -202
- package/src/evals/assertions.test.ts +0 -580
- package/src/evals/expect.test.ts +0 -144
- package/src/evals/judge.test.ts +0 -181
- package/src/evals/loaders.test.ts +0 -132
- package/src/evals/matchers.test.ts +0 -95
- package/src/evals/reporters.test.ts +0 -303
- package/src/evals/run-facts.test.ts +0 -259
- package/src/internal/ab-snapshot.test.ts +0 -325
- package/src/internal/approval-gate.test.ts +0 -49
- package/src/internal/approvals.integration.test.ts +0 -383
- package/src/internal/authored-loaders.test.ts +0 -31
- package/src/internal/builtin-tools/reminders.test.ts +0 -201
- package/src/internal/channel-route-schema.test.ts +0 -294
- package/src/internal/chat-attach.test.ts +0 -262
- package/src/internal/cli-deploy.test.ts +0 -1991
- package/src/internal/cli-mcp.test.ts +0 -789
- package/src/internal/cli-skills.test.ts +0 -133
- package/src/internal/cli-slack.test.ts +0 -1647
- package/src/internal/cloud-merge.test.ts +0 -74
- package/src/internal/cron.test.ts +0 -22
- package/src/internal/cursor/account-mcp.test.ts +0 -807
- package/src/internal/cursor/backend-client.test.ts +0 -591
- package/src/internal/cursor/credentials.test.ts +0 -351
- package/src/internal/cursor/github-credentials.test.ts +0 -136
- package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
- package/src/internal/cursor-account.integration.test.ts +0 -441
- package/src/internal/cursor-event-relay.test.ts +0 -746
- package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
- package/src/internal/cursor-slack-relay.test.ts +0 -525
- package/src/internal/deploy-source.test.ts +0 -111
- package/src/internal/discovery.builtin-tools.test.ts +0 -94
- package/src/internal/discovery.concurrency.test.ts +0 -60
- package/src/internal/discovery.cursor-account.test.ts +0 -133
- package/src/internal/discovery.cwd.test.ts +0 -83
- package/src/internal/discovery.hosting.test.ts +0 -80
- package/src/internal/discovery.identity.test.ts +0 -44
- package/src/internal/docs-site.test.ts +0 -66
- package/src/internal/duration.test.ts +0 -29
- package/src/internal/eval-judge-model.test.ts +0 -187
- package/src/internal/eval-run-store.cancel.test.ts +0 -142
- package/src/internal/eval-run-store.storage.test.ts +0 -211
- package/src/internal/eval-runner.http.test.ts +0 -403
- package/src/internal/eval-runner.run.test.ts +0 -928
- package/src/internal/evals-client.test.ts +0 -307
- package/src/internal/event-mapper.test.ts +0 -243
- package/src/internal/github-fanout.test.ts +0 -213
- package/src/internal/handleAgentServeTrigger.test.ts +0 -179
- package/src/internal/host-kv.test.ts +0 -82
- package/src/internal/host-platforms.test.ts +0 -126
- package/src/internal/http-channel.test.ts +0 -402
- package/src/internal/init-project.test.ts +0 -269
- package/src/internal/install-cursor-skills.test.ts +0 -262
- package/src/internal/local-env.test.ts +0 -120
- package/src/internal/log-ring.test.ts +0 -31
- package/src/internal/logs-client.test.ts +0 -350
- package/src/internal/mcp-endpoint.test.ts +0 -436
- package/src/internal/mcp-host.test.ts +0 -298
- package/src/internal/mcp-oauth.test.ts +0 -148
- package/src/internal/net.test.ts +0 -17
- package/src/internal/peer-connections.test.ts +0 -128
- package/src/internal/peer-mcp.integration.test.ts +0 -289
- package/src/internal/playground/toolchain.test.ts +0 -53
- package/src/internal/playground-cli.test.ts +0 -187
- package/src/internal/playground-proxy.test.ts +0 -376
- package/src/internal/prompt-context.integration.test.ts +0 -232
- package/src/internal/prompt-context.test.ts +0 -127
- package/src/internal/reminder-runner.test.ts +0 -390
- package/src/internal/reminder-store.test.ts +0 -53
- package/src/internal/request-headers.test.ts +0 -27
- package/src/internal/resolve-prod-target.test.ts +0 -787
- package/src/internal/resolved-connections.test.ts +0 -295
- package/src/internal/router.test.ts +0 -57
- package/src/internal/sdk-runner.test.ts +0 -290
- package/src/internal/session-engine.coalesce.test.ts +0 -169
- package/src/internal/session-engine.concurrency.test.ts +0 -250
- package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
- package/src/internal/session-engine.interrupt.test.ts +0 -577
- package/src/internal/session-engine.storage.test.ts +0 -547
- package/src/internal/session-urls.test.ts +0 -28
- package/src/internal/sessions-client.test.ts +0 -518
- package/src/internal/storage-coordinator.test.ts +0 -517
- package/src/internal/tool-call.test.ts +0 -458
- package/src/internal/tool-result.test.ts +0 -52
- package/src/internal/trajectory.approvals.test.ts +0 -83
- package/src/internal/trajectory.subagents.test.ts +0 -198
- package/src/internal/turn-governor.test.ts +0 -137
- package/src/internal/update-check.test.ts +0 -485
- package/src/internal/workspace.test.ts +0 -81
- 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
|
-
});
|