-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract.test.ts
More file actions
606 lines (527 loc) · 23.7 KB
/
extract.test.ts
File metadata and controls
606 lines (527 loc) · 23.7 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
import { describe, expect, test } from "bun:test";
import { existsSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { arb, fetchAllRepos, git, withEnv, write } from "./helpers/env";
// ── Helpers ──
/** Create a workspace with N commits in a single repo. Returns commit SHAs (oldest first). */
async function setupWithCommits(env: { projectDir: string }, wsName: string, commitCount: number): Promise<string[]> {
await arb(env, ["create", wsName, "-b", wsName, "repo-a"]);
const shas: string[] = [];
const wt = join(env.projectDir, wsName, "repo-a");
for (let i = 1; i <= commitCount; i++) {
await write(join(wt, `file${i}.txt`), `content ${i}`);
await git(wt, ["add", `file${i}.txt`]);
await git(wt, ["commit", "-m", `commit ${i}`]);
shas.push((await git(wt, ["rev-parse", "HEAD"])).trim());
}
return shas;
}
/** Read workspace config JSON. */
async function readConfig(env: { projectDir: string }, wsName: string): Promise<Record<string, string>> {
return JSON.parse(await readFile(join(env.projectDir, wsName, ".arbws/config.json"), "utf-8"));
}
/** Get log output from a worktree. */
async function logOneline(env: { projectDir: string }, wsName: string, repo: string): Promise<string> {
return git(join(env.projectDir, wsName, repo), ["log", "--oneline"]);
}
// ── Validation ──
describe("extract validation", () => {
test("errors when no direction flag given", () =>
withEnv(async (env) => {
await arb(env, ["create", "ws", "-b", "ws", "repo-a"]);
const result = await arb(env, ["extract", "new-ws"], { cwd: join(env.projectDir, "ws") });
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("Specify --ending-with");
}));
test("errors when workspace name already exists", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
await arb(env, ["create", "existing", "-b", "existing", "repo-a"]);
const result = await arb(env, ["extract", "existing", "--ending-with", shas[1] ?? ""], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("already exists");
}));
test("errors when target branch already exists in a repo", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
await git(join(env.projectDir, ".arb/repos/repo-a"), ["branch", "prereq"]);
const result = await arb(env, ["extract", "prereq", "--ending-with", shas[1] ?? ""], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("already exists");
}));
test("errors when target branch matches workspace branch", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
const result = await arb(env, ["extract", "other", "-b", "ws", "--ending-with", shas[1] ?? ""], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("current workspace branch");
}));
test("blocks when repo is dirty", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
await write(join(env.projectDir, "ws/repo-a/dirty.txt"), "dirty");
const result = await arb(env, ["extract", "prereq", "--ending-with", shas[1] ?? "", "--yes", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("blocked");
}));
test("dirty skip reason hints about --autostash", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
await write(join(env.projectDir, "ws/repo-a/dirty.txt"), "dirty");
const result = await arb(env, ["extract", "prereq", "--ending-with", shas[1] ?? "", "--dry-run", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.output).toContain("--autostash");
}));
test("succeeds with --autostash when repo is dirty", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
await write(join(env.projectDir, "ws/repo-a/dirty.txt"), "dirty");
const result = await arb(
env,
["extract", "prereq", "--ending-with", shas[1] ?? "", "--yes", "--no-fetch", "--autostash"],
{ cwd: join(env.projectDir, "ws") },
);
expect(result.exitCode).toBe(0);
expect(result.output).toContain("Created workspace");
}));
});
// ── Prefix extraction (--to) ──
describe("extract --to (prefix)", () => {
test("extracts prefix commits into new workspace", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 5);
const result = await arb(env, ["extract", "prereq", "--ending-with", shas[2] ?? "", "--yes", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).toBe(0);
expect(result.output).toContain("Created workspace");
expect(result.output).toContain("Created workspace 'prereq'");
// New workspace exists
expect(existsSync(join(env.projectDir, "prereq/.arbws/config.json"))).toBe(true);
// New workspace has commits 1-3
const prereqLog = await logOneline(env, "prereq", "repo-a");
expect(prereqLog).toContain("commit 1");
expect(prereqLog).toContain("commit 2");
expect(prereqLog).toContain("commit 3");
expect(prereqLog).not.toContain("commit 4");
// Original has commits 4-5 (rebased onto prereq)
const wsLog = await logOneline(env, "ws", "repo-a");
expect(wsLog).toContain("commit 4");
expect(wsLog).toContain("commit 5");
// Config updated
const wsConfig = await readConfig(env, "ws");
expect(wsConfig.base).toBe("prereq");
const prereqConfig = await readConfig(env, "prereq");
expect(prereqConfig.branch).toBe("prereq");
}));
test("dry-run shows plan without executing", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
const result = await arb(env, ["extract", "prereq", "--ending-with", shas[1] ?? "", "--dry-run", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).toBe(0);
expect(result.output).toContain("EXTRACTED (prereq)");
expect(result.output).toContain("STAYS (ws)");
expect(result.output).toContain("Dry run");
// Workspace should NOT be created
expect(existsSync(join(env.projectDir, "prereq"))).toBe(false);
}));
test("explicit branch name with -b", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
const result = await arb(
env,
["extract", "prereq", "-b", "feat/prereq", "--ending-with", shas[1] ?? "", "--yes", "--no-fetch"],
{ cwd: join(env.projectDir, "ws") },
);
expect(result.exitCode).toBe(0);
const config = await readConfig(env, "prereq");
expect(config.branch).toBe("feat/prereq");
}));
test("extracts all commits when boundary is HEAD", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
// Extract all 3 commits (boundary = HEAD)
const result = await arb(env, ["extract", "prereq", "--ending-with", shas[2] ?? "", "--yes", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).toBe(0);
// prereq has all 3 commits, ws is rebased on top with nothing new
const prereqLog = await logOneline(env, "prereq", "repo-a");
expect(prereqLog).toContain("commit 3");
expect(prereqLog).toContain("commit 1");
}));
});
// ── Suffix extraction (--starting-with) ──
describe("extract --starting-with (suffix)", () => {
test("extracts suffix commits into new workspace", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 5);
// Extract commits 4 and 5 (boundary = shas[3], inclusive)
const result = await arb(env, ["extract", "cont", "--starting-with", shas[3] ?? "", "--yes", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).toBe(0);
expect(result.output).toContain("Created workspace");
expect(result.output).toContain("Created workspace 'cont'");
// Original should have commits 1-3
const wsLog = await logOneline(env, "ws", "repo-a");
expect(wsLog).toContain("commit 1");
expect(wsLog).toContain("commit 2");
expect(wsLog).toContain("commit 3");
expect(wsLog).not.toContain("commit 4");
// New workspace should have commits 4-5 (plus the full history)
const contLog = await logOneline(env, "cont", "repo-a");
expect(contLog).toContain("commit 4");
expect(contLog).toContain("commit 5");
// New workspace stacks on original
const contConfig = await readConfig(env, "cont");
expect(contConfig.base).toBe("ws");
// Original config unchanged
const wsConfig = await readConfig(env, "ws");
expect(wsConfig.base).toBeUndefined();
}));
test("extracts single commit at tip", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
const result = await arb(env, ["extract", "tip", "--starting-with", shas[2] ?? "", "--yes", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).toBe(0);
// Original should have commits 1-2
const wsLog = await logOneline(env, "ws", "repo-a");
expect(wsLog).toContain("commit 2");
expect(wsLog).not.toContain("commit 3");
}));
});
// ── Split point syntax ──
describe("extract split point syntax", () => {
test("repo:commit-ish syntax", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
const result = await arb(
env,
["extract", "prereq", "--ending-with", `repo-a:${shas[1] ?? ""}`, "--yes", "--no-fetch"],
{
cwd: join(env.projectDir, "ws"),
},
);
expect(result.exitCode).toBe(0);
const prereqLog = await logOneline(env, "prereq", "repo-a");
expect(prereqLog).toContain("commit 1");
expect(prereqLog).toContain("commit 2");
expect(prereqLog).not.toContain("commit 3");
}));
test("bare SHA auto-detects repo", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
// Use a full SHA without repo prefix — should auto-detect repo-a
const result = await arb(env, ["extract", "prereq", "--ending-with", shas[0] ?? "", "--dry-run", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).toBe(0);
expect(result.output).toContain("EXTRACTED (prereq)");
}));
test("non-existent SHA gives clear error", () =>
withEnv(async (env) => {
await setupWithCommits(env, "ws", 3);
const result = await arb(
env,
["extract", "prereq", "--ending-with", "deadbeef00000000", "--dry-run", "--no-fetch"],
{ cwd: join(env.projectDir, "ws") },
);
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("cannot resolve");
}));
test("non-existent repo prefix gives clear error", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
const result = await arb(
env,
["extract", "prereq", "--ending-with", `nonexistent:${shas[0] ?? ""}`, "--dry-run", "--no-fetch"],
{ cwd: join(env.projectDir, "ws") },
);
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("not in this workspace");
}));
test("duplicate repo in split points gives clear error", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
const result = await arb(
env,
[
"extract",
"prereq",
"--ending-with",
`repo-a:${shas[0] ?? ""},repo-a:${shas[1] ?? ""}`,
"--dry-run",
"--no-fetch",
],
{ cwd: join(env.projectDir, "ws") },
);
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("duplicate");
}));
});
// ── Abort / continue validation ──
describe("extract --abort/--continue validation", () => {
test("--abort errors when no extract in progress", () =>
withEnv(async (env) => {
await arb(env, ["create", "ws", "-b", "ws", "repo-a"]);
const result = await arb(env, ["extract", "x", "--abort"], { cwd: join(env.projectDir, "ws") });
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("No extract in progress");
}));
test("--continue errors when no extract in progress", () =>
withEnv(async (env) => {
await arb(env, ["create", "ws", "-b", "ws", "repo-a"]);
const result = await arb(env, ["extract", "x", "--continue"], { cwd: join(env.projectDir, "ws") });
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("No extract in progress");
}));
test("--abort rejects --ending-with flag", () =>
withEnv(async (env) => {
await arb(env, ["create", "ws", "-b", "ws", "repo-a"]);
const result = await arb(env, ["extract", "x", "--abort", "--ending-with", "abc"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("does not accept");
}));
});
// ── Undo ──
describe("arb undo (extract)", () => {
test("undo reverses a completed prefix extraction", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 4);
const preSha = (await git(join(env.projectDir, "ws/repo-a"), ["rev-parse", "HEAD"])).trim();
await arb(env, ["extract", "prereq", "--ending-with", shas[1] ?? "", "--yes", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
// Verify extract worked
expect(existsSync(join(env.projectDir, "prereq/.arbws/config.json"))).toBe(true);
// Undo
const undoResult = await arb(env, ["undo", "--yes"], { cwd: join(env.projectDir, "ws") });
expect(undoResult.exitCode).toBe(0);
// Original HEAD should be restored
const postSha = (await git(join(env.projectDir, "ws/repo-a"), ["rev-parse", "HEAD"])).trim();
expect(postSha).toBe(preSha);
// Config should be restored (no base)
const wsConfig = await readConfig(env, "ws");
expect(wsConfig.base).toBeUndefined();
// Branch should be cleaned up in canonical repo
const branchList = await git(join(env.projectDir, ".arb/repos/repo-a"), ["branch", "--list", "prereq"]);
expect(branchList.trim()).toBe("");
}));
test("undo reverses a completed suffix extraction", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 4);
const preSha = (await git(join(env.projectDir, "ws/repo-a"), ["rev-parse", "HEAD"])).trim();
await arb(env, ["extract", "cont", "--starting-with", shas[2] ?? "", "--yes", "--no-fetch"], {
cwd: join(env.projectDir, "ws"),
});
const undoResult = await arb(env, ["undo", "--yes"], { cwd: join(env.projectDir, "ws") });
expect(undoResult.exitCode).toBe(0);
// Original HEAD restored
const postSha = (await git(join(env.projectDir, "ws/repo-a"), ["rev-parse", "HEAD"])).trim();
expect(postSha).toBe(preSha);
// Branch cleaned up
const branchList = await git(join(env.projectDir, ".arb/repos/repo-a"), ["branch", "--list", "cont"]);
expect(branchList.trim()).toBe("");
}));
test("undo reverses suffix extraction with autostash", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 4);
const wt = join(env.projectDir, "ws/repo-a");
// Make the workspace dirty
await write(join(wt, "dirty.txt"), "uncommitted work");
const preSha = (await git(wt, ["rev-parse", "HEAD"])).trim();
// Extract with autostash
const extractResult = await arb(
env,
["extract", "cont", "--starting-with", shas[2] ?? "", "--yes", "--no-fetch", "--autostash"],
{ cwd: join(env.projectDir, "ws") },
);
expect(extractResult.exitCode).toBe(0);
// After extract, original should be reset (dirty file stashed)
const wsAhead = await git(wt, ["rev-list", "--count", "origin/main..HEAD"]);
expect(Number.parseInt(wsAhead.trim(), 10)).toBe(2); // commits 1-2
// Undo
const undoResult = await arb(env, ["undo", "--yes"], { cwd: join(env.projectDir, "ws") });
expect(undoResult.exitCode).toBe(0);
// HEAD restored
const postSha = (await git(wt, ["rev-parse", "HEAD"])).trim();
expect(postSha).toBe(preSha);
// Branch cleaned up
const branchList = await git(join(env.projectDir, ".arb/repos/repo-a"), ["branch", "--list", "cont"]);
expect(branchList.trim()).toBe("");
}));
});
// ── Verbose mode ──
describe("extract --verbose", () => {
test("prefix verbose shows extracted and stays commit subjects", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 5);
const boundary = shas[2] ?? "";
const result = await arb(env, ["extract", "prereq", "--ending-with", boundary, "--verbose", "--dry-run", "-N"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).toBe(0);
// Extracted commits (1..3)
expect(result.output).toContain("Extracted to prereq:");
expect(result.output).toContain("commit 1");
expect(result.output).toContain("commit 2");
expect(result.output).toContain("commit 3");
// Stays commits (4..5)
expect(result.output).toContain("Stays in ws:");
expect(result.output).toContain("commit 4");
expect(result.output).toContain("commit 5");
}));
test("suffix verbose shows stays and extracted commit subjects", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 5);
const boundary = shas[2] ?? "";
const result = await arb(env, ["extract", "cont", "--starting-with", boundary, "--verbose", "--dry-run", "-N"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).toBe(0);
// Stays commits (1..2)
expect(result.output).toContain("Stays in ws:");
expect(result.output).toContain("commit 1");
expect(result.output).toContain("commit 2");
// Extracted commits (3..5)
expect(result.output).toContain("Extracted to cont:");
expect(result.output).toContain("commit 3");
expect(result.output).toContain("commit 4");
expect(result.output).toContain("commit 5");
}));
test("verbose does not show commits for no-op repos", () =>
withEnv(async (env) => {
// Create workspace with two repos
await arb(env, ["create", "ws", "-b", "ws", "repo-a", "repo-b"]);
const wt = join(env.projectDir, "ws", "repo-a");
const shas: string[] = [];
for (let i = 1; i <= 3; i++) {
await write(join(wt, `file${i}.txt`), `content ${i}`);
await git(wt, ["add", `file${i}.txt`]);
await git(wt, ["commit", "-m", `commit ${i}`]);
shas.push((await git(wt, ["rev-parse", "HEAD"])).trim());
}
// repo-b has no commits — will be no-op
const boundary = shas[1] ?? "";
const result = await arb(
env,
["extract", "prereq", "--ending-with", `repo-a:${boundary}`, "--verbose", "--dry-run", "-N"],
{
cwd: join(env.projectDir, "ws"),
},
);
expect(result.exitCode).toBe(0);
// repo-a should have verbose sections
expect(result.output).toContain("Extracted to prereq:");
// repo-b is no-op — output should show "no commits" but no verbose section for it
expect(result.output).toContain("repo-b");
// Only one "Extracted to prereq:" label (for repo-a, not repo-b)
const extractedCount = result.output.split("Extracted to prereq:").length - 1;
expect(extractedCount).toBe(1);
}));
test("verbose with --dry-run still shows verbose output", () =>
withEnv(async (env) => {
const shas = await setupWithCommits(env, "ws", 3);
const boundary = shas[1] ?? "";
const result = await arb(env, ["extract", "prereq", "--ending-with", boundary, "--verbose", "--dry-run", "-N"], {
cwd: join(env.projectDir, "ws"),
});
expect(result.exitCode).toBe(0);
expect(result.output).toContain("Extracted to prereq:");
expect(result.output).toContain("Stays in ws:");
expect(result.output).toContain("Dry run");
}));
});
// ── Merge-point floor validation ──
/**
* Set up a workspace whose branch has been squash-merged into the base,
* with additional post-merge commits.
*
* Returns { preMergeShas, postMergeShas } — the SHAs of commits before/after the merge point.
*/
async function setupMergedWithNewCommits(
env: { projectDir: string; testDir: string },
wsName: string,
preMergeCount: number,
postMergeCount: number,
): Promise<{ preMergeShas: string[]; postMergeShas: string[] }> {
await arb(env, ["create", wsName, "-b", wsName, "repo-a"]);
const wt = join(env.projectDir, `${wsName}/repo-a`);
// Make pre-merge commits and push
const preMergeShas: string[] = [];
for (let i = 1; i <= preMergeCount; i++) {
await write(join(wt, `pre${i}.txt`), `pre ${i}`);
await git(wt, ["add", `pre${i}.txt`]);
await git(wt, ["commit", "-m", `pre-merge commit ${i}`]);
preMergeShas.push((await git(wt, ["rev-parse", "HEAD"])).trim());
}
await git(wt, ["push", "-u", "origin", wsName]);
// Squash-merge the branch into main on the canonical repo
const mainRepo = join(env.projectDir, ".arb/repos/repo-a");
await git(mainRepo, ["merge", "--squash", `origin/${wsName}`]);
await git(mainRepo, ["commit", "-m", `squash: ${wsName}`]);
await git(mainRepo, ["push"]);
// Make post-merge commits on the branch
const postMergeShas: string[] = [];
for (let i = 1; i <= postMergeCount; i++) {
await write(join(wt, `post${i}.txt`), `post ${i}`);
await git(wt, ["add", `post${i}.txt`]);
await git(wt, ["commit", "-m", `post-merge commit ${i}`]);
postMergeShas.push((await git(wt, ["rev-parse", "HEAD"])).trim());
}
// Fetch so merge detection picks up the squash
await fetchAllRepos(env);
return { preMergeShas, postMergeShas };
}
describe("extract merge-point floor validation", () => {
test("rejects --starting-with pointing to a pre-merge commit", () =>
withEnv(async (env) => {
const { preMergeShas } = await setupMergedWithNewCommits(env, "ws", 2, 2);
const result = await arb(
env,
["extract", "cont", "--starting-with", preMergeShas[0] ?? "", "--dry-run", "--no-fetch"],
{ cwd: join(env.projectDir, "ws") },
);
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("before the merge point");
}));
test("rejects --ending-with pointing to a pre-merge commit", () =>
withEnv(async (env) => {
const { preMergeShas } = await setupMergedWithNewCommits(env, "ws", 2, 2);
const result = await arb(
env,
["extract", "prereq", "--ending-with", preMergeShas[0] ?? "", "--dry-run", "--no-fetch"],
{ cwd: join(env.projectDir, "ws") },
);
expect(result.exitCode).not.toBe(0);
expect(result.output).toContain("before the merge point");
}));
test("accepts --starting-with pointing to a post-merge commit", () =>
withEnv(async (env) => {
const { postMergeShas } = await setupMergedWithNewCommits(env, "ws", 2, 3);
const result = await arb(
env,
["extract", "cont", "--starting-with", postMergeShas[1] ?? "", "--yes", "--no-fetch"],
{ cwd: join(env.projectDir, "ws") },
);
expect(result.exitCode).toBe(0);
expect(result.output).toContain("Created workspace");
}));
});