-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathcreate_pull_request.test.cjs
More file actions
4011 lines (3462 loc) · 167 KB
/
Copy pathcreate_pull_request.test.cjs
File metadata and controls
4011 lines (3462 loc) · 167 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @ts-check
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { createRequire } from "module";
import { fileURLToPath } from "url";
import * as fs from "fs";
import * as path from "path";
import * as os from "os";
const require = createRequire(import.meta.url);
const { getPatchPathForBranch, getPatchPathForBranchInRepo } = require("./git_patch_utils.cjs");
const { getBundlePathForBranch, getBundlePathForBranchInRepo } = require("./generate_git_bundle.cjs");
// The privileged handler derives patch/bundle paths from `branch` (and `repo`)
// via resolveTransportPaths, so tests must write transport files at the
// canonical derived location and let the handler discover them.
//
// `/tmp/gh-aw` is a process-global path shared by every test file. Vitest runs
// test files in parallel processes, so a cleanup that globbed the whole
// directory would delete another file's in-flight transport files mid-test.
// Track only the paths this file created and delete just those.
const createdTransportPaths = new Set();
function canonicalPatchPath(branch, repo) {
fs.mkdirSync("/tmp/gh-aw", { recursive: true });
const p = repo ? getPatchPathForBranchInRepo(branch, repo) : getPatchPathForBranch(branch);
createdTransportPaths.add(p);
return p;
}
function canonicalBundlePath(branch, repo) {
fs.mkdirSync("/tmp/gh-aw", { recursive: true });
const p = repo ? getBundlePathForBranchInRepo(branch, repo) : getBundlePathForBranch(branch);
createdTransportPaths.add(p);
return p;
}
function cleanupCanonicalTransports() {
for (const p of createdTransportPaths) {
try {
fs.rmSync(p, { force: true });
} catch {}
}
createdTransportPaths.clear();
}
beforeEach(() => {
cleanupCanonicalTransports();
});
afterEach(() => {
cleanupCanonicalTransports();
});
describe("create_pull_request - draft policy enforcement", () => {
let tempDir;
let originalEnv;
beforeEach(() => {
originalEnv = { ...process.env };
process.env.GH_AW_WORKFLOW_ID = "test-workflow";
process.env.GITHUB_REPOSITORY = "test-owner/test-repo";
process.env.GITHUB_BASE_REF = "main";
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "create-pr-draft-test-"));
global.core = {
info: vi.fn(),
warning: vi.fn(),
error: vi.fn(),
debug: vi.fn(),
setFailed: vi.fn(),
setOutput: vi.fn(),
startGroup: vi.fn(),
endGroup: vi.fn(),
summary: {
addRaw: vi.fn().mockReturnThis(),
write: vi.fn().mockResolvedValue(undefined),
},
};
global.github = {
rest: {
pulls: {
create: vi.fn().mockResolvedValue({ data: { number: 1, html_url: "https://github.com/test", head: { sha: "abc123" } } }),
createReview: vi.fn().mockResolvedValue({ data: { id: 77, html_url: "https://github.com/test/review/77" } }),
},
repos: {
get: vi.fn().mockResolvedValue({ data: { default_branch: "main" } }),
},
issues: {
addLabels: vi.fn().mockResolvedValue({}),
},
},
graphql: vi.fn(),
};
global.context = {
eventName: "workflow_dispatch",
repo: { owner: "test-owner", repo: "test-repo" },
payload: {},
};
global.exec = {
exec: vi.fn().mockResolvedValue(0),
getExecOutput: vi.fn().mockResolvedValue({ exitCode: 0, stdout: "", stderr: "" }),
};
// Clear module cache so globals are picked up fresh
delete require.cache[require.resolve("./create_pull_request.cjs")];
});
afterEach(() => {
for (const key of Object.keys(process.env)) {
if (!(key in originalEnv)) {
delete process.env[key];
}
}
Object.assign(process.env, originalEnv);
if (tempDir && fs.existsSync(tempDir)) {
fs.rmSync(tempDir, { recursive: true, force: true });
}
delete global.core;
delete global.github;
delete global.context;
delete global.exec;
vi.clearAllMocks();
});
/** Returns the `core.warning` calls related to draft config override attempts. */
function getDraftOverrideWarnings() {
return global.core.warning.mock.calls.filter(args => String(args[0]).includes("Agent requested draft"));
}
it("should enforce draft: false from config even when agent requests draft: true", async () => {
const { main } = require("./create_pull_request.cjs");
const handler = await main({ draft: "false", allow_empty: true });
const result = await handler({ title: "Test PR", body: "Test body", draft: true }, {});
expect(result.success).toBe(true);
expect(global.github.rest.pulls.create).toHaveBeenCalledWith(expect.objectContaining({ draft: false }));
});
it("should enforce draft: true from config even when agent requests draft: false", async () => {
const { main } = require("./create_pull_request.cjs");
const handler = await main({ draft: "true", allow_empty: true });
const result = await handler({ title: "Test PR", body: "Test body", draft: false }, {});
expect(result.success).toBe(true);
expect(global.github.rest.pulls.create).toHaveBeenCalledWith(expect.objectContaining({ draft: true }));
});
it("should log a warning when agent attempts to override draft config", async () => {
const { main } = require("./create_pull_request.cjs");
const handler = await main({ draft: "false", allow_empty: true });
await handler({ title: "Test PR", body: "Test body", draft: true }, {});
expect(global.core.warning).toHaveBeenCalledWith(expect.stringContaining("Agent requested draft: true, but configuration enforces draft: false"));
});
it("should not log a warning when agent draft matches config", async () => {
const { main } = require("./create_pull_request.cjs");
const handler = await main({ draft: "false", allow_empty: true });
await handler({ title: "Test PR", body: "Test body", draft: false }, {});
expect(getDraftOverrideWarnings()).toHaveLength(0);
});
it("should not log a warning when agent does not specify draft", async () => {
const { main } = require("./create_pull_request.cjs");
const handler = await main({ draft: "false", allow_empty: true });
await handler({ title: "Test PR", body: "Test body" }, {});
expect(getDraftOverrideWarnings()).toHaveLength(0);
});
});
describe("create_pull_request - bundle transport shallow checkout", () => {
let tempDir;
let originalEnv;
let pushSignedSpy;
beforeEach(() => {
originalEnv = { ...process.env };
process.env.GH_AW_WORKFLOW_ID = "test-workflow";
process.env.GITHUB_REPOSITORY = "test-owner/test-repo";
process.env.GITHUB_BASE_REF = "main";
delete process.env.GITHUB_TOKEN;
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "create-pr-bundle-test-"));
global.core = {
info: vi.fn(),
warning: vi.fn(),
error: vi.fn(),
debug: vi.fn(),
setFailed: vi.fn(),
setOutput: vi.fn(),
startGroup: vi.fn(),
endGroup: vi.fn(),
summary: {
addRaw: vi.fn().mockReturnThis(),
write: vi.fn().mockResolvedValue(undefined),
},
};
global.github = {
rest: {
pulls: {
create: vi.fn().mockResolvedValue({ data: { number: 42, html_url: "https://github.com/test-owner/test-repo/pull/42" } }),
},
repos: {
get: vi.fn().mockResolvedValue({ data: { default_branch: "main" } }),
},
issues: {
create: vi.fn().mockResolvedValue({ data: { number: 99, html_url: "https://github.com/test-owner/test-repo/issues/99" } }),
addLabels: vi.fn().mockResolvedValue({}),
},
},
graphql: vi.fn(),
};
global.context = {
eventName: "workflow_dispatch",
repo: { owner: "test-owner", repo: "test-repo" },
payload: {},
};
global.exec = {
exec: vi.fn().mockResolvedValue(0),
getExecOutput: vi.fn().mockImplementation((cmd, args) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "bundle" && args[1] === "verify") {
// Declare a fake prerequisite so ensureFullHistoryForBundle proceeds.
return Promise.resolve({ exitCode: 1, stdout: "", stderr: `The bundle requires this ref:\n${"a".repeat(40)}\n` });
}
if (cmd === "git" && args[0] === "cat-file" && args[1] === "-e") {
// Report the prerequisite object as already present by default so
// ensureFullHistoryForBundle returns early (no fetch). Tests that need
// to exercise the fetch/deepen path override this within the test.
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
if (cmd === "git" && args && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}),
};
const pushSignedCommitsModule = require("./push_signed_commits.cjs");
pushSignedSpy = vi.spyOn(pushSignedCommitsModule, "pushSignedCommits").mockResolvedValue("bundle-tip");
delete require.cache[require.resolve("./create_pull_request.cjs")];
});
afterEach(() => {
if (pushSignedSpy) {
pushSignedSpy.mockRestore();
}
for (const key of Object.keys(process.env)) {
if (!(key in originalEnv)) {
delete process.env[key];
}
}
Object.assign(process.env, originalEnv);
if (tempDir && fs.existsSync(tempDir)) {
fs.rmSync(tempDir, { recursive: true, force: true });
}
delete global.core;
delete global.github;
delete global.context;
delete global.exec;
vi.clearAllMocks();
});
it("should fetch bundle prerequisite commits directly from origin in shallow repositories", async () => {
const patchPath = canonicalPatchPath("feature/test");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("feature/test");
fs.writeFileSync(bundlePath, "bundle content");
// Force the prerequisite-missing path so the direct SHA fetch runs.
const prereq = "a".repeat(40);
let prereqFetched = false;
global.exec.getExecOutput = vi.fn().mockImplementation((cmd, args) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "bundle" && args[1] === "verify") {
return Promise.resolve({ exitCode: 1, stdout: "", stderr: `The bundle requires this ref:\n${prereq}\n` });
}
if (cmd === "git" && args[0] === "config") {
return Promise.resolve({ exitCode: 1, stdout: "", stderr: "" });
}
if (cmd === "git" && args[0] === "cat-file" && args[1] === "-e") {
// Missing until the direct SHA fetch brings it in.
return Promise.resolve({ exitCode: prereqFetched ? 0 : 1, stdout: "", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
global.exec.exec = vi.fn().mockImplementation((cmd, args) => {
if (cmd === "git" && Array.isArray(args) && args[0] === "fetch" && args.includes("origin") && args.includes(prereq)) {
prereqFetched = true;
}
return Promise.resolve(0);
});
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: "feature/test" }, {});
expect(result.success).toBe(true);
// Initial bundle fetch is now via getExecOutput (with ignoreReturnCode: true) rather than exec,
// so the bundle fetch appears in getExecOutput.mock.calls.
const bundleFetchCall = global.exec.getExecOutput.mock.calls.find(([, args]) => Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath);
if (!bundleFetchCall) {
throw new Error("expected bundle fetch call via getExecOutput");
}
expect(bundleFetchCall[1][2]).toMatch(/^refs\/heads\/feature\/test:refs\/bundles\/create-pr-feature-test-[a-f0-9]{8}$/);
const bundleTempRef = bundleFetchCall[1][2].split(":")[1];
expect(global.exec.exec).toHaveBeenCalledWith("git", ["update-ref", "refs/heads/feature/test", bundleTempRef]);
expect(global.exec.exec).toHaveBeenCalledWith("git", ["reset", "--hard"]);
// Primary path: the exact prerequisite SHA is fetched directly from origin,
// with no broad iterative deepen and no --unshallow.
const directFetch = global.exec.exec.mock.calls.find(([, args]) => Array.isArray(args) && args[0] === "fetch" && args.includes("origin") && args.includes(prereq));
expect(directFetch).toBeTruthy();
const deepenCall = global.exec.exec.mock.calls.find(([, args]) => Array.isArray(args) && args[0] === "fetch" && typeof args[1] === "string" && args[1].startsWith("--deepen="));
expect(deepenCall).toBeUndefined();
const unshallowCall = global.exec.exec.mock.calls.find(([, args]) => Array.isArray(args) && args[0] === "fetch" && args.includes("--unshallow"));
expect(unshallowCall).toBeUndefined();
});
it("should pass signed_commits false to bundle pushes", async () => {
const patchPath = canonicalPatchPath("feature/test");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("feature/test");
fs.writeFileSync(bundlePath, "bundle content");
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true, signed_commits: false });
const result = await handler({ title: "Test PR", body: "Test body", branch: "feature/test" }, {});
expect(result.success).toBe(true);
expect(pushSignedSpy).toHaveBeenCalledWith(expect.objectContaining({ signedCommits: false }));
});
it("should rewrite bundle history to a single commit and retry when signed push rejects merge commits", async () => {
const patchPath = canonicalPatchPath("feature/test");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("feature/test");
fs.writeFileSync(bundlePath, "bundle content");
let revParseHeadCallCount = 0;
global.exec.getExecOutput.mockImplementation((cmd, args) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
if (cmd === "git" && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "HEAD") {
revParseHeadCallCount += 1;
return Promise.resolve({ exitCode: 0, stdout: revParseHeadCallCount === 1 ? "old-head-sha\n" : "new-head-sha\n", stderr: "" });
}
if (cmd === "git" && args[0] === "log" && args[1] === "-1" && args[2] === "--format=%s" && args[3] === "HEAD") {
return Promise.resolve({ exitCode: 0, stdout: "bundle merge headline\n", stderr: "" });
}
if (cmd === "git" && args[0] === "diff" && args[1] === "--cached" && args[2] === "--name-only") {
return Promise.resolve({ exitCode: 0, stdout: "test.txt\n", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
pushSignedSpy
.mockRejectedValueOnce(new Error("pushSignedCommits: refusing unsigned push for branch 'feature/test': merge commit detected. " + "GitHub's createCommitOnBranch GraphQL mutation cannot represent merge commits."))
.mockResolvedValueOnce("bundle-tip");
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: "feature/test" }, {});
expect(result.success).toBe(true);
expect(result.fallback_used).not.toBe(true);
expect(pushSignedSpy).toHaveBeenCalledTimes(2);
expect(global.exec.exec).toHaveBeenCalledWith("git", ["reset", "--soft", "origin/main"]);
expect(global.exec.exec).toHaveBeenCalledWith("git", ["commit", "-m", "bundle merge headline"]);
expect(global.github.rest.issues.create).not.toHaveBeenCalled();
});
it("should resolve bundle source ref from list-heads when JSONL branch ref is missing in bundle", async () => {
const patchPath = canonicalPatchPath("ops-review-may09-2026");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("ops-review-may09-2026");
fs.writeFileSync(bundlePath, "bundle content");
global.exec.getExecOutput.mockImplementation((cmd, args, options) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
// Initial bundle fetch via getExecOutput with ignoreReturnCode: the JSONL branch ref is missing
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode) {
return Promise.resolve({ exitCode: 1, stderr: "fatal: couldn't find remote ref refs/heads/ops-review-may09-2026", stdout: "" });
}
if (cmd === "git" && args[0] === "bundle" && args[1] === "list-heads" && args[2] === bundlePath) {
return Promise.resolve({
exitCode: 0,
stdout: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/heads/main\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD\n",
stderr: "",
});
}
if (cmd === "git" && args && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: "ops-review-may09-2026" }, {});
expect(result.success).toBe(true);
expect(global.exec.getExecOutput).toHaveBeenCalledWith("git", ["bundle", "list-heads", bundlePath]);
const resolvedFetchCall = global.exec.exec.mock.calls.find(([, args]) => Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath && args[2].startsWith("refs/heads/main:"));
if (!resolvedFetchCall) {
throw new Error("expected resolved bundle fetch call");
}
expect(resolvedFetchCall[1][2]).toMatch(/^refs\/heads\/main:refs\/bundles\/create-pr-ops-review-may09-2026-[a-f0-9]{8}$/);
});
it("should fall back to HEAD refspec when bundle contains only HEAD (no refs/heads/* entry)", async () => {
const patchPath = canonicalPatchPath("docs/update-migration-version-2026-05-19-4fe3b9f7f99fc1d6");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("docs/update-migration-version-2026-05-19-4fe3b9f7f99fc1d6");
fs.writeFileSync(bundlePath, "bundle content");
global.exec.getExecOutput.mockImplementation((cmd, args, options) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
// Initial bundle fetch (refs/heads/* refspec) fails because the JSONL branch ref is absent
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode && typeof args[2] === "string" && args[2].startsWith("refs/heads/")) {
return Promise.resolve({ exitCode: 1, stderr: "fatal: couldn't find remote ref refs/heads/docs/update-migration-version-2026-05-19-4fe3b9f7f99fc1d6", stdout: "" });
}
// HEAD-based bundle fetch (fallback path) succeeds — no prerequisite errors
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode && typeof args[2] === "string" && args[2].startsWith("HEAD:")) {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
// Bundle contains only HEAD — no refs/heads/* entry (the bug scenario)
if (cmd === "git" && args[0] === "bundle" && args[1] === "list-heads" && args[2] === bundlePath) {
return Promise.resolve({
exitCode: 0,
stdout: "ac85f4047717ec43c931d750575f5251c45dc705 HEAD\n",
stderr: "",
});
}
if (cmd === "git" && args && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: "docs/update-migration-version-2026-05-19-4fe3b9f7f99fc1d6" }, {});
expect(result.success).toBe(true);
expect(global.exec.getExecOutput).toHaveBeenCalledWith("git", ["bundle", "list-heads", bundlePath]);
// HEAD-based bundle fetch is now performed via getExecOutput (ignoreReturnCode: true)
// so the code can distinguish prerequisite errors from other failures.
const headFetchCall = global.exec.getExecOutput.mock.calls.find(
([, args, opts]) => Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath && typeof args[2] === "string" && args[2].startsWith("HEAD:") && opts && opts.ignoreReturnCode
);
if (!headFetchCall) {
throw new Error("expected HEAD-based bundle fetch call via getExecOutput");
}
expect(headFetchCall[1][2]).toMatch(/^HEAD:refs\/bundles\/create-pr-docs-update-migration-version-2026-05-19-4fe3b9f7f99fc1d6-[a-f0-9]{8}$/);
});
it("should fetch prerequisite commits from origin and retry when HEAD-only bundle has missing prerequisites (non-main dispatch scenario)", async () => {
// Simulates: worker was dispatched from a non-main branch; its bundle has only HEAD
// (no refs/heads/* entry) AND the prerequisite is the feature-branch tip, which is
// not reachable from the local main-only shallow checkout in safe_outputs.
// Fix: the fallback HEAD fetch path must do the same prerequisite recovery as the
// initial fetch path.
const branchName = "docs/update-migration-version-2026-05-19-4fe3b9f7f99fc1d6";
const patchPath = canonicalPatchPath(branchName);
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath(branchName);
fs.writeFileSync(bundlePath, "bundle content");
const featureBranchTip = "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2";
global.exec.getExecOutput.mockImplementation((cmd, args, options) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
// Initial bundle fetch (named ref) fails — bundle only has HEAD
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode && typeof args[2] === "string" && args[2].startsWith("refs/heads/")) {
return Promise.resolve({ exitCode: 1, stderr: `fatal: couldn't find remote ref refs/heads/${branchName}`, stdout: "" });
}
// HEAD-based bundle fetch fails because prerequisite (feature-branch tip) is missing
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode && typeof args[2] === "string" && args[2].startsWith("HEAD:")) {
return Promise.resolve({ exitCode: 1, stderr: `error: Repository lacks these prerequisite commits:\nerror: ${featureBranchTip}`, stdout: "" });
}
// Bundle contains only HEAD — no refs/heads/* entry
if (cmd === "git" && args[0] === "bundle" && args[1] === "list-heads" && args[2] === bundlePath) {
return Promise.resolve({
exitCode: 0,
stdout: `ac85f4047717ec43c931d750575f5251c45dc705 HEAD\n`,
stderr: "",
});
}
if (cmd === "git" && args && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: branchName }, {});
expect(result.success).toBe(true);
// Feature-branch tip prerequisite is fetched from origin
expect(global.exec.exec).toHaveBeenCalledWith("git", ["fetch", "--filter=blob:none", "origin", featureBranchTip]);
// After prerequisite recovery, HEAD bundle is retried via exec
const bundleRetryFetchCalls = global.exec.exec.mock.calls.filter(([, args]) => Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath && typeof args[2] === "string" && args[2].startsWith("HEAD:"));
expect(bundleRetryFetchCalls.length).toBe(1);
});
it("should include retry context when HEAD-only bundle fetch still fails after prerequisite recovery", async () => {
const branchName = "docs/update-migration-version-2026-05-19-4fe3b9f7f99fc1d6";
const patchPath = canonicalPatchPath(branchName);
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath(branchName);
fs.writeFileSync(bundlePath, "bundle content");
const featureBranchTip = "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2";
global.exec.getExecOutput.mockImplementation((cmd, args, options) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode && typeof args[2] === "string" && args[2].startsWith("refs/heads/")) {
return Promise.resolve({ exitCode: 1, stderr: `fatal: couldn't find remote ref refs/heads/${branchName}`, stdout: "" });
}
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode && typeof args[2] === "string" && args[2].startsWith("HEAD:")) {
return Promise.resolve({ exitCode: 1, stderr: `error: Repository lacks these prerequisite commits:\nerror: ${featureBranchTip}`, stdout: "" });
}
if (cmd === "git" && args[0] === "bundle" && args[1] === "list-heads" && args[2] === bundlePath) {
return Promise.resolve({
exitCode: 0,
stdout: `ac85f4047717ec43c931d750575f5251c45dc705 HEAD\n`,
stderr: "",
});
}
if (cmd === "git" && args && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
global.exec.exec.mockImplementation((cmd, args) => {
if (cmd === "git" && Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath && typeof args[2] === "string" && args[2].startsWith("HEAD:")) {
throw new Error("fatal: failed to read HEAD-only bundle");
}
return Promise.resolve(0);
});
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: branchName }, {});
expect(result.success).toBe(false);
expect(result.error).toBe("Failed to apply bundle");
expect(global.core.error).toHaveBeenCalledWith(expect.stringContaining("HEAD bundle fetch failed after fetching 1 prerequisite commit(s): fatal: failed to read HEAD-only bundle"));
});
it("should fetch prerequisite commits and retry bundle fetch when prerequisites are missing", async () => {
const patchPath = canonicalPatchPath("feature/test");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("feature/test");
fs.writeFileSync(bundlePath, "bundle content");
const missingSha = "256f08b38d9ce40cfa5d46385551caba8642a9df";
// The initial bundle fetch uses getExecOutput (ignoreReturnCode: true) so git stderr is captured.
// Real @actions/exec.exec only throws "The process '...' failed with exit code 1" — not the
// git error text — so the recovery path must read stderr from getExecOutput instead.
global.exec.getExecOutput.mockImplementation((cmd, args, options) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode) {
return Promise.resolve({ exitCode: 1, stderr: `error: Repository lacks these prerequisite commits:\nerror: ${missingSha}`, stdout: "" });
}
if (cmd === "git" && args && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: "feature/test" }, {});
expect(result.success).toBe(true);
// Prerequisites are fetched from origin via exec with --filter=blob:none to avoid downloading blobs
expect(global.exec.exec).toHaveBeenCalledWith("git", ["fetch", "--filter=blob:none", "origin", missingSha]);
// Retry bundle fetch is via exec (only the retry, not the initial attempt which was getExecOutput)
const bundleRetryFetchCalls = global.exec.exec.mock.calls.filter(([, args]) => Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath);
expect(bundleRetryFetchCalls.length).toBe(1);
expect(global.exec.getExecOutput).not.toHaveBeenCalledWith("git", ["bundle", "list-heads", bundlePath]);
});
it("should fetch all prerequisite commits in a single origin fetch and retry bundle fetch", async () => {
const patchPath = canonicalPatchPath("feature/test");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("feature/test");
fs.writeFileSync(bundlePath, "bundle content");
const missingSha1 = "256f08b38d9ce40cfa5d46385551caba8642a9df";
const missingSha2 = "aabbccddee1122334455667788990011aabbccdd";
global.exec.getExecOutput.mockImplementation((cmd, args, options) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode) {
return Promise.resolve({ exitCode: 1, stderr: `error: Repository lacks these prerequisite commits:\nerror: ${missingSha1}\nerror: ${missingSha2}`, stdout: "" });
}
if (cmd === "git" && args && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: "feature/test" }, {});
expect(result.success).toBe(true);
expect(global.exec.exec).toHaveBeenCalledWith("git", ["fetch", "--filter=blob:none", "origin", missingSha1, missingSha2]);
const bundleRetryFetchCalls = global.exec.exec.mock.calls.filter(([, args]) => Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath);
expect(bundleRetryFetchCalls.length).toBe(1);
expect(global.exec.getExecOutput).not.toHaveBeenCalledWith("git", ["bundle", "list-heads", bundlePath]);
});
it("should fail when fetching prerequisite commits from origin fails", async () => {
const patchPath = canonicalPatchPath("feature/test");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("feature/test");
fs.writeFileSync(bundlePath, "bundle content");
const missingSha = "256f08b38d9ce40cfa5d46385551caba8642a9df";
global.exec.getExecOutput.mockImplementation((cmd, args, options) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode) {
return Promise.resolve({ exitCode: 1, stderr: `error: Repository lacks these prerequisite commits:\nerror: ${missingSha}`, stdout: "" });
}
if (cmd === "git" && args && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
global.exec.exec.mockImplementation((cmd, args) => {
if (cmd === "git" && Array.isArray(args) && args[0] === "fetch" && args.includes("origin") && args.includes(missingSha)) {
throw new Error("fatal: couldn't connect to 'origin'");
}
return Promise.resolve(0);
});
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: "feature/test" }, {});
expect(result.success).toBe(false);
expect(result.error).toBe("Failed to apply bundle");
expect(global.core.error).toHaveBeenCalledWith(expect.stringContaining("Failed to apply bundle: fatal: couldn't connect to 'origin'"));
// No retry bundle fetch via exec — failed at prerequisite origin fetch
const bundleRetryFetchCalls = global.exec.exec.mock.calls.filter(([, args]) => Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath);
expect(bundleRetryFetchCalls.length).toBe(0);
});
it("should include retry context when bundle fetch still fails after prerequisite recovery", async () => {
const patchPath = canonicalPatchPath("feature/test");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("feature/test");
fs.writeFileSync(bundlePath, "bundle content");
const missingSha = "256f08b38d9ce40cfa5d46385551caba8642a9df";
global.exec.getExecOutput.mockImplementation((cmd, args, options) => {
if (cmd === "git" && args[0] === "rev-parse" && args[1] === "--is-shallow-repository") {
return Promise.resolve({ exitCode: 0, stdout: "true\n", stderr: "" });
}
if (cmd === "git" && args[0] === "rev-list") {
return Promise.resolve({ exitCode: 0, stdout: "1\n", stderr: "" });
}
if (cmd === "git" && args[0] === "fetch" && args[1] === bundlePath && options && options.ignoreReturnCode) {
return Promise.resolve({ exitCode: 1, stderr: `error: Repository lacks these prerequisite commits:\nerror: ${missingSha}`, stdout: "" });
}
if (cmd === "git" && args && args[0] === "ls-remote") {
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
}
return Promise.resolve({ exitCode: 0, stdout: "", stderr: "" });
});
global.exec.exec.mockImplementation((cmd, args) => {
if (cmd === "git" && Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath) {
throw new Error("fatal: failed to read bundle");
}
return Promise.resolve(0);
});
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body", branch: "feature/test" }, {});
expect(result.success).toBe(false);
expect(result.error).toBe("Failed to apply bundle");
expect(global.core.error).toHaveBeenCalledWith(expect.stringContaining("Bundle fetch failed after fetching 1 prerequisite commit(s): fatal: failed to read bundle"));
const bundleRetryFetchCalls = global.exec.exec.mock.calls.filter(([, args]) => Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath);
expect(bundleRetryFetchCalls.length).toBe(1);
});
it("should not fetch a bundle directly into the target branch", async () => {
const patchPath = canonicalPatchPath("autoloop/perf-comparison");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("autoloop/perf-comparison");
fs.writeFileSync(bundlePath, "bundle content");
const { main } = require("./create_pull_request.cjs");
const handler = await main({ base_branch: "main", preserve_branch_name: true });
const result = await handler({ title: "Test PR", body: "Test body\n\nCloses #57\nResolves test-owner/test-repo#58", branch: "autoloop/perf-comparison" }, {});
expect(result.success).toBe(true);
// The initial bundle fetch uses getExecOutput (not exec.exec) — ensure it never uses the direct branch refspec
expect(global.exec.getExecOutput).not.toHaveBeenCalledWith("git", ["fetch", bundlePath, "refs/heads/autoloop/perf-comparison:refs/heads/autoloop/perf-comparison"], expect.anything());
const bundleFetchCall = global.exec.getExecOutput.mock.calls.find(([, args]) => Array.isArray(args) && args[0] === "fetch" && args[1] === bundlePath);
if (!bundleFetchCall) {
throw new Error("expected bundle fetch call");
}
expect(bundleFetchCall[1][2]).toMatch(/^refs\/heads\/autoloop\/perf-comparison:refs\/bundles\/create-pr-autoloop-perf-comparison-[a-f0-9]{8}$/);
const bundleTempRef = bundleFetchCall[1][2].split(":")[1];
expect(global.exec.exec).toHaveBeenCalledWith("git", ["update-ref", "refs/heads/autoloop/perf-comparison", bundleTempRef]);
});
it("should give fallback issue bundle instructions that avoid direct branch fetches", async () => {
const patchPath = canonicalPatchPath("autoloop/perf-comparison");
fs.writeFileSync(
patchPath,
`From abc123 Mon Sep 17 00:00:00 2001
From: Test Author <test@example.com>
Date: Mon, 1 Jan 2024 00:00:00 +0000
Subject: [PATCH] Test commit
diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..abc1234
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+Hello World
--
2.34.1
`
);
const bundlePath = canonicalBundlePath("autoloop/perf-comparison");