@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,525 +0,0 @@
1
- import { mkdtemp, readFile, rm } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
- import type { CursorSlackEnvelope } from "../channels/slack/cursor-account.js";
6
- import { slackChannel } from "../channels/slack/slack-channel.js";
7
- import { httpChannel } from "../channels.js";
8
- import type {
9
- AgentProject,
10
- AgentServeHandle,
11
- ChannelDefinition,
12
- } from "../types.js";
13
- import { RelayOffsetStore } from "./cursor-event-relay.js";
14
- import {
15
- CursorSlackRelay,
16
- type CursorSlackRelayEvent,
17
- createCursorSlackApiCaller,
18
- formatCursorSlackEventLog,
19
- } from "./cursor-slack-relay.js";
20
- import type { AgentRunner } from "./sdk-runner.js";
21
- import { startServer } from "./server.js";
22
-
23
- interface RecordedRequest {
24
- method: string;
25
- url: string;
26
- body?: unknown;
27
- }
28
-
29
- /**
30
- * Minimal fake of the /v0/slack-events surface: records requests and serves
31
- * a scripted queue of poll responses. Registration echoes the requested
32
- * agents as subscribed on one workspace.
33
- */
34
- function fakeBackend(script: {
35
- anchorOffset?: string;
36
- polls?: Array<{
37
- events: CursorSlackRelayEvent[];
38
- nextOffset: string;
39
- gapDetected?: boolean;
40
- }>;
41
- registrationFailures?: number;
42
- apiResponses?: Record<string, unknown>;
43
- }) {
44
- const requests: RecordedRequest[] = [];
45
- const polls = [...(script.polls ?? [])];
46
- let registrationFailures = script.registrationFailures ?? 0;
47
- const fetchImpl: typeof fetch = async (input, init) => {
48
- const url = String(input);
49
- const method = init?.method ?? "GET";
50
- const body =
51
- typeof init?.body === "string"
52
- ? (JSON.parse(init.body) as unknown)
53
- : undefined;
54
- requests.push({ method, url, ...(body === undefined ? {} : { body }) });
55
-
56
- if (url.includes("/v0/slack-events/subscriptions")) {
57
- if (registrationFailures > 0) {
58
- registrationFailures -= 1;
59
- return new Response("storage unavailable", { status: 503 });
60
- }
61
- return jsonResponse({
62
- workspaces: [{ slackTeamId: "T0TEST", isSubscribed: true }],
63
- agents: (
64
- (body as { agents?: Array<{ name: string }> })?.agents ?? []
65
- ).map((agent) => ({ name: agent.name, isSubscribed: true })),
66
- expiresAt: new Date().toISOString(),
67
- });
68
- }
69
- if (url.includes("/v0/slack-events/api")) {
70
- const request = body as { method?: string };
71
- return jsonResponse(
72
- script.apiResponses?.[request.method ?? ""] ?? {
73
- ok: true,
74
- ts: "999.111",
75
- }
76
- );
77
- }
78
- if (url.includes("after=%24") || url.includes("after=$")) {
79
- return jsonResponse({
80
- events: [],
81
- nextOffset: script.anchorOffset ?? "",
82
- gapDetected: false,
83
- });
84
- }
85
- const page = polls.shift() ?? {
86
- events: [],
87
- nextOffset: "",
88
- gapDetected: false,
89
- };
90
- return jsonResponse(page);
91
- };
92
- return { requests, fetchImpl };
93
- }
94
-
95
- function jsonResponse(body: unknown): Response {
96
- return new Response(JSON.stringify(body), {
97
- status: 200,
98
- headers: { "content-type": "application/json" },
99
- });
100
- }
101
-
102
- function envelope(
103
- offset: string,
104
- overrides: Partial<CursorSlackEnvelope> = {}
105
- ): CursorSlackRelayEvent {
106
- return {
107
- offset,
108
- eventName: "app_mention",
109
- slackTeamId: "T0TEST",
110
- channelId: "C0100",
111
- channelType: "channel",
112
- threadTs: "111.222",
113
- messageTs: "111.222",
114
- slackUserId: "U0AAA",
115
- text: "what's the weather?",
116
- agentName: "Benny",
117
- consumerId: "consumer-under-test",
118
- matchedBy: "name",
119
- eventId: `Ev${offset}`,
120
- receivedAtMs: Date.now(),
121
- ...overrides,
122
- };
123
- }
124
-
125
- async function waitFor(
126
- predicate: () => boolean,
127
- timeoutMs = 2_000
128
- ): Promise<void> {
129
- const deadline = Date.now() + timeoutMs;
130
- while (!predicate()) {
131
- if (Date.now() > deadline) {
132
- throw new Error("waitFor timed out");
133
- }
134
- await new Promise((resolve) => setTimeout(resolve, 10));
135
- }
136
- }
137
-
138
- describe("formatCursorSlackEventLog", () => {
139
- it("names the agent, match kind, and thread", () => {
140
- expect(
141
- formatCursorSlackEventLog({
142
- eventName: "app_mention",
143
- agentName: "Benny",
144
- matchedBy: "name",
145
- channelId: "C0100",
146
- threadTs: "111.222",
147
- receivedAtMs: Date.parse("2026-07-14T16:00:00.000Z"),
148
- eventId: "Ev1",
149
- })
150
- ).toBe(
151
- "app_mention → Benny (name) in C0100/111.222 received=2026-07-14T16:00:00.000Z (Ev1)"
152
- );
153
- });
154
- });
155
-
156
- describe("createCursorSlackApiCaller", () => {
157
- it("POSTs the method, args, agent name, and consumer id; returns the body", async () => {
158
- const backend = fakeBackend({
159
- apiResponses: { "chat.postMessage": { ok: true, ts: "123.456" } },
160
- });
161
- const call = createCursorSlackApiCaller({
162
- baseUrl: "https://api2.example/",
163
- apiKey: "key_1",
164
- agentName: "Benny",
165
- consumerId: "consumer-1",
166
- fetchImpl: backend.fetchImpl,
167
- });
168
- const result = await call("chat.postMessage", {
169
- channel: "C0100",
170
- markdown_text: "hi",
171
- thread_ts: "111.222",
172
- });
173
- expect(result).toEqual({ ok: true, ts: "123.456" });
174
- expect(backend.requests).toHaveLength(1);
175
- expect(backend.requests[0]).toMatchObject({
176
- method: "POST",
177
- url: "https://api2.example/v0/slack-events/api",
178
- body: {
179
- method: "chat.postMessage",
180
- arguments: {
181
- channel: "C0100",
182
- markdown_text: "hi",
183
- thread_ts: "111.222",
184
- },
185
- agentName: "Benny",
186
- consumerId: "consumer-1",
187
- },
188
- });
189
- });
190
-
191
- it("soft-fails Slack-style when the backend is unreachable", async () => {
192
- const call = createCursorSlackApiCaller({
193
- baseUrl: "https://api2.example",
194
- apiKey: "key_1",
195
- agentName: "Benny",
196
- consumerId: "consumer-1",
197
- fetchImpl: async () => {
198
- throw new Error("ECONNREFUSED");
199
- },
200
- });
201
- expect(await call("chat.postMessage", {})).toEqual({
202
- ok: false,
203
- error: "cursor_backend_unreachable",
204
- });
205
- });
206
- });
207
-
208
- describe("CursorSlackRelay", () => {
209
- let dir: string;
210
- let relay: CursorSlackRelay | undefined;
211
-
212
- afterEach(async () => {
213
- await relay?.stop();
214
- relay = undefined;
215
- if (dir !== undefined) {
216
- await rm(dir, { recursive: true, force: true });
217
- }
218
- });
219
-
220
- async function makeRelay(
221
- backend: ReturnType<typeof fakeBackend>,
222
- options?: {
223
- dispatch?: (e: CursorSlackRelayEvent) => Promise<void>;
224
- logger?: (line: string) => void;
225
- agents?: Array<{ name: string; iconEmoji?: string }>;
226
- }
227
- ): Promise<{ dispatched: CursorSlackRelayEvent[]; consumerId: string }> {
228
- const dispatched: CursorSlackRelayEvent[] = [];
229
- relay = new CursorSlackRelay({
230
- baseUrl: "https://api2.example",
231
- apiKey: "key",
232
- agents: options?.agents ?? [{ name: "Benny", iconEmoji: ":robot:" }],
233
- stateDir: dir,
234
- dispatch:
235
- options?.dispatch ??
236
- (async (e) => {
237
- dispatched.push(e);
238
- }),
239
- logger: options?.logger ?? (() => {}),
240
- fetchImpl: backend.fetchImpl,
241
- pollWaitMs: 0,
242
- });
243
- const consumerId = await relay.resolveConsumerId();
244
- relay.start();
245
- return { dispatched, consumerId };
246
- }
247
-
248
- it("registers before consuming, anchors, dispatches in order, persists offset + consumer id", async () => {
249
- dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
250
- const store = new RelayOffsetStore(dir);
251
- const backendProbe = fakeBackend({});
252
- // Resolve the consumer id first so the scripted poll can carry it.
253
- const probe = new CursorSlackRelay({
254
- baseUrl: "https://api2.example",
255
- apiKey: "key",
256
- agents: [{ name: "Benny" }],
257
- stateDir: dir,
258
- dispatch: async () => {},
259
- logger: () => {},
260
- fetchImpl: backendProbe.fetchImpl,
261
- });
262
- const consumerId = await probe.resolveConsumerId();
263
-
264
- const backend = fakeBackend({
265
- anchorOffset: "100-0",
266
- polls: [
267
- {
268
- events: [
269
- envelope("101-0", { consumerId }),
270
- envelope("102-0", {
271
- consumerId,
272
- eventName: "message",
273
- matchedBy: "thread",
274
- messageTs: "111.333",
275
- }),
276
- ],
277
- nextOffset: "102-0",
278
- },
279
- ],
280
- });
281
- const { dispatched } = await makeRelay(backend);
282
-
283
- await waitFor(() => dispatched.length === 2);
284
- expect(dispatched.map((e) => e.eventName)).toEqual([
285
- "app_mention",
286
- "message",
287
- ]);
288
- await waitFor(() =>
289
- backend.requests.some((r) => r.url.includes("after=102-0"))
290
- );
291
- await relay?.stop();
292
- relay = undefined;
293
-
294
- expect(await store.load()).toBe("102-0");
295
-
296
- // Consumption is registration-gated: the first request is the PUT.
297
- expect(backend.requests[0]?.method).toBe("PUT");
298
- expect(backend.requests[0]?.body).toMatchObject({
299
- consumerId,
300
- agents: [{ name: "Benny", iconEmoji: ":robot:" }],
301
- });
302
- expect((await readFile(join(dir, "consumer-id"), "utf8")).trim()).toBe(
303
- consumerId
304
- );
305
- });
306
-
307
- it("skips sibling consumers' events and unknown agents but advances the offset", async () => {
308
- dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
309
- const probeBackend = fakeBackend({});
310
- const probe = new CursorSlackRelay({
311
- baseUrl: "https://api2.example",
312
- apiKey: "key",
313
- agents: [{ name: "Benny" }],
314
- stateDir: dir,
315
- dispatch: async () => {},
316
- logger: () => {},
317
- fetchImpl: probeBackend.fetchImpl,
318
- });
319
- const consumerId = await probe.resolveConsumerId();
320
-
321
- const backend = fakeBackend({
322
- anchorOffset: "0-1",
323
- polls: [
324
- {
325
- events: [
326
- // Another host (consumer) on the same principal stream.
327
- envelope("1-0", { consumerId: "other-host" }),
328
- // Our consumer id but an agent we did not register.
329
- envelope("2-0", { consumerId, agentName: "Stranger" }),
330
- // Ours.
331
- envelope("3-0", { consumerId }),
332
- ],
333
- nextOffset: "3-0",
334
- },
335
- ],
336
- });
337
- const { dispatched } = await makeRelay(backend);
338
-
339
- await waitFor(() => dispatched.length === 1);
340
- expect(dispatched[0]?.offset).toBe("3-0");
341
- await relay?.stop();
342
- relay = undefined;
343
- const store = new RelayOffsetStore(dir);
344
- expect(await store.load()).toBe("3-0");
345
- });
346
-
347
- it("deregisters its agents on clean stop", async () => {
348
- dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
349
- const backend = fakeBackend({ anchorOffset: "1-0" });
350
- const { consumerId } = await makeRelay(backend);
351
- await waitFor(() => backend.requests.some((r) => r.method === "GET"));
352
-
353
- await relay?.stop();
354
- relay = undefined;
355
-
356
- const lastPut = backend.requests.filter((r) => r.method === "PUT").at(-1);
357
- expect(lastPut?.body).toEqual({ consumerId, agents: [] });
358
- });
359
-
360
- it("retries registration until it succeeds before any consumption", async () => {
361
- dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
362
- const probeBackend = fakeBackend({});
363
- const probe = new CursorSlackRelay({
364
- baseUrl: "https://api2.example",
365
- apiKey: "key",
366
- agents: [{ name: "Benny" }],
367
- stateDir: dir,
368
- dispatch: async () => {},
369
- logger: () => {},
370
- fetchImpl: probeBackend.fetchImpl,
371
- });
372
- const consumerId = await probe.resolveConsumerId();
373
- const backend = fakeBackend({
374
- anchorOffset: "10-0",
375
- polls: [
376
- { events: [envelope("11-0", { consumerId })], nextOffset: "11-0" },
377
- ],
378
- registrationFailures: 1,
379
- });
380
- const { dispatched } = await makeRelay(backend);
381
-
382
- await waitFor(() => dispatched.length === 1, 10_000);
383
- const firstGetIndex = backend.requests.findIndex((r) => r.method === "GET");
384
- const successfulPutIndex = backend.requests.findIndex(
385
- (r, index) => r.method === "PUT" && index > 0
386
- );
387
- expect(successfulPutIndex).toBeGreaterThan(0);
388
- expect(firstGetIndex).toBeGreaterThan(successfulPutIndex);
389
- });
390
- });
391
-
392
- describe("serve with cursor-account Slack channels", () => {
393
- const savedEnv: Record<string, string | undefined> = {};
394
- let stateRoot: string | undefined;
395
- let handle: AgentServeHandle | undefined;
396
-
397
- const runner: AgentRunner = {
398
- async runTurn() {
399
- return { status: "finished", result: "unused" };
400
- },
401
- };
402
-
403
- function fixture(): AgentProject {
404
- return {
405
- rootDir: "/tmp/cursor-slack-fixture",
406
- agentDir: "/tmp/cursor-slack-fixture/agent",
407
- name: "slack-fixture",
408
- agent: {
409
- name: "slack-fixture",
410
- runtime: "local",
411
- tools: [],
412
- skills: [],
413
- connections: [],
414
- subagents: [],
415
- seedFiles: [],
416
- },
417
- httpChannel: httpChannel(),
418
- channels: [
419
- {
420
- id: "slack",
421
- // Same erasure discovery performs when loading authored channels.
422
- definition: slackChannel({
423
- cursorAccount: true,
424
- agentName: "Benny",
425
- }) as unknown as ChannelDefinition,
426
- },
427
- ],
428
- schedules: [],
429
- hooks: [],
430
- abs: [],
431
- diagnostics: [],
432
- };
433
- }
434
-
435
- beforeEach(() => {
436
- for (const key of [
437
- "CURSOR_API_KEY",
438
- "CURSOR_API_BASE_URL",
439
- "AGENT_SERVE_CONFIG_DIR",
440
- ]) {
441
- savedEnv[key] = process.env[key];
442
- delete process.env[key];
443
- }
444
- // No stored login can leak in from the developer's machine.
445
- process.env.AGENT_SERVE_CONFIG_DIR = "/nonexistent-agent-serve-config";
446
- });
447
-
448
- afterEach(async () => {
449
- await handle?.close();
450
- handle = undefined;
451
- if (stateRoot !== undefined) {
452
- await rm(stateRoot, { recursive: true, force: true });
453
- stateRoot = undefined;
454
- }
455
- for (const [key, value] of Object.entries(savedEnv)) {
456
- if (value === undefined) {
457
- delete process.env[key];
458
- } else {
459
- process.env[key] = value;
460
- }
461
- }
462
- });
463
-
464
- it("refuses to serve when the host is not signed in to Cursor", async () => {
465
- const root = await mkdtemp(join(tmpdir(), "agent-serve-cursor-slack-"));
466
- stateRoot = root;
467
- await expect(
468
- startServer([{ slug: "", project: fixture() }], {
469
- port: 0,
470
- stateRoot: root,
471
- playground: false,
472
- runner,
473
- })
474
- ).rejects.toThrow(
475
- /cursorAccount: true[\s\S]*signed in to Cursor[\s\S]*agentkit login/
476
- );
477
- });
478
-
479
- it("starts the relay when a credential is present", async () => {
480
- const root = await mkdtemp(join(tmpdir(), "agent-serve-cursor-slack-"));
481
- stateRoot = root;
482
- process.env.CURSOR_API_KEY = "crsr_env";
483
- // Point at a closed local port so the background relay fails fast and
484
- // hermetically instead of reaching the real backend.
485
- process.env.CURSOR_API_BASE_URL = "http://127.0.0.1:9";
486
- const logs: string[] = [];
487
- handle = await startServer([{ slug: "", project: fixture() }], {
488
- port: 0,
489
- stateRoot: root,
490
- playground: false,
491
- runner,
492
- logger: (line) => logs.push(line),
493
- });
494
- expect(
495
- logs.some(
496
- (line) =>
497
- line.includes("cursor-slack: relaying Slack for") &&
498
- line.includes("Benny")
499
- )
500
- ).toBe(true);
501
- });
502
-
503
- it("rejects duplicate registered agent names across mounts", async () => {
504
- const root = await mkdtemp(join(tmpdir(), "agent-serve-cursor-slack-"));
505
- stateRoot = root;
506
- process.env.CURSOR_API_KEY = "crsr_env";
507
- process.env.CURSOR_API_BASE_URL = "http://127.0.0.1:9";
508
- const projectA = fixture();
509
- const projectB = fixture();
510
- await expect(
511
- startServer(
512
- [
513
- { slug: "a", project: projectA },
514
- { slug: "b", project: projectB },
515
- ],
516
- {
517
- port: 0,
518
- stateRoot: root,
519
- playground: false,
520
- runner,
521
- }
522
- )
523
- ).rejects.toThrow(/register the Slack name "Benny"/);
524
- });
525
- });
@@ -1,111 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- agentPathRelativeToGitRoot,
4
- type GitRunner,
5
- httpsGitRepoUrlFromRemote,
6
- inferDeployGitSource,
7
- } from "./deploy-source.js";
8
-
9
- describe("httpsGitRepoUrlFromRemote", () => {
10
- it("normalizes https, ssh, and git@ remotes", () => {
11
- expect(
12
- httpsGitRepoUrlFromRemote("https://github.com/acme/agents.git")
13
- ).toBe("https://github.com/acme/agents");
14
- expect(httpsGitRepoUrlFromRemote("git@github.com:acme/agents.git")).toBe(
15
- "https://github.com/acme/agents"
16
- );
17
- expect(
18
- httpsGitRepoUrlFromRemote("ssh://git@github.com/acme/agents.git")
19
- ).toBe("https://github.com/acme/agents");
20
- expect(
21
- httpsGitRepoUrlFromRemote("ssh://git@github.com:22/acme/agents.git")
22
- ).toBe("https://github.com/acme/agents");
23
- });
24
-
25
- it("normalizes GitHub org-scoped SSH remotes (org-NNNN@github.com:…)", () => {
26
- expect(
27
- httpsGitRepoUrlFromRemote(
28
- "org-96667180@github.com:anysphere/everysphere.git"
29
- )
30
- ).toBe("https://github.com/anysphere/everysphere");
31
- });
32
-
33
- it("rejects unusable remotes", () => {
34
- expect(httpsGitRepoUrlFromRemote("")).toBeUndefined();
35
- expect(httpsGitRepoUrlFromRemote("not-a-url")).toBeUndefined();
36
- expect(httpsGitRepoUrlFromRemote("https://github.com/")).toBeUndefined();
37
- });
38
- });
39
-
40
- describe("agentPathRelativeToGitRoot", () => {
41
- it("returns a posix-relative path for nested dirs and omits the root", () => {
42
- expect(
43
- agentPathRelativeToGitRoot(
44
- "/repo/packages/agent-serve/examples/approval-buddy",
45
- "/repo"
46
- )
47
- ).toBe("packages/agent-serve/examples/approval-buddy");
48
- expect(agentPathRelativeToGitRoot("/repo", "/repo")).toBeUndefined();
49
- });
50
-
51
- it("returns undefined when dir is outside the repo", () => {
52
- expect(
53
- agentPathRelativeToGitRoot("/elsewhere/agent", "/repo")
54
- ).toBeUndefined();
55
- });
56
- });
57
-
58
- describe("inferDeployGitSource", () => {
59
- it("assembles repo, ref, and path from git probes", async () => {
60
- const git: GitRunner = async (args) => {
61
- const key = args.join(" ");
62
- switch (key) {
63
- case "rev-parse --show-toplevel":
64
- return "/repo";
65
- case "remote get-url origin":
66
- return "git@github.com:acme/agents.git";
67
- case "rev-parse --abbrev-ref HEAD":
68
- return "main";
69
- default:
70
- return undefined;
71
- }
72
- };
73
- await expect(
74
- inferDeployGitSource("/repo/examples/weather-agent", { git })
75
- ).resolves.toEqual({
76
- gitRepoUrl: "https://github.com/acme/agents",
77
- gitRef: "main",
78
- agentPath: "examples/weather-agent",
79
- });
80
- });
81
-
82
- it("pins a detached HEAD to the commit SHA", async () => {
83
- const git: GitRunner = async (args) => {
84
- const key = args.join(" ");
85
- switch (key) {
86
- case "rev-parse --show-toplevel":
87
- return "/repo";
88
- case "remote get-url origin":
89
- return "https://github.com/acme/agents.git";
90
- case "rev-parse --abbrev-ref HEAD":
91
- return "HEAD";
92
- case "rev-parse HEAD":
93
- return "abcdef0123456789";
94
- default:
95
- return undefined;
96
- }
97
- };
98
- await expect(inferDeployGitSource("/repo", { git })).resolves.toEqual({
99
- gitRepoUrl: "https://github.com/acme/agents",
100
- gitRef: "abcdef0123456789",
101
- agentPath: undefined,
102
- });
103
- });
104
-
105
- it("returns empty when not inside a git checkout", async () => {
106
- const git: GitRunner = async () => undefined;
107
- await expect(inferDeployGitSource("/tmp/agent", { git })).resolves.toEqual(
108
- {}
109
- );
110
- });
111
- });