@cursor/july 0.1.23 → 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 (174) hide show
  1. package/dist/bin/agent-serve.js +0 -0
  2. package/dist/docs/404.html +1 -1
  3. package/dist/docs/ab.html +2 -2
  4. package/dist/docs/assets/{app.DYcC9FY-.js → app.CvSGaAxk.js} +1 -1
  5. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
  6. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
  7. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.C7vfzr7h.js} +2 -2
  8. package/dist/docs/building-with-agents.html +2 -2
  9. package/dist/docs/concepts.html +2 -2
  10. package/dist/docs/deployment.html +2 -2
  11. package/dist/docs/evals.html +2 -2
  12. package/dist/docs/example-agents/approval-buddy.html +2 -2
  13. package/dist/docs/example-agents/benny.html +2 -2
  14. package/dist/docs/example-agents/bugbot.html +2 -2
  15. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  16. package/dist/docs/example-agents/codeowners-review.html +2 -2
  17. package/dist/docs/example-agents/concierge.html +2 -2
  18. package/dist/docs/example-agents/fsd.html +2 -2
  19. package/dist/docs/example-agents/index.html +2 -2
  20. package/dist/docs/example-agents/knowledge-base.html +2 -2
  21. package/dist/docs/example-agents/oncall.html +2 -2
  22. package/dist/docs/example-agents/security-reviewer.html +2 -2
  23. package/dist/docs/example-agents/slack-agent.html +2 -2
  24. package/dist/docs/example-agents/weather-agent.html +2 -2
  25. package/dist/docs/guides/agent-to-agent.html +2 -2
  26. package/dist/docs/guides/cloud-runtime.html +2 -2
  27. package/dist/docs/guides/github.html +2 -2
  28. package/dist/docs/guides/human-in-the-loop.html +2 -2
  29. package/dist/docs/guides/mcp-oauth.html +2 -2
  30. package/dist/docs/guides/slack.html +2 -2
  31. package/dist/docs/guides/webhooks.html +2 -2
  32. package/dist/docs/hillclimbing.html +2 -2
  33. package/dist/docs/index.html +2 -2
  34. package/dist/docs/quickstart.html +2 -2
  35. package/dist/docs/reference/agent-config.html +2 -2
  36. package/dist/docs/reference/channels.html +2 -2
  37. package/dist/docs/reference/cli.html +2 -2
  38. package/dist/docs/reference/connections.html +2 -2
  39. package/dist/docs/reference/hooks.html +2 -2
  40. package/dist/docs/reference/http-api.html +2 -2
  41. package/dist/docs/reference/instructions.html +2 -2
  42. package/dist/docs/reference/playground.html +2 -2
  43. package/dist/docs/reference/project-layout.html +2 -2
  44. package/dist/docs/reference/prompt.html +2 -2
  45. package/dist/docs/reference/schedules.html +2 -2
  46. package/dist/docs/reference/sessions.html +2 -2
  47. package/dist/docs/reference/skills.html +2 -2
  48. package/dist/docs/reference/subagents.html +2 -2
  49. package/dist/docs/reference/tools.html +2 -2
  50. package/dist/docs/scaffolding-agents.html +2 -2
  51. package/dist/docs/storage.html +2 -2
  52. package/dist/docs/troubleshooting.html +2 -2
  53. package/dist/playground/assets/index-CidizGZv.css +1 -0
  54. package/dist/playground/assets/{index-DqXdAFGa.js → index-DTG9OsPV.js} +41 -41
  55. package/dist/playground/index.html +2 -2
  56. package/package.json +24 -24
  57. package/dist/channels/github/instrument.d.ts +0 -20
  58. package/dist/channels/github/instrument.d.ts.map +0 -1
  59. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  60. package/dist/internal/json-dir-store.d.ts +0 -32
  61. package/dist/internal/json-dir-store.d.ts.map +0 -1
  62. package/dist/internal/json-dir-store.js +0 -100
  63. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  64. package/src/bin/agent-serve.version.test.ts +0 -64
  65. package/src/channels/github/api.test.ts +0 -64
  66. package/src/channels/github/auth.test.ts +0 -105
  67. package/src/channels/github/cursor-account.test.ts +0 -204
  68. package/src/channels/github/forward.test.ts +0 -457
  69. package/src/channels/github/github.test.ts +0 -937
  70. package/src/channels/github/replay.test.ts +0 -179
  71. package/src/channels/slack/api.post-message.test.ts +0 -148
  72. package/src/channels/slack/approvals.test.ts +0 -328
  73. package/src/channels/slack/block-actions.test.ts +0 -452
  74. package/src/channels/slack/bot-mentions.test.ts +0 -267
  75. package/src/channels/slack/channel-watch.test.ts +0 -363
  76. package/src/channels/slack/cursor-account.test.ts +0 -253
  77. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  78. package/src/channels/slack/dispatch.test.ts +0 -795
  79. package/src/channels/slack/eval-directive.test.ts +0 -273
  80. package/src/channels/slack/message-body.test.ts +0 -54
  81. package/src/channels/slack/nudge-store.test.ts +0 -143
  82. package/src/channels/slack/slack.test.ts +0 -391
  83. package/src/channels/slack/stop.test.ts +0 -23
  84. package/src/channels/slack/thread-context.test.ts +0 -202
  85. package/src/evals/assertions.test.ts +0 -580
  86. package/src/evals/expect.test.ts +0 -144
  87. package/src/evals/judge.test.ts +0 -181
  88. package/src/evals/loaders.test.ts +0 -132
  89. package/src/evals/matchers.test.ts +0 -95
  90. package/src/evals/reporters.test.ts +0 -303
  91. package/src/evals/run-facts.test.ts +0 -259
  92. package/src/internal/ab-snapshot.test.ts +0 -325
  93. package/src/internal/approval-gate.test.ts +0 -49
  94. package/src/internal/approvals.integration.test.ts +0 -383
  95. package/src/internal/authored-loaders.test.ts +0 -31
  96. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  97. package/src/internal/channel-route-schema.test.ts +0 -294
  98. package/src/internal/chat-attach.test.ts +0 -262
  99. package/src/internal/cli-deploy.test.ts +0 -1991
  100. package/src/internal/cli-docs.test.ts +0 -161
  101. package/src/internal/cli-mcp.test.ts +0 -789
  102. package/src/internal/cli-skills.test.ts +0 -133
  103. package/src/internal/cli-slack.test.ts +0 -1647
  104. package/src/internal/cloud-merge.test.ts +0 -74
  105. package/src/internal/cron.test.ts +0 -22
  106. package/src/internal/cursor/account-mcp.test.ts +0 -807
  107. package/src/internal/cursor/backend-client.test.ts +0 -591
  108. package/src/internal/cursor/credentials.test.ts +0 -351
  109. package/src/internal/cursor/github-credentials.test.ts +0 -136
  110. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  111. package/src/internal/cursor-account.integration.test.ts +0 -441
  112. package/src/internal/cursor-event-relay.test.ts +0 -746
  113. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  114. package/src/internal/cursor-slack-relay.test.ts +0 -525
  115. package/src/internal/deploy-source.test.ts +0 -111
  116. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  117. package/src/internal/discovery.concurrency.test.ts +0 -60
  118. package/src/internal/discovery.cursor-account.test.ts +0 -133
  119. package/src/internal/discovery.cwd.test.ts +0 -83
  120. package/src/internal/discovery.hosting.test.ts +0 -80
  121. package/src/internal/discovery.identity.test.ts +0 -44
  122. package/src/internal/docs-site.test.ts +0 -66
  123. package/src/internal/duration.test.ts +0 -29
  124. package/src/internal/eval-judge-model.test.ts +0 -187
  125. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  126. package/src/internal/eval-run-store.storage.test.ts +0 -211
  127. package/src/internal/eval-runner.http.test.ts +0 -403
  128. package/src/internal/eval-runner.run.test.ts +0 -928
  129. package/src/internal/evals-client.test.ts +0 -307
  130. package/src/internal/event-mapper.test.ts +0 -243
  131. package/src/internal/github-fanout.test.ts +0 -213
  132. package/src/internal/handleAgentServeTrigger.test.ts +0 -179
  133. package/src/internal/host-kv.test.ts +0 -82
  134. package/src/internal/host-platforms.test.ts +0 -126
  135. package/src/internal/http-channel.test.ts +0 -402
  136. package/src/internal/init-project.test.ts +0 -270
  137. package/src/internal/install-cursor-skills.test.ts +0 -262
  138. package/src/internal/local-env.test.ts +0 -120
  139. package/src/internal/log-ring.test.ts +0 -31
  140. package/src/internal/logs-client.test.ts +0 -350
  141. package/src/internal/mcp-endpoint.test.ts +0 -436
  142. package/src/internal/mcp-host.test.ts +0 -298
  143. package/src/internal/mcp-oauth.test.ts +0 -148
  144. package/src/internal/net.test.ts +0 -17
  145. package/src/internal/peer-connections.test.ts +0 -128
  146. package/src/internal/peer-mcp.integration.test.ts +0 -289
  147. package/src/internal/playground/toolchain.test.ts +0 -53
  148. package/src/internal/playground-cli.test.ts +0 -187
  149. package/src/internal/playground-proxy.test.ts +0 -376
  150. package/src/internal/prompt-context.integration.test.ts +0 -232
  151. package/src/internal/prompt-context.test.ts +0 -127
  152. package/src/internal/reminder-runner.test.ts +0 -390
  153. package/src/internal/reminder-store.test.ts +0 -53
  154. package/src/internal/request-headers.test.ts +0 -27
  155. package/src/internal/resolve-prod-target.test.ts +0 -787
  156. package/src/internal/resolved-connections.test.ts +0 -295
  157. package/src/internal/router.test.ts +0 -57
  158. package/src/internal/sdk-runner.test.ts +0 -290
  159. package/src/internal/session-engine.coalesce.test.ts +0 -169
  160. package/src/internal/session-engine.concurrency.test.ts +0 -250
  161. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  162. package/src/internal/session-engine.interrupt.test.ts +0 -577
  163. package/src/internal/session-engine.storage.test.ts +0 -547
  164. package/src/internal/session-urls.test.ts +0 -28
  165. package/src/internal/sessions-client.test.ts +0 -518
  166. package/src/internal/storage-coordinator.test.ts +0 -517
  167. package/src/internal/tool-call.test.ts +0 -458
  168. package/src/internal/tool-result.test.ts +0 -52
  169. package/src/internal/trajectory.approvals.test.ts +0 -83
  170. package/src/internal/trajectory.subagents.test.ts +0 -198
  171. package/src/internal/turn-governor.test.ts +0 -137
  172. package/src/internal/update-check.test.ts +0 -485
  173. package/src/internal/workspace.test.ts +0 -207
  174. 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
- });