@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,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
- });