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