@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,213 +0,0 @@
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
- });
@@ -1,179 +0,0 @@
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
- }
@@ -1,82 +0,0 @@
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
- });
@@ -1,126 +0,0 @@
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
- });