@cursor/july 0.1.25 → 0.1.27

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 (288) hide show
  1. package/dist/ab.d.ts +6 -0
  2. package/dist/ab.d.ts.map +1 -1
  3. package/dist/ab.js +1 -0
  4. package/dist/artifacts.d.ts +34 -0
  5. package/dist/artifacts.d.ts.map +1 -0
  6. package/dist/artifacts.js +57 -0
  7. package/dist/bin/agent-serve.js +31 -9
  8. package/dist/channels/github/github-channel.d.ts +1 -1
  9. package/dist/channels/github/github-channel.d.ts.map +1 -1
  10. package/dist/channels/github/github-channel.js +14 -1
  11. package/dist/channels/github/types.d.ts +6 -1
  12. package/dist/channels/github/types.d.ts.map +1 -1
  13. package/dist/channels/slack/api.d.ts +2 -1
  14. package/dist/channels/slack/api.d.ts.map +1 -1
  15. package/dist/channels/slack/api.js +1 -0
  16. package/dist/channels/slack/cursor-account.d.ts +2 -1
  17. package/dist/channels/slack/cursor-account.d.ts.map +1 -1
  18. package/dist/channels/slack/cursor-account.js +1 -1
  19. package/dist/channels/slack/dispatch.d.ts +4 -1
  20. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  21. package/dist/channels/slack/dispatch.js +3 -3
  22. package/dist/channels/slack/interactive.d.ts +2 -1
  23. package/dist/channels/slack/interactive.d.ts.map +1 -1
  24. package/dist/channels/slack/interactive.js +1 -0
  25. package/dist/channels/slack/slack-channel.d.ts.map +1 -1
  26. package/dist/channels/slack/slack-channel.js +4 -3
  27. package/dist/channels/slack/types.d.ts +6 -1
  28. package/dist/channels/slack/types.d.ts.map +1 -1
  29. package/dist/docs/404.html +1 -1
  30. package/dist/docs/ab.html +2 -2
  31. package/dist/docs/assets/{app.DYcC9FY-.js → app.BICLoJYF.js} +1 -1
  32. package/dist/docs/assets/chunks/@localSearchIndexroot.CQJytDwU.js +1 -0
  33. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.wN4Ko9dT.js} +1 -1
  34. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.dnnTE-Co.js} +2 -2
  35. package/dist/docs/building-with-agents.html +2 -2
  36. package/dist/docs/concepts.html +2 -2
  37. package/dist/docs/deployment.html +2 -2
  38. package/dist/docs/evals.html +2 -2
  39. package/dist/docs/example-agents/approval-buddy.html +2 -2
  40. package/dist/docs/example-agents/benny.html +2 -2
  41. package/dist/docs/example-agents/bugbot.html +2 -2
  42. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  43. package/dist/docs/example-agents/codeowners-review.html +2 -2
  44. package/dist/docs/example-agents/concierge.html +2 -2
  45. package/dist/docs/example-agents/fsd.html +2 -2
  46. package/dist/docs/example-agents/index.html +2 -2
  47. package/dist/docs/example-agents/knowledge-base.html +2 -2
  48. package/dist/docs/example-agents/oncall.html +2 -2
  49. package/dist/docs/example-agents/security-reviewer.html +2 -2
  50. package/dist/docs/example-agents/slack-agent.html +2 -2
  51. package/dist/docs/example-agents/weather-agent.html +2 -2
  52. package/dist/docs/guides/agent-to-agent.html +2 -2
  53. package/dist/docs/guides/cloud-runtime.html +2 -2
  54. package/dist/docs/guides/github.html +2 -2
  55. package/dist/docs/guides/human-in-the-loop.html +2 -2
  56. package/dist/docs/guides/mcp-oauth.html +2 -2
  57. package/dist/docs/guides/slack.html +2 -2
  58. package/dist/docs/guides/webhooks.html +2 -2
  59. package/dist/docs/hillclimbing.html +2 -2
  60. package/dist/docs/index.html +2 -2
  61. package/dist/docs/quickstart.html +2 -2
  62. package/dist/docs/reference/agent-config.html +2 -2
  63. package/dist/docs/reference/channels.html +2 -2
  64. package/dist/docs/reference/cli.html +2 -2
  65. package/dist/docs/reference/connections.html +2 -2
  66. package/dist/docs/reference/hooks.html +2 -2
  67. package/dist/docs/reference/http-api.html +2 -2
  68. package/dist/docs/reference/instructions.html +2 -2
  69. package/dist/docs/reference/playground.html +2 -2
  70. package/dist/docs/reference/project-layout.html +2 -2
  71. package/dist/docs/reference/prompt.html +2 -2
  72. package/dist/docs/reference/schedules.html +2 -2
  73. package/dist/docs/reference/sessions.html +2 -2
  74. package/dist/docs/reference/skills.html +2 -2
  75. package/dist/docs/reference/subagents.html +2 -2
  76. package/dist/docs/reference/tools.html +2 -2
  77. package/dist/docs/scaffolding-agents.html +2 -2
  78. package/dist/docs/storage.html +2 -2
  79. package/dist/docs/troubleshooting.html +2 -2
  80. package/dist/evals/assertions.d.ts +10 -1
  81. package/dist/evals/assertions.d.ts.map +1 -1
  82. package/dist/evals/assertions.js +12 -0
  83. package/dist/evals.d.ts +1 -1
  84. package/dist/evals.d.ts.map +1 -1
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +1 -0
  88. package/dist/internal/ab-fold.d.ts.map +1 -1
  89. package/dist/internal/ab-fold.js +4 -0
  90. package/dist/internal/ab-snapshot.d.ts.map +1 -1
  91. package/dist/internal/ab-snapshot.js +1 -0
  92. package/dist/internal/artifacts-store.d.ts +45 -0
  93. package/dist/internal/artifacts-store.d.ts.map +1 -0
  94. package/dist/internal/artifacts-store.js +250 -0
  95. package/dist/internal/builtin-tools/artifacts.d.ts +10 -0
  96. package/dist/internal/builtin-tools/artifacts.d.ts.map +1 -0
  97. package/dist/internal/builtin-tools/artifacts.js +73 -0
  98. package/dist/internal/builtin-tools/index.d.ts +8 -1
  99. package/dist/internal/builtin-tools/index.d.ts.map +1 -1
  100. package/dist/internal/builtin-tools/index.js +15 -0
  101. package/dist/internal/cli-ax.d.ts +11 -0
  102. package/dist/internal/cli-ax.d.ts.map +1 -1
  103. package/dist/internal/cli-ax.js +80 -0
  104. package/dist/internal/cli-slack.d.ts.map +1 -1
  105. package/dist/internal/cli-slack.js +14 -6
  106. package/dist/internal/discovery.d.ts.map +1 -1
  107. package/dist/internal/discovery.js +83 -2
  108. package/dist/internal/distribution.d.ts.map +1 -1
  109. package/dist/internal/distribution.js +1 -0
  110. package/dist/internal/model-pricing.d.ts +49 -0
  111. package/dist/internal/model-pricing.d.ts.map +1 -0
  112. package/dist/internal/model-pricing.js +377 -0
  113. package/dist/internal/reminder-runner.d.ts.map +1 -1
  114. package/dist/internal/reminder-runner.js +1 -0
  115. package/dist/internal/schedule-runner.d.ts.map +1 -1
  116. package/dist/internal/schedule-runner.js +1 -0
  117. package/dist/internal/sdk-runner.d.ts.map +1 -1
  118. package/dist/internal/sdk-runner.js +9 -1
  119. package/dist/internal/server.d.ts.map +1 -1
  120. package/dist/internal/server.js +39 -0
  121. package/dist/internal/session-cost.d.ts +49 -0
  122. package/dist/internal/session-cost.d.ts.map +1 -0
  123. package/dist/internal/session-cost.js +175 -0
  124. package/dist/internal/session-engine.d.ts +35 -1
  125. package/dist/internal/session-engine.d.ts.map +1 -1
  126. package/dist/internal/session-engine.js +128 -7
  127. package/dist/internal/storage-coordinator.d.ts +15 -0
  128. package/dist/internal/storage-coordinator.d.ts.map +1 -1
  129. package/dist/internal/storage-coordinator.js +52 -0
  130. package/dist/internal/trajectory.d.ts +9 -1
  131. package/dist/internal/trajectory.d.ts.map +1 -1
  132. package/dist/internal/trajectory.js +32 -5
  133. package/dist/playground/assets/index-BDCeW4uc.js +86 -0
  134. package/dist/playground/assets/index-Bul1WfrB.css +1 -0
  135. package/dist/playground/index.html +2 -2
  136. package/dist/storage.d.ts +4 -0
  137. package/dist/storage.d.ts.map +1 -1
  138. package/dist/storage.js +4 -0
  139. package/dist/types.d.ts +164 -1
  140. package/dist/types.d.ts.map +1 -1
  141. package/package.json +26 -26
  142. package/src/ab.ts +7 -0
  143. package/src/bin/agent-serve.ts +30 -2
  144. package/src/channels/github/github-channel.ts +19 -2
  145. package/src/channels/github/types.ts +6 -0
  146. package/src/channels/slack/api.ts +3 -1
  147. package/src/channels/slack/cursor-account.ts +3 -1
  148. package/src/channels/slack/dispatch.ts +12 -1
  149. package/src/channels/slack/interactive.ts +3 -0
  150. package/src/channels/slack/slack-channel.ts +6 -0
  151. package/src/channels/slack/types.ts +6 -0
  152. package/src/internal/ab-fold.ts +4 -0
  153. package/src/internal/ab-snapshot.ts +1 -0
  154. package/src/internal/cli-ax.ts +95 -0
  155. package/src/internal/model-pricing.ts +426 -0
  156. package/src/internal/reminder-runner.ts +1 -0
  157. package/src/internal/schedule-runner.ts +1 -0
  158. package/src/internal/sdk-runner.ts +10 -2
  159. package/src/internal/server.ts +2 -0
  160. package/src/internal/session-cost.ts +231 -0
  161. package/src/internal/session-engine.ts +32 -1
  162. package/src/internal/trajectory.ts +45 -3
  163. package/src/types.ts +42 -2
  164. package/dist/channels/github/instrument.d.ts +0 -20
  165. package/dist/channels/github/instrument.d.ts.map +0 -1
  166. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  167. package/dist/internal/json-dir-store.d.ts +0 -32
  168. package/dist/internal/json-dir-store.d.ts.map +0 -1
  169. package/dist/internal/json-dir-store.js +0 -100
  170. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  171. package/dist/playground/assets/index-DqXdAFGa.js +0 -85
  172. package/src/bin/agent-serve.version.test.ts +0 -64
  173. package/src/channels/github/api.test.ts +0 -64
  174. package/src/channels/github/auth.test.ts +0 -105
  175. package/src/channels/github/cursor-account.test.ts +0 -204
  176. package/src/channels/github/forward.test.ts +0 -457
  177. package/src/channels/github/github.test.ts +0 -943
  178. package/src/channels/github/replay.test.ts +0 -179
  179. package/src/channels/slack/api.post-message.test.ts +0 -148
  180. package/src/channels/slack/approvals.test.ts +0 -328
  181. package/src/channels/slack/block-actions.test.ts +0 -452
  182. package/src/channels/slack/bot-mentions.test.ts +0 -267
  183. package/src/channels/slack/channel-watch.test.ts +0 -363
  184. package/src/channels/slack/cursor-account.test.ts +0 -253
  185. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  186. package/src/channels/slack/dispatch.test.ts +0 -795
  187. package/src/channels/slack/eval-directive.test.ts +0 -273
  188. package/src/channels/slack/message-body.test.ts +0 -54
  189. package/src/channels/slack/nudge-store.test.ts +0 -143
  190. package/src/channels/slack/slack.test.ts +0 -391
  191. package/src/channels/slack/stop.test.ts +0 -23
  192. package/src/channels/slack/thread-context.test.ts +0 -202
  193. package/src/evals/assertions.test.ts +0 -617
  194. package/src/evals/expect.test.ts +0 -144
  195. package/src/evals/judge.test.ts +0 -181
  196. package/src/evals/loaders.test.ts +0 -132
  197. package/src/evals/matchers.test.ts +0 -95
  198. package/src/evals/reporters.test.ts +0 -303
  199. package/src/evals/run-facts.test.ts +0 -259
  200. package/src/internal/ab-snapshot.test.ts +0 -325
  201. package/src/internal/approval-gate.test.ts +0 -49
  202. package/src/internal/approvals.integration.test.ts +0 -383
  203. package/src/internal/artifacts-store.test.ts +0 -283
  204. package/src/internal/authored-loaders.test.ts +0 -31
  205. package/src/internal/builtin-tools/artifacts.test.ts +0 -247
  206. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  207. package/src/internal/channel-route-schema.test.ts +0 -294
  208. package/src/internal/chat-attach.test.ts +0 -262
  209. package/src/internal/cli-deploy.test.ts +0 -1991
  210. package/src/internal/cli-docs.test.ts +0 -161
  211. package/src/internal/cli-mcp.test.ts +0 -789
  212. package/src/internal/cli-skills.test.ts +0 -133
  213. package/src/internal/cli-slack.test.ts +0 -1654
  214. package/src/internal/cloud-merge.test.ts +0 -74
  215. package/src/internal/cron.test.ts +0 -22
  216. package/src/internal/cursor/account-mcp.test.ts +0 -807
  217. package/src/internal/cursor/backend-client.test.ts +0 -591
  218. package/src/internal/cursor/credentials.test.ts +0 -351
  219. package/src/internal/cursor/github-credentials.test.ts +0 -136
  220. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  221. package/src/internal/cursor-account.integration.test.ts +0 -441
  222. package/src/internal/cursor-event-relay.test.ts +0 -746
  223. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  224. package/src/internal/cursor-slack-relay.test.ts +0 -525
  225. package/src/internal/deploy-source.test.ts +0 -111
  226. package/src/internal/discovery.artifact-tool.test.ts +0 -136
  227. package/src/internal/discovery.artifacts.test.ts +0 -119
  228. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  229. package/src/internal/discovery.concurrency.test.ts +0 -60
  230. package/src/internal/discovery.cursor-account.test.ts +0 -133
  231. package/src/internal/discovery.cwd.test.ts +0 -83
  232. package/src/internal/discovery.hosting.test.ts +0 -80
  233. package/src/internal/discovery.identity.test.ts +0 -44
  234. package/src/internal/docs-site.test.ts +0 -66
  235. package/src/internal/duration.test.ts +0 -29
  236. package/src/internal/eval-judge-model.test.ts +0 -187
  237. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  238. package/src/internal/eval-run-store.storage.test.ts +0 -211
  239. package/src/internal/eval-runner.http.test.ts +0 -403
  240. package/src/internal/eval-runner.run.test.ts +0 -928
  241. package/src/internal/evals-client.test.ts +0 -307
  242. package/src/internal/event-mapper.test.ts +0 -243
  243. package/src/internal/github-fanout.test.ts +0 -213
  244. package/src/internal/handleAgentServeTrigger.test.ts +0 -185
  245. package/src/internal/host-kv.test.ts +0 -82
  246. package/src/internal/host-platforms.test.ts +0 -126
  247. package/src/internal/http-channel.test.ts +0 -402
  248. package/src/internal/init-project.test.ts +0 -270
  249. package/src/internal/install-cursor-skills.test.ts +0 -262
  250. package/src/internal/local-env.test.ts +0 -120
  251. package/src/internal/log-ring.test.ts +0 -31
  252. package/src/internal/logs-client.test.ts +0 -350
  253. package/src/internal/mcp-endpoint.test.ts +0 -436
  254. package/src/internal/mcp-host.test.ts +0 -298
  255. package/src/internal/mcp-oauth.test.ts +0 -148
  256. package/src/internal/net.test.ts +0 -17
  257. package/src/internal/peer-connections.test.ts +0 -128
  258. package/src/internal/peer-mcp.integration.test.ts +0 -289
  259. package/src/internal/playground/toolchain.test.ts +0 -53
  260. package/src/internal/playground-cli.test.ts +0 -187
  261. package/src/internal/playground-proxy.test.ts +0 -376
  262. package/src/internal/prompt-context.integration.test.ts +0 -232
  263. package/src/internal/prompt-context.test.ts +0 -127
  264. package/src/internal/reminder-runner.test.ts +0 -390
  265. package/src/internal/reminder-store.test.ts +0 -53
  266. package/src/internal/request-headers.test.ts +0 -27
  267. package/src/internal/resolve-prod-target.test.ts +0 -787
  268. package/src/internal/resolved-connections.test.ts +0 -295
  269. package/src/internal/router.test.ts +0 -57
  270. package/src/internal/sdk-runner.test.ts +0 -290
  271. package/src/internal/server.artifacts.test.ts +0 -303
  272. package/src/internal/session-engine.artifacts.test.ts +0 -243
  273. package/src/internal/session-engine.coalesce.test.ts +0 -169
  274. package/src/internal/session-engine.concurrency.test.ts +0 -250
  275. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  276. package/src/internal/session-engine.interrupt.test.ts +0 -577
  277. package/src/internal/session-engine.storage.test.ts +0 -547
  278. package/src/internal/session-urls.test.ts +0 -28
  279. package/src/internal/sessions-client.test.ts +0 -518
  280. package/src/internal/storage-coordinator.test.ts +0 -517
  281. package/src/internal/tool-call.test.ts +0 -458
  282. package/src/internal/tool-result.test.ts +0 -52
  283. package/src/internal/trajectory.approvals.test.ts +0 -83
  284. package/src/internal/trajectory.subagents.test.ts +0 -198
  285. package/src/internal/turn-governor.test.ts +0 -137
  286. package/src/internal/update-check.test.ts +0 -485
  287. package/src/internal/workspace.test.ts +0 -207
  288. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,213 +0,0 @@
1
- import { createHmac } from "node:crypto";
2
- import { createServer, type IncomingMessage, type Server } from "node:http";
3
- import type { AddressInfo } from "node:net";
4
- import { afterEach, describe, expect, it } from "vitest";
5
- import type { GitHubForwardTarget } from "../channels/github/forward.js";
6
- import { fanoutDelivery, startFanoutServer } from "./github-fanout.js";
7
-
8
- interface Captured {
9
- method: string;
10
- headers: IncomingMessage["headers"];
11
- body: string;
12
- }
13
-
14
- /** A stand-in GitHub channel that records the requests it receives. */
15
- function recordingServer(): Promise<{
16
- url: string;
17
- received: Captured[];
18
- close: () => void;
19
- }> {
20
- const received: Captured[] = [];
21
- const server: Server = createServer((req, res) => {
22
- const chunks: Buffer[] = [];
23
- req.on("data", (chunk: Buffer) => chunks.push(chunk));
24
- req.on("end", () => {
25
- received.push({
26
- method: req.method ?? "",
27
- headers: req.headers,
28
- body: Buffer.concat(chunks).toString("utf8"),
29
- });
30
- res.writeHead(200, { "content-type": "application/json" });
31
- res.end(JSON.stringify({ ok: true }));
32
- });
33
- });
34
- return new Promise((resolve) => {
35
- server.listen(0, "127.0.0.1", () => {
36
- const { port } = server.address() as AddressInfo;
37
- resolve({
38
- url: `http://127.0.0.1:${port}`,
39
- received,
40
- close: () => server.close(),
41
- });
42
- });
43
- });
44
- }
45
-
46
- const cleanups: Array<() => void> = [];
47
- afterEach(() => {
48
- for (const cleanup of cleanups.splice(0)) {
49
- cleanup();
50
- }
51
- });
52
-
53
- describe("fanoutDelivery", () => {
54
- it("re-posts the raw body + signature to every matching channel", async () => {
55
- const a = await recordingServer();
56
- const b = await recordingServer();
57
- cleanups.push(a.close, b.close);
58
-
59
- const targets: GitHubForwardTarget[] = [
60
- {
61
- slug: "fsd",
62
- channelId: "github",
63
- url: a.url,
64
- events: ["pull_request"],
65
- },
66
- {
67
- slug: "reviewer",
68
- channelId: "github",
69
- url: b.url,
70
- events: ["pull_request"],
71
- },
72
- ];
73
-
74
- const body = Buffer.from(JSON.stringify({ action: "opened" }));
75
- const signature = `sha256=${createHmac("sha256", "s3cr3t").update(body).digest("hex")}`;
76
- const delivered = await fanoutDelivery(
77
- body,
78
- {
79
- "content-type": "application/json",
80
- "x-github-event": "pull_request",
81
- "x-hub-signature-256": signature,
82
- },
83
- targets,
84
- { logger: () => {} }
85
- );
86
-
87
- expect(delivered.sort()).toEqual(["fsd/github", "reviewer/github"]);
88
- for (const server of [a, b]) {
89
- expect(server.received).toHaveLength(1);
90
- expect(server.received[0]?.body).toBe(body.toString("utf8"));
91
- expect(server.received[0]?.headers["x-hub-signature-256"]).toBe(
92
- signature
93
- );
94
- expect(server.received[0]?.headers["x-github-event"]).toBe(
95
- "pull_request"
96
- );
97
- }
98
- });
99
-
100
- it("delivers only to channels whose event set matches", async () => {
101
- const fsd = await recordingServer();
102
- const reviewer = await recordingServer();
103
- cleanups.push(fsd.close, reviewer.close);
104
-
105
- const targets: GitHubForwardTarget[] = [
106
- {
107
- slug: "fsd",
108
- channelId: "github",
109
- url: fsd.url,
110
- events: ["pull_request", "check_run"],
111
- },
112
- {
113
- slug: "reviewer",
114
- channelId: "github",
115
- url: reviewer.url,
116
- events: ["pull_request"],
117
- },
118
- ];
119
-
120
- const delivered = await fanoutDelivery(
121
- Buffer.from("{}"),
122
- { "x-github-event": "check_run" },
123
- targets,
124
- { logger: () => {} }
125
- );
126
-
127
- expect(delivered).toEqual(["fsd/github"]);
128
- expect(fsd.received).toHaveLength(1);
129
- expect(reviewer.received).toHaveLength(0);
130
- });
131
-
132
- it("does not count HTTP error responses as delivered", async () => {
133
- const ok = await recordingServer();
134
- const failing = createServer((req, res) => {
135
- const chunks: Buffer[] = [];
136
- req.on("data", (chunk: Buffer) => chunks.push(chunk));
137
- req.on("end", () => {
138
- res.writeHead(500);
139
- res.end("error");
140
- });
141
- });
142
- await new Promise<void>((resolve) => {
143
- failing.listen(0, "127.0.0.1", () => resolve());
144
- });
145
- const failingPort = (failing.address() as AddressInfo).port;
146
- cleanups.push(ok.close, () => failing.close());
147
-
148
- const targets: GitHubForwardTarget[] = [
149
- {
150
- slug: "ok",
151
- channelId: "github",
152
- url: ok.url,
153
- events: ["pull_request"],
154
- },
155
- {
156
- slug: "bad",
157
- channelId: "github",
158
- url: `http://127.0.0.1:${failingPort}`,
159
- events: ["pull_request"],
160
- },
161
- ];
162
-
163
- const delivered = await fanoutDelivery(
164
- Buffer.from("{}"),
165
- { "x-github-event": "pull_request" },
166
- targets,
167
- { logger: () => {} }
168
- );
169
-
170
- expect(delivered).toEqual(["ok/github"]);
171
- expect(ok.received).toHaveLength(1);
172
- });
173
- });
174
-
175
- describe("startFanoutServer", () => {
176
- it("proxies a POST through to matching channels", async () => {
177
- const channel = await recordingServer();
178
- cleanups.push(channel.close);
179
-
180
- const proxy = await startFanoutServer(
181
- [
182
- {
183
- slug: "fsd",
184
- channelId: "github",
185
- url: channel.url,
186
- events: ["pull_request"],
187
- },
188
- ],
189
- { logger: () => {} }
190
- );
191
- cleanups.push(proxy.close);
192
-
193
- const response = await fetch(proxy.url, {
194
- method: "POST",
195
- headers: {
196
- "content-type": "application/json",
197
- "x-github-event": "pull_request",
198
- },
199
- body: JSON.stringify({ action: "synchronize" }),
200
- });
201
- const result = (await response.json()) as {
202
- ok: boolean;
203
- delivered: string[];
204
- };
205
-
206
- expect(response.status).toBe(200);
207
- expect(result).toEqual({ ok: true, delivered: ["fsd/github"] });
208
- expect(channel.received).toHaveLength(1);
209
- expect(channel.received[0]?.body).toBe(
210
- JSON.stringify({ action: "synchronize" })
211
- );
212
- });
213
- });
@@ -1,185 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { githubChannel } from "../channels/github/github-channel.js";
3
- import type {
4
- ChannelHandlerArgs,
5
- ChannelSession,
6
- SendMessageFn,
7
- } from "../types.js";
8
- import {
9
- collectGitHubTriggerTargets,
10
- handleAgentServeTrigger,
11
- } from "./handleAgentServeTrigger.js";
12
-
13
- describe("handleAgentServeTrigger", () => {
14
- it("fans out a pull_request delivery to every github channel target", async () => {
15
- const sendA = vi.fn<SendMessageFn>(async () => fakeSession("a"));
16
- const sendB = vi.fn<SendMessageFn>(async () => fakeSession("b"));
17
-
18
- const channelA = githubChannel({
19
- auth: [],
20
- onPullRequest: (ctx) => ({
21
- auth: {
22
- authenticator: "github-webhook",
23
- principalId: ctx.senderLogin ?? "github",
24
- principalType: "user",
25
- },
26
- }),
27
- });
28
- const channelB = githubChannel({
29
- auth: [],
30
- onPullRequest: () => null,
31
- });
32
- const buildSecurityReviewerArgs = vi.fn(() => handlerArgs(sendA));
33
-
34
- const targets = collectGitHubTriggerTargets({
35
- mounts: [
36
- {
37
- slug: "security-reviewer",
38
- channels: [{ id: "reviewer", definition: channelA }],
39
- buildHandlerArgs: buildSecurityReviewerArgs,
40
- },
41
- {
42
- slug: "fsd",
43
- channels: [{ id: "github", definition: channelB }],
44
- buildHandlerArgs: () => handlerArgs(sendB),
45
- },
46
- {
47
- slug: "weather-agent",
48
- channels: [],
49
- buildHandlerArgs: () => handlerArgs(vi.fn()),
50
- },
51
- ],
52
- });
53
-
54
- expect(targets.map((t) => t.slug)).toEqual(["security-reviewer", "fsd"]);
55
- expect(buildSecurityReviewerArgs).toHaveBeenCalledWith("reviewer");
56
-
57
- const result = await handleAgentServeTrigger({
58
- type: "github",
59
- bodyText: JSON.stringify(pullRequestPayload()),
60
- eventName: "pull_request",
61
- deliveryId: "delivery-1",
62
- targets,
63
- });
64
-
65
- expect(result.ok).toBe(true);
66
- expect(result.targets).toHaveLength(2);
67
- expect(result.targets[0]?.slug).toBe("security-reviewer");
68
- expect(result.targets[0]?.status).toBe(200);
69
- expect(result.targets[1]?.slug).toBe("fsd");
70
- expect(result.targets[1]?.body).toMatchObject({
71
- ok: true,
72
- skipped: true,
73
- reason: "not_dispatched",
74
- });
75
- expect(sendA).toHaveBeenCalledOnce();
76
- expect(sendB).not.toHaveBeenCalled();
77
- });
78
-
79
- it("rejects invalid JSON without dispatching", async () => {
80
- const result = await handleAgentServeTrigger({
81
- type: "github",
82
- bodyText: "not-json",
83
- eventName: "pull_request",
84
- targets: [],
85
- });
86
- expect(result.ok).toBe(false);
87
- expect(result.targets[0]?.status).toBe(400);
88
- });
89
- });
90
-
91
- function handlerArgs(send: SendMessageFn): ChannelHandlerArgs {
92
- return {
93
- params: {},
94
- requestIp: "127.0.0.1",
95
- auth: null,
96
- host: {
97
- mcp: {
98
- names: () => [],
99
- listTools: async () => [],
100
- callTool: async () => ({ content: [] }),
101
- },
102
- github: {
103
- getOctokit: async () => {
104
- throw new Error("github client not configured in test");
105
- },
106
- },
107
- slack: {
108
- getClient: async () => {
109
- throw new Error("slack client not configured in test");
110
- },
111
- },
112
- kv: {
113
- get: async () => undefined,
114
- put: async () => {},
115
- delete: async () => {},
116
- },
117
- },
118
- artifacts: {
119
- tag: async () => {
120
- throw new Error("artifacts not configured in test");
121
- },
122
- list: async () => [],
123
- },
124
- send,
125
- getSession: async () => null,
126
- receive: async () => fakeSession("recv"),
127
- callTool: async (toolName) => ({
128
- toolName,
129
- callId: "call-1",
130
- isError: false,
131
- result: null,
132
- durationMs: 0,
133
- }),
134
- waitUntil: () => {},
135
- sessionUrls: () => ({
136
- playgroundUrl: "http://127.0.0.1:3000/playground",
137
- traceUrl: "http://127.0.0.1:3000/v1/session/x/events",
138
- }),
139
- };
140
- }
141
-
142
- function fakeSession(id: string): ChannelSession {
143
- return {
144
- id,
145
- isNew: true,
146
- continuationToken: `github-pr:acme/widgets#42:${id}`,
147
- info: {
148
- id,
149
- channelId: "github",
150
- mode: "chat",
151
- auth: null,
152
- sdkAgentId: undefined,
153
- title: "GitHub acme/widgets#42",
154
- },
155
- getEventStream: async () => new ReadableStream<Uint8Array>(),
156
- waitForCompletion: async () => ({ status: "finished", result: "done" }),
157
- setContinuationToken: async () => {},
158
- };
159
- }
160
-
161
- function pullRequestPayload(): Record<string, unknown> {
162
- return {
163
- action: "opened",
164
- repository: {
165
- full_name: "acme/widgets",
166
- html_url: "https://github.com/acme/widgets",
167
- },
168
- pull_request: {
169
- number: 42,
170
- html_url: "https://github.com/acme/widgets/pull/42",
171
- title: "Add widgets",
172
- body: "PR body",
173
- draft: false,
174
- user: { login: "octocat" },
175
- head: {
176
- ref: "feature/widgets",
177
- sha: "abc123",
178
- },
179
- base: {
180
- ref: "main",
181
- },
182
- },
183
- sender: { login: "sender" },
184
- };
185
- }
@@ -1,82 +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 } from "vitest";
5
- import { defineStorage, storageKeys } from "../storage.js";
6
- import { createHostKvApi } from "./host-kv.js";
7
- import { StorageCoordinator } from "./storage-coordinator.js";
8
-
9
- describe("createHostKvApi", () => {
10
- const dirs: string[] = [];
11
-
12
- afterEach(async () => {
13
- await Promise.all(
14
- dirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true }))
15
- );
16
- });
17
-
18
- async function tempDir(): Promise<string> {
19
- const dir = await mkdtemp(join(tmpdir(), "agentkit-host-kv-"));
20
- dirs.push(dir);
21
- return dir;
22
- }
23
-
24
- it("falls back to state-root files when defineStorage is absent", async () => {
25
- const stateRoot = await tempDir();
26
- const kv = createHostKvApi({ agentName: "jenny", stateRoot });
27
-
28
- expect(await kv.get("alert-memory/a")).toBeUndefined();
29
- await kv.put("alert-memory/a", { class: "monitor:1", updated: "t" });
30
- expect(await kv.get("alert-memory/a")).toEqual({
31
- class: "monitor:1",
32
- updated: "t",
33
- });
34
- await kv.delete("alert-memory/a");
35
- expect(await kv.get("alert-memory/a")).toBeUndefined();
36
- });
37
-
38
- it("uses defineStorage under storageKeys.kv when get is present", async () => {
39
- const stateRoot = await tempDir();
40
- const store = new Map<string, unknown>();
41
- const coordinator = new StorageCoordinator({
42
- definition: defineStorage({
43
- put: (key, value) => {
44
- store.set(key, value);
45
- },
46
- get: (key) => store.get(key) as never,
47
- delete: (key) => {
48
- store.delete(key);
49
- },
50
- list: (prefix) =>
51
- [...store.entries()]
52
- .filter(([key]) => key.startsWith(prefix))
53
- .map(([key, value]) => ({ key, value: value as never }))
54
- .sort((a, b) => a.key.localeCompare(b.key)),
55
- }),
56
- agentName: "jenny",
57
- projectRoot: stateRoot,
58
- logger: () => {},
59
- });
60
- const kv = createHostKvApi({
61
- agentName: "jenny",
62
- stateRoot,
63
- storage: coordinator,
64
- });
65
-
66
- await kv.put("alert-memory/x", { ok: true });
67
- expect(store.get(storageKeys.kv("jenny", "alert-memory/x"))).toEqual({
68
- ok: true,
69
- });
70
- expect(await kv.get("alert-memory/x")).toEqual({ ok: true });
71
- await kv.delete("alert-memory/x");
72
- expect(store.has(storageKeys.kv("jenny", "alert-memory/x"))).toBe(false);
73
- });
74
-
75
- it("rejects empty keys", async () => {
76
- const kv = createHostKvApi({
77
- agentName: "jenny",
78
- stateRoot: await tempDir(),
79
- });
80
- await expect(kv.get(" ")).rejects.toThrow(/non-empty/);
81
- });
82
- });
@@ -1,126 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- const tryResolveGhAuthToken = vi.hoisted(() => vi.fn());
4
- const hasGitHubAppCredentials = vi.hoisted(() => vi.fn());
5
- const resolveGitHubInstallationId = vi.hoisted(() => vi.fn());
6
- const ensureGhCliTokenEnv = vi.hoisted(() => vi.fn());
7
-
8
- vi.mock("../channels/github/auth.js", async (importOriginal) => {
9
- const actual =
10
- await importOriginal<typeof import("../channels/github/auth.js")>();
11
- return {
12
- ...actual,
13
- tryResolveGhAuthToken,
14
- hasGitHubAppCredentials,
15
- resolveGitHubInstallationId,
16
- ensureGhCliTokenEnv,
17
- };
18
- });
19
-
20
- import { clearGitHubAuthCaches } from "../channels/github/auth.js";
21
- import {
22
- resolveHostGitHubAuthSource,
23
- warmupHostGitHubAuth,
24
- } from "./host-platforms.js";
25
-
26
- describe("host GitHub auth warmup", () => {
27
- beforeEach(() => {
28
- clearGitHubAuthCaches();
29
- tryResolveGhAuthToken.mockReset();
30
- hasGitHubAppCredentials.mockReset();
31
- resolveGitHubInstallationId.mockReset();
32
- ensureGhCliTokenEnv.mockReset();
33
- hasGitHubAppCredentials.mockResolvedValue(false);
34
- resolveGitHubInstallationId.mockResolvedValue(undefined);
35
- ensureGhCliTokenEnv.mockResolvedValue(false);
36
- delete process.env.GITHUB_TOKEN;
37
- delete process.env.GH_TOKEN;
38
- });
39
-
40
- afterEach(() => {
41
- clearGitHubAuthCaches();
42
- tryResolveGhAuthToken.mockReset();
43
- hasGitHubAppCredentials.mockReset();
44
- resolveGitHubInstallationId.mockReset();
45
- ensureGhCliTokenEnv.mockReset();
46
- delete process.env.GITHUB_TOKEN;
47
- delete process.env.GH_TOKEN;
48
- });
49
-
50
- it("prefers App installation auth over env PAT", async () => {
51
- process.env.GITHUB_TOKEN = "env-token";
52
- hasGitHubAppCredentials.mockResolvedValue(true);
53
- resolveGitHubInstallationId.mockResolvedValue(42);
54
- await expect(resolveHostGitHubAuthSource()).resolves.toBe("app");
55
- expect(tryResolveGhAuthToken).not.toHaveBeenCalled();
56
- });
57
-
58
- it("prefers env over gh when App creds are unset", async () => {
59
- process.env.GITHUB_TOKEN = "env-token";
60
- tryResolveGhAuthToken.mockResolvedValue("gh-token");
61
- await expect(resolveHostGitHubAuthSource()).resolves.toBe("env");
62
- expect(tryResolveGhAuthToken).not.toHaveBeenCalled();
63
- });
64
-
65
- it("falls back to gh auth token", async () => {
66
- tryResolveGhAuthToken.mockResolvedValue("gh-token");
67
- await expect(resolveHostGitHubAuthSource()).resolves.toBe("gh");
68
- expect(tryResolveGhAuthToken).toHaveBeenCalledOnce();
69
- });
70
-
71
- it("reports unavailable when neither App, env, nor gh works", async () => {
72
- tryResolveGhAuthToken.mockResolvedValue(undefined);
73
- await expect(resolveHostGitHubAuthSource()).resolves.toBe("unavailable");
74
- });
75
-
76
- it("logs and primes Octokit on successful warmup", async () => {
77
- process.env.GITHUB_TOKEN = "env-token";
78
- const lines: string[] = [];
79
- const getOctokit = vi.fn(async () => ({ ok: true }) as never);
80
- await expect(
81
- warmupHostGitHubAuth({
82
- logger: (line) => lines.push(line),
83
- github: { getOctokit },
84
- })
85
- ).resolves.toBe("env");
86
- expect(getOctokit).toHaveBeenCalledOnce();
87
- expect(lines.some((line) => line.includes("GITHUB_TOKEN/GH_TOKEN"))).toBe(
88
- true
89
- );
90
- });
91
-
92
- it("warns without failing when auth is unavailable", async () => {
93
- tryResolveGhAuthToken.mockResolvedValue(undefined);
94
- const lines: string[] = [];
95
- const getOctokit = vi.fn(async () => {
96
- throw new Error("should not be called");
97
- });
98
- await expect(
99
- warmupHostGitHubAuth({
100
- logger: (line) => lines.push(line),
101
- github: { getOctokit },
102
- })
103
- ).resolves.toBe("unavailable");
104
- expect(getOctokit).not.toHaveBeenCalled();
105
- expect(ensureGhCliTokenEnv).not.toHaveBeenCalled();
106
- expect(lines.some((line) => line.includes("unavailable"))).toBe(true);
107
- });
108
-
109
- it("exports GH_TOKEN for gh CLI when App auth is configured", async () => {
110
- hasGitHubAppCredentials.mockResolvedValue(true);
111
- resolveGitHubInstallationId.mockResolvedValue(42);
112
- ensureGhCliTokenEnv.mockResolvedValue(true);
113
- const lines: string[] = [];
114
- const getOctokit = vi.fn(async () => ({ ok: true }) as never);
115
- await expect(
116
- warmupHostGitHubAuth({
117
- logger: (line) => lines.push(line),
118
- github: { getOctokit },
119
- })
120
- ).resolves.toBe("app");
121
- expect(ensureGhCliTokenEnv).toHaveBeenCalledOnce();
122
- expect(
123
- lines.some((line) => line.includes("exported as GH_TOKEN for gh CLI"))
124
- ).toBe(true);
125
- });
126
- });