@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.
Files changed (219) hide show
  1. package/README.md +5 -5
  2. package/dist/bin/agent-serve.d.ts +1 -0
  3. package/dist/bin/agent-serve.d.ts.map +1 -1
  4. package/dist/bin/agent-serve.js +21 -3
  5. package/dist/docs/404.html +2 -2
  6. package/dist/docs/ab.html +3 -3
  7. package/dist/docs/assets/{app.BKNKMLp4.js → app.CvSGaAxk.js} +1 -1
  8. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
  9. package/dist/docs/assets/chunks/{VPLocalSearchBox.sOSfEZR6.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
  10. package/dist/docs/assets/chunks/{theme.BvCHT5lj.js → theme.C7vfzr7h.js} +2 -2
  11. package/dist/docs/assets/index.md.Dfv5ic9t.js +20 -0
  12. package/dist/docs/assets/{index.md.t0TM2Qzz.lean.js → index.md.Dfv5ic9t.lean.js} +1 -1
  13. package/dist/docs/assets/{reference_cli.md.DnYfr5V2.js → reference_cli.md.ccoKOoXt.js} +4 -3
  14. package/dist/docs/assets/{reference_cli.md.DnYfr5V2.lean.js → reference_cli.md.ccoKOoXt.lean.js} +1 -1
  15. package/dist/docs/building-with-agents.html +3 -3
  16. package/dist/docs/concepts.html +3 -3
  17. package/dist/docs/deployment.html +3 -3
  18. package/dist/docs/evals.html +3 -3
  19. package/dist/docs/example-agents/approval-buddy.html +3 -3
  20. package/dist/docs/example-agents/benny.html +3 -3
  21. package/dist/docs/example-agents/bugbot.html +3 -3
  22. package/dist/docs/example-agents/codebase-wiki.html +3 -3
  23. package/dist/docs/example-agents/codeowners-review.html +3 -3
  24. package/dist/docs/example-agents/concierge.html +3 -3
  25. package/dist/docs/example-agents/fsd.html +3 -3
  26. package/dist/docs/example-agents/index.html +3 -3
  27. package/dist/docs/example-agents/knowledge-base.html +3 -3
  28. package/dist/docs/example-agents/oncall.html +3 -3
  29. package/dist/docs/example-agents/security-reviewer.html +3 -3
  30. package/dist/docs/example-agents/slack-agent.html +3 -3
  31. package/dist/docs/example-agents/weather-agent.html +3 -3
  32. package/dist/docs/guides/agent-to-agent.html +3 -3
  33. package/dist/docs/guides/cloud-runtime.html +3 -3
  34. package/dist/docs/guides/github.html +3 -3
  35. package/dist/docs/guides/human-in-the-loop.html +3 -3
  36. package/dist/docs/guides/mcp-oauth.html +3 -3
  37. package/dist/docs/guides/slack.html +3 -3
  38. package/dist/docs/guides/webhooks.html +3 -3
  39. package/dist/docs/hashmap.json +1 -1
  40. package/dist/docs/hillclimbing.html +3 -3
  41. package/dist/docs/index.html +6 -6
  42. package/dist/docs/quickstart.html +3 -3
  43. package/dist/docs/reference/agent-config.html +3 -3
  44. package/dist/docs/reference/channels.html +3 -3
  45. package/dist/docs/reference/cli.html +7 -6
  46. package/dist/docs/reference/connections.html +3 -3
  47. package/dist/docs/reference/hooks.html +3 -3
  48. package/dist/docs/reference/http-api.html +3 -3
  49. package/dist/docs/reference/instructions.html +3 -3
  50. package/dist/docs/reference/playground.html +3 -3
  51. package/dist/docs/reference/project-layout.html +3 -3
  52. package/dist/docs/reference/prompt.html +3 -3
  53. package/dist/docs/reference/schedules.html +3 -3
  54. package/dist/docs/reference/sessions.html +3 -3
  55. package/dist/docs/reference/skills.html +3 -3
  56. package/dist/docs/reference/subagents.html +3 -3
  57. package/dist/docs/reference/tools.html +3 -3
  58. package/dist/docs/scaffolding-agents.html +3 -3
  59. package/dist/docs/storage.html +3 -3
  60. package/dist/docs/troubleshooting.html +3 -3
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +1 -0
  64. package/dist/internal/cli-docs.d.ts +34 -0
  65. package/dist/internal/cli-docs.d.ts.map +1 -0
  66. package/dist/internal/cli-docs.js +162 -0
  67. package/dist/internal/distribution.d.ts +2 -1
  68. package/dist/internal/distribution.d.ts.map +1 -1
  69. package/dist/internal/distribution.js +3 -1
  70. package/dist/internal/docs-site.d.ts +4 -2
  71. package/dist/internal/docs-site.d.ts.map +1 -1
  72. package/dist/internal/docs-site.js +15 -11
  73. package/dist/internal/init-project.d.ts.map +1 -1
  74. package/dist/internal/init-project.js +19 -0
  75. package/dist/internal/session-engine.d.ts.map +1 -1
  76. package/dist/internal/session-engine.js +5 -0
  77. package/dist/internal/workspace.d.ts +9 -0
  78. package/dist/internal/workspace.d.ts.map +1 -1
  79. package/dist/internal/workspace.js +52 -5
  80. package/dist/memory.d.ts +79 -0
  81. package/dist/memory.d.ts.map +1 -0
  82. package/dist/memory.js +164 -0
  83. package/dist/playground/assets/index-CidizGZv.css +1 -0
  84. package/dist/playground/assets/index-DTG9OsPV.js +85 -0
  85. package/dist/playground/index.html +2 -2
  86. package/dist/types.d.ts +11 -0
  87. package/dist/types.d.ts.map +1 -1
  88. package/docs/README.md +8 -1
  89. package/docs/reference/cli.md +20 -4
  90. package/package.json +32 -24
  91. package/src/bin/agent-serve.ts +23 -3
  92. package/src/index.ts +2 -0
  93. package/src/internal/cli-docs.ts +191 -0
  94. package/src/internal/distribution.ts +3 -1
  95. package/src/internal/docs-site.ts +19 -11
  96. package/src/internal/init-project.ts +22 -0
  97. package/src/internal/session-engine.ts +5 -0
  98. package/src/internal/workspace.ts +81 -5
  99. package/src/memory.ts +215 -0
  100. package/src/types.ts +11 -0
  101. package/dist/channels/github/instrument.d.ts +0 -20
  102. package/dist/channels/github/instrument.d.ts.map +0 -1
  103. package/dist/docs/assets/chunks/@localSearchIndexroot.YFE6WoMB.js +0 -1
  104. package/dist/docs/assets/index.md.t0TM2Qzz.js +0 -20
  105. package/dist/internal/json-dir-store.d.ts +0 -32
  106. package/dist/internal/json-dir-store.d.ts.map +0 -1
  107. package/dist/internal/json-dir-store.js +0 -100
  108. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  109. package/dist/playground/assets/index-dshZQJCp.js +0 -85
  110. package/src/bin/agent-serve.version.test.ts +0 -62
  111. package/src/channels/github/api.test.ts +0 -64
  112. package/src/channels/github/auth.test.ts +0 -105
  113. package/src/channels/github/cursor-account.test.ts +0 -204
  114. package/src/channels/github/forward.test.ts +0 -457
  115. package/src/channels/github/github.test.ts +0 -937
  116. package/src/channels/github/replay.test.ts +0 -179
  117. package/src/channels/slack/api.post-message.test.ts +0 -148
  118. package/src/channels/slack/approvals.test.ts +0 -328
  119. package/src/channels/slack/block-actions.test.ts +0 -452
  120. package/src/channels/slack/bot-mentions.test.ts +0 -267
  121. package/src/channels/slack/channel-watch.test.ts +0 -363
  122. package/src/channels/slack/cursor-account.test.ts +0 -253
  123. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  124. package/src/channels/slack/dispatch.test.ts +0 -795
  125. package/src/channels/slack/eval-directive.test.ts +0 -273
  126. package/src/channels/slack/message-body.test.ts +0 -54
  127. package/src/channels/slack/nudge-store.test.ts +0 -143
  128. package/src/channels/slack/slack.test.ts +0 -391
  129. package/src/channels/slack/stop.test.ts +0 -23
  130. package/src/channels/slack/thread-context.test.ts +0 -202
  131. package/src/evals/assertions.test.ts +0 -580
  132. package/src/evals/expect.test.ts +0 -144
  133. package/src/evals/judge.test.ts +0 -181
  134. package/src/evals/loaders.test.ts +0 -132
  135. package/src/evals/matchers.test.ts +0 -95
  136. package/src/evals/reporters.test.ts +0 -303
  137. package/src/evals/run-facts.test.ts +0 -259
  138. package/src/internal/ab-snapshot.test.ts +0 -325
  139. package/src/internal/approval-gate.test.ts +0 -49
  140. package/src/internal/approvals.integration.test.ts +0 -383
  141. package/src/internal/authored-loaders.test.ts +0 -31
  142. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  143. package/src/internal/channel-route-schema.test.ts +0 -294
  144. package/src/internal/chat-attach.test.ts +0 -262
  145. package/src/internal/cli-deploy.test.ts +0 -1991
  146. package/src/internal/cli-mcp.test.ts +0 -789
  147. package/src/internal/cli-skills.test.ts +0 -133
  148. package/src/internal/cli-slack.test.ts +0 -1647
  149. package/src/internal/cloud-merge.test.ts +0 -74
  150. package/src/internal/cron.test.ts +0 -22
  151. package/src/internal/cursor/account-mcp.test.ts +0 -807
  152. package/src/internal/cursor/backend-client.test.ts +0 -591
  153. package/src/internal/cursor/credentials.test.ts +0 -351
  154. package/src/internal/cursor/github-credentials.test.ts +0 -136
  155. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  156. package/src/internal/cursor-account.integration.test.ts +0 -441
  157. package/src/internal/cursor-event-relay.test.ts +0 -746
  158. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  159. package/src/internal/cursor-slack-relay.test.ts +0 -525
  160. package/src/internal/deploy-source.test.ts +0 -111
  161. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  162. package/src/internal/discovery.concurrency.test.ts +0 -60
  163. package/src/internal/discovery.cursor-account.test.ts +0 -133
  164. package/src/internal/discovery.cwd.test.ts +0 -83
  165. package/src/internal/discovery.hosting.test.ts +0 -80
  166. package/src/internal/discovery.identity.test.ts +0 -44
  167. package/src/internal/docs-site.test.ts +0 -66
  168. package/src/internal/duration.test.ts +0 -29
  169. package/src/internal/eval-judge-model.test.ts +0 -187
  170. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  171. package/src/internal/eval-run-store.storage.test.ts +0 -211
  172. package/src/internal/eval-runner.http.test.ts +0 -403
  173. package/src/internal/eval-runner.run.test.ts +0 -928
  174. package/src/internal/evals-client.test.ts +0 -307
  175. package/src/internal/event-mapper.test.ts +0 -243
  176. package/src/internal/github-fanout.test.ts +0 -213
  177. package/src/internal/handleAgentServeTrigger.test.ts +0 -179
  178. package/src/internal/host-kv.test.ts +0 -82
  179. package/src/internal/host-platforms.test.ts +0 -126
  180. package/src/internal/http-channel.test.ts +0 -402
  181. package/src/internal/init-project.test.ts +0 -269
  182. package/src/internal/install-cursor-skills.test.ts +0 -262
  183. package/src/internal/local-env.test.ts +0 -120
  184. package/src/internal/log-ring.test.ts +0 -31
  185. package/src/internal/logs-client.test.ts +0 -350
  186. package/src/internal/mcp-endpoint.test.ts +0 -436
  187. package/src/internal/mcp-host.test.ts +0 -298
  188. package/src/internal/mcp-oauth.test.ts +0 -148
  189. package/src/internal/net.test.ts +0 -17
  190. package/src/internal/peer-connections.test.ts +0 -128
  191. package/src/internal/peer-mcp.integration.test.ts +0 -289
  192. package/src/internal/playground/toolchain.test.ts +0 -53
  193. package/src/internal/playground-cli.test.ts +0 -187
  194. package/src/internal/playground-proxy.test.ts +0 -376
  195. package/src/internal/prompt-context.integration.test.ts +0 -232
  196. package/src/internal/prompt-context.test.ts +0 -127
  197. package/src/internal/reminder-runner.test.ts +0 -390
  198. package/src/internal/reminder-store.test.ts +0 -53
  199. package/src/internal/request-headers.test.ts +0 -27
  200. package/src/internal/resolve-prod-target.test.ts +0 -787
  201. package/src/internal/resolved-connections.test.ts +0 -295
  202. package/src/internal/router.test.ts +0 -57
  203. package/src/internal/sdk-runner.test.ts +0 -290
  204. package/src/internal/session-engine.coalesce.test.ts +0 -169
  205. package/src/internal/session-engine.concurrency.test.ts +0 -250
  206. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  207. package/src/internal/session-engine.interrupt.test.ts +0 -577
  208. package/src/internal/session-engine.storage.test.ts +0 -547
  209. package/src/internal/session-urls.test.ts +0 -28
  210. package/src/internal/sessions-client.test.ts +0 -518
  211. package/src/internal/storage-coordinator.test.ts +0 -517
  212. package/src/internal/tool-call.test.ts +0 -458
  213. package/src/internal/tool-result.test.ts +0 -52
  214. package/src/internal/trajectory.approvals.test.ts +0 -83
  215. package/src/internal/trajectory.subagents.test.ts +0 -198
  216. package/src/internal/turn-governor.test.ts +0 -137
  217. package/src/internal/update-check.test.ts +0 -485
  218. package/src/internal/workspace.test.ts +0 -81
  219. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,937 +0,0 @@
1
- import { createHmac } from "node:crypto";
2
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
- import { scmMetadataToGitHubPayload } from "../../internal/cursor-event-relay.js";
4
- import type {
5
- ChannelHandlerArgs,
6
- ChannelRouteHandler,
7
- ChannelSession,
8
- SendMessageFn,
9
- } from "../../types.js";
10
- import { formatGitHubOutboundComment } from "./binding.js";
11
- import {
12
- clearGitHubAuthCaches,
13
- defaultGitHubAuth,
14
- defaultGitHubPullRequestMessage,
15
- defaultOnComment,
16
- type GitHubEventContext,
17
- type GitHubRawEvent,
18
- githubChannel,
19
- githubPullRequestContinuationKey,
20
- isGitHubAppBotAuthor,
21
- parseGitHubPullRequestEvent,
22
- shouldDispatchGitHubComment,
23
- verifyGitHubWebhookSignature,
24
- } from "./index.js";
25
-
26
- describe("parseGitHubPullRequestEvent", () => {
27
- it("normalizes a GitHub pull_request payload", () => {
28
- const parsed = parseGitHubPullRequestEvent({
29
- deliveryId: "delivery-1",
30
- payload: pullRequestPayload(),
31
- });
32
-
33
- expect(parsed).toEqual({
34
- ctx: {
35
- deliveryId: "delivery-1",
36
- eventName: "pull_request",
37
- repository: {
38
- fullName: "acme/widgets",
39
- url: "https://github.com/acme/widgets",
40
- owner: "acme",
41
- name: "widgets",
42
- },
43
- conversation: {
44
- kind: "pull_request",
45
- number: 42,
46
- url: "https://github.com/acme/widgets/pull/42",
47
- },
48
- senderLogin: "sender",
49
- sender: { login: "sender" },
50
- },
51
- pullRequest: {
52
- action: "opened",
53
- number: 42,
54
- url: "https://github.com/acme/widgets/pull/42",
55
- title: "Add widgets",
56
- body: "PR body",
57
- headRef: "feature/widgets",
58
- headSha: "abc123",
59
- baseRef: "main",
60
- draft: false,
61
- merged: false,
62
- authorLogin: "octocat",
63
- },
64
- });
65
- });
66
-
67
- it("rejects malformed payloads", () => {
68
- expect(
69
- parseGitHubPullRequestEvent({
70
- payload: { action: "opened" },
71
- })
72
- ).toBeNull();
73
- });
74
- });
75
-
76
- describe("GitHub pull request prompt helpers", () => {
77
- it("builds stable continuation keys and context-rich messages", () => {
78
- const parsed = parseGitHubPullRequestEvent({
79
- payload: pullRequestPayload(),
80
- });
81
- expect(parsed).not.toBeNull();
82
- if (parsed === null) {
83
- return;
84
- }
85
-
86
- expect(githubPullRequestContinuationKey(parsed.ctx)).toBe(
87
- "github-pr:acme/widgets#42"
88
- );
89
- const message = defaultGitHubPullRequestMessage(
90
- parsed.ctx,
91
- parsed.pullRequest
92
- );
93
- expect(message).toContain("GitHub pull request trigger: acme/widgets#42");
94
- expect(message).toContain("Head: feature/widgets (abc123)");
95
- });
96
-
97
- it("derives the turn auth from the delivery actor", () => {
98
- const parsed = parseGitHubPullRequestEvent({
99
- payload: pullRequestPayload(),
100
- });
101
- expect(parsed).not.toBeNull();
102
- if (parsed === null) {
103
- return;
104
- }
105
-
106
- expect(defaultGitHubAuth(parsed.ctx)).toEqual({
107
- authenticator: "github-webhook",
108
- principalId: "sender",
109
- principalType: "user",
110
- attributes: expect.objectContaining({ repository: "acme/widgets" }),
111
- });
112
- });
113
- });
114
-
115
- describe("defaultOnComment / mention gate", () => {
116
- it("dispatches only when the bot is @mentioned", () => {
117
- expect(
118
- shouldDispatchGitHubComment({
119
- body: "hey @my-agent please look",
120
- botName: "my-agent",
121
- })
122
- ).toBe(true);
123
- expect(
124
- shouldDispatchGitHubComment({
125
- body: "no mention here",
126
- botName: "my-agent",
127
- })
128
- ).toBe(false);
129
- expect(
130
- shouldDispatchGitHubComment({
131
- body: "@my-agent hi",
132
- botName: undefined,
133
- })
134
- ).toBe(false);
135
- });
136
-
137
- it("ignores comments from the GitHub App bot actor", () => {
138
- expect(
139
- shouldDispatchGitHubComment({
140
- body: "hey @my-agent please look",
141
- author: { login: "my-agent[bot]", type: "Bot" },
142
- botName: "my-agent",
143
- })
144
- ).toBe(false);
145
- expect(
146
- isGitHubAppBotAuthor({ login: "my-agent[bot]", type: "Bot" }, "my-agent")
147
- ).toBe(true);
148
- });
149
-
150
- it("returns auth when mentioned", () => {
151
- const ctx = {
152
- eventName: "issue_comment",
153
- repository: {
154
- fullName: "acme/widgets",
155
- url: "https://github.com/acme/widgets",
156
- owner: "acme",
157
- name: "widgets",
158
- },
159
- conversation: {
160
- kind: "pull_request" as const,
161
- number: 42,
162
- url: "https://github.com/acme/widgets/pull/42",
163
- },
164
- senderLogin: "sender",
165
- };
166
- expect(
167
- defaultOnComment(
168
- ctx,
169
- {
170
- id: 1,
171
- body: "@my-agent triage this",
172
- url: "https://github.com/acme/widgets/issues/42#issuecomment-1",
173
- htmlUrl: "https://github.com/acme/widgets/issues/42#issuecomment-1",
174
- },
175
- { botName: "my-agent" }
176
- )
177
- ).toEqual({ auth: defaultGitHubAuth(ctx) });
178
- });
179
- });
180
-
181
- describe("verifyGitHubWebhookSignature", () => {
182
- it("accepts a valid sha256 signature", async () => {
183
- const body = JSON.stringify(pullRequestPayload());
184
- const signature = `sha256=${createHmac("sha256", "secret")
185
- .update(body)
186
- .digest("hex")}`;
187
-
188
- await expect(
189
- verifyGitHubWebhookSignature({
190
- body,
191
- signatureHeader: signature,
192
- secret: "secret",
193
- })
194
- ).resolves.toBe("verified");
195
- });
196
-
197
- it("rejects mismatched signatures", async () => {
198
- await expect(
199
- verifyGitHubWebhookSignature({
200
- body: "{}",
201
- signatureHeader: "sha256=bad",
202
- secret: "secret",
203
- })
204
- ).resolves.toBe("mismatch");
205
- });
206
- });
207
-
208
- describe("githubChannel", () => {
209
- let priorWebhookSecret: string | undefined;
210
-
211
- beforeEach(() => {
212
- priorWebhookSecret = process.env.GITHUB_WEBHOOK_SECRET;
213
- delete process.env.GITHUB_WEBHOOK_SECRET;
214
- });
215
-
216
- afterEach(() => {
217
- if (priorWebhookSecret === undefined) {
218
- delete process.env.GITHUB_WEBHOOK_SECRET;
219
- } else {
220
- process.env.GITHUB_WEBHOOK_SECRET = priorWebhookSecret;
221
- }
222
- });
223
-
224
- it("dispatches default review triggers as the delivery actor", async () => {
225
- const body = JSON.stringify(pullRequestPayload());
226
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
227
- const response = await routeHandler(
228
- githubChannel({
229
- auth: [],
230
- cloud: true,
231
- })
232
- )(
233
- new Request("http://127.0.0.1:3000/v1/channels/github", {
234
- method: "POST",
235
- headers: {
236
- "x-github-event": "pull_request",
237
- "x-github-delivery": "delivery-1",
238
- "content-type": "application/json",
239
- },
240
- body,
241
- }),
242
- handlerArgs(send)
243
- );
244
-
245
- await expect(response.json()).resolves.toEqual({
246
- ok: true,
247
- sessionId: "session-1",
248
- isNew: true,
249
- continuationToken: "github-pr:acme/widgets#42",
250
- });
251
- expect(send).toHaveBeenCalledExactlyOnceWith(
252
- expect.stringContaining("GitHub pull request trigger: acme/widgets#42"),
253
- expect.objectContaining({
254
- auth: expect.objectContaining({
255
- authenticator: "github-webhook",
256
- principalId: "sender",
257
- principalType: "user",
258
- }),
259
- continuationToken: "github-pr:acme/widgets#42",
260
- title: "GitHub acme/widgets#42",
261
- cloud: {
262
- repos: [
263
- {
264
- url: "https://github.com/acme/widgets",
265
- prUrl: "https://github.com/acme/widgets/pull/42",
266
- startingRef: "abc123",
267
- },
268
- ],
269
- },
270
- })
271
- );
272
- });
273
-
274
- it("ignores actions outside the default gate without starting a session", async () => {
275
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
276
- const response = await routeHandler(githubChannel({ auth: [] }))(
277
- new Request("http://127.0.0.1:3000/v1/channels/github", {
278
- method: "POST",
279
- headers: { "x-github-event": "pull_request" },
280
- body: JSON.stringify(pullRequestPayload({ action: "closed" })),
281
- }),
282
- handlerArgs(send)
283
- );
284
-
285
- await expect(response.json()).resolves.toEqual({
286
- ok: true,
287
- skipped: true,
288
- reason: "not_dispatched",
289
- action: "closed",
290
- });
291
- expect(send).not.toHaveBeenCalled();
292
- });
293
-
294
- it("replaces the default gate with the onPullRequest hook", async () => {
295
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
296
- const handler = routeHandler(
297
- githubChannel({
298
- auth: [],
299
- onPullRequest: (ctx, pr) =>
300
- pr.action === "synchronize"
301
- ? { auth: defaultGitHubAuth(ctx), context: ["Focus on the diff."] }
302
- : null,
303
- })
304
- );
305
-
306
- const ignored = await handler(
307
- new Request("http://127.0.0.1:3000/v1/channels/github", {
308
- method: "POST",
309
- headers: { "x-github-event": "pull_request" },
310
- body: JSON.stringify(pullRequestPayload({ action: "opened" })),
311
- }),
312
- handlerArgs(send)
313
- );
314
- await expect(ignored.json()).resolves.toEqual({
315
- ok: true,
316
- skipped: true,
317
- reason: "not_dispatched",
318
- action: "opened",
319
- });
320
- expect(send).not.toHaveBeenCalled();
321
-
322
- const dispatched = await handler(
323
- new Request("http://127.0.0.1:3000/v1/channels/github", {
324
- method: "POST",
325
- headers: { "x-github-event": "pull_request" },
326
- body: JSON.stringify(pullRequestPayload({ action: "synchronize" })),
327
- }),
328
- handlerArgs(send)
329
- );
330
- await expect(dispatched.json()).resolves.toMatchObject({ ok: true });
331
- expect(send).toHaveBeenCalledExactlyOnceWith(
332
- expect.stringContaining("Focus on the diff."),
333
- expect.anything()
334
- );
335
- });
336
-
337
- it("dispatches @mention issue comments via the default onComment gate", async () => {
338
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
339
- const response = await routeHandler(
340
- githubChannel({
341
- auth: [],
342
- botName: "my-agent",
343
- })
344
- )(
345
- new Request("http://127.0.0.1:3000/v1/channels/github", {
346
- method: "POST",
347
- headers: {
348
- "x-github-event": "issue_comment",
349
- "x-github-delivery": "delivery-comment",
350
- },
351
- body: JSON.stringify(issueCommentPayload("@my-agent please triage")),
352
- }),
353
- handlerArgs(send)
354
- );
355
-
356
- await expect(response.json()).resolves.toMatchObject({ ok: true });
357
- expect(send).toHaveBeenCalledExactlyOnceWith(
358
- "please triage",
359
- expect.objectContaining({
360
- continuationToken: "github-pr:acme/widgets#42",
361
- auth: expect.objectContaining({ principalId: "sender" }),
362
- })
363
- );
364
- });
365
-
366
- it("dispatches relay-stubbed issue_comment payloads (scm-events metadata)", async () => {
367
- // Regression guard for the /v0/scm-events comment gap: a metadata-only
368
- // envelope with a comment snapshot must clear the issue_comment Zod
369
- // schema and dispatch, without a payload round-trip to GitHub.
370
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
371
- const response = await routeHandler(
372
- githubChannel({ auth: [], botName: "my-agent" })
373
- )(
374
- new Request("http://127.0.0.1:3000/v1/channels/github", {
375
- method: "POST",
376
- headers: {
377
- "x-github-event": "issue_comment",
378
- "x-github-delivery": "delivery-relay-comment",
379
- },
380
- body: JSON.stringify(
381
- scmMetadataToGitHubPayload({
382
- repo: "acme/widgets",
383
- action: "created",
384
- prNumber: 42,
385
- prUrl: "https://github.com/acme/widgets/pull/42",
386
- comment: {
387
- id: 7,
388
- body: "@my-agent please triage",
389
- htmlUrl: "https://github.com/acme/widgets/pull/42#issuecomment-7",
390
- authorLogin: "sender",
391
- },
392
- })
393
- ),
394
- }),
395
- handlerArgs(send)
396
- );
397
-
398
- await expect(response.json()).resolves.toMatchObject({ ok: true });
399
- expect(send).toHaveBeenCalledExactlyOnceWith(
400
- "please triage",
401
- expect.objectContaining({
402
- continuationToken: "github-pr:acme/widgets#42",
403
- auth: expect.objectContaining({ principalId: "sender" }),
404
- })
405
- );
406
- });
407
-
408
- it("skips relay-stubbed comments from the agent's own bot (self/bot-loop gate)", async () => {
409
- // Regression guard: the relay stub must carry user.type through so
410
- // isGitHubAppBotAuthor keeps failing CLOSED for the agent's own
411
- // comments on the scm-events path. Without it, a bot comment that
412
- // @mentions the agent would wake it again (self-wake loop).
413
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
414
- const response = await routeHandler(
415
- githubChannel({ auth: [], botName: "my-agent" })
416
- )(
417
- new Request("http://127.0.0.1:3000/v1/channels/github", {
418
- method: "POST",
419
- headers: {
420
- "x-github-event": "issue_comment",
421
- "x-github-delivery": "delivery-relay-bot-comment",
422
- },
423
- body: JSON.stringify(
424
- scmMetadataToGitHubPayload({
425
- repo: "acme/widgets",
426
- action: "created",
427
- prNumber: 42,
428
- prUrl: "https://github.com/acme/widgets/pull/42",
429
- comment: {
430
- id: 8,
431
- body: "@my-agent looks done to me",
432
- htmlUrl: "https://github.com/acme/widgets/pull/42#issuecomment-8",
433
- authorLogin: "my-agent[bot]",
434
- authorType: "Bot",
435
- },
436
- })
437
- ),
438
- }),
439
- handlerArgs(send)
440
- );
441
-
442
- await expect(response.json()).resolves.toEqual({
443
- ok: true,
444
- skipped: true,
445
- reason: "ignored_comment",
446
- });
447
- expect(send).not.toHaveBeenCalled();
448
- });
449
-
450
- it("skips issue comments without an @mention", async () => {
451
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
452
- const response = await routeHandler(
453
- githubChannel({ auth: [], botName: "my-agent" })
454
- )(
455
- new Request("http://127.0.0.1:3000/v1/channels/github", {
456
- method: "POST",
457
- headers: { "x-github-event": "issue_comment" },
458
- body: JSON.stringify(issueCommentPayload("no bot here")),
459
- }),
460
- handlerArgs(send)
461
- );
462
- await expect(response.json()).resolves.toEqual({
463
- ok: true,
464
- skipped: true,
465
- reason: "not_dispatched",
466
- });
467
- expect(send).not.toHaveBeenCalled();
468
- });
469
-
470
- it("dispatches failed check_suite via onCheckSuite when a PR is attached", async () => {
471
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
472
- const response = await routeHandler(
473
- githubChannel({
474
- auth: [],
475
- onCheckSuite: (ctx, suite) =>
476
- suite.action === "completed" &&
477
- suite.conclusion === "failure" &&
478
- suite.app.slug === "github-actions" &&
479
- suite.pullRequests.length > 0
480
- ? {
481
- auth: defaultGitHubAuth(ctx),
482
- context: [
483
- `Triage failed check suite ${suite.checkSuiteId} at ${suite.headSha}.`,
484
- ],
485
- }
486
- : null,
487
- })
488
- )(
489
- new Request("http://127.0.0.1:3000/v1/channels/github", {
490
- method: "POST",
491
- headers: { "x-github-event": "check_suite" },
492
- body: JSON.stringify(checkSuitePayload()),
493
- }),
494
- handlerArgs(send)
495
- );
496
-
497
- await expect(response.json()).resolves.toMatchObject({ ok: true });
498
- expect(send).toHaveBeenCalledExactlyOnceWith(
499
- expect.stringContaining("Triage failed check suite 99 at deadbeef"),
500
- expect.objectContaining({
501
- continuationToken: "github-pr:acme/widgets#42",
502
- })
503
- );
504
- });
505
-
506
- it("requires a valid signature when a webhook secret is configured", async () => {
507
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
508
- const response = await routeHandler(
509
- githubChannel({
510
- credentials: { webhookSecret: "secret" },
511
- })
512
- )(
513
- new Request("http://127.0.0.1:3000/v1/channels/github", {
514
- method: "POST",
515
- headers: { "x-github-event": "pull_request" },
516
- body: JSON.stringify(pullRequestPayload()),
517
- }),
518
- handlerArgs(send)
519
- );
520
-
521
- expect(response.status).toBe(401);
522
- await expect(response.json()).resolves.toEqual({
523
- ok: false,
524
- error: "missing_signature",
525
- });
526
- expect(send).not.toHaveBeenCalled();
527
- });
528
-
529
- it("returns 202 and schedules waitUntil for task dispatch", async () => {
530
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
531
- const waitUntil = vi.fn();
532
- const task = vi.fn(async () => {});
533
- const response = await routeHandler(
534
- githubChannel({
535
- auth: [],
536
- onPullRequest: async () => ({ task }),
537
- })
538
- )(
539
- new Request("http://127.0.0.1:3000/v1/channels/github", {
540
- method: "POST",
541
- headers: { "x-github-event": "pull_request" },
542
- body: JSON.stringify(pullRequestPayload()),
543
- }),
544
- { ...handlerArgs(send), waitUntil }
545
- );
546
-
547
- expect(response.status).toBe(202);
548
- await expect(response.json()).resolves.toEqual({
549
- ok: true,
550
- dispatched: true,
551
- mode: "task",
552
- action: "opened",
553
- prUrl: "https://github.com/acme/widgets/pull/42",
554
- headSha: "abc123",
555
- });
556
- expect(waitUntil).toHaveBeenCalledTimes(1);
557
- expect(task).not.toHaveBeenCalled();
558
- expect(send).not.toHaveBeenCalled();
559
-
560
- const scheduled = waitUntil.mock.calls[0]?.[0] as Promise<unknown>;
561
- await scheduled;
562
- expect(task).toHaveBeenCalledTimes(1);
563
- });
564
-
565
- it("exposes ctx.github and ctx.thread to inbound hooks", async () => {
566
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
567
- let captured: GitHubEventContext | undefined;
568
- await routeHandler(
569
- githubChannel({
570
- auth: [],
571
- onPullRequest: (ctx, pr) => {
572
- captured = ctx;
573
- return pr.action === "opened"
574
- ? { auth: defaultGitHubAuth(ctx) }
575
- : null;
576
- },
577
- })
578
- )(
579
- new Request("http://127.0.0.1:3000/v1/channels/github", {
580
- method: "POST",
581
- headers: { "x-github-event": "pull_request" },
582
- body: JSON.stringify(pullRequestPayload()),
583
- }),
584
- handlerArgs(send)
585
- );
586
-
587
- expect(captured).toBeDefined();
588
- expect(typeof captured?.github.request).toBe("function");
589
- expect(typeof captured?.github.createStatus).toBe("function");
590
- expect(typeof captured?.github.getOctokit).toBe("function");
591
- expect(typeof captured?.thread.post).toBe("function");
592
- expect(captured?.thread.kind).toBe("pull_request");
593
- expect(captured?.github.repository.fullName).toBe("acme/widgets");
594
- });
595
-
596
- it("runs onStatus task dispatch with ctx.github.createStatus", async () => {
597
- clearGitHubAuthCaches();
598
- const fetchMock = vi.fn(
599
- async () => new Response(JSON.stringify({}), { status: 201 })
600
- );
601
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
602
- const waitUntil = vi.fn();
603
- const response = await routeHandler(
604
- githubChannel({
605
- auth: [],
606
- credentials: { token: "test-token" },
607
- api: { fetch: fetchMock as unknown as typeof fetch },
608
- onStatus: (ctx, status) =>
609
- status.state === "failure"
610
- ? {
611
- task: async () => {
612
- await ctx.github.createStatus({
613
- sha: status.sha,
614
- state: "pending",
615
- context: "agent/triage",
616
- });
617
- },
618
- }
619
- : null,
620
- })
621
- )(
622
- new Request("http://127.0.0.1:3000/v1/channels/github", {
623
- method: "POST",
624
- headers: { "x-github-event": "status" },
625
- body: JSON.stringify(statusPayload()),
626
- }),
627
- { ...handlerArgs(send), waitUntil }
628
- );
629
-
630
- expect(response.status).toBe(202);
631
- await expect(response.json()).resolves.toMatchObject({
632
- ok: true,
633
- dispatched: true,
634
- mode: "task",
635
- event: "status",
636
- state: "failure",
637
- sha: "deadbeef",
638
- });
639
- expect(send).not.toHaveBeenCalled();
640
-
641
- const scheduled = waitUntil.mock.calls[0]?.[0] as Promise<unknown>;
642
- await scheduled;
643
- expect(fetchMock).toHaveBeenCalledOnce();
644
- const call = fetchMock.mock.calls[0];
645
- expect(call).toBeDefined();
646
- const [url, init] = call as unknown as [unknown, RequestInit | undefined];
647
- expect(String(url)).toContain("/repos/acme/widgets/statuses/deadbeef");
648
- expect(init?.method).toBe("POST");
649
- });
650
-
651
- it("dispatches unknown events through onEvent", async () => {
652
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
653
- let capturedEvent: GitHubRawEvent | undefined;
654
- const response = await routeHandler(
655
- githubChannel({
656
- auth: [],
657
- onEvent: (ctx, event) => {
658
- capturedEvent = event;
659
- return event.eventName === "label"
660
- ? { auth: defaultGitHubAuth(ctx) }
661
- : null;
662
- },
663
- })
664
- )(
665
- new Request("http://127.0.0.1:3000/v1/channels/github", {
666
- method: "POST",
667
- headers: {
668
- "x-github-event": "label",
669
- "x-github-delivery": "delivery-label",
670
- },
671
- body: JSON.stringify(labelPayload()),
672
- }),
673
- handlerArgs(send)
674
- );
675
-
676
- await expect(response.json()).resolves.toMatchObject({ ok: true });
677
- expect(capturedEvent?.eventName).toBe("label");
678
- expect(capturedEvent?.action).toBe("created");
679
- expect(send).toHaveBeenCalledExactlyOnceWith(
680
- expect.stringContaining("GitHub label event"),
681
- expect.objectContaining({
682
- continuationToken: "github-issue:acme/widgets#42",
683
- })
684
- );
685
- });
686
-
687
- it("schedules task dispatch for unanchored check_suite events", async () => {
688
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
689
- const waitUntil = vi.fn();
690
- const task = vi.fn(async () => {});
691
- const response = await routeHandler(
692
- githubChannel({
693
- auth: [],
694
- onCheckSuite: async () => ({ task }),
695
- })
696
- )(
697
- new Request("http://127.0.0.1:3000/v1/channels/github", {
698
- method: "POST",
699
- headers: { "x-github-event": "check_suite" },
700
- body: JSON.stringify({
701
- ...checkSuitePayload(),
702
- check_suite: {
703
- ...(checkSuitePayload().check_suite as Record<string, unknown>),
704
- pull_requests: [],
705
- },
706
- }),
707
- }),
708
- { ...handlerArgs(send), waitUntil }
709
- );
710
-
711
- expect(response.status).toBe(202);
712
- await expect(response.json()).resolves.toMatchObject({
713
- ok: true,
714
- dispatched: true,
715
- mode: "task",
716
- event: "check_suite",
717
- });
718
- expect(send).not.toHaveBeenCalled();
719
- const scheduled = waitUntil.mock.calls[0]?.[0] as Promise<unknown>;
720
- await scheduled;
721
- expect(task).toHaveBeenCalledTimes(1);
722
- });
723
-
724
- it("ignores outbound comments stamped with the agent marker", async () => {
725
- const send = vi.fn<SendMessageFn>(async () => fakeSession());
726
- const response = await routeHandler(
727
- githubChannel({
728
- auth: [],
729
- botName: "my-agent",
730
- })
731
- )(
732
- new Request("http://127.0.0.1:3000/v1/channels/github", {
733
- method: "POST",
734
- headers: { "x-github-event": "issue_comment" },
735
- body: JSON.stringify(
736
- issueCommentPayload(
737
- formatGitHubOutboundComment("Thanks @my-agent for the help!")
738
- )
739
- ),
740
- }),
741
- handlerArgs(send)
742
- );
743
-
744
- await expect(response.json()).resolves.toEqual({
745
- ok: true,
746
- skipped: true,
747
- reason: "ignored_comment",
748
- });
749
- expect(send).not.toHaveBeenCalled();
750
- });
751
- });
752
-
753
- function routeHandler(
754
- channel: ReturnType<typeof githubChannel>
755
- ): ChannelRouteHandler {
756
- const route = channel.routes?.[0];
757
- if (route === undefined) {
758
- throw new Error("expected github channel route");
759
- }
760
- return route.handler;
761
- }
762
-
763
- function handlerArgs(send: SendMessageFn): ChannelHandlerArgs {
764
- return {
765
- params: {},
766
- requestIp: "127.0.0.1",
767
- auth: null,
768
- host: {
769
- mcp: {
770
- names: () => [],
771
- listTools: async () => [],
772
- callTool: async () => ({ content: [] }),
773
- },
774
- github: {
775
- getOctokit: async () => {
776
- throw new Error("github client not configured in test");
777
- },
778
- },
779
- slack: {
780
- getClient: async () => {
781
- throw new Error("slack client not configured in test");
782
- },
783
- },
784
- kv: {
785
- get: async () => undefined,
786
- put: async () => {},
787
- delete: async () => {},
788
- },
789
- },
790
- send,
791
- getSession: async () => null,
792
- receive: async () => fakeSession(),
793
- callTool: async (toolName) => ({
794
- toolName,
795
- callId: "call-1",
796
- isError: false,
797
- result: null,
798
- durationMs: 0,
799
- }),
800
- waitUntil: () => {},
801
- sessionUrls: (_request, sessionId) => ({
802
- playgroundUrl: `http://127.0.0.1:3000/playground?sessionId=${sessionId}`,
803
- traceUrl: `http://127.0.0.1:3000/v1/session/${sessionId}/events`,
804
- }),
805
- };
806
- }
807
-
808
- function fakeSession(): ChannelSession {
809
- return {
810
- id: "session-1",
811
- isNew: true,
812
- continuationToken: "github-pr:acme/widgets#42",
813
- info: {
814
- id: "session-1",
815
- channelId: "github",
816
- mode: "chat",
817
- auth: null,
818
- sdkAgentId: undefined,
819
- title: "GitHub acme/widgets#42",
820
- },
821
- getEventStream: async () => new ReadableStream<Uint8Array>(),
822
- waitForCompletion: async () => ({ status: "finished", result: "done" }),
823
- setContinuationToken: async () => {},
824
- };
825
- }
826
-
827
- function pullRequestPayload(
828
- overrides: { action?: string } = {}
829
- ): Record<string, unknown> {
830
- return {
831
- action: overrides.action ?? "opened",
832
- repository: {
833
- full_name: "acme/widgets",
834
- html_url: "https://github.com/acme/widgets",
835
- },
836
- pull_request: {
837
- number: 42,
838
- html_url: "https://github.com/acme/widgets/pull/42",
839
- title: "Add widgets",
840
- body: "PR body",
841
- draft: false,
842
- user: { login: "octocat" },
843
- head: {
844
- ref: "feature/widgets",
845
- sha: "abc123",
846
- },
847
- base: {
848
- ref: "main",
849
- },
850
- },
851
- sender: { login: "sender" },
852
- };
853
- }
854
-
855
- function issueCommentPayload(body: string): Record<string, unknown> {
856
- return {
857
- action: "created",
858
- repository: {
859
- full_name: "acme/widgets",
860
- html_url: "https://github.com/acme/widgets",
861
- },
862
- issue: {
863
- number: 42,
864
- html_url: "https://github.com/acme/widgets/pull/42",
865
- pull_request: {},
866
- },
867
- comment: {
868
- id: 7,
869
- body,
870
- html_url: "https://github.com/acme/widgets/pull/42#issuecomment-7",
871
- url: "https://api.github.com/repos/acme/widgets/issues/comments/7",
872
- user: { login: "sender", type: "User" },
873
- },
874
- sender: { login: "sender", type: "User" },
875
- };
876
- }
877
-
878
- function statusPayload(): Record<string, unknown> {
879
- return {
880
- state: "failure",
881
- sha: "deadbeef",
882
- context: "ci/build",
883
- description: "Build failed",
884
- target_url: "https://ci.example.com/build/1",
885
- name: "acme/widgets",
886
- branches: [{ name: "main", commit: { sha: "deadbeef" } }],
887
- commit: {
888
- sha: "deadbeef",
889
- html_url: "https://github.com/acme/widgets/commit/deadbeef",
890
- },
891
- repository: {
892
- full_name: "acme/widgets",
893
- html_url: "https://github.com/acme/widgets",
894
- },
895
- sender: { login: "ci-bot", type: "Bot" },
896
- };
897
- }
898
-
899
- function labelPayload(): Record<string, unknown> {
900
- return {
901
- action: "created",
902
- label: { name: "bug", color: "ff0000" },
903
- repository: {
904
- full_name: "acme/widgets",
905
- html_url: "https://github.com/acme/widgets",
906
- },
907
- issue: {
908
- number: 42,
909
- html_url: "https://github.com/acme/widgets/issues/42",
910
- },
911
- sender: { login: "sender", type: "User" },
912
- };
913
- }
914
-
915
- function checkSuitePayload(): Record<string, unknown> {
916
- return {
917
- action: "completed",
918
- repository: {
919
- full_name: "acme/widgets",
920
- html_url: "https://github.com/acme/widgets",
921
- },
922
- check_suite: {
923
- id: 99,
924
- head_sha: "deadbeef",
925
- status: "completed",
926
- conclusion: "failure",
927
- app: { slug: "github-actions", name: "GitHub Actions" },
928
- pull_requests: [
929
- {
930
- number: 42,
931
- html_url: "https://github.com/acme/widgets/pull/42",
932
- },
933
- ],
934
- },
935
- sender: { login: "github-actions[bot]", type: "Bot" },
936
- };
937
- }