Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

handlers.test.ts

697 lines24.3 KB

1import {
2 EnvironmentId,
3 ProjectId,
4 ProviderInstanceId,
5 ThreadId,
6 type OrchestrationV2ServerCommand as OrchestrationCommand,
7 PullRequestOperationError,
8 type OrchestrationProjectShell,
9 type PullRequestRef,
10 type PullRequestReviewGuideResult,
11 type ThreadPullRequestLink,
12} from "@t3tools/contracts";
13import { describe, expect, it } from "@effect/vitest";
14import * as Crypto from "effect/Crypto";
15import * as Effect from "effect/Effect";
16import * as Layer from "effect/Layer";
17import * as Option from "effect/Option";
18import * as Ref from "effect/Ref";
19import * as Stream from "effect/Stream";
20import type { Tool } from "effect/ai";
21​
22import * as Orchestrator from "../../../orchestration-v2/Orchestrator.ts";
23import {
24 type PullRequestTestThread,
25 v2PullRequestThread,
26} from "../../../orchestration-v2/testkit/pullRequestFixtures.ts";
27import * as ProjectService from "../../../project/ProjectService.ts";
28import * as PullRequestReviewGuideService from "../../../pullRequest/PullRequestReviewGuideService.ts";
29import * as McpInvocationContext from "../../McpInvocationContext.ts";
30import * as McpToolAccess from "../../McpToolAccess.ts";
31import * as McpToolAccessTestkit from "../../McpToolAccess.testkit.ts";
32import { listThreadPullRequests } from "./handlers.ts";
33import * as PullRequestsHandlers from "./handlers.ts";
34import { PullRequestsToolkit } from "./tools.ts";
35​
36const PROJECT_ID = ProjectId.make("project-1");
37const THREAD_ID = ThreadId.make("thread-1");
38​
39const testCrypto = Crypto.make({
40 randomBytes: (size) => new Uint8Array(size).fill(7),
41 digest: (_algorithm, data) => Effect.succeed(data),
42});
43​
44const invocation = (
45 capabilities: ReadonlyArray<McpInvocationContext.McpCapability>,
46): McpInvocationContext.McpInvocationScope => ({
47 environmentId: EnvironmentId.make("environment-1"),
48 requestNamespace: "provider-session-1",
49 thread: {
50 threadId: THREAD_ID,
51 providerSessionId: "provider-session-1",
52 providerInstanceId: ProviderInstanceId.make("codex"),
53 },
54 client: undefined,
55 capabilities: new Set(capabilities),
56 issuedAt: 1,
57});
58​
59function makeProject(
60 repositoryIdentity: OrchestrationProjectShell["repositoryIdentity"] = {
61 canonicalKey: "github.com/t3tools/t3code",
62 locator: {
63 source: "git-remote",
64 remoteName: "origin",
65 remoteUrl: "git@github.com:T3Tools/T3Code.git",
66 },
67 provider: "github",
68 displayName: "T3Tools/T3Code",
69 owner: "T3Tools",
70 name: "T3Code",
71 },
72): OrchestrationProjectShell {
73 return {
74 id: PROJECT_ID,
75 title: "Project",
76 workspaceRoot: "/workspace/project",
77 defaultModelSelection: null,
78 scripts: [],
79 repositoryIdentity,
80 createdAt: "2026-08-01T00:00:00.000Z",
81 updatedAt: "2026-08-01T00:00:00.000Z",
82 };
84​
85function makeThread(pullRequests: ReadonlyArray<ThreadPullRequestLink>): PullRequestTestThread {
86 return {
87 id: THREAD_ID,
88 projectId: PROJECT_ID,
89 title: "Thread",
90 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5" },
91 runtimeMode: "full-access",
92 interactionMode: "default",
93 branch: null,
94 worktreePath: null,
95 pullRequests,
96 createdAt: "2026-08-01T00:00:00.000Z",
97 updatedAt: "2026-08-20T00:00:00.000Z",
98 archivedAt: null,
99 settledOverride: null,
100 settledAt: null,
101 latestUserMessageAt: "2026-08-20T00:00:00.000Z",
102 };
104​
105function makeLink(
106 number: number,
107 overrides: Partial<ThreadPullRequestLink> & {
108 readonly headBranch?: string;
109 readonly baseBranch?: string;
110 } = {},
111): ThreadPullRequestLink {
112 const { headBranch, baseBranch, ...rest } = overrides;
113 return {
114 host: "github.com",
115 repository: "t3tools/t3code",
116 number,
117 url: `https://github.com/t3tools/t3code/pull/${number}`,
118 source: "manual",
119 linkedAt: "2026-08-10T00:00:00.000Z",
120 snapshot:
121 headBranch === undefined
122 ? null
123 : {
124 state: "open",
125 title: `PR ${number}`,
126 headBranch,
127 baseBranch: baseBranch ?? "main",
128 isDraft: false,
129 updatedAt: null,
130 syncedAt: "2026-08-27T00:00:00.000Z",
131 },
132 stack: null,
133 ...rest,
134 };
136​
137interface HarnessOptions {
138 readonly thread?: PullRequestTestThread | null;
139 readonly project?: OrchestrationProjectShell | null;
140 readonly reject?: (command: OrchestrationCommand) => string | null;
141 readonly projects?: ReadonlyArray<OrchestrationProjectShell>;
142 readonly generate?: (
143 input: PullRequestRef,
144 ) => Effect.Effect<
145 PullRequestReviewGuideResult & { started: boolean },
146 PullRequestOperationError
147 >;
149​
150const NO_GUIDE: PullRequestReviewGuideResult = { guide: null, run: null, currentHeadSha: "head-1" };
151​
152const makeHarness = Effect.fn("makePullRequestsToolkitHarness")(function* (
153 options: HarnessOptions = {},
154) {
155 const commands = yield* Ref.make<ReadonlyArray<OrchestrationCommand>>([]);
156 const guideRequests = yield* Ref.make<ReadonlyArray<PullRequestRef>>([]);
157 const thread = options.thread === undefined ? makeThread([]) : options.thread;
158 const project = options.project === undefined ? makeProject() : options.project;
159 const dispatch: Orchestrator.OrchestratorV2Shape["dispatch"] = (command) =>
160 Effect.gen(function* () {
161 const rejection = options.reject?.(command) ?? null;
162 if (rejection !== null)
163 return yield* new Orchestrator.OrchestratorDispatchError({
164 commandId: command.commandId,
165 commandType: command.type,
166 cause: rejection,
167 });
168 yield* Ref.update(commands, (recorded) => [...recorded, command]);
169 return { sequence: 1, storedEvents: [] };
170 });
171 const layerDependencies = Layer.mergeAll(
172 Layer.mock(ProjectService.ProjectService)({
173 getShell: () => Effect.succeed(Option.fromNullishOr(project)),
174 listShells: () => Effect.succeed(options.projects ?? (project ? [project] : [])),
175 }),
176 Layer.mock(PullRequestReviewGuideService.PullRequestReviewGuideService)({
177 get: () => Effect.succeed(NO_GUIDE),
178 generate: (input) =>
179 Ref.update(guideRequests, (recorded) => [...recorded, input]).pipe(
180 Effect.andThen(
181 options.generate?.(input) ??
182 Effect.succeed({
183 ...NO_GUIDE,
184 run: {
185 _tag: "Running" as const,
186 headSha: "head-1",
187 startedAt: "2026-10-11T00:00:00.000Z",
188 },
189 started: true,
190 }),
191 ),
192 ),
193 }),
194 Layer.mock(Orchestrator.OrchestratorV2)({
195 getThreadShell: (id) =>
196 Effect.succeed(id === THREAD_ID && thread ? v2PullRequestThread(thread) : null),
197 dispatch,
198 }),
199 Layer.succeed(Crypto.Crypto, testCrypto),
200 McpToolAccessTestkit.liveThreadsLayer,
201 );
202 const toolkit = yield* PullRequestsToolkit.pipe(
203 Effect.provide(
204 McpToolAccess.HandlersLayer.layer(PullRequestsHandlers.layer).pipe(
205 Layer.provide(layerDependencies),
206 ),
207 ),
208 );
209 const call = <Name extends keyof typeof PullRequestsToolkit.tools>(
210 name: Name,
211 params: Parameters<typeof toolkit.handle<Name>>[1],
212 capabilities: ReadonlyArray<McpInvocationContext.McpCapability> = ["pull-requests"],
213 ) =>
214 toolkit.handle(name, params).pipe(
215 Stream.unwrap,
216 Stream.runCollect,
217 Effect.map(
218 (chunk) => chunk.at(-1)!.result as Tool.Success<(typeof PullRequestsToolkit.tools)[Name]>,
219 ),
220 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation(capabilities)),
221 Effect.provide(layerDependencies),
222 );
223 return { commands, guideRequests, call };
224});
225​
226describe("pull request toolkit handlers", () => {
227 it.effect("refuses a credential without the pull-requests capability", () =>
228 Effect.gen(function* () {
229 const harness = yield* makeHarness();
230 const error = yield* harness
231 .call("list_thread_pull_requests", {}, ["preview"])
232 .pipe(Effect.flip);
233 expect(error).toMatchObject({
234 _tag: "McpCapabilityUnavailableError",
235 capability: "pull-requests",
236 threadId: THREAD_ID,
237 });
238 expect(yield* Ref.get(harness.commands)).toEqual([]);
239 }),
240 );
241​
242 it.effect("links by URL with source agent on the token's thread", () =>
243 Effect.gen(function* () {
244 const harness = yield* makeHarness();
245 const result = yield* harness.call("link_pull_request", {
246 url: "https://github.com/T3Tools/T3Code/pull/123/files",
247 });
248 expect(result).toEqual({
249 host: "github.com",
250 repository: "t3tools/t3code",
251 number: 123,
252 url: "https://github.com/T3Tools/T3Code/pull/123/files",
253 alreadyLinked: false,
254 });
255 expect(yield* Ref.get(harness.commands)).toMatchObject([
256 {
257 type: "thread.pull-request.link",
258 threadId: THREAD_ID,
259 host: "github.com",
260 repository: "t3tools/t3code",
261 number: 123,
262 source: "agent",
263 },
264 ]);
265 }),
266 );
267​
268 it.effect("links a GitCafe pull request by its canonical /pull/ URL", () =>
269 Effect.gen(function* () {
270 const harness = yield* makeHarness();
271 const result = yield* harness.call("link_pull_request", {
272 url: "https://git.cafe/pingdotgg/t3code/pull/23897",
273 });
274 expect(result).toMatchObject({
275 host: "git.cafe",
276 repository: "pingdotgg/t3code",
277 number: 23897,
278 alreadyLinked: false,
279 });
280 expect(yield* Ref.get(harness.commands)).toMatchObject([
281 { type: "thread.pull-request.link", host: "git.cafe", number: 23897 },
282 ]);
283 }),
284 );
285​
286 it.effect("watching an unlinked pull request links it first", () =>
287 Effect.gen(function* () {
288 const harness = yield* makeHarness();
289 const result = yield* harness.call("watch_pull_request", {
290 url: "https://github.com/t3tools/t3code/pull/9",
291 });
292 expect(result).toMatchObject({ number: 9, watching: false, wasWatching: false });
293 expect(yield* Ref.get(harness.commands)).toMatchObject([
294 {
295 type: "thread.pull-request.watch",
296 number: 9,
297 watching: true,
298 link: { url: "https://github.com/t3tools/t3code/pull/9", source: "agent" },
299 },
300 ]);
301 }),
302 );
303​
304 it.effect("refuses to watch a merged pull request and stops an existing watch", () =>
305 Effect.gen(function* () {
306 const watch = {
307 startedAt: "2026-08-20T00:00:00.000Z",
308 headSha: null,
309 failedChecks: [],
310 passed: false,
311 passedChecks: [],
312 remarksThrough: "2026-08-20T00:00:00.000Z",
313 remarkIds: [],
314 conflicting: false,
315 wakes: 0,
316 };
317 const merged = makeLink(1, { headBranch: "done" });
318 const harness = yield* makeHarness({
319 thread: makeThread([
320 { ...merged, snapshot: merged.snapshot && { ...merged.snapshot, state: "merged" } },
321 makeLink(2, { headBranch: "idle" }),
322 makeLink(3, { headBranch: "watched", watch }),
323 ]),
324 });
325 const error = yield* harness
326 .call("watch_pull_request", { repository: "t3tools/t3code", number: 1 })
327 .pipe(Effect.flip);
328 expect(error).toMatchObject({ _tag: "PullRequestNotOpenError", state: "merged" });
329 expect(
330 yield* harness.call("unwatch_pull_request", { repository: "t3tools/t3code", number: 3 }),
331 ).toMatchObject({ wasWatching: true });
332 expect(yield* Ref.get(harness.commands)).toMatchObject([
333 { type: "thread.pull-request.watch", number: 3, watching: false },
334 ]);
335 }),
336 );
337​
338 it.effect("watches a pull request saved as closed, since it may have reopened", () =>
339 Effect.gen(function* () {
340 const closed = makeLink(1, { headBranch: "closed" });
341 const harness = yield* makeHarness({
342 thread: makeThread([
343 { ...closed, snapshot: closed.snapshot && { ...closed.snapshot, state: "closed" } },
344 ]),
345 });
346 yield* harness.call("watch_pull_request", { repository: "t3tools/t3code", number: 1 });
347 expect(yield* Ref.get(harness.commands)).toMatchObject([
348 { type: "thread.pull-request.watch", number: 1, watching: true },
349 ]);
350 }),
351 );
352​
353 it.effect("refuses a watch from a subagent thread, whose parent owns the pull request", () =>
354 Effect.gen(function* () {
355 const harness = yield* makeHarness({
356 thread: {
357 ...makeThread([makeLink(1, { headBranch: "feature" })]),
358 lineage: {
359 rootThreadId: ThreadId.make("parent"),
360 parentThreadId: ThreadId.make("parent"),
361 relationshipToParent: "subagent",
362 },
363 },
364 });
365 const error = yield* harness
366 .call("watch_pull_request", { repository: "t3tools/t3code", number: 1 })
367 .pipe(Effect.flip);
368 expect(error).toMatchObject({ _tag: "PullRequestWatchFromSubagentError" });
369 expect(yield* Ref.get(harness.commands)).toEqual([]);
370 }),
371 );
372​
373 it.effect("builds the URL in the project host's own shape", () =>
374 Effect.gen(function* () {
375 const harness = yield* makeHarness({
376 project: makeProject({
377 canonicalKey: "gitlab.com/group/sub/project",
378 locator: {
379 source: "git-remote",
380 remoteName: "origin",
381 remoteUrl: "git@gitlab.com:group/sub/project.git",
382 },
383 provider: "gitlab",
384 displayName: "group/sub/project",
385 }),
386 });
387 const result = yield* harness.call("link_pull_request", {
388 repository: "group/sub/project",
389 number: 42,
390 });
391 expect(result.url).toBe("https://gitlab.com/group/sub/project/-/merge_requests/42");
392 expect(result.host).toBe("gitlab.com");
393 }),
394 );
395​
396 it.effect("links a numeric Forgejo reference with its remote's web origin and mount path", () =>
397 Effect.gen(function* () {
398 const harness = yield* makeHarness({
399 project: makeProject({
400 canonicalKey: "forge.example/git/owner/repo",
401 locator: {
402 source: "git-remote",
403 remoteName: "origin",
404 remoteUrl: "http://forge.example:3000/git/owner/repo.git",
405 },
406 provider: "forgejo",
407 displayName: "git/owner/repo",
408 }),
409 });
410 const result = yield* harness.call("link_pull_request", {
411 repository: "git/owner/repo",
412 number: 42,
413 });
414 expect(result).toEqual({
415 host: "forge.example:3000",
416 repository: "git/owner/repo",
417 number: 42,
418 url: "http://forge.example:3000/git/owner/repo/pulls/42",
419 alreadyLinked: false,
420 });
421 const other = yield* harness.call("link_pull_request", {
422 host: "other.example",
423 repository: "owner/repo",
424 number: 42,
425 });
426 expect(other.url).toBe("https://other.example/owner/repo/pull/42");
427 }),
428 );
429​
430 it.effect("links Azure DevOps Server URLs and numeric references without a known provider", () =>
431 Effect.gen(function* () {
432 const harness = yield* makeHarness({
433 project: makeProject({
434 canonicalKey: "scm.example.test/tfs/collection/project/_git/repo",
435 locator: {
436 source: "git-remote",
437 remoteName: "origin",
438 remoteUrl: "http://dummy:secret@scm.example.test:8080/tfs/Collection/Project/_git/Repo",
439 },
440 provider: "unknown",
441 displayName: "tfs/collection/project/_git/repo",
442 }),
443 });
444 const generated =
445 "http://scm.example.test:8080/tfs/collection/project/_git/repo/pullrequest/124";
446 const fromNumber = yield* harness.call("link_pull_request", {
447 repository: "tfs/Collection/Project/_git/Repo",
448 number: 124,
449 });
450 expect.soft(fromNumber.url).toBe(generated);
451​
452 const supplied = "https://scm.example.test/tfs/Collection/Project/_git/Repo/pullrequest/123";
453 const fromUrl = yield* harness.call("link_pull_request", { url: supplied });
454 expect(fromUrl).toEqual({
455 host: "scm.example.test",
456 repository: "tfs/collection/project/_git/repo",
457 number: 123,
458 url: supplied,
459 alreadyLinked: false,
460 });
461 expect(yield* Ref.get(harness.commands)).toMatchObject([
462 { type: "thread.pull-request.link", number: 124, url: generated },
463 { type: "thread.pull-request.link", number: 123, url: supplied },
464 ]);
465 }),
466 );
467​
468 it.effect("treats a duplicate link as alreadyLinked rather than an error", () =>
469 Effect.gen(function* () {
470 const harness = yield* makeHarness({
471 thread: makeThread([makeLink(123)]),
472 reject: (command) =>
473 command.type === "thread.pull-request.link" ? "already linked" : null,
474 });
475 const result = yield* harness.call("link_pull_request", {
476 url: "https://github.com/t3tools/t3code/pull/123",
477 });
478 expect(result.alreadyLinked).toBe(true);
479 }),
480 );
481​
482 it.effect("unlinks a linked pull request and reports a missing one as wasLinked=false", () =>
483 Effect.gen(function* () {
484 const harness = yield* makeHarness({
485 thread: makeThread([makeLink(5)]),
486 reject: (command) =>
487 command.type === "thread.pull-request.unlink" && command.number !== 5
488 ? "not linked"
489 : null,
490 });
491 const linked = yield* harness.call("unlink_pull_request", {
492 repository: "t3tools/t3code",
493 number: 5,
494 });
495 expect(linked).toEqual({
496 host: "github.com",
497 repository: "t3tools/t3code",
498 number: 5,
499 wasLinked: true,
500 });
501 const missing = yield* harness.call("unlink_pull_request", {
502 url: "https://github.com/t3tools/t3code/pull/9",
503 });
504 expect(missing.wasLinked).toBe(false);
505 expect(yield* Ref.get(harness.commands)).toMatchObject([
506 { type: "thread.pull-request.unlink", number: 5 },
507 ]);
508 }),
509 );
510​
511 it("reports an older Forgejo link's HTTP port when listing thread links", () => {
512 const result = listThreadPullRequests(
513 makeThread([
514 makeLink(42, {
515 host: "forge.example",
516 url: "http://forge.example:3000/t3tools/t3code/pulls/42",
517 }),
518 ]),
519 );
520 expect(result.pullRequests[0]?.host).toBe("forge.example:3000");
521 });
522​
523 it.effect("lists visible links with host state and derived chain order", () =>
524 Effect.gen(function* () {
525 const harness = yield* makeHarness({
526 thread: makeThread([
527 makeLink(3, { headBranch: "feat-c", baseBranch: "feat-b", source: "agent" }),
528 makeLink(1, { headBranch: "feat-a", baseBranch: "main", source: "created" }),
529 makeLink(2, { headBranch: "feat-b", baseBranch: "feat-a", source: "agent" }),
530 makeLink(9, { source: "stack-dismissed" }),
531 makeLink(10),
532 ]),
533 });
534 const result = yield* harness.call("list_thread_pull_requests", {});
535 expect(result.pullRequests.map((entry) => entry.number)).toEqual([3, 1, 2, 10]);
536 expect(result.pullRequests[0]).toEqual({
537 host: "github.com",
538 repository: "t3tools/t3code",
539 number: 3,
540 url: "https://github.com/t3tools/t3code/pull/3",
541 source: "agent",
542 watching: false,
543 state: "open",
544 title: "PR 3",
545 headBranch: "feat-c",
546 baseBranch: "feat-b",
547 isDraft: false,
548 stack: { kind: "derived", position: 3, size: 3 },
549 });
550 expect(result.pullRequests[3]).toMatchObject({
551 number: 10,
552 state: null,
553 title: null,
554 headBranch: null,
555 stack: null,
556 });
557 expect(result.chains).toEqual([
558 { kind: "derived", numbers: [1, 2, 3] },
559 { kind: "derived", numbers: [10] },
560 ]);
561 }),
562 );
563});
564​
565describe("listThreadPullRequests", () => {
566 it("reports a native stack position for each member", () => {
567 const stack = {
568 kind: "native" as const,
569 id: "stack-1",
570 number: 1,
571 url: "https://github.com/t3tools/t3code/stack/1",
572 base: "main",
573 layers: [
574 { number: 1, headBranch: "a", state: "open" as const },
575 { number: 2, headBranch: "b", state: "open" as const },
576 ],
577 };
578 const result = listThreadPullRequests({
579 pullRequests: [
580 makeLink(2, { stack, source: "stack" }),
581 makeLink(1, { stack, source: "created" }),
582 ],
583 });
584 expect(result.pullRequests.map((entry) => [entry.number, entry.stack])).toEqual([
585 [2, { kind: "native", position: 2, size: 2 }],
586 [1, { kind: "native", position: 1, size: 2 }],
587 ]);
588 expect(result.chains).toEqual([{ kind: "native", numbers: [1, 2] }]);
589 });
590​
591 it("gives pull requests built on the same one the same position", () => {
592 const result = listThreadPullRequests({
593 pullRequests: [
594 makeLink(1, { headBranch: "feat-a", baseBranch: "main" }),
595 makeLink(2, { headBranch: "feat-b", baseBranch: "feat-a" }),
596 makeLink(3, { headBranch: "feat-c", baseBranch: "feat-a" }),
597 ],
598 });
599 expect(result.pullRequests.map((entry) => [entry.number, entry.stack])).toEqual([
600 [1, { kind: "derived", position: 1, size: 3 }],
601 [2, { kind: "derived", position: 2, size: 3 }],
602 [3, { kind: "derived", position: 2, size: 3 }],
603 ]);
604 expect(result.chains).toEqual([{ kind: "derived", numbers: [1, 2, 3] }]);
605 });
606});
607​
608describe("pull request guide tools", () => {
609 it.effect(
610 "writes guides through the project whose checkout is each pull request's repository",
611 () =>
612 Effect.gen(function* () {
613 const other = {
614 ...makeProject({
615 canonicalKey: "github.com/acme/web",
616 locator: {
617 source: "git-remote",
618 remoteName: "origin",
619 remoteUrl: "git@github.com:acme/web.git",
620 },
621 provider: "github",
622 displayName: "acme/web",
623 owner: "acme",
624 name: "web",
625 }),
626 id: ProjectId.make("project-web"),
627 };
628 const harness = yield* makeHarness({ projects: [makeProject(), other] });
629 const result = yield* harness.call("write_pull_request_guides", {
630 pullRequests: [
631 { url: "https://github.com/acme/web/pull/7" },
632 { repository: "t3tools/t3code", number: 12 },
633 { url: "https://github.com/someone/else/pull/1" },
634 ],
635 });
636 expect(
637 result.guides.map((guide) => [guide.repository, guide.number, guide.outcome]),
638 ).toEqual([
639 ["acme/web", 7, "started"],
640 ["t3tools/t3code", 12, "started"],
641 ["someone/else", 1, "failed"],
642 ]);
643 expect(result.guides[2]?.detail).toContain("No project in this environment");
644 expect(
645 (yield* Ref.get(harness.guideRequests)).map((ref) => [ref.projectId, ref.number]),
646 ).toEqual([
647 ["project-web", 7],
648 [PROJECT_ID, 12],
649 ]);
650 }),
651 );
652​
653 it.effect("reports an unreadable entry on its own and still writes the rest of the batch", () =>
654 Effect.gen(function* () {
655 const harness = yield* makeHarness();
656 const result = yield* harness.call("write_pull_request_guides", {
657 pullRequests: [
658 { url: "https://example.com/not-a-pull-request" },
659 { repository: "t3tools/t3code" },
660 { repository: "t3tools/t3code", number: 5 },
661 ],
662 });
663 expect(result.guides.map((guide) => guide.outcome)).toEqual(["failed", "failed", "started"]);
664 expect(result.guides[0]?.detail).toContain("not a recognised pull request URL");
665 expect(result.guides[1]?.detail).toContain("Pass either url");
666 expect((yield* Ref.get(harness.guideRequests)).map((ref) => ref.number)).toEqual([5]);
667 }),
668 );
669​
670 it.effect("finds an Azure DevOps checkout for a pull request named by its full path", () =>
671 Effect.gen(function* () {
672 const azure = {
673 ...makeProject({
674 canonicalKey: "dev.azure.com/org/project/_git/web",
675 locator: {
676 source: "git-remote",
677 remoteName: "origin",
678 remoteUrl: "https://dev.azure.com/org/project/_git/web",
679 },
680 provider: "azure-devops",
681 displayName: "org/project/_git/web",
682 owner: "org",
683 name: "web",
684 }),
685 id: ProjectId.make("project-azure"),
686 };
687 const harness = yield* makeHarness({ projects: [makeProject(), azure] });
688 const result = yield* harness.call("write_pull_request_guides", {
689 pullRequests: [{ host: "dev.azure.com", repository: "org/project/_git/web", number: 9 }],
690 });
691 expect(result.guides.map((guide) => guide.outcome)).toEqual(["started"]);
692 expect((yield* Ref.get(harness.guideRequests)).map((ref) => ref.projectId)).toEqual([
693 "project-azure",
694 ]);
695 }),
696 );
697});