Open History to see the last commit
1import { afterEach, assert, expect, it, vi } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import { ChildProcessSpawner } from "effect/process";
5
6import * as AzureDevOpsCli from "./AzureDevOpsCli.ts";
7import * as AzureDevOpsPullRequestCli from "./AzureDevOpsPullRequestCli.ts";
8import * as AzureDevOpsPullRequestProvider from "./AzureDevOpsPullRequestProvider.ts";
9
10const mockedExecute = vi.fn<AzureDevOpsCli.AzureDevOpsCli["Service"]["execute"]>();
11
12const layer = it.layer(
13 AzureDevOpsPullRequestCli.layer.pipe(
14 Layer.provide(
15 Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({
16 execute: mockedExecute,
17 }),
18 ),
19 ),
20);
21
22function output(stdout: string) {
23 return {
24 exitCode: ChildProcessSpawner.ExitCode(0),
25 stdout,
26 stderr: "",
27 stdoutTruncated: false,
28 stderrTruncated: false,
29 };
30}
31
32const VCS_DEFAULT_MAX_OUTPUT_BYTES = 1_000_000;
33
34function outputWithin(maxOutputBytes: number | undefined, response: string) {
35 const ceiling = maxOutputBytes ?? VCS_DEFAULT_MAX_OUTPUT_BYTES;
36 return ceiling >= Buffer.byteLength(response)
37 ? output(response)
38 : { ...output(response.slice(0, ceiling)), stdoutTruncated: true };
39}
40
41const json = (value: Record<string, unknown>) => JSON.stringify(value);
42
43const pullRequestRow = {
44 pullRequestId: 42,
45 title: "Add the page",
46 status: "active",
47 sourceRefName: "refs/heads/feat/page",
48 targetRefName: "refs/heads/main",
49 creationDate: "2026-07-01T00:00:00Z",
50 url: "https://dev.azure.com/acme/_apis/git/repositories/web/pullRequests/42",
51 repository: { name: "web", project: { name: "platform" } },
52};
53
54const oneIteration = {
55 value: [
56 {
57 id: 1,
58 sourceRefCommit: { commitId: "a".repeat(40) },
59 commonRefCommit: { commitId: "b".repeat(40) },
60 },
61 ],
62};
63
64function pullRequestRows(
65 count: number,
66 firstNumber: number,
67): ReadonlyArray<Record<string, unknown>> {
68 return Array.from({ length: count }, (_, index) => ({
69 pullRequestId: firstNumber + index,
70 title: `Pull request ${firstNumber + index}`,
71 status: "active",
72 sourceRefName: "refs/heads/feat/page",
73 targetRefName: "refs/heads/main",
74 creationDate: "2026-07-01T00:00:00Z",
75 repository: { name: "web", project: { name: "platform" } },
76 url: `https://dev.azure.com/acme/_apis/git/repositories/web/pullRequests/${firstNumber + index}`,
77 }));
78}
79
80function pullRequests(count: number, firstNumber: number): string {
81 return JSON.stringify(pullRequestRows(count, firstNumber));
82}
83
84function argsOfCall(index: number): ReadonlyArray<string> {
85 const call = mockedExecute.mock.calls[index];
86 assert.isDefined(call);
87 return call[0].args;
88}
89
90function maxOutputBytesOfCall(index: number) {
91 const call = mockedExecute.mock.calls[index];
92 assert.isDefined(call);
93 return call[0].maxOutputBytes;
94}
95
96function changeEntries(count: number): ReadonlyArray<Record<string, unknown>> {
97 const commit = "c".repeat(40);
98 return Array.from({ length: count }, (_, index) => {
99 const path = `/apps/server/src/generated/module-${index}/persisted-projection-${index}.ts`;
100 return {
101 changeType: "edit",
102 item: {
103 path,
104 objectId: "a".repeat(40),
105 originalObjectId: "b".repeat(40),
106 commitId: commit,
107 gitObjectType: "blob",
108 url: `https://dev.azure.com/acme/platform/_apis/git/repositories/6f9c9b7f-0000-0000-0000-000000000000/items${path}?versionType=Commit&version=${commit}`,
109 },
110 };
111 });
112}
113
114function identity(name: string) {
115 const id = "6f9c9b7f-0000-0000-0000-000000000000";
116 return {
117 displayName: name,
118 id,
119 uniqueName: `${name.toLowerCase().replace(/ /g, ".")}@acme.com`,
120 descriptor: `aad.${"z".repeat(52)}`,
121 imageUrl: `https://dev.azure.com/acme/_api/_common/identityImage?id=${id}`,
122 url: `https://spsprodweu1.vssps.visualstudio.com/A${id}/_apis/Identities/${id}`,
123 _links: {
124 avatar: {
125 href: `https://dev.azure.com/acme/_apis/GraphProfile/MemberAvatars/aad.${"z".repeat(52)}`,
126 },
127 },
128 };
129}
130
131function threadRows(count: number): ReadonlyArray<Record<string, unknown>> {
132 return Array.from({ length: count }, (_, index) => ({
133 id: index + 1,
134 publishedDate: "2026-07-02T00:00:00Z",
135 lastUpdatedDate: "2026-07-02T00:00:00Z",
136 status: "active",
137 threadContext: { filePath: `/apps/server/src/generated/module-${index}.ts` },
138 identities: { 1: identity("Reviewer One") },
139 isDeleted: false,
140 comments: [
141 {
142 id: 1,
143 parentCommentId: 0,
144 author: identity("Reviewer One"),
145 content: `Comment ${index}: ${"this needs another look. ".repeat(20)}`,
146 publishedDate: "2026-07-02T00:00:00Z",
147 lastUpdatedDate: "2026-07-02T00:00:00Z",
148 commentType: "text",
149 usersLiked: [],
150 },
151 ],
152 }));
153}
154
155function iterationRows(count: number): ReadonlyArray<Record<string, unknown>> {
156 return Array.from({ length: count }, (_, index) => ({
157 id: index + 1,
158 description: `Pushed ${index} commits`,
159 author: identity("Author One"),
160 createdDate: "2026-07-02T00:00:00Z",
161 updatedDate: "2026-07-02T00:00:00Z",
162 sourceRefCommit: { commitId: `${index}`.padStart(40, "a") },
163 targetRefCommit: { commitId: "b".repeat(40) },
164 commonRefCommit: { commitId: "c".repeat(40) },
165 hasMultipleCommits: true,
166 reason: "push",
167 push: { pushId: index + 1, date: "2026-07-02T00:00:00Z", pushedBy: identity("Author One") },
168 }));
169}
170
171afterEach(() => {
172 mockedExecute.mockReset();
173});
174
175layer("AzureDevOpsPullRequestCli.layer", (it) => {
176 it.effect("reports the latest pushed source commit even while the trial merge is stale", () =>
177 Effect.gen(function* () {
178 const previousHead = "a".repeat(40);
179 const latestHead = "c".repeat(40);
180 mockedExecute
181 .mockReturnValueOnce(
182 Effect.succeed(
183 output(json({ ...pullRequestRow, lastMergeSourceCommit: { commitId: previousHead } })),
184 ),
185 )
186 .mockReturnValueOnce(
187 Effect.succeed(
188 output(
189 json({
190 value: [
191 {
192 id: 2,
193 sourceRefCommit: { commitId: latestHead },
194 commonRefCommit: { commitId: "b".repeat(40) },
195 },
196 ...oneIteration.value,
197 ],
198 }),
199 ),
200 ),
201 )
202 .mockReturnValueOnce(Effect.succeed(output(json({ changeEntries: [] }))));
203 const provider = yield* AzureDevOpsPullRequestProvider.make;
204 const detail = yield* provider.getChangeRequest({
205 cwd: "/w",
206 repository: "platform/web",
207 host: "dev.azure.com",
208 number: 42,
209 });
210
211 expect(detail.headSha).toBe(latestHead);
212 expect(argsOfCall(2)).toContain("iterationId=2");
213 expect(mockedExecute).toHaveBeenCalledTimes(3);
214 }),
215 );
216
217 it.effect("asks for one row more than the page, to probe for a next page", () =>
218 Effect.gen(function* () {
219 mockedExecute.mockReturnValueOnce(Effect.succeed(output(pullRequests(3, 1))));
220 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
221
222 const batch = yield* cli.listPullRequests({
223 cwd: "/w",
224 repository: "web",
225 state: "open",
226 involvement: "all",
227 viewer: "bilal@acme.dev",
228 limit: 10,
229 });
230
231 assert.strictEqual(batch.items.length, 3);
232 assert.isFalse(batch.truncated);
233 expect(argsOfCall(0)).toEqual([
234 "repos",
235 "pr",
236 "list",
237 "--detect",
238 "true",
239 "--repository",
240 "web",
241 "--status",
242 "active",
243 "--include-links",
244 "--top",
245 "11",
246 "--only-show-errors",
247 "--output",
248 "json",
249 ]);
250 }),
251 );
252
253 it.effect("reads an Azure pull request page larger than the VCS default output limit", () =>
254 Effect.gen(function* () {
255 const rows = pullRequestRows(100, 1).map((row) => ({
256 ...row,
257 description: "x".repeat(10_000),
258 }));
259 const response = JSON.stringify(rows);
260 expect(Buffer.byteLength(response)).toBeGreaterThan(1_000_000);
261
262 mockedExecute.mockImplementationOnce((input) =>
263 Effect.succeed(outputWithin(input.maxOutputBytes, response)),
264 );
265 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
266
267 const batch = yield* cli.listPullRequests({
268 cwd: "/w",
269 repository: "web",
270 state: "merged",
271 involvement: "all",
272 viewer: "bilal@acme.dev",
273 limit: 99,
274 });
275
276 assert.strictEqual(batch.items.length, 99);
277 assert.isTrue(batch.truncated);
278 }),
279 );
280
281 it.effect("reads the page unnarrowed when asked to search, having nothing to search with", () =>
282 Effect.gen(function* () {
283 mockedExecute.mockReturnValueOnce(Effect.succeed(output(pullRequests(3, 1))));
284 const provider = yield* AzureDevOpsPullRequestProvider.make;
285
286 const page = yield* provider.listChangeRequests({
287 cwd: "/w",
288 repository: "web",
289 host: "dev.azure.com",
290 state: "open",
291 involvement: "all",
292 viewer: "bilal@acme.dev",
293 limit: 10,
294 query: "page",
295 });
296
297 assert.strictEqual(page.items.length, 3);
298 expect(argsOfCall(0)).toEqual([
299 "repos",
300 "pr",
301 "list",
302 "--detect",
303 "true",
304 "--repository",
305 "web",
306 "--status",
307 "active",
308 "--include-links",
309 "--top",
310 "11",
311 "--only-show-errors",
312 "--output",
313 "json",
314 ]);
315 }),
316 );
317
318 it.effect("steps over what it has already handed over, which is all Azure can be told", () =>
319 Effect.gen(function* () {
320 mockedExecute.mockReturnValueOnce(Effect.succeed(output(pullRequests(3, 1))));
321 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
322
323 yield* cli.listPullRequests({
324 cwd: "/w",
325 repository: "web",
326 state: "open",
327 involvement: "all",
328 viewer: "bilal@acme.dev",
329 limit: 10,
330 cursor: { updatedBefore: "2026-07-02T00:00:00Z", delivered: 20 },
331 });
332
333 const args = argsOfCall(0);
334 expect(args).toContain("--skip");
335 assert.strictEqual(args[args.indexOf("--skip") + 1], "20");
336 expect(args).not.toContain("2026-07-02T00:00:00Z");
337 }),
338 );
339
340 it.effect("reports truncation from the extra row", () =>
341 Effect.gen(function* () {
342 mockedExecute.mockReturnValueOnce(Effect.succeed(output(pullRequests(11, 1))));
343 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
344
345 const batch = yield* cli.listPullRequests({
346 cwd: "/w",
347 repository: "web",
348 state: "open",
349 involvement: "all",
350 viewer: "bilal@acme.dev",
351 limit: 10,
352 });
353
354 assert.strictEqual(batch.items.length, 10);
355 assert.isTrue(batch.truncated);
356 assert.strictEqual(batch.cursorAdvance, 10);
357 }),
358 );
359
360 it.effect("advances by malformed raw rows and keeps reading until the page is full", () =>
361 Effect.gen(function* () {
362 mockedExecute
363 .mockReturnValueOnce(
364 Effect.succeed(
365 output(
366 JSON.stringify([
367 { pullRequestId: "malformed" },
368 pullRequestRows(1, 1)[0],
369 { pullRequestId: "also malformed" },
370 ]),
371 ),
372 ),
373 )
374 .mockReturnValueOnce(Effect.succeed(output(pullRequests(2, 2))));
375 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
376
377 const batch = yield* cli.listPullRequests({
378 cwd: "/w",
379 repository: "web",
380 state: "open",
381 involvement: "all",
382 viewer: "bilal@acme.dev",
383 limit: 2,
384 });
385
386 expect(batch.items.map((item) => item.number)).toEqual([1, 2]);
387 assert.isTrue(batch.truncated);
388 assert.strictEqual(batch.cursorAdvance, 4);
389 const secondArgs = argsOfCall(1);
390 assert.strictEqual(secondArgs[secondArgs.indexOf("--skip") + 1], "3");
391 assert.strictEqual(secondArgs[secondArgs.indexOf("--top") + 1], "2");
392 }),
393 );
394
395 it.effect("narrows to the author on the authored tab", () =>
396 Effect.gen(function* () {
397 mockedExecute.mockReturnValueOnce(Effect.succeed(output("[]")));
398 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
399
400 yield* cli.listPullRequests({
401 cwd: "/w",
402 repository: "web",
403 state: "closed",
404 involvement: "authored",
405 viewer: "bilal@acme.dev",
406 limit: 10,
407 });
408
409 expect(argsOfCall(0)).toContain("--creator");
410 expect(argsOfCall(0)).toContain("bilal@acme.dev");
411 expect(argsOfCall(0)).toContain("abandoned");
412 }),
413 );
414
415 it.effect("asks Azure for every status on the All tab", () =>
416 Effect.gen(function* () {
417 mockedExecute.mockReturnValueOnce(Effect.succeed(output("[]")));
418 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
419
420 yield* cli.listPullRequests({
421 cwd: "/w",
422 repository: "web",
423 state: "all",
424 involvement: "all",
425 viewer: "bilal@acme.dev",
426 limit: 10,
427 });
428
429 expect(argsOfCall(0)).toContain("--status");
430 expect(argsOfCall(0)).toContain("all");
431 }),
432 );
433
434 it.effect("narrows to the reviewer on the reviewing tab", () =>
435 Effect.gen(function* () {
436 mockedExecute.mockReturnValueOnce(Effect.succeed(output("[]")));
437 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
438
439 yield* cli.listPullRequests({
440 cwd: "/w",
441 repository: "web",
442 state: "open",
443 involvement: "reviewing",
444 viewer: "bilal@acme.dev",
445 limit: 10,
446 });
447
448 expect(argsOfCall(0)).toContain("--reviewer");
449 }),
450 );
451
452 it.effect("reads the signed-in account, which az reports as a bare value", () =>
453 Effect.gen(function* () {
454 mockedExecute.mockReturnValueOnce(
455 Effect.succeed(output(JSON.stringify({ name: "bilal@acme.dev", type: "user" }))),
456 );
457 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
458
459 const viewer = yield* cli.getViewer({ cwd: "/w" });
460
461 assert.strictEqual(viewer, "bilal@acme.dev");
462 expect(argsOfCall(0)).toEqual([
463 "account",
464 "show",
465 "--query",
466 "user",
467 "--only-show-errors",
468 "--output",
469 "json",
470 ]);
471 }),
472 );
473
474 it.effect("names a token sign-in by the viewer's own pull request", () =>
475 Effect.gen(function* () {
476 const notLoggedIn = new AzureDevOpsCli.AzureDevOpsCliAuthenticationError({
477 operation: "execute",
478 command: "az",
479 cwd: "/w",
480 argumentCount: 7,
481 cause: new Error("Please run 'az login' to setup account."),
482 });
483 mockedExecute
484 .mockReturnValueOnce(Effect.fail(notLoggedIn))
485 .mockReturnValueOnce(
486 Effect.succeed(
487 output(
488 JSON.stringify([{ ...pullRequestRow, createdBy: { uniqueName: "bilal@acme.dev" } }]),
489 ),
490 ),
491 )
492 .mockReturnValueOnce(Effect.succeed(output("")))
493 .mockReturnValueOnce(Effect.succeed(output("[]")));
494 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
495
496 assert.strictEqual(yield* cli.getViewer({ cwd: "/w" }), "bilal@acme.dev");
497 expect(argsOfCall(1)).toEqual(expect.arrayContaining(["--creator", "me", "--top", "1"]));
498 const error = yield* Effect.flip(cli.getViewer({ cwd: "/w" }));
499 assert.strictEqual(error._tag, "AzureDevOpsViewerUnavailableError");
500 }),
501 );
502
503 it.effect("fails when no sign-in can read pull requests", () =>
504 Effect.gen(function* () {
505 const signedOut = new AzureDevOpsCli.AzureDevOpsCliAuthenticationError({
506 operation: "execute",
507 command: "az",
508 cwd: "/w",
509 argumentCount: 7,
510 cause: new Error("signed out"),
511 });
512 mockedExecute.mockReturnValue(Effect.fail(signedOut));
513 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
514
515 const error = yield* Effect.flip(cli.getViewer({ cwd: "/w" }));
516
517 assert.strictEqual(error._tag, "AzureDevOpsCliAuthenticationError");
518 }),
519 );
520
521 it.effect("completes a pull request to merge it, squashing only when asked", () =>
522 Effect.gen(function* () {
523 mockedExecute.mockReturnValue(Effect.succeed(output("{}")));
524 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
525
526 yield* cli.runPullRequestAction({
527 cwd: "/w",
528 number: 42,
529 action: "merge",
530 mergeMethod: "squash",
531 });
532
533 expect(argsOfCall(0)).toEqual([
534 "repos",
535 "pr",
536 "update",
537 "--detect",
538 "true",
539 "--id",
540 "42",
541 "--status",
542 "completed",
543 "--squash",
544 "true",
545 "--only-show-errors",
546 "--output",
547 "json",
548 ]);
549 }),
550 );
551
552 it.effect("stores the squash choice with an auto-completion, as a merge now does", () =>
553 Effect.gen(function* () {
554 mockedExecute.mockReturnValue(Effect.succeed(output("{}")));
555 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
556
557 yield* cli.runPullRequestAction({
558 cwd: "/w",
559 number: 42,
560 action: "enable-auto-merge",
561 mergeMethod: "squash",
562 });
563
564 expect(argsOfCall(0)).toEqual([
565 "repos",
566 "pr",
567 "update",
568 "--detect",
569 "true",
570 "--id",
571 "42",
572 "--auto-complete",
573 "true",
574 "--squash",
575 "true",
576 "--only-show-errors",
577 "--output",
578 "json",
579 ]);
580 }),
581 );
582
583 it.effect.each([
584 { action: "enable-auto-merge", expected: ["--auto-complete", "true"] },
585 { action: "disable-auto-merge", expected: ["--auto-complete", "false"] },
586 { action: "draft", expected: ["--draft", "true"] },
587 { action: "ready", expected: ["--draft", "false"] },
588 { action: "close", expected: ["--status", "abandoned"] },
589 { action: "reopen", expected: ["--status", "active"] },
590 ] as const)("moves a pull request with $action", ({ action, expected }) =>
591 Effect.gen(function* () {
592 mockedExecute.mockReturnValue(Effect.succeed(output("{}")));
593 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
594
595 yield* cli.runPullRequestAction({ cwd: "/w", number: 42, action });
596
597 expect(argsOfCall(0)).toEqual([
598 "repos",
599 "pr",
600 "update",
601 "--detect",
602 "true",
603 "--id",
604 "42",
605 ...expected,
606 "--only-show-errors",
607 "--output",
608 "json",
609 ]);
610 }),
611 );
612
613 it.effect.each([
614 { name: "a title", rewrite: { title: "Add the page" }, expected: ["--title=Add the page"] },
615 {
616 name: "a description",
617 rewrite: { body: "Why the page changed" },
618 expected: ["--description=Why the page changed"],
619 },
620 {
621 name: "both",
622 rewrite: { title: "Add the page", body: "Why the page changed" },
623 expected: ["--title=Add the page", "--description=Why the page changed"],
624 },
625 ] as const)("rewrites $name, sending nothing it was not given", ({ rewrite, expected }) =>
626 Effect.gen(function* () {
627 mockedExecute.mockReturnValue(Effect.succeed(output("{}")));
628 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
629
630 yield* cli.updatePullRequest({ cwd: "/w", number: 42, ...rewrite });
631
632 expect(argsOfCall(0)).toEqual([
633 "repos",
634 "pr",
635 "update",
636 "--detect",
637 "true",
638 "--id",
639 "42",
640 ...expected,
641 "--only-show-errors",
642 "--output",
643 "json",
644 ]);
645 }),
646 );
647
648 it.effect("sends a description that starts with a dash as one value, not as a flag", () =>
649 Effect.gen(function* () {
650 mockedExecute.mockReturnValue(Effect.succeed(output("{}")));
651 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
652
653 yield* cli.updatePullRequest({
654 cwd: "/w",
655 number: 42,
656 body: "- rewrote the page\n- kept the rest",
657 });
658
659 expect(argsOfCall(0)).toContain("--description=- rewrote the page\n- kept the rest");
660 }),
661 );
662
663 it.effect("rewrites through the provider, which says it takes one", () =>
664 Effect.gen(function* () {
665 mockedExecute.mockReturnValue(Effect.succeed(output("{}")));
666 const provider = yield* AzureDevOpsPullRequestProvider.make;
667
668 expect(provider.capabilities.edit).toEqual({ changeRequest: true, comment: false });
669 assert.isDefined(provider.updateChangeRequest);
670 yield* provider.updateChangeRequest({
671 cwd: "/w",
672 repository: "web",
673 host: "dev.azure.com",
674 number: 42,
675 title: "Add the page",
676 });
677
678 expect(argsOfCall(0)).toContain("--title=Add the page");
679 expect(argsOfCall(0)).not.toContain("--description");
680 }),
681 );
682
683 it.effect("names the head's blob as what a cleared file was cleared at", () =>
684 Effect.gen(function* () {
685 mockedExecute
686 .mockReturnValueOnce(
687 Effect.succeed(
688 output(
689 JSON.stringify({
690 pullRequestId: 42,
691 title: "Add the page",
692 status: "active",
693 sourceRefName: "refs/heads/feat/page",
694 targetRefName: "refs/heads/main",
695 creationDate: "2026-07-01T00:00:00Z",
696 url: "https://dev.azure.com/acme/_apis/git/repositories/web/pullRequests/42",
697 repository: { name: "web", project: { name: "platform" } },
698 }),
699 ),
700 ),
701 )
702 .mockReturnValueOnce(
703 Effect.succeed(
704 output(
705 JSON.stringify({
706 value: [
707 {
708 id: 1,
709 sourceRefCommit: { commitId: "a".repeat(40) },
710 commonRefCommit: { commitId: "b".repeat(40) },
711 },
712 {
713 id: 2,
714 sourceRefCommit: { commitId: "c".repeat(40) },
715 commonRefCommit: { commitId: "b".repeat(40) },
716 },
717 ],
718 }),
719 ),
720 ),
721 )
722 .mockReturnValueOnce(
723 Effect.succeed(
724 output(
725 JSON.stringify({
726 changeEntries: [
727 { changeType: "edit", item: { path: "/README.md", objectId: "8f80" } },
728 { changeType: "add", item: { path: "/DEMO.md", objectId: "0ca4" } },
729 ],
730 }),
731 ),
732 ),
733 );
734 const provider = yield* AzureDevOpsPullRequestProvider.make;
735
736 assert.strictEqual(provider.capabilities.viewedFiles, "environment");
737 assert.isDefined(provider.getFileRevisions);
738 const answer = yield* provider.getFileRevisions({
739 cwd: "/w",
740 repository: "web",
741 host: "dev.azure.com",
742 number: 42,
743 paths: ["README.md"],
744 });
745
746 expect(argsOfCall(2)).toContain("iterationId=2");
747 expect([...answer.revisions]).toEqual([["README.md", "8f80"]]);
748 }),
749 );
750
751 it.effect("reads where a pull request lives once, however often it is asked about", () =>
752 Effect.gen(function* () {
753 const pullRequest = Effect.succeed(
754 output(
755 JSON.stringify({
756 pullRequestId: 42,
757 title: "Add the page",
758 status: "active",
759 sourceRefName: "refs/heads/feat/page",
760 targetRefName: "refs/heads/main",
761 creationDate: "2026-07-01T00:00:00Z",
762 url: "https://dev.azure.com/acme/_apis/git/repositories/web/pullRequests/42",
763 repository: { name: "web", project: { name: "platform" } },
764 }),
765 ),
766 );
767 const iterations = () =>
768 Effect.succeed(
769 output(
770 JSON.stringify({
771 value: [
772 {
773 id: 1,
774 sourceRefCommit: { commitId: "a".repeat(40) },
775 commonRefCommit: { commitId: "b".repeat(40) },
776 },
777 ],
778 }),
779 ),
780 );
781 const changes = () =>
782 Effect.succeed(
783 output(
784 JSON.stringify({
785 changeEntries: [
786 { changeType: "edit", item: { path: "/README.md", objectId: "8f80" } },
787 ],
788 }),
789 ),
790 );
791 mockedExecute
792 .mockReturnValueOnce(pullRequest)
793 .mockReturnValueOnce(iterations())
794 .mockReturnValueOnce(changes())
795 .mockReturnValueOnce(iterations())
796 .mockReturnValueOnce(changes());
797 const provider = yield* AzureDevOpsPullRequestProvider.make;
798 const read = provider.getFileRevisions;
799 assert.isDefined(read);
800 const ask = () =>
801 read({
802 cwd: "/w",
803 repository: "web",
804 host: "dev.azure.com",
805 number: 42,
806 paths: ["README.md"],
807 });
808
809 yield* ask();
810 const again = yield* ask();
811
812 assert.strictEqual(mockedExecute.mock.calls.length, 5);
813 expect(argsOfCall(3)).toContain("pullRequestIterations");
814 expect([...again.revisions]).toEqual([["README.md", "8f80"]]);
815 }),
816 );
817
818 it.effect(
819 "answers for a marked file the pull request no longer changes as the empty version",
820 () =>
821 Effect.gen(function* () {
822 mockedExecute
823 .mockReturnValueOnce(
824 Effect.succeed(
825 output(
826 json({
827 pullRequestId: 42,
828 title: "Add the page",
829 status: "active",
830 sourceRefName: "refs/heads/feat/page",
831 targetRefName: "refs/heads/main",
832 creationDate: "2026-07-01T00:00:00Z",
833 url: "https://dev.azure.com/acme/_apis/git/repositories/web/pullRequests/42",
834 repository: { name: "web", project: { name: "platform" } },
835 }),
836 ),
837 ),
838 )
839 .mockReturnValueOnce(
840 Effect.succeed(
841 output(
842 json({
843 value: [
844 {
845 id: 1,
846 sourceRefCommit: { commitId: "a".repeat(40) },
847 commonRefCommit: { commitId: "b".repeat(40) },
848 },
849 ],
850 }),
851 ),
852 ),
853 )
854 .mockReturnValueOnce(Effect.succeed(output('{"changeEntries":[]}')));
855 const provider = yield* AzureDevOpsPullRequestProvider.make;
856 assert.isDefined(provider.getFileRevisions);
857
858 const answer = yield* provider.getFileRevisions({
859 cwd: "/w",
860 repository: "web",
861 host: "dev.azure.com",
862 number: 42,
863 paths: ["GONE.md"],
864 });
865
866 expect([...answer.revisions]).toEqual([["GONE.md", ""]]);
867 }),
868 );
869
870 it.effect("says nothing about the files past the end of a change it gave up following", () =>
871 Effect.gen(function* () {
872 const entries = (from: number, count: number) =>
873 Array.from({ length: count }, (_, index) => ({
874 changeType: "edit",
875 item: { path: `/src/f${from + index}.ts`, objectId: `blob-${from + index}` },
876 }));
877 mockedExecute
878 .mockReturnValueOnce(
879 Effect.succeed(
880 output(
881 json({
882 pullRequestId: 42,
883 title: "Add the page",
884 status: "active",
885 sourceRefName: "refs/heads/feat/page",
886 targetRefName: "refs/heads/main",
887 creationDate: "2026-07-01T00:00:00Z",
888 url: "https://dev.azure.com/acme/_apis/git/repositories/web/pullRequests/42",
889 repository: { name: "web", project: { name: "platform" } },
890 }),
891 ),
892 ),
893 )
894 .mockReturnValueOnce(
895 Effect.succeed(
896 output(
897 json({
898 value: [
899 {
900 id: 1,
901 sourceRefCommit: { commitId: "a".repeat(40) },
902 commonRefCommit: { commitId: "b".repeat(40) },
903 },
904 ],
905 }),
906 ),
907 ),
908 )
909 .mockReturnValueOnce(
910 Effect.succeed(output(json({ changeEntries: entries(0, 5_000), nextSkip: 5_000 }))),
911 )
912 .mockReturnValueOnce(
913 Effect.succeed(output(json({ changeEntries: entries(5_000, 5_000), nextSkip: 10_000 }))),
914 );
915 const provider = yield* AzureDevOpsPullRequestProvider.make;
916 assert.isDefined(provider.getFileRevisions);
917
918 const answer = yield* provider.getFileRevisions({
919 cwd: "/w",
920 repository: "web",
921 host: "dev.azure.com",
922 number: 42,
923 paths: ["src/f1.ts", "src/f5001.ts", "src/past-the-cut.ts"],
924 });
925
926 expect(argsOfCall(3)).toContain("$skip=5000");
927 expect([...answer.revisions]).toEqual([
928 ["src/f1.ts", "blob-1"],
929 ["src/f5001.ts", "blob-5001"],
930 ]);
931 }),
932 );
933
934 it.effect("stops following pages by what Azure counts, not by what survives decoding", () =>
935 Effect.gen(function* () {
936 mockedExecute
937 .mockReturnValueOnce(
938 Effect.succeed(
939 output(
940 json({
941 pullRequestId: 42,
942 title: "Add the page",
943 status: "active",
944 sourceRefName: "refs/heads/feat/page",
945 targetRefName: "refs/heads/main",
946 creationDate: "2026-07-01T00:00:00Z",
947 url: "https://dev.azure.com/acme/_apis/git/repositories/web/pullRequests/42",
948 repository: { name: "web", project: { name: "platform" } },
949 }),
950 ),
951 ),
952 )
953 .mockReturnValueOnce(
954 Effect.succeed(
955 output(
956 json({
957 value: [
958 {
959 id: 1,
960 sourceRefCommit: { commitId: "a".repeat(40) },
961 commonRefCommit: { commitId: "b".repeat(40) },
962 },
963 ],
964 }),
965 ),
966 ),
967 )
968 .mockImplementation((command) => {
969 const skip = command.args.find((arg) => arg.startsWith("$skip="));
970 const from = Number(skip?.slice("$skip=".length) ?? 0);
971 return Effect.succeed(
972 output(
973 json({
974 changeEntries: [{ changeType: "add", item: { path: "/src", isFolder: true } }],
975 nextSkip: from + 2_000,
976 }),
977 ),
978 );
979 });
980 const provider = yield* AzureDevOpsPullRequestProvider.make;
981 assert.isDefined(provider.getFileRevisions);
982
983 const answer = yield* provider.getFileRevisions({
984 cwd: "/w",
985 repository: "web",
986 host: "dev.azure.com",
987 number: 42,
988 paths: ["src/page.ts"],
989 });
990
991 assert.strictEqual(mockedExecute.mock.calls.length, 7);
992 assert.strictEqual(answer.revisions.size, 0);
993 }),
994 );
995
996 it.effect("leaves one file the host would not hand over listed without its hunks", () =>
997 Effect.gen(function* () {
998 mockedExecute
999 .mockReturnValueOnce(Effect.succeed(output(json(pullRequestRow))))
1000 .mockReturnValueOnce(Effect.succeed(output(json(oneIteration))))
1001 .mockReturnValueOnce(
1002 Effect.succeed(
1003 output(
1004 json({
1005 changeEntries: [
1006 { changeType: "add", item: { path: "/huge.bin", objectId: "8f80" } },
1007 { changeType: "add", item: { path: "/DEMO.md", objectId: "0ca4" } },
1008 ],
1009 }),
1010 ),
1011 ),
1012 )
1013 .mockReturnValueOnce(
1014 Effect.fail(
1015 new AzureDevOpsCli.AzureDevOpsCommandFailedError({
1016 operation: "execute",
1017 command: "az",
1018 cwd: "/w",
1019 argumentCount: 1,
1020 cause: "the blob is past what the route will carry",
1021 }),
1022 ),
1023 )
1024 .mockReturnValueOnce(Effect.succeed(output(json({ content: "hello\n" }))));
1025 const provider = yield* AzureDevOpsPullRequestProvider.make;
1026
1027 const slice = yield* provider.getDiff({
1028 cwd: "/w",
1029 repository: "web",
1030 host: "dev.azure.com",
1031 number: 42,
1032 });
1033
1034 assert.isTrue(slice.truncated);
1035 expect(slice.patch).toContain("diff --git a/huge.bin b/huge.bin");
1036 expect(slice.patch).toContain("+hello");
1037 }),
1038 );
1039
1040 it.effect("fails the whole read when it is the connection that would not answer", () =>
1041 Effect.gen(function* () {
1042 mockedExecute
1043 .mockReturnValueOnce(Effect.succeed(output(json(pullRequestRow))))
1044 .mockReturnValueOnce(Effect.succeed(output(json(oneIteration))))
1045 .mockReturnValueOnce(
1046 Effect.succeed(
1047 output(
1048 json({
1049 changeEntries: [
1050 { changeType: "add", item: { path: "/DEMO.md", objectId: "0ca4" } },
1051 ],
1052 }),
1053 ),
1054 ),
1055 )
1056 .mockReturnValueOnce(
1057 Effect.fail(
1058 new AzureDevOpsCli.AzureDevOpsCliRateLimitError({
1059 operation: "execute",
1060 command: "az",
1061 cwd: "/w",
1062 argumentCount: 1,
1063 cause: "429",
1064 }),
1065 ),
1066 );
1067 const provider = yield* AzureDevOpsPullRequestProvider.make;
1068
1069 const error = yield* Effect.flip(
1070 provider.getDiff({ cwd: "/w", repository: "web", host: "dev.azure.com", number: 42 }),
1071 );
1072
1073 assert.strictEqual(error.reason, "rate-limited");
1074 }),
1075 );
1076
1077 it.effect("takes Azure's own word on a file it will not spell out", () =>
1078 Effect.gen(function* () {
1079 mockedExecute
1080 .mockReturnValueOnce(
1081 Effect.succeed(
1082 output(
1083 json({
1084 pullRequestId: 42,
1085 title: "Add the page",
1086 status: "active",
1087 sourceRefName: "refs/heads/feat/page",
1088 targetRefName: "refs/heads/main",
1089 creationDate: "2026-07-01T00:00:00Z",
1090 url: "https://dev.azure.com/acme/_apis/git/repositories/web/pullRequests/42",
1091 repository: { name: "web", project: { name: "platform" } },
1092 }),
1093 ),
1094 ),
1095 )
1096 .mockReturnValueOnce(
1097 Effect.succeed(
1098 output(
1099 json({
1100 value: [
1101 {
1102 id: 1,
1103 sourceRefCommit: { commitId: "a".repeat(40) },
1104 commonRefCommit: { commitId: "b".repeat(40) },
1105 },
1106 ],
1107 }),
1108 ),
1109 ),
1110 )
1111 .mockReturnValueOnce(
1112 Effect.succeed(
1113 output(
1114 json({
1115 changeEntries: [
1116 { changeType: "add", item: { path: "/logo.png", objectId: "8f80" } },
1117 ],
1118 }),
1119 ),
1120 ),
1121 )
1122 .mockReturnValueOnce(
1123 Effect.succeed(
1124 output(json({ content: "iVBORw0KGgo=", contentMetadata: { isBinary: true } })),
1125 ),
1126 );
1127 const provider = yield* AzureDevOpsPullRequestProvider.make;
1128
1129 const slice = yield* provider.getDiff({
1130 cwd: "/w",
1131 repository: "web",
1132 host: "dev.azure.com",
1133 number: 42,
1134 });
1135
1136 expect(argsOfCall(3)).toContain("includeContentMetadata=true");
1137 expect(slice.patch).toContain("Binary files a/logo.png and b/logo.png differ");
1138 assert.isTrue(slice.truncated);
1139 }),
1140 );
1141
1142 it.effect("stops following pages when one of them does not move the cursor on", () =>
1143 Effect.gen(function* () {
1144 mockedExecute
1145 .mockReturnValueOnce(
1146 Effect.succeed(
1147 output(
1148 json({
1149 pullRequestId: 42,
1150 title: "Add the page",
1151 status: "active",
1152 sourceRefName: "refs/heads/feat/page",
1153 targetRefName: "refs/heads/main",
1154 creationDate: "2026-07-01T00:00:00Z",
1155 url: "https://dev.azure.com/acme/_apis/git/repositories/web/pullRequests/42",
1156 repository: { name: "web", project: { name: "platform" } },
1157 }),
1158 ),
1159 ),
1160 )
1161 .mockReturnValueOnce(
1162 Effect.succeed(
1163 output(
1164 json({
1165 value: [
1166 {
1167 id: 1,
1168 sourceRefCommit: { commitId: "a".repeat(40) },
1169 commonRefCommit: { commitId: "b".repeat(40) },
1170 },
1171 ],
1172 }),
1173 ),
1174 ),
1175 )
1176 .mockReturnValueOnce(
1177 Effect.succeed(
1178 output(
1179 json({
1180 changeEntries: [{ changeType: "edit", item: { path: "/a.ts", objectId: "8f80" } }],
1181 nextSkip: 2_000,
1182 }),
1183 ),
1184 ),
1185 )
1186 .mockReturnValueOnce(
1187 Effect.succeed(
1188 output(
1189 json({
1190 changeEntries: [{ changeType: "edit", item: { path: "/b.ts", objectId: "0ca4" } }],
1191 nextSkip: 2_000,
1192 }),
1193 ),
1194 ),
1195 );
1196 const provider = yield* AzureDevOpsPullRequestProvider.make;
1197 assert.isDefined(provider.getFileRevisions);
1198
1199 const answer = yield* provider.getFileRevisions({
1200 cwd: "/w",
1201 repository: "web",
1202 host: "dev.azure.com",
1203 number: 42,
1204 paths: ["a.ts", "b.ts", "unlisted.ts"],
1205 });
1206
1207 assert.strictEqual(mockedExecute.mock.calls.length, 4);
1208 expect([...answer.revisions]).toEqual([
1209 ["a.ts", "8f80"],
1210 ["b.ts", "0ca4"],
1211 ]);
1212 }),
1213 );
1214
1215 it.effect("asks Azure nothing when no file has been ticked off", () =>
1216 Effect.gen(function* () {
1217 mockedExecute.mockReturnValue(Effect.succeed(output('{"changeEntries":[]}')));
1218 const provider = yield* AzureDevOpsPullRequestProvider.make;
1219 assert.isDefined(provider.getFileRevisions);
1220
1221 const answer = yield* provider.getFileRevisions({
1222 cwd: "/w",
1223 repository: "web",
1224 host: "dev.azure.com",
1225 number: 42,
1226 paths: [],
1227 });
1228
1229 expect(answer.revisions.size).toBe(0);
1230 assert.strictEqual(mockedExecute.mock.calls.length, 0);
1231 }),
1232 );
1233
1234 it.effect("reads the conversation through the REST API, pinned to a version", () =>
1235 Effect.gen(function* () {
1236 mockedExecute.mockReturnValueOnce(
1237 Effect.succeed(
1238 output(
1239 JSON.stringify({
1240 value: [
1241 {
1242 id: 1,
1243 comments: [
1244 { id: 1, content: "Looks good.", publishedDate: "2026-07-02T00:00:00Z" },
1245 ],
1246 },
1247 ],
1248 }),
1249 ),
1250 ),
1251 );
1252 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1253
1254 const comments = yield* cli.listThreads({
1255 cwd: "/w",
1256 location: { project: "platform", repository: "web" },
1257 number: 42,
1258 });
1259
1260 assert.strictEqual(comments.length, 1);
1261 expect(argsOfCall(0)).toContain("invoke");
1262 expect(argsOfCall(0)).toContain("pullRequestThreads");
1263 expect(argsOfCall(0)).toContain("project=platform");
1264 expect(argsOfCall(0)).toContain("repositoryId=web");
1265 expect(argsOfCall(0)).toContain("pullRequestId=42");
1266 expect(maxOutputBytesOfCall(0)).toBeGreaterThan(VCS_DEFAULT_MAX_OUTPUT_BYTES);
1267 }),
1268 );
1269
1270 it.effect("reads a long review's threads, which are past the default output limit", () =>
1271 Effect.gen(function* () {
1272 const response = json({ value: threadRows(800) });
1273 expect(Buffer.byteLength(response)).toBeGreaterThan(VCS_DEFAULT_MAX_OUTPUT_BYTES);
1274 mockedExecute.mockImplementationOnce((input) =>
1275 Effect.succeed(outputWithin(input.maxOutputBytes, response)),
1276 );
1277 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1278
1279 const comments = yield* cli.listThreads({
1280 cwd: "/w",
1281 location: { project: "platform", repository: "web" },
1282 number: 42,
1283 });
1284
1285 assert.strictEqual(comments.length, 800);
1286 }),
1287 );
1288
1289 it.effect("reads a long review's iterations, which are past the default output limit", () =>
1290 Effect.gen(function* () {
1291 const response = json({ value: iterationRows(1_200) });
1292 expect(Buffer.byteLength(response)).toBeGreaterThan(VCS_DEFAULT_MAX_OUTPUT_BYTES);
1293 mockedExecute.mockImplementationOnce((input) =>
1294 Effect.succeed(outputWithin(input.maxOutputBytes, response)),
1295 );
1296 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1297
1298 const iterations = yield* cli.listIterations({
1299 cwd: "/w",
1300 location: { project: "platform", repository: "web" },
1301 number: 42,
1302 });
1303
1304 assert.strictEqual(iterations.length, 1_200);
1305 assert.strictEqual(iterations.at(-1)?.id, 1_200);
1306 }),
1307 );
1308
1309 it.effect("reads a full page of change entries, which is past the default output limit", () =>
1310 Effect.gen(function* () {
1311 const response = json({ changeEntries: changeEntries(2_000) });
1312 expect(Buffer.byteLength(response)).toBeGreaterThan(VCS_DEFAULT_MAX_OUTPUT_BYTES);
1313 mockedExecute.mockImplementationOnce((input) =>
1314 Effect.succeed(outputWithin(input.maxOutputBytes, response)),
1315 );
1316 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1317
1318 const page = yield* cli.listIterationChanges({
1319 cwd: "/w",
1320 location: { project: "platform", repository: "web" },
1321 number: 42,
1322 iterationId: 1,
1323 });
1324
1325 assert.strictEqual(page.changes.length, 2_000);
1326 assert.isFalse(page.truncated);
1327 }),
1328 );
1329
1330 it.effect("reads a file whose JSON envelope is past the default output limit", () =>
1331 Effect.gen(function* () {
1332 const file = "const value = 1;\n".repeat(57_000);
1333 const response = json({ content: file });
1334 expect(Buffer.byteLength(file)).toBeLessThan(VCS_DEFAULT_MAX_OUTPUT_BYTES);
1335 expect(Buffer.byteLength(response)).toBeGreaterThan(VCS_DEFAULT_MAX_OUTPUT_BYTES);
1336 mockedExecute.mockImplementationOnce((input) =>
1337 Effect.succeed(outputWithin(input.maxOutputBytes, response)),
1338 );
1339 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1340
1341 const item = yield* cli.readItemContent({
1342 cwd: "/w",
1343 location: { project: "platform", repository: "web" },
1344 path: "src/generated/schema.ts",
1345 commit: "a".repeat(40),
1346 });
1347
1348 assert.strictEqual(item.contents, file);
1349 assert.isFalse(item.isBinary);
1350 }),
1351 );
1352
1353 it.effect("asks for a file by Azure's own spelling of its path", () =>
1354 Effect.gen(function* () {
1355 mockedExecute.mockReturnValueOnce(Effect.succeed(output(json({ content: "const a = 1;" }))));
1356 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1357
1358 yield* cli.readItemContent({
1359 cwd: "/w",
1360 location: { project: "platform", repository: "web" },
1361 path: "src/app.ts",
1362 commit: "a".repeat(40),
1363 });
1364
1365 expect(argsOfCall(0)).toContain("path=/src/app.ts");
1366 }),
1367 );
1368
1369 it.effect("reports a pull request it cannot place as its own outcome", () =>
1370 Effect.gen(function* () {
1371 mockedExecute.mockReturnValueOnce(
1372 Effect.succeed(
1373 output(
1374 JSON.stringify({
1375 pullRequestId: 42,
1376 title: "Add the page",
1377 sourceRefName: "refs/heads/feat/page",
1378 targetRefName: "refs/heads/main",
1379 creationDate: "2026-07-01T00:00:00Z",
1380 }),
1381 ),
1382 ),
1383 );
1384 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1385
1386 const error = yield* Effect.flip(cli.getPullRequest({ cwd: "/w", number: 42 }));
1387
1388 assert.strictEqual(error._tag, "AzureDevOpsPullRequestIncompleteError");
1389 }),
1390 );
1391
1392 it.effect("fails the read when az returns something unreadable", () =>
1393 Effect.gen(function* () {
1394 mockedExecute.mockReturnValueOnce(Effect.succeed(output('{"message":"not found"}')));
1395 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1396
1397 const error = yield* Effect.flip(cli.getPullRequest({ cwd: "/w", number: 42 }));
1398
1399 assert.strictEqual(error._tag, "AzureDevOpsPullRequestReadError");
1400 }),
1401 );
1402
1403 it.effect("adds reviewers with the one command Azure has for it", () =>
1404 Effect.gen(function* () {
1405 mockedExecute.mockReturnValueOnce(Effect.succeed(output("[]")));
1406 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1407
1408 yield* cli.setPullRequestReviewers({
1409 cwd: "/w",
1410 number: 42,
1411 reviewers: ["octocat@acme.test", "hubot@acme.test"],
1412 requested: true,
1413 });
1414
1415 expect(argsOfCall(0)).toEqual([
1416 "repos",
1417 "pr",
1418 "reviewer",
1419 "add",
1420 "--detect",
1421 "true",
1422 "--id",
1423 "42",
1424 "--reviewers",
1425 "octocat@acme.test",
1426 "hubot@acme.test",
1427 "--only-show-errors",
1428 "--output",
1429 "json",
1430 ]);
1431 }),
1432 );
1433
1434 it.effect("takes a reviewer off the pull request with the same command's counterpart", () =>
1435 Effect.gen(function* () {
1436 mockedExecute.mockReturnValueOnce(Effect.succeed(output("[]")));
1437 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1438
1439 yield* cli.setPullRequestReviewers({
1440 cwd: "/w",
1441 number: 42,
1442 reviewers: ["octocat@acme.test"],
1443 requested: false,
1444 });
1445
1446 expect(argsOfCall(0)).toContain("remove");
1447 }),
1448 );
1449
1450 it.effect("refuses a reviewer az would read as a flag, before running anything", () =>
1451 Effect.gen(function* () {
1452 const cli = yield* AzureDevOpsPullRequestCli.AzureDevOpsPullRequestCli;
1453
1454 const error = yield* Effect.flip(
1455 cli.setPullRequestReviewers({
1456 cwd: "/w",
1457 number: 42,
1458 reviewers: ["--query"],
1459 requested: true,
1460 }),
1461 );
1462
1463 assert.strictEqual(error._tag, "AzureDevOpsReviewerNameError");
1464 assert.strictEqual(mockedExecute.mock.calls.length, 0);
1465 }),
1466 );
1467});