@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,213 @@
|
|
|
1
|
+
import { createHmac } from "node:crypto";
|
|
2
|
+
import { createServer, type IncomingMessage, type Server } from "node:http";
|
|
3
|
+
import type { AddressInfo } from "node:net";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import type { GitHubForwardTarget } from "../channels/github/forward.js";
|
|
6
|
+
import { fanoutDelivery, startFanoutServer } from "./github-fanout.js";
|
|
7
|
+
|
|
8
|
+
interface Captured {
|
|
9
|
+
method: string;
|
|
10
|
+
headers: IncomingMessage["headers"];
|
|
11
|
+
body: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A stand-in GitHub channel that records the requests it receives. */
|
|
15
|
+
function recordingServer(): Promise<{
|
|
16
|
+
url: string;
|
|
17
|
+
received: Captured[];
|
|
18
|
+
close: () => void;
|
|
19
|
+
}> {
|
|
20
|
+
const received: Captured[] = [];
|
|
21
|
+
const server: Server = createServer((req, res) => {
|
|
22
|
+
const chunks: Buffer[] = [];
|
|
23
|
+
req.on("data", (chunk: Buffer) => chunks.push(chunk));
|
|
24
|
+
req.on("end", () => {
|
|
25
|
+
received.push({
|
|
26
|
+
method: req.method ?? "",
|
|
27
|
+
headers: req.headers,
|
|
28
|
+
body: Buffer.concat(chunks).toString("utf8"),
|
|
29
|
+
});
|
|
30
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
31
|
+
res.end(JSON.stringify({ ok: true }));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
server.listen(0, "127.0.0.1", () => {
|
|
36
|
+
const { port } = server.address() as AddressInfo;
|
|
37
|
+
resolve({
|
|
38
|
+
url: `http://127.0.0.1:${port}`,
|
|
39
|
+
received,
|
|
40
|
+
close: () => server.close(),
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const cleanups: Array<() => void> = [];
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
for (const cleanup of cleanups.splice(0)) {
|
|
49
|
+
cleanup();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("fanoutDelivery", () => {
|
|
54
|
+
it("re-posts the raw body + signature to every matching channel", async () => {
|
|
55
|
+
const a = await recordingServer();
|
|
56
|
+
const b = await recordingServer();
|
|
57
|
+
cleanups.push(a.close, b.close);
|
|
58
|
+
|
|
59
|
+
const targets: GitHubForwardTarget[] = [
|
|
60
|
+
{
|
|
61
|
+
slug: "fsd",
|
|
62
|
+
channelId: "github",
|
|
63
|
+
url: a.url,
|
|
64
|
+
events: ["pull_request"],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
slug: "reviewer",
|
|
68
|
+
channelId: "github",
|
|
69
|
+
url: b.url,
|
|
70
|
+
events: ["pull_request"],
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
const body = Buffer.from(JSON.stringify({ action: "opened" }));
|
|
75
|
+
const signature = `sha256=${createHmac("sha256", "s3cr3t").update(body).digest("hex")}`;
|
|
76
|
+
const delivered = await fanoutDelivery(
|
|
77
|
+
body,
|
|
78
|
+
{
|
|
79
|
+
"content-type": "application/json",
|
|
80
|
+
"x-github-event": "pull_request",
|
|
81
|
+
"x-hub-signature-256": signature,
|
|
82
|
+
},
|
|
83
|
+
targets,
|
|
84
|
+
{ logger: () => {} }
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(delivered.sort()).toEqual(["fsd/github", "reviewer/github"]);
|
|
88
|
+
for (const server of [a, b]) {
|
|
89
|
+
expect(server.received).toHaveLength(1);
|
|
90
|
+
expect(server.received[0]?.body).toBe(body.toString("utf8"));
|
|
91
|
+
expect(server.received[0]?.headers["x-hub-signature-256"]).toBe(
|
|
92
|
+
signature
|
|
93
|
+
);
|
|
94
|
+
expect(server.received[0]?.headers["x-github-event"]).toBe(
|
|
95
|
+
"pull_request"
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("delivers only to channels whose event set matches", async () => {
|
|
101
|
+
const fsd = await recordingServer();
|
|
102
|
+
const reviewer = await recordingServer();
|
|
103
|
+
cleanups.push(fsd.close, reviewer.close);
|
|
104
|
+
|
|
105
|
+
const targets: GitHubForwardTarget[] = [
|
|
106
|
+
{
|
|
107
|
+
slug: "fsd",
|
|
108
|
+
channelId: "github",
|
|
109
|
+
url: fsd.url,
|
|
110
|
+
events: ["pull_request", "check_run"],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
slug: "reviewer",
|
|
114
|
+
channelId: "github",
|
|
115
|
+
url: reviewer.url,
|
|
116
|
+
events: ["pull_request"],
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
const delivered = await fanoutDelivery(
|
|
121
|
+
Buffer.from("{}"),
|
|
122
|
+
{ "x-github-event": "check_run" },
|
|
123
|
+
targets,
|
|
124
|
+
{ logger: () => {} }
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
expect(delivered).toEqual(["fsd/github"]);
|
|
128
|
+
expect(fsd.received).toHaveLength(1);
|
|
129
|
+
expect(reviewer.received).toHaveLength(0);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("does not count HTTP error responses as delivered", async () => {
|
|
133
|
+
const ok = await recordingServer();
|
|
134
|
+
const failing = createServer((req, res) => {
|
|
135
|
+
const chunks: Buffer[] = [];
|
|
136
|
+
req.on("data", (chunk: Buffer) => chunks.push(chunk));
|
|
137
|
+
req.on("end", () => {
|
|
138
|
+
res.writeHead(500);
|
|
139
|
+
res.end("error");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
await new Promise<void>((resolve) => {
|
|
143
|
+
failing.listen(0, "127.0.0.1", () => resolve());
|
|
144
|
+
});
|
|
145
|
+
const failingPort = (failing.address() as AddressInfo).port;
|
|
146
|
+
cleanups.push(ok.close, () => failing.close());
|
|
147
|
+
|
|
148
|
+
const targets: GitHubForwardTarget[] = [
|
|
149
|
+
{
|
|
150
|
+
slug: "ok",
|
|
151
|
+
channelId: "github",
|
|
152
|
+
url: ok.url,
|
|
153
|
+
events: ["pull_request"],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
slug: "bad",
|
|
157
|
+
channelId: "github",
|
|
158
|
+
url: `http://127.0.0.1:${failingPort}`,
|
|
159
|
+
events: ["pull_request"],
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
const delivered = await fanoutDelivery(
|
|
164
|
+
Buffer.from("{}"),
|
|
165
|
+
{ "x-github-event": "pull_request" },
|
|
166
|
+
targets,
|
|
167
|
+
{ logger: () => {} }
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
expect(delivered).toEqual(["ok/github"]);
|
|
171
|
+
expect(ok.received).toHaveLength(1);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("startFanoutServer", () => {
|
|
176
|
+
it("proxies a POST through to matching channels", async () => {
|
|
177
|
+
const channel = await recordingServer();
|
|
178
|
+
cleanups.push(channel.close);
|
|
179
|
+
|
|
180
|
+
const proxy = await startFanoutServer(
|
|
181
|
+
[
|
|
182
|
+
{
|
|
183
|
+
slug: "fsd",
|
|
184
|
+
channelId: "github",
|
|
185
|
+
url: channel.url,
|
|
186
|
+
events: ["pull_request"],
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
{ logger: () => {} }
|
|
190
|
+
);
|
|
191
|
+
cleanups.push(proxy.close);
|
|
192
|
+
|
|
193
|
+
const response = await fetch(proxy.url, {
|
|
194
|
+
method: "POST",
|
|
195
|
+
headers: {
|
|
196
|
+
"content-type": "application/json",
|
|
197
|
+
"x-github-event": "pull_request",
|
|
198
|
+
},
|
|
199
|
+
body: JSON.stringify({ action: "synchronize" }),
|
|
200
|
+
});
|
|
201
|
+
const result = (await response.json()) as {
|
|
202
|
+
ok: boolean;
|
|
203
|
+
delivered: string[];
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
expect(response.status).toBe(200);
|
|
207
|
+
expect(result).toEqual({ ok: true, delivered: ["fsd/github"] });
|
|
208
|
+
expect(channel.received).toHaveLength(1);
|
|
209
|
+
expect(channel.received[0]?.body).toBe(
|
|
210
|
+
JSON.stringify({ action: "synchronize" })
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { githubChannel } from "../channels/github/github-channel.js";
|
|
3
|
+
import type {
|
|
4
|
+
ChannelHandlerArgs,
|
|
5
|
+
ChannelSession,
|
|
6
|
+
SendMessageFn,
|
|
7
|
+
} from "../types.js";
|
|
8
|
+
import {
|
|
9
|
+
collectGitHubTriggerTargets,
|
|
10
|
+
handleAgentServeTrigger,
|
|
11
|
+
} from "./handleAgentServeTrigger.js";
|
|
12
|
+
|
|
13
|
+
describe("handleAgentServeTrigger", () => {
|
|
14
|
+
it("fans out a pull_request delivery to every github channel target", async () => {
|
|
15
|
+
const sendA = vi.fn<SendMessageFn>(async () => fakeSession("a"));
|
|
16
|
+
const sendB = vi.fn<SendMessageFn>(async () => fakeSession("b"));
|
|
17
|
+
|
|
18
|
+
const channelA = githubChannel({
|
|
19
|
+
auth: [],
|
|
20
|
+
onPullRequest: (ctx) => ({
|
|
21
|
+
auth: {
|
|
22
|
+
authenticator: "github-webhook",
|
|
23
|
+
principalId: ctx.senderLogin ?? "github",
|
|
24
|
+
principalType: "user",
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
const channelB = githubChannel({
|
|
29
|
+
auth: [],
|
|
30
|
+
onPullRequest: () => null,
|
|
31
|
+
});
|
|
32
|
+
const buildSecurityReviewerArgs = vi.fn(() => handlerArgs(sendA));
|
|
33
|
+
|
|
34
|
+
const targets = collectGitHubTriggerTargets({
|
|
35
|
+
mounts: [
|
|
36
|
+
{
|
|
37
|
+
slug: "security-reviewer",
|
|
38
|
+
channels: [{ id: "reviewer", definition: channelA }],
|
|
39
|
+
buildHandlerArgs: buildSecurityReviewerArgs,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
slug: "fsd",
|
|
43
|
+
channels: [{ id: "github", definition: channelB }],
|
|
44
|
+
buildHandlerArgs: () => handlerArgs(sendB),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
slug: "weather-agent",
|
|
48
|
+
channels: [],
|
|
49
|
+
buildHandlerArgs: () => handlerArgs(vi.fn()),
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(targets.map((t) => t.slug)).toEqual(["security-reviewer", "fsd"]);
|
|
55
|
+
expect(buildSecurityReviewerArgs).toHaveBeenCalledWith("reviewer");
|
|
56
|
+
|
|
57
|
+
const result = await handleAgentServeTrigger({
|
|
58
|
+
type: "github",
|
|
59
|
+
bodyText: JSON.stringify(pullRequestPayload()),
|
|
60
|
+
eventName: "pull_request",
|
|
61
|
+
deliveryId: "delivery-1",
|
|
62
|
+
targets,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(result.ok).toBe(true);
|
|
66
|
+
expect(result.targets).toHaveLength(2);
|
|
67
|
+
expect(result.targets[0]?.slug).toBe("security-reviewer");
|
|
68
|
+
expect(result.targets[0]?.status).toBe(200);
|
|
69
|
+
expect(result.targets[1]?.slug).toBe("fsd");
|
|
70
|
+
expect(result.targets[1]?.body).toMatchObject({
|
|
71
|
+
ok: true,
|
|
72
|
+
skipped: true,
|
|
73
|
+
reason: "not_dispatched",
|
|
74
|
+
});
|
|
75
|
+
expect(sendA).toHaveBeenCalledOnce();
|
|
76
|
+
expect(sendB).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("rejects invalid JSON without dispatching", async () => {
|
|
80
|
+
const result = await handleAgentServeTrigger({
|
|
81
|
+
type: "github",
|
|
82
|
+
bodyText: "not-json",
|
|
83
|
+
eventName: "pull_request",
|
|
84
|
+
targets: [],
|
|
85
|
+
});
|
|
86
|
+
expect(result.ok).toBe(false);
|
|
87
|
+
expect(result.targets[0]?.status).toBe(400);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
function handlerArgs(send: SendMessageFn): ChannelHandlerArgs {
|
|
92
|
+
return {
|
|
93
|
+
params: {},
|
|
94
|
+
requestIp: "127.0.0.1",
|
|
95
|
+
auth: null,
|
|
96
|
+
host: {
|
|
97
|
+
mcp: {
|
|
98
|
+
names: () => [],
|
|
99
|
+
listTools: async () => [],
|
|
100
|
+
callTool: async () => ({ content: [] }),
|
|
101
|
+
},
|
|
102
|
+
github: {
|
|
103
|
+
getOctokit: async () => {
|
|
104
|
+
throw new Error("github client not configured in test");
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
slack: {
|
|
108
|
+
getClient: async () => {
|
|
109
|
+
throw new Error("slack client not configured in test");
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
kv: {
|
|
113
|
+
get: async () => undefined,
|
|
114
|
+
put: async () => {},
|
|
115
|
+
delete: async () => {},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
send,
|
|
119
|
+
getSession: async () => null,
|
|
120
|
+
receive: async () => fakeSession("recv"),
|
|
121
|
+
callTool: async (toolName) => ({
|
|
122
|
+
toolName,
|
|
123
|
+
callId: "call-1",
|
|
124
|
+
isError: false,
|
|
125
|
+
result: null,
|
|
126
|
+
durationMs: 0,
|
|
127
|
+
}),
|
|
128
|
+
waitUntil: () => {},
|
|
129
|
+
sessionUrls: () => ({
|
|
130
|
+
playgroundUrl: "http://127.0.0.1:3000/playground",
|
|
131
|
+
traceUrl: "http://127.0.0.1:3000/v1/session/x/events",
|
|
132
|
+
}),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function fakeSession(id: string): ChannelSession {
|
|
137
|
+
return {
|
|
138
|
+
id,
|
|
139
|
+
isNew: true,
|
|
140
|
+
continuationToken: `github-pr:acme/widgets#42:${id}`,
|
|
141
|
+
info: {
|
|
142
|
+
id,
|
|
143
|
+
channelId: "github",
|
|
144
|
+
mode: "chat",
|
|
145
|
+
auth: null,
|
|
146
|
+
sdkAgentId: undefined,
|
|
147
|
+
title: "GitHub acme/widgets#42",
|
|
148
|
+
},
|
|
149
|
+
getEventStream: async () => new ReadableStream<Uint8Array>(),
|
|
150
|
+
waitForCompletion: async () => ({ status: "finished", result: "done" }),
|
|
151
|
+
setContinuationToken: async () => {},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function pullRequestPayload(): Record<string, unknown> {
|
|
156
|
+
return {
|
|
157
|
+
action: "opened",
|
|
158
|
+
repository: {
|
|
159
|
+
full_name: "acme/widgets",
|
|
160
|
+
html_url: "https://github.com/acme/widgets",
|
|
161
|
+
},
|
|
162
|
+
pull_request: {
|
|
163
|
+
number: 42,
|
|
164
|
+
html_url: "https://github.com/acme/widgets/pull/42",
|
|
165
|
+
title: "Add widgets",
|
|
166
|
+
body: "PR body",
|
|
167
|
+
draft: false,
|
|
168
|
+
user: { login: "octocat" },
|
|
169
|
+
head: {
|
|
170
|
+
ref: "feature/widgets",
|
|
171
|
+
sha: "abc123",
|
|
172
|
+
},
|
|
173
|
+
base: {
|
|
174
|
+
ref: "main",
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
sender: { login: "sender" },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { defineStorage, storageKeys } from "../storage.js";
|
|
6
|
+
import { createHostKvApi } from "./host-kv.js";
|
|
7
|
+
import { StorageCoordinator } from "./storage-coordinator.js";
|
|
8
|
+
|
|
9
|
+
describe("createHostKvApi", () => {
|
|
10
|
+
const dirs: string[] = [];
|
|
11
|
+
|
|
12
|
+
afterEach(async () => {
|
|
13
|
+
await Promise.all(
|
|
14
|
+
dirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true }))
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
async function tempDir(): Promise<string> {
|
|
19
|
+
const dir = await mkdtemp(join(tmpdir(), "agentkit-host-kv-"));
|
|
20
|
+
dirs.push(dir);
|
|
21
|
+
return dir;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
it("falls back to state-root files when defineStorage is absent", async () => {
|
|
25
|
+
const stateRoot = await tempDir();
|
|
26
|
+
const kv = createHostKvApi({ agentName: "jenny", stateRoot });
|
|
27
|
+
|
|
28
|
+
expect(await kv.get("alert-memory/a")).toBeUndefined();
|
|
29
|
+
await kv.put("alert-memory/a", { class: "monitor:1", updated: "t" });
|
|
30
|
+
expect(await kv.get("alert-memory/a")).toEqual({
|
|
31
|
+
class: "monitor:1",
|
|
32
|
+
updated: "t",
|
|
33
|
+
});
|
|
34
|
+
await kv.delete("alert-memory/a");
|
|
35
|
+
expect(await kv.get("alert-memory/a")).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("uses defineStorage under storageKeys.kv when get is present", async () => {
|
|
39
|
+
const stateRoot = await tempDir();
|
|
40
|
+
const store = new Map<string, unknown>();
|
|
41
|
+
const coordinator = new StorageCoordinator({
|
|
42
|
+
definition: defineStorage({
|
|
43
|
+
put: (key, value) => {
|
|
44
|
+
store.set(key, value);
|
|
45
|
+
},
|
|
46
|
+
get: (key) => store.get(key) as never,
|
|
47
|
+
delete: (key) => {
|
|
48
|
+
store.delete(key);
|
|
49
|
+
},
|
|
50
|
+
list: (prefix) =>
|
|
51
|
+
[...store.entries()]
|
|
52
|
+
.filter(([key]) => key.startsWith(prefix))
|
|
53
|
+
.map(([key, value]) => ({ key, value: value as never }))
|
|
54
|
+
.sort((a, b) => a.key.localeCompare(b.key)),
|
|
55
|
+
}),
|
|
56
|
+
agentName: "jenny",
|
|
57
|
+
projectRoot: stateRoot,
|
|
58
|
+
logger: () => {},
|
|
59
|
+
});
|
|
60
|
+
const kv = createHostKvApi({
|
|
61
|
+
agentName: "jenny",
|
|
62
|
+
stateRoot,
|
|
63
|
+
storage: coordinator,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
await kv.put("alert-memory/x", { ok: true });
|
|
67
|
+
expect(store.get(storageKeys.kv("jenny", "alert-memory/x"))).toEqual({
|
|
68
|
+
ok: true,
|
|
69
|
+
});
|
|
70
|
+
expect(await kv.get("alert-memory/x")).toEqual({ ok: true });
|
|
71
|
+
await kv.delete("alert-memory/x");
|
|
72
|
+
expect(store.has(storageKeys.kv("jenny", "alert-memory/x"))).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("rejects empty keys", async () => {
|
|
76
|
+
const kv = createHostKvApi({
|
|
77
|
+
agentName: "jenny",
|
|
78
|
+
stateRoot: await tempDir(),
|
|
79
|
+
});
|
|
80
|
+
await expect(kv.get(" ")).rejects.toThrow(/non-empty/);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const tryResolveGhAuthToken = vi.hoisted(() => vi.fn());
|
|
4
|
+
const hasGitHubAppCredentials = vi.hoisted(() => vi.fn());
|
|
5
|
+
const resolveGitHubInstallationId = vi.hoisted(() => vi.fn());
|
|
6
|
+
const ensureGhCliTokenEnv = vi.hoisted(() => vi.fn());
|
|
7
|
+
|
|
8
|
+
vi.mock("../channels/github/auth.js", async (importOriginal) => {
|
|
9
|
+
const actual =
|
|
10
|
+
await importOriginal<typeof import("../channels/github/auth.js")>();
|
|
11
|
+
return {
|
|
12
|
+
...actual,
|
|
13
|
+
tryResolveGhAuthToken,
|
|
14
|
+
hasGitHubAppCredentials,
|
|
15
|
+
resolveGitHubInstallationId,
|
|
16
|
+
ensureGhCliTokenEnv,
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
import { clearGitHubAuthCaches } from "../channels/github/auth.js";
|
|
21
|
+
import {
|
|
22
|
+
resolveHostGitHubAuthSource,
|
|
23
|
+
warmupHostGitHubAuth,
|
|
24
|
+
} from "./host-platforms.js";
|
|
25
|
+
|
|
26
|
+
describe("host GitHub auth warmup", () => {
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
clearGitHubAuthCaches();
|
|
29
|
+
tryResolveGhAuthToken.mockReset();
|
|
30
|
+
hasGitHubAppCredentials.mockReset();
|
|
31
|
+
resolveGitHubInstallationId.mockReset();
|
|
32
|
+
ensureGhCliTokenEnv.mockReset();
|
|
33
|
+
hasGitHubAppCredentials.mockResolvedValue(false);
|
|
34
|
+
resolveGitHubInstallationId.mockResolvedValue(undefined);
|
|
35
|
+
ensureGhCliTokenEnv.mockResolvedValue(false);
|
|
36
|
+
delete process.env.GITHUB_TOKEN;
|
|
37
|
+
delete process.env.GH_TOKEN;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
clearGitHubAuthCaches();
|
|
42
|
+
tryResolveGhAuthToken.mockReset();
|
|
43
|
+
hasGitHubAppCredentials.mockReset();
|
|
44
|
+
resolveGitHubInstallationId.mockReset();
|
|
45
|
+
ensureGhCliTokenEnv.mockReset();
|
|
46
|
+
delete process.env.GITHUB_TOKEN;
|
|
47
|
+
delete process.env.GH_TOKEN;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("prefers App installation auth over env PAT", async () => {
|
|
51
|
+
process.env.GITHUB_TOKEN = "env-token";
|
|
52
|
+
hasGitHubAppCredentials.mockResolvedValue(true);
|
|
53
|
+
resolveGitHubInstallationId.mockResolvedValue(42);
|
|
54
|
+
await expect(resolveHostGitHubAuthSource()).resolves.toBe("app");
|
|
55
|
+
expect(tryResolveGhAuthToken).not.toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("prefers env over gh when App creds are unset", async () => {
|
|
59
|
+
process.env.GITHUB_TOKEN = "env-token";
|
|
60
|
+
tryResolveGhAuthToken.mockResolvedValue("gh-token");
|
|
61
|
+
await expect(resolveHostGitHubAuthSource()).resolves.toBe("env");
|
|
62
|
+
expect(tryResolveGhAuthToken).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("falls back to gh auth token", async () => {
|
|
66
|
+
tryResolveGhAuthToken.mockResolvedValue("gh-token");
|
|
67
|
+
await expect(resolveHostGitHubAuthSource()).resolves.toBe("gh");
|
|
68
|
+
expect(tryResolveGhAuthToken).toHaveBeenCalledOnce();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("reports unavailable when neither App, env, nor gh works", async () => {
|
|
72
|
+
tryResolveGhAuthToken.mockResolvedValue(undefined);
|
|
73
|
+
await expect(resolveHostGitHubAuthSource()).resolves.toBe("unavailable");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("logs and primes Octokit on successful warmup", async () => {
|
|
77
|
+
process.env.GITHUB_TOKEN = "env-token";
|
|
78
|
+
const lines: string[] = [];
|
|
79
|
+
const getOctokit = vi.fn(async () => ({ ok: true }) as never);
|
|
80
|
+
await expect(
|
|
81
|
+
warmupHostGitHubAuth({
|
|
82
|
+
logger: (line) => lines.push(line),
|
|
83
|
+
github: { getOctokit },
|
|
84
|
+
})
|
|
85
|
+
).resolves.toBe("env");
|
|
86
|
+
expect(getOctokit).toHaveBeenCalledOnce();
|
|
87
|
+
expect(lines.some((line) => line.includes("GITHUB_TOKEN/GH_TOKEN"))).toBe(
|
|
88
|
+
true
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("warns without failing when auth is unavailable", async () => {
|
|
93
|
+
tryResolveGhAuthToken.mockResolvedValue(undefined);
|
|
94
|
+
const lines: string[] = [];
|
|
95
|
+
const getOctokit = vi.fn(async () => {
|
|
96
|
+
throw new Error("should not be called");
|
|
97
|
+
});
|
|
98
|
+
await expect(
|
|
99
|
+
warmupHostGitHubAuth({
|
|
100
|
+
logger: (line) => lines.push(line),
|
|
101
|
+
github: { getOctokit },
|
|
102
|
+
})
|
|
103
|
+
).resolves.toBe("unavailable");
|
|
104
|
+
expect(getOctokit).not.toHaveBeenCalled();
|
|
105
|
+
expect(ensureGhCliTokenEnv).not.toHaveBeenCalled();
|
|
106
|
+
expect(lines.some((line) => line.includes("unavailable"))).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("exports GH_TOKEN for gh CLI when App auth is configured", async () => {
|
|
110
|
+
hasGitHubAppCredentials.mockResolvedValue(true);
|
|
111
|
+
resolveGitHubInstallationId.mockResolvedValue(42);
|
|
112
|
+
ensureGhCliTokenEnv.mockResolvedValue(true);
|
|
113
|
+
const lines: string[] = [];
|
|
114
|
+
const getOctokit = vi.fn(async () => ({ ok: true }) as never);
|
|
115
|
+
await expect(
|
|
116
|
+
warmupHostGitHubAuth({
|
|
117
|
+
logger: (line) => lines.push(line),
|
|
118
|
+
github: { getOctokit },
|
|
119
|
+
})
|
|
120
|
+
).resolves.toBe("app");
|
|
121
|
+
expect(ensureGhCliTokenEnv).toHaveBeenCalledOnce();
|
|
122
|
+
expect(
|
|
123
|
+
lines.some((line) => line.includes("exported as GH_TOKEN for gh CLI"))
|
|
124
|
+
).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
});
|