@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,179 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- parseGitHubPullRequestEvent,
4
- verifyGitHubWebhookSignature,
5
- } from "./index.js";
6
- import {
7
- parseGitHubPrRef,
8
- type ReplayPull,
9
- type ReplayRepo,
10
- selectReplayEvents,
11
- signGitHubWebhookBody,
12
- synthesizeGitHubEvent,
13
- } from "./replay.js";
14
-
15
- const repo: ReplayRepo = {
16
- id: 1,
17
- full_name: "acme/widgets",
18
- html_url: "https://github.com/acme/widgets",
19
- default_branch: "main",
20
- owner: { login: "acme" },
21
- };
22
-
23
- const pull: ReplayPull = {
24
- number: 42,
25
- html_url: "https://github.com/acme/widgets/pull/42",
26
- title: "Add widgets",
27
- body: "body",
28
- draft: false,
29
- user: { login: "octocat", id: 5, type: "User" },
30
- head: { ref: "feature", sha: "abc123", repo: { id: 1, name: "widgets" } },
31
- base: { ref: "main", sha: "def456" },
32
- };
33
-
34
- function synth(input: Parameters<typeof synthesizeGitHubEvent>[0]): {
35
- eventName: string;
36
- action?: string;
37
- payload: Record<string, unknown>;
38
- } {
39
- const result = synthesizeGitHubEvent(input);
40
- if ("error" in result) {
41
- throw new Error(result.error);
42
- }
43
- return result;
44
- }
45
-
46
- describe("parseGitHubPrRef", () => {
47
- it("parses PR URLs and owner/repo#N", () => {
48
- expect(parseGitHubPrRef("https://github.com/acme/widgets/pull/42")).toEqual(
49
- {
50
- owner: "acme",
51
- repo: "widgets",
52
- number: 42,
53
- url: "https://github.com/acme/widgets/pull/42",
54
- label: "acme/widgets#42",
55
- }
56
- );
57
- expect(parseGitHubPrRef("acme/widgets#7")?.number).toBe(7);
58
- });
59
-
60
- it("returns undefined for non-PR input", () => {
61
- expect(parseGitHubPrRef("not a pr")).toBeUndefined();
62
- expect(
63
- parseGitHubPrRef("https://github.com/acme/widgets/issues/1")
64
- ).toBeUndefined();
65
- });
66
- });
67
-
68
- describe("selectReplayEvents", () => {
69
- it("defaults to pull_request", () => {
70
- expect(
71
- selectReplayEvents(undefined, ["pull_request", "check_run"])
72
- ).toEqual({ events: ["pull_request"], unsupported: [] });
73
- });
74
-
75
- it("expands * against the channel's declared events (synthesizable only)", () => {
76
- expect(
77
- selectReplayEvents(["*"], ["pull_request", "check_run", "push"])
78
- ).toEqual({ events: ["pull_request", "check_run"], unsupported: [] });
79
- });
80
-
81
- it("separates unsupported explicit events", () => {
82
- expect(selectReplayEvents(["pull_request", "push"], [])).toEqual({
83
- events: ["pull_request"],
84
- unsupported: ["push"],
85
- });
86
- });
87
- });
88
-
89
- describe("synthesizeGitHubEvent", () => {
90
- it("produces a pull_request payload the channel parser accepts", () => {
91
- const { payload, action } = synth({ event: "pull_request", repo, pull });
92
- expect(action).toBe("synchronize");
93
- const parsed = parseGitHubPullRequestEvent({ payload });
94
- expect(parsed?.pullRequest.action).toBe("synchronize");
95
- expect(parsed?.pullRequest.headSha).toBe("abc123");
96
- expect(parsed?.pullRequest.baseRef).toBe("main");
97
- expect(parsed?.ctx.repository.fullName).toBe("acme/widgets");
98
- });
99
-
100
- it("honors --action", () => {
101
- const { payload } = synth({
102
- event: "pull_request",
103
- repo,
104
- pull,
105
- action: "opened",
106
- });
107
- expect(parseGitHubPullRequestEvent({ payload })?.pullRequest.action).toBe(
108
- "opened"
109
- );
110
- });
111
-
112
- it("anchors CI events to the PR with a default failure conclusion", () => {
113
- const { payload } = synth({ event: "check_run", repo, pull });
114
- const checkRun = (payload as { check_run: Record<string, unknown> })
115
- .check_run;
116
- expect(checkRun.conclusion).toBe("failure");
117
- expect(checkRun.head_sha).toBe("abc123");
118
- expect(
119
- (checkRun.pull_requests as Array<{ number: number }>)[0]?.number
120
- ).toBe(42);
121
- });
122
-
123
- it("uses a real check's app slug + conclusion when provided", () => {
124
- const { payload } = synth({
125
- event: "check_suite",
126
- repo,
127
- pull,
128
- check: { app: { slug: "buildkite" }, conclusion: "failure" },
129
- });
130
- const suite = (payload as { check_suite: Record<string, unknown> })
131
- .check_suite;
132
- expect((suite.app as { slug: string }).slug).toBe("buildkite");
133
- });
134
-
135
- it("requires a comment for issue_comment", () => {
136
- expect(
137
- synthesizeGitHubEvent({ event: "issue_comment", repo, pull })
138
- ).toEqual({ error: "issue_comment needs --comment" });
139
- const { payload } = synth({
140
- event: "issue_comment",
141
- repo,
142
- pull,
143
- comment: "@bot please review",
144
- });
145
- const comment = (payload as { comment: { body: string } }).comment;
146
- expect(comment.body).toBe("@bot please review");
147
- expect(
148
- (payload as { issue: { pull_request: unknown } }).issue.pull_request
149
- ).toBeDefined();
150
- });
151
- });
152
-
153
- describe("signGitHubWebhookBody", () => {
154
- it("produces a signature the channel verifier accepts", async () => {
155
- const body = Buffer.from(
156
- JSON.stringify(synth({ event: "pull_request", repo, pull }).payload)
157
- );
158
- const header = `sha256=${signGitHubWebhookBody({ secret: "s3cr3t", body })}`;
159
- await expect(
160
- verifyGitHubWebhookSignature({
161
- body: body.toString("utf8"),
162
- signatureHeader: header,
163
- secret: "s3cr3t",
164
- })
165
- ).resolves.toBe("verified");
166
- });
167
-
168
- it("does not verify under the wrong secret", async () => {
169
- const body = "{}";
170
- const header = `sha256=${signGitHubWebhookBody({ secret: "right", body })}`;
171
- await expect(
172
- verifyGitHubWebhookSignature({
173
- body,
174
- signatureHeader: header,
175
- secret: "wrong",
176
- })
177
- ).resolves.toBe("mismatch");
178
- });
179
- });
@@ -1,148 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { postMessage, updateMessage } from "./api.js";
3
- import type { SlackApiTransport } from "./types.js";
4
-
5
- function transport(impl: SlackApiTransport["call"]): SlackApiTransport {
6
- return { kind: "api-transport", label: "test", call: impl };
7
- }
8
-
9
- describe("postMessage plainText", () => {
10
- it("posts with text only when plainText is set", async () => {
11
- const call = vi.fn(async () => ({
12
- ok: true,
13
- ts: "2.0",
14
- channel: "C1",
15
- message: { thread_ts: "1.0" },
16
- }));
17
- await postMessage({
18
- botToken: transport(call),
19
- channel: "C1",
20
- text: "finding body",
21
- threadTs: "1.0",
22
- plainText: true,
23
- });
24
- expect(call).toHaveBeenCalledTimes(1);
25
- expect(call).toHaveBeenCalledWith("chat.postMessage", {
26
- channel: "C1",
27
- text: "finding body",
28
- thread_ts: "1.0",
29
- unfurl_links: false,
30
- unfurl_media: false,
31
- });
32
- });
33
-
34
- it("still prefers markdown_text by default", async () => {
35
- const call = vi.fn(async () => ({
36
- ok: true,
37
- ts: "2.0",
38
- channel: "C1",
39
- }));
40
- await postMessage({
41
- botToken: transport(call),
42
- channel: "C1",
43
- text: "hi",
44
- });
45
- expect(call).toHaveBeenCalledWith("chat.postMessage", {
46
- channel: "C1",
47
- markdown_text: "hi",
48
- unfurl_links: false,
49
- unfurl_media: false,
50
- });
51
- });
52
-
53
- it("uses mrkdwn text when the body has a user-group mention", async () => {
54
- const call = vi.fn(async () => ({
55
- ok: true,
56
- ts: "2.0",
57
- channel: "C1",
58
- }));
59
- const text = "ping <!subteam^S0B1V748HV2|@review-agents-primary-oncall>";
60
- await postMessage({
61
- botToken: transport(call),
62
- channel: "C1",
63
- text,
64
- });
65
- expect(call).toHaveBeenCalledWith("chat.postMessage", {
66
- channel: "C1",
67
- text,
68
- unfurl_links: false,
69
- unfurl_media: false,
70
- });
71
- });
72
-
73
- it("uses mrkdwn text when the body has a Slack link", async () => {
74
- const call = vi.fn(async () => ({
75
- ok: true,
76
- ts: "2.0",
77
- channel: "C1",
78
- }));
79
- const text = "filed <https://linear.app/issue/RA-143|RA-143>";
80
- await postMessage({
81
- botToken: transport(call),
82
- channel: "C1",
83
- text,
84
- });
85
- expect(call).toHaveBeenCalledWith("chat.postMessage", {
86
- channel: "C1",
87
- text,
88
- unfurl_links: false,
89
- unfurl_media: false,
90
- });
91
- });
92
-
93
- it("does not fail when threaded response omits message.thread_ts", async () => {
94
- const call = vi.fn(async () => ({
95
- ok: true,
96
- ts: "2.0",
97
- channel: "C1",
98
- // Cursor Slack proxy / customize-username responses sometimes omit this.
99
- message: { text: "finding body" },
100
- }));
101
- await expect(
102
- postMessage({
103
- botToken: transport(call),
104
- channel: "C1",
105
- text: "finding body",
106
- threadTs: "1.0",
107
- plainText: true,
108
- })
109
- ).resolves.toEqual({ ts: "2.0", channel: "C1" });
110
- });
111
-
112
- it("still fails when message.thread_ts is present but wrong", async () => {
113
- const call = vi.fn(async () => ({
114
- ok: true,
115
- ts: "2.0",
116
- channel: "C1",
117
- message: { thread_ts: "9.9" },
118
- }));
119
- await expect(
120
- postMessage({
121
- botToken: transport(call),
122
- channel: "C1",
123
- text: "finding body",
124
- threadTs: "1.0",
125
- plainText: true,
126
- })
127
- ).rejects.toThrow(/ignored thread_ts/);
128
- });
129
- });
130
-
131
- describe("updateMessage plainText", () => {
132
- it("updates with text only when plainText is set", async () => {
133
- const call = vi.fn(async () => ({ ok: true }));
134
- const result = await updateMessage({
135
- botToken: transport(call),
136
- channel: "C1",
137
- ts: "1.0",
138
- text: "inlined",
139
- plainText: true,
140
- });
141
- expect(result.ok).toBe(true);
142
- expect(call).toHaveBeenCalledWith("chat.update", {
143
- channel: "C1",
144
- ts: "1.0",
145
- text: "inlined",
146
- });
147
- });
148
- });
@@ -1,328 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- buildApprovalBlocks,
4
- buildResolvedApprovalBlocks,
5
- decisionFromActionId,
6
- encodeApprovalActionValue,
7
- formatArgsForSlackDisplay,
8
- parseApprovalActionValue,
9
- redactSensitiveValues,
10
- SLACK_APPROVE_ACTION_ID,
11
- SLACK_DENY_ACTION_ID,
12
- } from "./approvals.js";
13
- import { buildDefaultEvents } from "./defaults.js";
14
- import { dispatchInteractiveFromPayload } from "./interactive.js";
15
- import { buildToolApprovalEvents } from "./tool-approval-events.js";
16
-
17
- describe("slack approval blocks", () => {
18
- it("encodes and parses action values", () => {
19
- const raw = encodeApprovalActionValue({
20
- sessionId: "ses_abc",
21
- callId: "call_1",
22
- });
23
- expect(parseApprovalActionValue(raw)).toEqual({
24
- sessionId: "ses_abc",
25
- callId: "call_1",
26
- });
27
- expect(parseApprovalActionValue("not-json")).toBeNull();
28
- });
29
-
30
- it("maps action ids to decisions", () => {
31
- expect(decisionFromActionId(SLACK_APPROVE_ACTION_ID)).toBe("approve");
32
- expect(decisionFromActionId(SLACK_DENY_ACTION_ID)).toBe("deny");
33
- expect(decisionFromActionId("other")).toBeNull();
34
- });
35
-
36
- it("builds approve/deny buttons with session + call ids", () => {
37
- const blocks = buildApprovalBlocks({
38
- sessionId: "ses_1",
39
- callId: "call_9",
40
- toolName: "post_weather_alert",
41
- args: { city: "NYC" },
42
- });
43
- const actions = blocks.find(
44
- (block) =>
45
- typeof block === "object" &&
46
- block !== null &&
47
- (block as { type?: string }).type === "actions"
48
- ) as { elements: Array<{ action_id: string; value: string }> };
49
- expect(actions.elements).toHaveLength(2);
50
- expect(actions.elements[0]?.action_id).toBe(SLACK_APPROVE_ACTION_ID);
51
- expect(parseApprovalActionValue(actions.elements[0]!.value)).toEqual({
52
- sessionId: "ses_1",
53
- callId: "call_9",
54
- });
55
- });
56
-
57
- it("builds a resolved card without action buttons", () => {
58
- const blocks = buildResolvedApprovalBlocks({
59
- toolName: "post_weather_alert",
60
- decision: "deny",
61
- byUserId: "U123",
62
- });
63
- expect(JSON.stringify(blocks)).toContain("Denied");
64
- expect(JSON.stringify(blocks)).toContain("<@U123>");
65
- expect(JSON.stringify(blocks)).not.toContain(SLACK_APPROVE_ACTION_ID);
66
- });
67
-
68
- it("redacts sensitive arg keys for Slack display", () => {
69
- const redacted = redactSensitiveValues({
70
- city: "NYC",
71
- api_key: "sk-secret",
72
- nested: { password: "hunter2" },
73
- });
74
- expect(redacted).toEqual({
75
- city: "NYC",
76
- api_key: "[REDACTED]",
77
- nested: { password: "[REDACTED]" },
78
- });
79
- });
80
-
81
- it("notes when Slack arg display exceeds the block limit", () => {
82
- const display = formatArgsForSlackDisplay({ blob: "x".repeat(2500) });
83
- expect(display).toContain("execution uses full args");
84
- expect(display.length).toBeLessThanOrEqual(1975);
85
- });
86
-
87
- it("keeps approval card arg fields within Slack mrkdwn limits", () => {
88
- const blocks = buildApprovalBlocks({
89
- sessionId: "ses_1",
90
- callId: "call_1",
91
- toolName: "big_tool",
92
- args: { blob: "x".repeat(2500) },
93
- });
94
- const section = blocks.find(
95
- (block) =>
96
- typeof block === "object" &&
97
- block !== null &&
98
- (block as { type?: string }).type === "section" &&
99
- Array.isArray((block as { fields?: unknown }).fields)
100
- ) as { fields: Array<{ text: string }> };
101
- const argsField = section.fields.find((field) =>
102
- field.text.includes("Args (redacted)")
103
- );
104
- expect(argsField?.text.length).toBeLessThanOrEqual(2000);
105
- });
106
- });
107
-
108
- describe("dispatchInteractiveFromPayload", () => {
109
- it("resolves approve for a matching session/thread with clicker auth", async () => {
110
- const calls: Array<{
111
- sessionId: string;
112
- callId: string;
113
- decision: string;
114
- authPrincipalId: string | undefined;
115
- }> = [];
116
- const handled = await dispatchInteractiveFromPayload(
117
- {
118
- type: "block_actions",
119
- user: { id: "U1" },
120
- channel: { id: "C9" },
121
- message: { ts: "2.0", thread_ts: "1.0" },
122
- actions: [
123
- {
124
- action_id: SLACK_APPROVE_ACTION_ID,
125
- value: encodeApprovalActionValue({
126
- sessionId: "ses_1",
127
- callId: "call_1",
128
- }),
129
- },
130
- ],
131
- },
132
- {
133
- credentials: undefined,
134
- getSession: async () => ({
135
- id: "ses_1",
136
- continuationToken: "C9:1.0",
137
- isNew: false,
138
- info: {
139
- id: "ses_1",
140
- channelId: "slack",
141
- mode: "chat",
142
- auth: {
143
- authenticator: "slack",
144
- principalId: "slack:T:C9:1.0",
145
- principalType: "user",
146
- attributes: {
147
- channel_id: "C9",
148
- thread_ts: "1.0",
149
- team_id: "T",
150
- },
151
- },
152
- },
153
- getEventStream: async () => new ReadableStream(),
154
- waitForCompletion: async () => ({ status: "finished" }),
155
- setContinuationToken: async () => {},
156
- }),
157
- resolveApproval: async (sessionId, callId, decision, auth) => {
158
- calls.push({
159
- sessionId,
160
- callId,
161
- decision,
162
- authPrincipalId: auth?.principalId,
163
- });
164
- return {
165
- callId,
166
- turnId: "turn_1",
167
- toolName: "risky",
168
- args: {},
169
- requestedAt: "2026-01-01T00:00:00.000Z",
170
- };
171
- },
172
- waitUntil: () => {},
173
- }
174
- );
175
- expect(handled).toBe(true);
176
- expect(calls).toEqual([
177
- {
178
- sessionId: "ses_1",
179
- callId: "call_1",
180
- decision: "approve",
181
- authPrincipalId: "slack:T:C9:1.0",
182
- },
183
- ]);
184
- });
185
-
186
- it("does not resolve when clicker auth does not match a narrower session principal", async () => {
187
- let resolved = false;
188
- const handled = await dispatchInteractiveFromPayload(
189
- {
190
- type: "block_actions",
191
- user: { id: "U2" },
192
- channel: { id: "C9" },
193
- message: { ts: "2.0", thread_ts: "1.0" },
194
- actions: [
195
- {
196
- action_id: SLACK_APPROVE_ACTION_ID,
197
- value: encodeApprovalActionValue({
198
- sessionId: "ses_1",
199
- callId: "call_1",
200
- }),
201
- },
202
- ],
203
- },
204
- {
205
- credentials: undefined,
206
- getSession: async () => ({
207
- id: "ses_1",
208
- continuationToken: "C9:1.0",
209
- isNew: false,
210
- info: {
211
- id: "ses_1",
212
- channelId: "slack",
213
- mode: "chat",
214
- auth: {
215
- authenticator: "slack",
216
- principalId: "slack:T:C9:1.0:U1",
217
- principalType: "user",
218
- attributes: {
219
- channel_id: "C9",
220
- thread_ts: "1.0",
221
- team_id: "T",
222
- user_id: "U1",
223
- },
224
- },
225
- },
226
- getEventStream: async () => new ReadableStream(),
227
- waitForCompletion: async () => ({ status: "finished" }),
228
- setContinuationToken: async () => {},
229
- }),
230
- resolveApproval: async (_sessionId, _callId, _decision, auth) => {
231
- if (auth?.principalId !== "slack:T:C9:1.0:U1") {
232
- throw new Error("SessionAuthError");
233
- }
234
- resolved = true;
235
- return {
236
- callId: "call_1",
237
- turnId: "turn_1",
238
- toolName: "risky",
239
- args: {},
240
- requestedAt: "2026-01-01T00:00:00.000Z",
241
- };
242
- },
243
- waitUntil: () => {},
244
- }
245
- );
246
- expect(handled).toBe(true);
247
- expect(resolved).toBe(false);
248
- });
249
-
250
- it("rejects channel mismatches without resolving", async () => {
251
- let resolved = false;
252
- const handled = await dispatchInteractiveFromPayload(
253
- {
254
- type: "block_actions",
255
- user: { id: "U1" },
256
- channel: { id: "C_OTHER" },
257
- message: { ts: "2.0", thread_ts: "1.0" },
258
- actions: [
259
- {
260
- action_id: SLACK_DENY_ACTION_ID,
261
- value: encodeApprovalActionValue({
262
- sessionId: "ses_1",
263
- callId: "call_1",
264
- }),
265
- },
266
- ],
267
- },
268
- {
269
- credentials: undefined,
270
- getSession: async () => ({
271
- id: "ses_1",
272
- continuationToken: null,
273
- isNew: false,
274
- info: {
275
- id: "ses_1",
276
- channelId: "slack",
277
- mode: "chat",
278
- auth: {
279
- authenticator: "slack",
280
- principalId: "slack:T:C9:1.0",
281
- principalType: "user",
282
- attributes: { channel_id: "C9", thread_ts: "1.0" },
283
- },
284
- },
285
- getEventStream: async () => new ReadableStream(),
286
- waitForCompletion: async () => ({ status: "finished" }),
287
- setContinuationToken: async () => {},
288
- }),
289
- resolveApproval: async () => {
290
- resolved = true;
291
- return {
292
- callId: "call_1",
293
- turnId: "turn_1",
294
- toolName: "risky",
295
- args: {},
296
- requestedAt: "2026-01-01T00:00:00.000Z",
297
- };
298
- },
299
- waitUntil: () => {},
300
- }
301
- );
302
- expect(handled).toBe(true);
303
- expect(resolved).toBe(false);
304
- });
305
- });
306
-
307
- describe("HITL + Slack event composition", () => {
308
- it("keeps approval handlers out of buildDefaultEvents", () => {
309
- const defaults = buildDefaultEvents({});
310
- expect(defaults["action.approval_requested"]).toBeUndefined();
311
- expect(defaults["action.approval_resolved"]).toBeUndefined();
312
- });
313
-
314
- it("buildToolApprovalEvents is the opt-in Slack surface", () => {
315
- const approvals = buildToolApprovalEvents({});
316
- expect(typeof approvals["action.approval_requested"]).toBe("function");
317
- expect(typeof approvals["action.approval_resolved"]).toBe("function");
318
- });
319
-
320
- it("composes with a shallow merge", () => {
321
- const composed = {
322
- ...buildDefaultEvents({}),
323
- ...buildToolApprovalEvents({}),
324
- };
325
- expect(typeof composed["message.completed"]).toBe("function");
326
- expect(typeof composed["action.approval_requested"]).toBe("function");
327
- });
328
- });