@cursor/july 0.1.20 → 0.1.21
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.
- package/dist/bin/agent-serve.js +0 -0
- package/dist/channels/github/instrument.d.ts +20 -0
- package/dist/channels/github/instrument.d.ts.map +1 -0
- package/dist/channels/slack/api.d.ts +2 -0
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +3 -0
- package/dist/channels/slack/bot-mentions.d.ts +106 -0
- package/dist/channels/slack/bot-mentions.d.ts.map +1 -0
- package/dist/channels/slack/bot-mentions.js +243 -0
- package/dist/channels/slack/dispatch.d.ts +6 -0
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/dispatch.js +24 -3
- package/dist/channels/slack/inbound.d.ts +10 -1
- package/dist/channels/slack/inbound.d.ts.map +1 -1
- package/dist/channels/slack/inbound.js +12 -4
- package/dist/channels/slack/index.d.ts +1 -0
- package/dist/channels/slack/index.d.ts.map +1 -1
- package/dist/channels/slack/index.js +1 -0
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +61 -22
- package/dist/channels/slack/types.d.ts +58 -0
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/docs/404.html +1 -1
- package/dist/docs/ab.html +2 -2
- package/dist/docs/assets/{app.T-5ImnM3.js → app.jDxLzWv4.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DoJHJjqF.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.OMGMWH6H.js → VPLocalSearchBox.Y6bDR1-a.js} +1 -1
- package/dist/docs/assets/chunks/{theme.DLg4yB4D.js → theme.CLazCWlJ.js} +2 -2
- package/dist/docs/building-with-agents.html +2 -2
- package/dist/docs/concepts.html +2 -2
- package/dist/docs/deployment.html +2 -2
- package/dist/docs/evals.html +2 -2
- package/dist/docs/example-agents/approval-buddy.html +2 -2
- package/dist/docs/example-agents/benny.html +2 -2
- package/dist/docs/example-agents/bugbot.html +2 -2
- package/dist/docs/example-agents/codebase-wiki.html +2 -2
- package/dist/docs/example-agents/codeowners-review.html +2 -2
- package/dist/docs/example-agents/concierge.html +2 -2
- package/dist/docs/example-agents/fsd.html +2 -2
- package/dist/docs/example-agents/index.html +2 -2
- package/dist/docs/example-agents/knowledge-base.html +2 -2
- package/dist/docs/example-agents/oncall.html +2 -2
- package/dist/docs/example-agents/security-reviewer.html +2 -2
- package/dist/docs/example-agents/slack-agent.html +2 -2
- package/dist/docs/example-agents/weather-agent.html +2 -2
- package/dist/docs/guides/agent-to-agent.html +2 -2
- package/dist/docs/guides/cloud-runtime.html +2 -2
- package/dist/docs/guides/github.html +2 -2
- package/dist/docs/guides/human-in-the-loop.html +2 -2
- package/dist/docs/guides/mcp-oauth.html +2 -2
- package/dist/docs/guides/slack.html +2 -2
- package/dist/docs/guides/webhooks.html +2 -2
- package/dist/docs/hillclimbing.html +2 -2
- package/dist/docs/index.html +2 -2
- package/dist/docs/quickstart.html +2 -2
- package/dist/docs/reference/agent-config.html +2 -2
- package/dist/docs/reference/channels.html +2 -2
- package/dist/docs/reference/cli.html +2 -2
- package/dist/docs/reference/connections.html +2 -2
- package/dist/docs/reference/hooks.html +2 -2
- package/dist/docs/reference/http-api.html +2 -2
- package/dist/docs/reference/instructions.html +2 -2
- package/dist/docs/reference/playground.html +2 -2
- package/dist/docs/reference/project-layout.html +2 -2
- package/dist/docs/reference/prompt.html +2 -2
- package/dist/docs/reference/schedules.html +2 -2
- package/dist/docs/reference/sessions.html +2 -2
- package/dist/docs/reference/skills.html +2 -2
- package/dist/docs/reference/subagents.html +2 -2
- package/dist/docs/reference/tools.html +2 -2
- package/dist/docs/scaffolding-agents.html +2 -2
- package/dist/docs/storage.html +2 -2
- package/dist/docs/troubleshooting.html +2 -2
- package/dist/internal/json-dir-store.d.ts +32 -0
- package/dist/internal/json-dir-store.d.ts.map +1 -0
- package/dist/internal/json-dir-store.js +100 -0
- package/dist/internal/resolved-connections.d.ts +1 -1
- package/dist/internal/resolved-connections.d.ts.map +1 -1
- package/dist/internal/resolved-connections.js +10 -0
- package/dist/internal/session-engine.d.ts +4 -1
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +13 -2
- package/dist/playground/assets/index-CjOQ4hN9.css +1 -0
- package/dist/playground/assets/index-dshZQJCp.js +85 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/package.json +24 -24
- package/src/bin/agent-serve.version.test.ts +62 -0
- package/src/channels/github/api.test.ts +64 -0
- package/src/channels/github/auth.test.ts +105 -0
- package/src/channels/github/cursor-account.test.ts +204 -0
- package/src/channels/github/forward.test.ts +457 -0
- package/src/channels/github/github.test.ts +937 -0
- package/src/channels/github/replay.test.ts +179 -0
- package/src/channels/slack/api.post-message.test.ts +148 -0
- package/src/channels/slack/api.ts +5 -0
- package/src/channels/slack/approvals.test.ts +328 -0
- package/src/channels/slack/block-actions.test.ts +452 -0
- package/src/channels/slack/bot-mentions.test.ts +217 -0
- package/src/channels/slack/bot-mentions.ts +315 -0
- package/src/channels/slack/channel-watch.test.ts +363 -0
- package/src/channels/slack/cursor-account.test.ts +253 -0
- package/src/channels/slack/defaults.final-post.test.ts +182 -0
- package/src/channels/slack/dispatch.test.ts +795 -0
- package/src/channels/slack/dispatch.ts +27 -1
- package/src/channels/slack/eval-directive.test.ts +273 -0
- package/src/channels/slack/inbound.ts +25 -4
- package/src/channels/slack/index.ts +1 -0
- package/src/channels/slack/message-body.test.ts +54 -0
- package/src/channels/slack/nudge-store.test.ts +143 -0
- package/src/channels/slack/slack-channel.ts +66 -8
- package/src/channels/slack/slack.test.ts +391 -0
- package/src/channels/slack/stop.test.ts +23 -0
- package/src/channels/slack/thread-context.test.ts +202 -0
- package/src/channels/slack/types.ts +60 -0
- package/src/evals/assertions.test.ts +580 -0
- package/src/evals/expect.test.ts +144 -0
- package/src/evals/judge.test.ts +181 -0
- package/src/evals/loaders.test.ts +132 -0
- package/src/evals/matchers.test.ts +95 -0
- package/src/evals/reporters.test.ts +303 -0
- package/src/evals/run-facts.test.ts +259 -0
- package/src/internal/ab-snapshot.test.ts +325 -0
- package/src/internal/approval-gate.test.ts +49 -0
- package/src/internal/approvals.integration.test.ts +383 -0
- package/src/internal/authored-loaders.test.ts +31 -0
- package/src/internal/builtin-tools/reminders.test.ts +201 -0
- package/src/internal/channel-route-schema.test.ts +294 -0
- package/src/internal/chat-attach.test.ts +262 -0
- package/src/internal/cli-deploy.test.ts +1991 -0
- package/src/internal/cli-mcp.test.ts +789 -0
- package/src/internal/cli-skills.test.ts +133 -0
- package/src/internal/cli-slack.test.ts +1647 -0
- package/src/internal/cloud-merge.test.ts +74 -0
- package/src/internal/cron.test.ts +22 -0
- package/src/internal/cursor/account-mcp.test.ts +807 -0
- package/src/internal/cursor/backend-client.test.ts +591 -0
- package/src/internal/cursor/credentials.test.ts +351 -0
- package/src/internal/cursor/github-credentials.test.ts +136 -0
- package/src/internal/cursor-account-mcp-auth.test.ts +310 -0
- package/src/internal/cursor-account.integration.test.ts +441 -0
- package/src/internal/cursor-event-relay.test.ts +746 -0
- package/src/internal/cursor-github-credentials.integration.test.ts +271 -0
- package/src/internal/cursor-slack-relay.test.ts +525 -0
- package/src/internal/deploy-source.test.ts +111 -0
- package/src/internal/discovery.builtin-tools.test.ts +94 -0
- package/src/internal/discovery.concurrency.test.ts +60 -0
- package/src/internal/discovery.cursor-account.test.ts +133 -0
- package/src/internal/discovery.cwd.test.ts +83 -0
- package/src/internal/discovery.hosting.test.ts +80 -0
- package/src/internal/discovery.identity.test.ts +44 -0
- package/src/internal/docs-site.test.ts +66 -0
- package/src/internal/duration.test.ts +29 -0
- package/src/internal/eval-judge-model.test.ts +187 -0
- package/src/internal/eval-run-store.cancel.test.ts +142 -0
- package/src/internal/eval-run-store.storage.test.ts +211 -0
- package/src/internal/eval-runner.http.test.ts +403 -0
- package/src/internal/eval-runner.run.test.ts +928 -0
- package/src/internal/evals-client.test.ts +307 -0
- package/src/internal/event-mapper.test.ts +243 -0
- package/src/internal/github-fanout.test.ts +213 -0
- package/src/internal/handleAgentServeTrigger.test.ts +179 -0
- package/src/internal/host-kv.test.ts +82 -0
- package/src/internal/host-platforms.test.ts +126 -0
- package/src/internal/http-channel.test.ts +402 -0
- package/src/internal/init-project.test.ts +269 -0
- package/src/internal/install-cursor-skills.test.ts +262 -0
- package/src/internal/local-env.test.ts +100 -0
- package/src/internal/log-ring.test.ts +31 -0
- package/src/internal/logs-client.test.ts +350 -0
- package/src/internal/mcp-endpoint.test.ts +436 -0
- package/src/internal/mcp-host.test.ts +298 -0
- package/src/internal/mcp-oauth.test.ts +148 -0
- package/src/internal/net.test.ts +17 -0
- package/src/internal/peer-connections.test.ts +128 -0
- package/src/internal/peer-mcp.integration.test.ts +289 -0
- package/src/internal/playground/toolchain.test.ts +53 -0
- package/src/internal/playground-cli.test.ts +187 -0
- package/src/internal/playground-proxy.test.ts +376 -0
- package/src/internal/prompt-context.integration.test.ts +232 -0
- package/src/internal/prompt-context.test.ts +127 -0
- package/src/internal/reminder-runner.test.ts +390 -0
- package/src/internal/reminder-store.test.ts +53 -0
- package/src/internal/request-headers.test.ts +27 -0
- package/src/internal/resolve-prod-target.test.ts +787 -0
- package/src/internal/resolved-connections.test.ts +295 -0
- package/src/internal/resolved-connections.ts +18 -1
- package/src/internal/router.test.ts +57 -0
- package/src/internal/sdk-runner.test.ts +290 -0
- package/src/internal/session-engine.coalesce.test.ts +169 -0
- package/src/internal/session-engine.concurrency.test.ts +250 -0
- package/src/internal/session-engine.host-oauth-mcp.test.ts +110 -0
- package/src/internal/session-engine.interrupt.test.ts +577 -0
- package/src/internal/session-engine.storage.test.ts +547 -0
- package/src/internal/session-engine.ts +15 -1
- package/src/internal/session-urls.test.ts +28 -0
- package/src/internal/sessions-client.test.ts +518 -0
- package/src/internal/storage-coordinator.test.ts +517 -0
- package/src/internal/tool-call.test.ts +458 -0
- package/src/internal/tool-result.test.ts +52 -0
- package/src/internal/trajectory.approvals.test.ts +83 -0
- package/src/internal/trajectory.subagents.test.ts +198 -0
- package/src/internal/turn-governor.test.ts +137 -0
- package/src/internal/update-check.test.ts +485 -0
- package/src/internal/workspace.test.ts +81 -0
- package/src/storage-backends/cursor-hosted.test.ts +121 -0
- package/src/types.ts +12 -0
- package/dist/docs/assets/chunks/@localSearchIndexroot.CvejISXF.js +0 -1
- package/dist/playground/assets/index-CidizGZv.css +0 -1
- package/dist/playground/assets/index-CuiAKZaP.js +0 -85
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
});
|
|
@@ -337,6 +337,8 @@ export async function postMessage(args: {
|
|
|
337
337
|
* `markdown_text` hard-caps at 12k while `text` allows ~40k.
|
|
338
338
|
*/
|
|
339
339
|
plainText?: boolean;
|
|
340
|
+
/** Slack message metadata (`{ event_type, event_payload }`). */
|
|
341
|
+
metadata?: Record<string, unknown>;
|
|
340
342
|
}): Promise<{ ts: string; channel: string }> {
|
|
341
343
|
// Slack treats markdown_text as mutually exclusive with text and blocks
|
|
342
344
|
// (error: markdown_text_conflict). Prefer markdown when we have no
|
|
@@ -349,6 +351,9 @@ export async function postMessage(args: {
|
|
|
349
351
|
if (args.threadTs !== undefined && args.threadTs !== "") {
|
|
350
352
|
base.thread_ts = args.threadTs;
|
|
351
353
|
}
|
|
354
|
+
if (args.metadata !== undefined) {
|
|
355
|
+
base.metadata = args.metadata;
|
|
356
|
+
}
|
|
352
357
|
const hasBlocks = args.blocks !== undefined && args.blocks.length > 0;
|
|
353
358
|
// User-group mentions (`<!subteam^…>`) and Slack mrkdwn links
|
|
354
359
|
// (`<https://…|label>`) only render correctly via mrkdwn `text`,
|
|
@@ -0,0 +1,328 @@
|
|
|
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
|
+
});
|