@cursor/july 0.1.22 → 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 (219) hide show
  1. package/README.md +5 -5
  2. package/dist/bin/agent-serve.d.ts +1 -0
  3. package/dist/bin/agent-serve.d.ts.map +1 -1
  4. package/dist/bin/agent-serve.js +21 -3
  5. package/dist/docs/404.html +2 -2
  6. package/dist/docs/ab.html +3 -3
  7. package/dist/docs/assets/{app.BKNKMLp4.js → app.CvSGaAxk.js} +1 -1
  8. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
  9. package/dist/docs/assets/chunks/{VPLocalSearchBox.sOSfEZR6.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
  10. package/dist/docs/assets/chunks/{theme.BvCHT5lj.js → theme.C7vfzr7h.js} +2 -2
  11. package/dist/docs/assets/index.md.Dfv5ic9t.js +20 -0
  12. package/dist/docs/assets/{index.md.t0TM2Qzz.lean.js → index.md.Dfv5ic9t.lean.js} +1 -1
  13. package/dist/docs/assets/{reference_cli.md.DnYfr5V2.js → reference_cli.md.ccoKOoXt.js} +4 -3
  14. package/dist/docs/assets/{reference_cli.md.DnYfr5V2.lean.js → reference_cli.md.ccoKOoXt.lean.js} +1 -1
  15. package/dist/docs/building-with-agents.html +3 -3
  16. package/dist/docs/concepts.html +3 -3
  17. package/dist/docs/deployment.html +3 -3
  18. package/dist/docs/evals.html +3 -3
  19. package/dist/docs/example-agents/approval-buddy.html +3 -3
  20. package/dist/docs/example-agents/benny.html +3 -3
  21. package/dist/docs/example-agents/bugbot.html +3 -3
  22. package/dist/docs/example-agents/codebase-wiki.html +3 -3
  23. package/dist/docs/example-agents/codeowners-review.html +3 -3
  24. package/dist/docs/example-agents/concierge.html +3 -3
  25. package/dist/docs/example-agents/fsd.html +3 -3
  26. package/dist/docs/example-agents/index.html +3 -3
  27. package/dist/docs/example-agents/knowledge-base.html +3 -3
  28. package/dist/docs/example-agents/oncall.html +3 -3
  29. package/dist/docs/example-agents/security-reviewer.html +3 -3
  30. package/dist/docs/example-agents/slack-agent.html +3 -3
  31. package/dist/docs/example-agents/weather-agent.html +3 -3
  32. package/dist/docs/guides/agent-to-agent.html +3 -3
  33. package/dist/docs/guides/cloud-runtime.html +3 -3
  34. package/dist/docs/guides/github.html +3 -3
  35. package/dist/docs/guides/human-in-the-loop.html +3 -3
  36. package/dist/docs/guides/mcp-oauth.html +3 -3
  37. package/dist/docs/guides/slack.html +3 -3
  38. package/dist/docs/guides/webhooks.html +3 -3
  39. package/dist/docs/hashmap.json +1 -1
  40. package/dist/docs/hillclimbing.html +3 -3
  41. package/dist/docs/index.html +6 -6
  42. package/dist/docs/quickstart.html +3 -3
  43. package/dist/docs/reference/agent-config.html +3 -3
  44. package/dist/docs/reference/channels.html +3 -3
  45. package/dist/docs/reference/cli.html +7 -6
  46. package/dist/docs/reference/connections.html +3 -3
  47. package/dist/docs/reference/hooks.html +3 -3
  48. package/dist/docs/reference/http-api.html +3 -3
  49. package/dist/docs/reference/instructions.html +3 -3
  50. package/dist/docs/reference/playground.html +3 -3
  51. package/dist/docs/reference/project-layout.html +3 -3
  52. package/dist/docs/reference/prompt.html +3 -3
  53. package/dist/docs/reference/schedules.html +3 -3
  54. package/dist/docs/reference/sessions.html +3 -3
  55. package/dist/docs/reference/skills.html +3 -3
  56. package/dist/docs/reference/subagents.html +3 -3
  57. package/dist/docs/reference/tools.html +3 -3
  58. package/dist/docs/scaffolding-agents.html +3 -3
  59. package/dist/docs/storage.html +3 -3
  60. package/dist/docs/troubleshooting.html +3 -3
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +1 -0
  64. package/dist/internal/cli-docs.d.ts +34 -0
  65. package/dist/internal/cli-docs.d.ts.map +1 -0
  66. package/dist/internal/cli-docs.js +162 -0
  67. package/dist/internal/distribution.d.ts +2 -1
  68. package/dist/internal/distribution.d.ts.map +1 -1
  69. package/dist/internal/distribution.js +3 -1
  70. package/dist/internal/docs-site.d.ts +4 -2
  71. package/dist/internal/docs-site.d.ts.map +1 -1
  72. package/dist/internal/docs-site.js +15 -11
  73. package/dist/internal/init-project.d.ts.map +1 -1
  74. package/dist/internal/init-project.js +19 -0
  75. package/dist/internal/session-engine.d.ts.map +1 -1
  76. package/dist/internal/session-engine.js +5 -0
  77. package/dist/internal/workspace.d.ts +9 -0
  78. package/dist/internal/workspace.d.ts.map +1 -1
  79. package/dist/internal/workspace.js +52 -5
  80. package/dist/memory.d.ts +79 -0
  81. package/dist/memory.d.ts.map +1 -0
  82. package/dist/memory.js +164 -0
  83. package/dist/playground/assets/index-CidizGZv.css +1 -0
  84. package/dist/playground/assets/index-DTG9OsPV.js +85 -0
  85. package/dist/playground/index.html +2 -2
  86. package/dist/types.d.ts +11 -0
  87. package/dist/types.d.ts.map +1 -1
  88. package/docs/README.md +8 -1
  89. package/docs/reference/cli.md +20 -4
  90. package/package.json +32 -24
  91. package/src/bin/agent-serve.ts +23 -3
  92. package/src/index.ts +2 -0
  93. package/src/internal/cli-docs.ts +191 -0
  94. package/src/internal/distribution.ts +3 -1
  95. package/src/internal/docs-site.ts +19 -11
  96. package/src/internal/init-project.ts +22 -0
  97. package/src/internal/session-engine.ts +5 -0
  98. package/src/internal/workspace.ts +81 -5
  99. package/src/memory.ts +215 -0
  100. package/src/types.ts +11 -0
  101. package/dist/channels/github/instrument.d.ts +0 -20
  102. package/dist/channels/github/instrument.d.ts.map +0 -1
  103. package/dist/docs/assets/chunks/@localSearchIndexroot.YFE6WoMB.js +0 -1
  104. package/dist/docs/assets/index.md.t0TM2Qzz.js +0 -20
  105. package/dist/internal/json-dir-store.d.ts +0 -32
  106. package/dist/internal/json-dir-store.d.ts.map +0 -1
  107. package/dist/internal/json-dir-store.js +0 -100
  108. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  109. package/dist/playground/assets/index-dshZQJCp.js +0 -85
  110. package/src/bin/agent-serve.version.test.ts +0 -62
  111. package/src/channels/github/api.test.ts +0 -64
  112. package/src/channels/github/auth.test.ts +0 -105
  113. package/src/channels/github/cursor-account.test.ts +0 -204
  114. package/src/channels/github/forward.test.ts +0 -457
  115. package/src/channels/github/github.test.ts +0 -937
  116. package/src/channels/github/replay.test.ts +0 -179
  117. package/src/channels/slack/api.post-message.test.ts +0 -148
  118. package/src/channels/slack/approvals.test.ts +0 -328
  119. package/src/channels/slack/block-actions.test.ts +0 -452
  120. package/src/channels/slack/bot-mentions.test.ts +0 -267
  121. package/src/channels/slack/channel-watch.test.ts +0 -363
  122. package/src/channels/slack/cursor-account.test.ts +0 -253
  123. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  124. package/src/channels/slack/dispatch.test.ts +0 -795
  125. package/src/channels/slack/eval-directive.test.ts +0 -273
  126. package/src/channels/slack/message-body.test.ts +0 -54
  127. package/src/channels/slack/nudge-store.test.ts +0 -143
  128. package/src/channels/slack/slack.test.ts +0 -391
  129. package/src/channels/slack/stop.test.ts +0 -23
  130. package/src/channels/slack/thread-context.test.ts +0 -202
  131. package/src/evals/assertions.test.ts +0 -580
  132. package/src/evals/expect.test.ts +0 -144
  133. package/src/evals/judge.test.ts +0 -181
  134. package/src/evals/loaders.test.ts +0 -132
  135. package/src/evals/matchers.test.ts +0 -95
  136. package/src/evals/reporters.test.ts +0 -303
  137. package/src/evals/run-facts.test.ts +0 -259
  138. package/src/internal/ab-snapshot.test.ts +0 -325
  139. package/src/internal/approval-gate.test.ts +0 -49
  140. package/src/internal/approvals.integration.test.ts +0 -383
  141. package/src/internal/authored-loaders.test.ts +0 -31
  142. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  143. package/src/internal/channel-route-schema.test.ts +0 -294
  144. package/src/internal/chat-attach.test.ts +0 -262
  145. package/src/internal/cli-deploy.test.ts +0 -1991
  146. package/src/internal/cli-mcp.test.ts +0 -789
  147. package/src/internal/cli-skills.test.ts +0 -133
  148. package/src/internal/cli-slack.test.ts +0 -1647
  149. package/src/internal/cloud-merge.test.ts +0 -74
  150. package/src/internal/cron.test.ts +0 -22
  151. package/src/internal/cursor/account-mcp.test.ts +0 -807
  152. package/src/internal/cursor/backend-client.test.ts +0 -591
  153. package/src/internal/cursor/credentials.test.ts +0 -351
  154. package/src/internal/cursor/github-credentials.test.ts +0 -136
  155. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  156. package/src/internal/cursor-account.integration.test.ts +0 -441
  157. package/src/internal/cursor-event-relay.test.ts +0 -746
  158. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  159. package/src/internal/cursor-slack-relay.test.ts +0 -525
  160. package/src/internal/deploy-source.test.ts +0 -111
  161. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  162. package/src/internal/discovery.concurrency.test.ts +0 -60
  163. package/src/internal/discovery.cursor-account.test.ts +0 -133
  164. package/src/internal/discovery.cwd.test.ts +0 -83
  165. package/src/internal/discovery.hosting.test.ts +0 -80
  166. package/src/internal/discovery.identity.test.ts +0 -44
  167. package/src/internal/docs-site.test.ts +0 -66
  168. package/src/internal/duration.test.ts +0 -29
  169. package/src/internal/eval-judge-model.test.ts +0 -187
  170. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  171. package/src/internal/eval-run-store.storage.test.ts +0 -211
  172. package/src/internal/eval-runner.http.test.ts +0 -403
  173. package/src/internal/eval-runner.run.test.ts +0 -928
  174. package/src/internal/evals-client.test.ts +0 -307
  175. package/src/internal/event-mapper.test.ts +0 -243
  176. package/src/internal/github-fanout.test.ts +0 -213
  177. package/src/internal/handleAgentServeTrigger.test.ts +0 -179
  178. package/src/internal/host-kv.test.ts +0 -82
  179. package/src/internal/host-platforms.test.ts +0 -126
  180. package/src/internal/http-channel.test.ts +0 -402
  181. package/src/internal/init-project.test.ts +0 -269
  182. package/src/internal/install-cursor-skills.test.ts +0 -262
  183. package/src/internal/local-env.test.ts +0 -120
  184. package/src/internal/log-ring.test.ts +0 -31
  185. package/src/internal/logs-client.test.ts +0 -350
  186. package/src/internal/mcp-endpoint.test.ts +0 -436
  187. package/src/internal/mcp-host.test.ts +0 -298
  188. package/src/internal/mcp-oauth.test.ts +0 -148
  189. package/src/internal/net.test.ts +0 -17
  190. package/src/internal/peer-connections.test.ts +0 -128
  191. package/src/internal/peer-mcp.integration.test.ts +0 -289
  192. package/src/internal/playground/toolchain.test.ts +0 -53
  193. package/src/internal/playground-cli.test.ts +0 -187
  194. package/src/internal/playground-proxy.test.ts +0 -376
  195. package/src/internal/prompt-context.integration.test.ts +0 -232
  196. package/src/internal/prompt-context.test.ts +0 -127
  197. package/src/internal/reminder-runner.test.ts +0 -390
  198. package/src/internal/reminder-store.test.ts +0 -53
  199. package/src/internal/request-headers.test.ts +0 -27
  200. package/src/internal/resolve-prod-target.test.ts +0 -787
  201. package/src/internal/resolved-connections.test.ts +0 -295
  202. package/src/internal/router.test.ts +0 -57
  203. package/src/internal/sdk-runner.test.ts +0 -290
  204. package/src/internal/session-engine.coalesce.test.ts +0 -169
  205. package/src/internal/session-engine.concurrency.test.ts +0 -250
  206. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  207. package/src/internal/session-engine.interrupt.test.ts +0 -577
  208. package/src/internal/session-engine.storage.test.ts +0 -547
  209. package/src/internal/session-urls.test.ts +0 -28
  210. package/src/internal/sessions-client.test.ts +0 -518
  211. package/src/internal/storage-coordinator.test.ts +0 -517
  212. package/src/internal/tool-call.test.ts +0 -458
  213. package/src/internal/tool-result.test.ts +0 -52
  214. package/src/internal/trajectory.approvals.test.ts +0 -83
  215. package/src/internal/trajectory.subagents.test.ts +0 -198
  216. package/src/internal/turn-governor.test.ts +0 -137
  217. package/src/internal/update-check.test.ts +0 -485
  218. package/src/internal/workspace.test.ts +0 -81
  219. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,457 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
- import { setDevMode } from "../../internal/dev-mode.js";
3
- import type { AgentProject, DiscoveredChannel } from "../../types.js";
4
- import { deriveGitHubWebhookEvents, GITHUB_CHANNEL_KIND } from "./events.js";
5
- import {
6
- type AgentMountLike,
7
- buildGitHubForwardArgs,
8
- channelForwardUrl,
9
- detectGitHubEnvTokenOverride,
10
- findGitHubChannelTargets,
11
- GITHUB_WEBHOOK_EXTENSION_PIN,
12
- ghWebhookExtensionInstallArgs,
13
- ghWebhookExtensionPinSatisfied,
14
- parseGhWebhookExtensionInstalled,
15
- parseGhWebhookExtensionVersion,
16
- parseRepoFromRemoteUrl,
17
- resolveGitHubForwardTargets,
18
- unionForwardEvents,
19
- } from "./forward.js";
20
- import { githubChannel } from "./github-channel.js";
21
-
22
- describe("deriveGitHubWebhookEvents", () => {
23
- it("returns the base set for a hookless channel", () => {
24
- expect(deriveGitHubWebhookEvents({})).toEqual([
25
- "pull_request",
26
- "issue_comment",
27
- "pull_request_review_comment",
28
- ]);
29
- });
30
-
31
- it("adds an event per declared typed hook", () => {
32
- const events = deriveGitHubWebhookEvents({
33
- onCheckSuite: () => null,
34
- onStatus: () => null,
35
- });
36
- expect(events).toContain("check_suite");
37
- expect(events).toContain("status");
38
- expect(events).not.toContain("check_run");
39
- });
40
-
41
- it("adds the review catch-all events when onEvent is declared", () => {
42
- const events = deriveGitHubWebhookEvents({ onEvent: () => null });
43
- expect(events).toContain("pull_request_review");
44
- expect(events).toContain("pull_request_review_thread");
45
- });
46
-
47
- it("treats webhookEvents as authoritative (deduped)", () => {
48
- expect(
49
- deriveGitHubWebhookEvents({
50
- webhookEvents: ["pull_request", "pull_request", " status "],
51
- onCheckRun: () => null,
52
- })
53
- ).toEqual(["pull_request", "status"]);
54
- });
55
- });
56
-
57
- describe("githubChannel meta", () => {
58
- it("publishes the github kind and derived events", () => {
59
- const channel = githubChannel({ onCheckRun: () => null });
60
- expect(channel.meta?.kind).toBe(GITHUB_CHANNEL_KIND);
61
- expect(channel.meta?.githubWebhookEvents).toContain("check_run");
62
- });
63
-
64
- it("honors an explicit webhookEvents pin", () => {
65
- const channel = githubChannel({ webhookEvents: ["pull_request"] });
66
- expect(channel.meta?.githubWebhookEvents).toEqual(["pull_request"]);
67
- });
68
- });
69
-
70
- describe("githubChannel dev auth default", () => {
71
- const savedWebhookSecret = process.env.GITHUB_WEBHOOK_SECRET;
72
- beforeEach(() => {
73
- delete process.env.GITHUB_WEBHOOK_SECRET;
74
- });
75
- afterEach(() => {
76
- setDevMode(false);
77
- if (savedWebhookSecret === undefined) {
78
- delete process.env.GITHUB_WEBHOOK_SECRET;
79
- } else {
80
- process.env.GITHUB_WEBHOOK_SECRET = savedWebhookSecret;
81
- }
82
- });
83
- const forwarded = new Request("http://example.com/hook");
84
- const nonLoopback = { requestIp: "203.0.113.4" };
85
- const loopback = { requestIp: "127.0.0.1" };
86
-
87
- it("admits loopback deliveries in dev without a secret", async () => {
88
- setDevMode(true);
89
- const policy = githubChannel().auth?.[0];
90
- expect(
91
- await policy?.(new Request("http://127.0.0.1/hook"), loopback)
92
- ).not.toBeNull();
93
- });
94
-
95
- it("admits loopback deliveries carrying gh forwarding headers in dev", async () => {
96
- // `gh webhook forward` relays GitHub's edge X-Forwarded-For / X-Real-Ip;
97
- // dev auth must admit them from a loopback peer (localDev/localDevStrict
98
- // would reject on those headers and break forwarding).
99
- setDevMode(true);
100
- const policy = githubChannel().auth?.[0];
101
- const ghForwarded = new Request("http://127.0.0.1/hook", {
102
- headers: {
103
- "x-github-event": "pull_request",
104
- "x-forwarded-for": "140.82.115.1",
105
- "x-real-ip": "140.82.115.1",
106
- },
107
- });
108
- expect(await policy?.(ghForwarded, loopback)).not.toBeNull();
109
- });
110
-
111
- it("rejects loopback tunneled traffic with forwarding headers but no GitHub delivery headers in dev", async () => {
112
- setDevMode(true);
113
- const policy = githubChannel().auth?.[0];
114
- const tunneled = new Request("http://127.0.0.1/hook", {
115
- headers: {
116
- "x-forwarded-for": "203.0.113.4",
117
- "x-real-ip": "203.0.113.4",
118
- },
119
- });
120
- expect(await policy?.(tunneled, loopback)).toBeNull();
121
- });
122
-
123
- it("rejects non-loopback deliveries in dev without a secret", async () => {
124
- setDevMode(true);
125
- const policy = githubChannel().auth?.[0];
126
- expect(await policy?.(forwarded, nonLoopback)).toBeNull();
127
- });
128
-
129
- it("stays loopback-strict outside dev without a secret", async () => {
130
- setDevMode(false);
131
- const policy = githubChannel().auth?.[0];
132
- expect(await policy?.(forwarded, nonLoopback)).toBeNull();
133
- });
134
-
135
- it("re-evaluates isDevMode per request on a cached channel definition", async () => {
136
- // Channel modules call githubChannel() once at import; flipping --dev
137
- // later must still change auth behavior for the same policy closure.
138
- setDevMode(false);
139
- const policy = githubChannel().auth?.[0];
140
- const ghForwarded = new Request("http://127.0.0.1/hook", {
141
- headers: {
142
- "x-github-event": "pull_request",
143
- "x-forwarded-for": "140.82.115.1",
144
- "x-real-ip": "140.82.115.1",
145
- },
146
- });
147
- // Outside --dev, localDevStrict rejects proxy-forwarded headers.
148
- expect(await policy?.(ghForwarded, loopback)).toBeNull();
149
- setDevMode(true);
150
- // In --dev, loopbackGitHubDev admits gh webhook forward deliveries.
151
- expect(await policy?.(ghForwarded, loopback)).not.toBeNull();
152
- });
153
- });
154
-
155
- describe("findGitHubChannelTargets", () => {
156
- it("collects github channels across mounts and ignores others", () => {
157
- const mounts: AgentMountLike[] = [
158
- mount("fsd", [
159
- channel("github", githubChannel({ onCheckSuite: () => null })),
160
- channel("drive", { __agentServe: "channel", routes: [] }),
161
- ]),
162
- mount("reviewer", [
163
- channel(
164
- "github",
165
- githubChannel({ webhookEvents: ["pull_request"], path: "/hook" })
166
- ),
167
- ]),
168
- ];
169
-
170
- const targets = findGitHubChannelTargets(mounts);
171
- expect(targets).toHaveLength(2);
172
- expect(targets[0]).toMatchObject({
173
- slug: "fsd",
174
- channelId: "github",
175
- routePath: "/",
176
- });
177
- expect(targets[0]?.events).toContain("check_suite");
178
- expect(targets[1]).toMatchObject({
179
- slug: "reviewer",
180
- channelId: "github",
181
- routePath: "/hook",
182
- events: ["pull_request"],
183
- });
184
- });
185
- });
186
-
187
- describe("channelForwardUrl", () => {
188
- it("omits the slug prefix and the default path", () => {
189
- expect(
190
- channelForwardUrl({
191
- host: "127.0.0.1",
192
- port: 3000,
193
- slug: "",
194
- channelId: "github",
195
- routePath: "/",
196
- })
197
- ).toBe("http://127.0.0.1:3000/v1/channels/github");
198
- });
199
-
200
- it("includes the slug and a custom path", () => {
201
- expect(
202
- channelForwardUrl({
203
- host: "localhost",
204
- port: 4000,
205
- slug: "fsd",
206
- channelId: "github",
207
- routePath: "/hook",
208
- })
209
- ).toBe("http://localhost:4000/fsd/v1/channels/github/hook");
210
- });
211
- });
212
-
213
- describe("resolveGitHubForwardTargets", () => {
214
- const target = {
215
- slug: "fsd",
216
- channelId: "github",
217
- routePath: "/",
218
- events: ["pull_request", "check_run"],
219
- };
220
-
221
- it("derives the url and events from a single target", () => {
222
- const result = resolveGitHubForwardTargets({
223
- targets: [target],
224
- host: "127.0.0.1",
225
- port: 3000,
226
- });
227
- expect(result).toEqual({
228
- ok: true,
229
- targets: [
230
- {
231
- slug: "fsd",
232
- channelId: "github",
233
- url: "http://127.0.0.1:3000/fsd/v1/channels/github",
234
- events: ["pull_request", "check_run"],
235
- },
236
- ],
237
- });
238
- });
239
-
240
- it("returns every matching channel for fan-out", () => {
241
- const reviewer = {
242
- slug: "reviewer",
243
- channelId: "github",
244
- routePath: "/",
245
- events: ["pull_request"],
246
- };
247
- const result = resolveGitHubForwardTargets({
248
- targets: [target, reviewer],
249
- host: "127.0.0.1",
250
- port: 3000,
251
- });
252
- expect(result.ok && result.targets.map((t) => t.slug)).toEqual([
253
- "fsd",
254
- "reviewer",
255
- ]);
256
- expect(result.ok && unionForwardEvents(result.targets)).toEqual([
257
- "pull_request",
258
- "check_run",
259
- ]);
260
- });
261
-
262
- it("applies an explicit event override to all targets", () => {
263
- const result = resolveGitHubForwardTargets({
264
- targets: [target, { ...target, slug: "reviewer" }],
265
- host: "127.0.0.1",
266
- port: 3000,
267
- events: ["issues"],
268
- });
269
- expect(result.ok && result.targets.map((t) => t.events)).toEqual([
270
- ["issues"],
271
- ["issues"],
272
- ]);
273
- });
274
-
275
- it("narrows by slug and channel", () => {
276
- const other = { ...target, slug: "reviewer", channelId: "gh2" };
277
- const result = resolveGitHubForwardTargets({
278
- targets: [target, other],
279
- slug: "reviewer",
280
- channel: "gh2",
281
- host: "127.0.0.1",
282
- port: 3000,
283
- });
284
- expect(result.ok && result.targets).toHaveLength(1);
285
- expect(result.ok && result.targets[0]?.channelId).toBe("gh2");
286
- });
287
-
288
- it("uses an explicit url with a single target's events", () => {
289
- const result = resolveGitHubForwardTargets({
290
- targets: [target],
291
- host: "127.0.0.1",
292
- port: 3000,
293
- url: "https://example.ngrok.app/hook",
294
- });
295
- expect(result.ok && result.targets[0]?.url).toBe(
296
- "https://example.ngrok.app/hook"
297
- );
298
- expect(result.ok && result.targets[0]?.events).toEqual([
299
- "pull_request",
300
- "check_run",
301
- ]);
302
- });
303
-
304
- it("rejects --url when several channels match", () => {
305
- const result = resolveGitHubForwardTargets({
306
- targets: [target, { ...target, slug: "reviewer" }],
307
- host: "127.0.0.1",
308
- port: 3000,
309
- url: "https://example.ngrok.app/hook",
310
- });
311
- expect(result.ok).toBe(false);
312
- });
313
-
314
- it("requires --events for --url when no single target matches", () => {
315
- const result = resolveGitHubForwardTargets({
316
- targets: [],
317
- host: "127.0.0.1",
318
- port: 3000,
319
- url: "https://example.ngrok.app/hook",
320
- });
321
- expect(result.ok).toBe(false);
322
- });
323
-
324
- it("errors when no github channel exists", () => {
325
- const result = resolveGitHubForwardTargets({
326
- targets: [],
327
- host: "127.0.0.1",
328
- port: 3000,
329
- });
330
- expect(result.ok).toBe(false);
331
- expect(!result.ok && result.error).toContain("no GitHub channel found");
332
- });
333
- });
334
-
335
- describe("buildGitHubForwardArgs", () => {
336
- it("builds repo + events + url args", () => {
337
- expect(
338
- buildGitHubForwardArgs({
339
- url: "http://127.0.0.1:3000/v1/channels/github",
340
- events: ["pull_request", "issue_comment"],
341
- repo: "acme/widgets",
342
- })
343
- ).toEqual([
344
- "webhook",
345
- "forward",
346
- "--url=http://127.0.0.1:3000/v1/channels/github",
347
- "--events=pull_request,issue_comment",
348
- "--repo=acme/widgets",
349
- ]);
350
- });
351
-
352
- it("supports org + secret and dedupes events", () => {
353
- const args = buildGitHubForwardArgs({
354
- url: "http://127.0.0.1:3000/v1/channels/github",
355
- events: ["pull_request", "pull_request"],
356
- org: "octo-org",
357
- secret: "s3cr3t",
358
- });
359
- expect(args).toContain("--org=octo-org");
360
- expect(args).toContain("--secret=s3cr3t");
361
- expect(args).toContain("--events=pull_request");
362
- });
363
- });
364
-
365
- describe("parseGhWebhookExtensionInstalled", () => {
366
- it("detects the extension in gh extension list output", () => {
367
- expect(
368
- parseGhWebhookExtensionInstalled("gh webhook\tcli/gh-webhook\tv1.0.0\n")
369
- ).toBe(true);
370
- });
371
-
372
- it("returns false when absent", () => {
373
- expect(parseGhWebhookExtensionInstalled("gh dash\tdlvhdr/gh-dash\n")).toBe(
374
- false
375
- );
376
- });
377
- });
378
-
379
- describe("gh webhook extension pin", () => {
380
- const listLine = `gh webhook\tcli/gh-webhook\t${GITHUB_WEBHOOK_EXTENSION_PIN}\n`;
381
-
382
- it("parses the installed version", () => {
383
- expect(parseGhWebhookExtensionVersion(listLine)).toBe(
384
- GITHUB_WEBHOOK_EXTENSION_PIN
385
- );
386
- });
387
-
388
- it("reports pin satisfaction", () => {
389
- expect(ghWebhookExtensionPinSatisfied(listLine)).toBe(true);
390
- expect(
391
- ghWebhookExtensionPinSatisfied("gh webhook\tcli/gh-webhook\tv0.1.0\n")
392
- ).toBe(false);
393
- });
394
-
395
- it("builds pinned install argv", () => {
396
- expect(ghWebhookExtensionInstallArgs()).toEqual([
397
- "extension",
398
- "install",
399
- "cli/gh-webhook",
400
- "--pin",
401
- GITHUB_WEBHOOK_EXTENSION_PIN,
402
- ]);
403
- expect(ghWebhookExtensionInstallArgs({ force: true })).toContain("--force");
404
- });
405
- });
406
-
407
- describe("detectGitHubEnvTokenOverride", () => {
408
- it("flags GITHUB_TOKEN, then GH_TOKEN", () => {
409
- expect(detectGitHubEnvTokenOverride({ GITHUB_TOKEN: "x" })).toBe(
410
- "GITHUB_TOKEN"
411
- );
412
- expect(detectGitHubEnvTokenOverride({ GH_TOKEN: "x" })).toBe("GH_TOKEN");
413
- });
414
-
415
- it("ignores empty/absent tokens", () => {
416
- expect(detectGitHubEnvTokenOverride({})).toBeUndefined();
417
- expect(
418
- detectGitHubEnvTokenOverride({ GITHUB_TOKEN: "", GH_TOKEN: "" })
419
- ).toBeUndefined();
420
- });
421
- });
422
-
423
- describe("parseRepoFromRemoteUrl", () => {
424
- it("parses https, ssh, and git@ remotes", () => {
425
- expect(parseRepoFromRemoteUrl("https://github.com/acme/widgets.git")).toBe(
426
- "acme/widgets"
427
- );
428
- expect(parseRepoFromRemoteUrl("git@github.com:acme/widgets.git")).toBe(
429
- "acme/widgets"
430
- );
431
- expect(parseRepoFromRemoteUrl("ssh://git@github.com/acme/widgets")).toBe(
432
- "acme/widgets"
433
- );
434
- expect(parseRepoFromRemoteUrl("https://github.com/acme/widgets/\n")).toBe(
435
- "acme/widgets"
436
- );
437
- });
438
-
439
- it("returns undefined for unrecognized input", () => {
440
- expect(parseRepoFromRemoteUrl("")).toBeUndefined();
441
- expect(parseRepoFromRemoteUrl("not-a-url")).toBeUndefined();
442
- });
443
- });
444
-
445
- function mount(slug: string, channels: DiscoveredChannel[]): AgentMountLike {
446
- return {
447
- slug,
448
- project: { channels } as unknown as AgentProject,
449
- };
450
- }
451
-
452
- // Discovery erases the channel's state generic (`mod.default as
453
- // ChannelDefinition`); mirror that here so githubChannel()'s typed state
454
- // assigns to DiscoveredChannel.
455
- function channel(id: string, definition: unknown): DiscoveredChannel {
456
- return { id, definition: definition as DiscoveredChannel["definition"] };
457
- }