Open History to see the last commit
1import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { assert, it } from "@effect/vitest";
4import * as SecureRandom from "effect/crypto/SecureRandom";
5import * as Effect from "effect/Effect";
6import * as FileSystem from "effect/FileSystem";
7import * as Layer from "effect/Layer";
8import * as Path from "effect/Path";
9
10import * as VcsProcess from "../../vcs/VcsProcess.ts";
11import * as HandoffGit from "./HandoffGit.ts";
12
13// A thread's git work moves from the laptop's checkout to the box's clone of
14// the same repository: the commits the remote lacks, the edits, the deletes
15// and the new files, exactly, and nothing on the box is overwritten.
16
17const layer = HandoffGit.layer.pipe(
18 Layer.provideMerge(VcsProcess.layer),
19 Layer.provideMerge(Layer.merge(NodeServices.layer, NodeCrypto.layer)),
20);
21
22const sh = (cwd: string, args: ReadonlyArray<string>) =>
23 VcsProcess.VcsProcess.pipe(
24 Effect.flatMap((processes) =>
25 processes.run({
26 operation: "HandoffGit.test",
27 command: "git",
28 cwd,
29 args,
30 env: {
31 ...process.env,
32 GIT_AUTHOR_NAME: "Test",
33 GIT_AUTHOR_EMAIL: "test@example.com",
34 GIT_COMMITTER_NAME: "Test",
35 GIT_COMMITTER_EMAIL: "test@example.com",
36 },
37 }),
38 ),
39 Effect.map((result) => result.stdout.trim()),
40 Effect.orDie,
41 );
42
43/** `git status --porcelain`, sorted; untrimmed, since its first column is a space. */
44const status = (cwd: string) =>
45 VcsProcess.VcsProcess.pipe(
46 Effect.flatMap((processes) =>
47 processes.run({
48 operation: "HandoffGit.test",
49 command: "git",
50 cwd,
51 args: ["status", "--porcelain"],
52 }),
53 ),
54 Effect.map((result) =>
55 result.stdout
56 .split("\n")
57 .filter((line) => line !== "")
58 .sort(),
59 ),
60 Effect.orDie,
61 );
62
63/** An origin with one commit on main, and the laptop's and the box's clones of it. */
64const repos = Effect.gen(function* () {
65 const fileSystem = yield* FileSystem.FileSystem;
66 const path = yield* Path.Path;
67 const root = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-handoff-git-" });
68 const origin = path.join(root, "origin.git");
69 const seed = path.join(root, "seed");
70 yield* fileSystem.makeDirectory(seed);
71 yield* sh(root, ["init", "--quiet", "--bare", "--initial-branch=main", origin]);
72 yield* sh(seed, ["init", "--quiet", "--initial-branch=main"]);
73 yield* fileSystem.writeFileString(path.join(seed, "app.ts"), "export const version = 1;\n");
74 yield* fileSystem.writeFileString(path.join(seed, "old.ts"), "export const gone = true;\n");
75 yield* sh(seed, ["add", "."]);
76 yield* sh(seed, ["commit", "--quiet", "-m", "start"]);
77 yield* sh(seed, ["remote", "add", "origin", origin]);
78 yield* sh(seed, ["push", "--quiet", "origin", "main"]);
79 const laptop = path.join(root, "laptop");
80 const box = path.join(root, "box");
81 yield* sh(root, ["clone", "--quiet", origin, laptop]);
82 yield* sh(root, ["clone", "--quiet", origin, box]);
83 const outDir = path.join(root, "out");
84 yield* fileSystem.makeDirectory(outDir);
85 return { root, origin, laptop, box, outDir };
86});
87
88/** The laptop's thread: an unpushed commit on a branch, then uncommitted work. */
89const workOnLaptop = (laptop: string) =>
90 Effect.gen(function* () {
91 const fileSystem = yield* FileSystem.FileSystem;
92 const path = yield* Path.Path;
93 yield* sh(laptop, ["checkout", "--quiet", "-b", "fix/login"]);
94 yield* fileSystem.writeFileString(path.join(laptop, "app.ts"), "export const version = 2;\n");
95 yield* sh(laptop, ["commit", "--quiet", "-am", "unpushed: bump version"]);
96 yield* fileSystem.writeFileString(path.join(laptop, "app.ts"), "export const version = 3;\n");
97 yield* fileSystem.remove(path.join(laptop, "old.ts"));
98 yield* fileSystem.writeFileString(path.join(laptop, "new.ts"), "export const fresh = true;\n");
99 yield* fileSystem.writeFileString(path.join(laptop, ".env"), "SECRET=1\n");
100 yield* fileSystem.writeFileString(path.join(laptop, ".gitignore"), ".env\n");
101 yield* sh(laptop, ["add", "new.ts"]);
102 });
103
104it.layer(layer)("handing a thread's git work to another checkout", (it) => {
105 it.effect("refuses to move a checkout containing Git submodules", () =>
106 Effect.scoped(
107 Effect.gen(function* () {
108 const handoff = yield* HandoffGit.HandoffGit;
109 const { origin, laptop, outDir } = yield* repos;
110 yield* sh(laptop, [
111 "-c",
112 "protocol.file.allow=always",
113 "submodule",
114 "add",
115 origin,
116 "module",
117 ]);
118 const added = yield* Effect.flip(
119 handoff.pack({ cwd: laptop, handoffId: "added-module", outDir }),
120 );
121 assert.match(added.message, /repositories with Git submodules/);
122
123 yield* sh(laptop, ["commit", "--quiet", "-m", "Add submodule"]);
124 yield* sh(laptop, ["submodule", "deinit", "--", "module"]);
125 const inactive = yield* Effect.flip(
126 handoff.pack({ cwd: laptop, handoffId: "inactive-module", outDir }),
127 );
128 assert.match(inactive.message, /repositories with Git submodules/);
129 }),
130 ),
131 );
132
133 it.effect("refuses a bundle from an older peer that contains a submodule", () =>
134 Effect.scoped(
135 Effect.gen(function* () {
136 const fileSystem = yield* FileSystem.FileSystem;
137 const path = yield* Path.Path;
138 const handoff = yield* HandoffGit.HandoffGit;
139 const { root, origin, laptop, box, outDir } = yield* repos;
140 yield* sh(laptop, [
141 "-c",
142 "protocol.file.allow=always",
143 "submodule",
144 "add",
145 origin,
146 "module",
147 ]);
148 yield* sh(laptop, ["commit", "--quiet", "-m", "Add submodule"]);
149 const tip = yield* sh(laptop, ["rev-parse", "HEAD"]);
150 yield* sh(laptop, ["commit", "--quiet", "--allow-empty", "-m", "Snapshot"]);
151 const snapshot = yield* sh(laptop, ["rev-parse", "HEAD"]);
152 const ref = "refs/t3code/handoff/legacy-module/snapshot";
153 yield* sh(laptop, ["update-ref", ref, snapshot]);
154 const bundlePath = path.join(outDir, "legacy.bundle");
155 yield* sh(laptop, ["bundle", "create", bundlePath, ref, "--not", "--remotes=origin"]);
156
157 const worktreePath = path.join(root, "legacy-checkout");
158 const refused = yield* Effect.flip(
159 handoff.apply({
160 repoRoot: box,
161 worktreePath,
162 handoffId: "legacy-module",
163 bundlePath,
164 branch: null,
165 tip,
166 snapshot,
167 }),
168 );
169 assert.match(refused.message, /repositories with Git submodules/);
170 assert.isFalse(yield* fileSystem.exists(worktreePath));
171 }),
172 ),
173 );
174
175 it.effect("refuses an LFS pointer added to the workspace", () =>
176 Effect.scoped(
177 Effect.gen(function* () {
178 const fileSystem = yield* FileSystem.FileSystem;
179 const path = yield* Path.Path;
180 const handoff = yield* HandoffGit.HandoffGit;
181 const { laptop, outDir } = yield* repos;
182 yield* fileSystem.writeFileString(
183 path.join(laptop, "asset.bin"),
184 `version https://git-lfs.github.com/spec/v1\noid sha256:${"a".repeat(64)}\nsize 123\n`,
185 );
186 const refused = yield* Effect.flip(
187 handoff.pack({ cwd: laptop, handoffId: "lfs-pointer", outDir }),
188 );
189 assert.match(refused.message, /Git LFS files/);
190 }),
191 ),
192 );
193
194 it.effect("carries an unpushed commit, edits, deletes and new files exactly", () =>
195 Effect.scoped(
196 Effect.gen(function* () {
197 const fileSystem = yield* FileSystem.FileSystem;
198 const path = yield* Path.Path;
199 const handoff = yield* HandoffGit.HandoffGit;
200 const { laptop, box, outDir, root } = yield* repos;
201 yield* workOnLaptop(laptop);
202 const stagedBefore = yield* sh(laptop, ["diff", "--cached", "--name-only"]);
203
204 const packed = yield* handoff.pack({ cwd: laptop, handoffId: "h1", outDir });
205 assert.equal(packed.branch, "fix/login");
206 // Packing leaves the laptop's own staging and refs as they were.
207 assert.equal(yield* sh(laptop, ["diff", "--cached", "--name-only"]), stagedBefore);
208 assert.equal(yield* sh(laptop, ["for-each-ref", "refs/t3code"]), "");
209
210 const worktree = path.join(root, "box-worktree");
211 const applied = yield* handoff.apply({
212 repoRoot: box,
213 worktreePath: worktree,
214 handoffId: "h1",
215 bundlePath: packed.bundlePath,
216 branch: packed.branch,
217 tip: packed.tip,
218 snapshot: packed.snapshot,
219 });
220 assert.equal(applied.branch, "fix/login");
221 // The committed work, unpushed on the laptop, is the branch here.
222 assert.equal(yield* sh(worktree, ["rev-parse", "HEAD"]), packed.tip);
223 assert.equal(yield* sh(worktree, ["log", "-1", "--format=%s"]), "unpushed: bump version");
224 // The working tree matches, and shows as uncommitted.
225 assert.equal(
226 yield* fileSystem.readFileString(path.join(worktree, "app.ts")),
227 "export const version = 3;\n",
228 );
229 assert.isFalse(yield* fileSystem.exists(path.join(worktree, "old.ts")));
230 assert.equal(
231 yield* fileSystem.readFileString(path.join(worktree, "new.ts")),
232 "export const fresh = true;\n",
233 );
234 assert.deepEqual(yield* status(worktree), [
235 " D old.ts",
236 " M app.ts",
237 "?? .gitignore",
238 "?? new.ts",
239 ]);
240 // Ignored files stay where they were.
241 assert.isFalse(yield* fileSystem.exists(path.join(worktree, ".env")));
242 assert.equal(yield* sh(box, ["for-each-ref", "refs/t3code"]), "");
243 }),
244 ),
245 );
246
247 it.effect("preserves a branch ending in a nonbreaking space, even when already checked out", () =>
248 Effect.scoped(
249 Effect.gen(function* () {
250 const path = yield* Path.Path;
251 const handoff = yield* HandoffGit.HandoffGit;
252 const { laptop, box, outDir, root } = yield* repos;
253 const branch = "topic\u00a0";
254 yield* sh(laptop, ["checkout", "--quiet", "-b", branch]);
255
256 const packed = yield* handoff.pack({ cwd: laptop, handoffId: "unicode-branch", outDir });
257 const worktree = path.join(root, "box-worktree");
258 const input = {
259 repoRoot: box,
260 worktreePath: worktree,
261 handoffId: "unicode-branch",
262 bundlePath: packed.bundlePath,
263 branch: packed.branch,
264 tip: packed.tip,
265 snapshot: packed.snapshot,
266 };
267 const applied = yield* handoff.apply(input);
268
269 const checkedOut = yield* sh(worktree, [
270 "for-each-ref",
271 "--format=%(HEAD) %(refname) end",
272 "refs/heads",
273 ]);
274 assert.equal(
275 checkedOut.split("\n").find((line) => line.startsWith("* ")),
276 `* refs/heads/${branch} end`,
277 );
278
279 // The destination's only worktree now takes the exact branch at the incoming tip.
280 yield* applied.undo;
281 yield* sh(box, ["checkout", "--quiet", "-b", branch, packed.tip]);
282 yield* handoff.apply(input);
283 assert.equal(yield* sh(worktree, ["rev-parse", "--abbrev-ref", "HEAD"]), "HEAD");
284 assert.equal(yield* sh(worktree, ["rev-parse", "HEAD"]), packed.tip);
285 }),
286 ),
287 );
288
289 it.effect("keeps the branch name when a tag has the same name", () =>
290 Effect.scoped(
291 Effect.gen(function* () {
292 const path = yield* Path.Path;
293 const handoff = yield* HandoffGit.HandoffGit;
294 const { laptop, box, outDir, root } = yield* repos;
295 const branch = "topic";
296 yield* sh(laptop, ["checkout", "--quiet", "-b", branch]);
297 yield* sh(laptop, ["update-ref", `refs/tags/${branch}`, "HEAD"]);
298
299 const packed = yield* handoff.pack({ cwd: laptop, handoffId: "tagged-branch", outDir });
300 const worktree = path.join(root, "box-worktree");
301 yield* handoff.apply({
302 repoRoot: box,
303 worktreePath: worktree,
304 handoffId: "tagged-branch",
305 bundlePath: packed.bundlePath,
306 branch: packed.branch,
307 tip: packed.tip,
308 snapshot: packed.snapshot,
309 });
310
311 assert.equal(yield* sh(worktree, ["symbolic-ref", "HEAD"]), `refs/heads/${branch}`);
312 }),
313 ),
314 );
315
316 it.effect("refuses a branch that moved on here, and leaves everything as it was", () =>
317 Effect.scoped(
318 Effect.gen(function* () {
319 const fileSystem = yield* FileSystem.FileSystem;
320 const path = yield* Path.Path;
321 const handoff = yield* HandoffGit.HandoffGit;
322 const { laptop, box, outDir, root } = yield* repos;
323 yield* workOnLaptop(laptop);
324 const packed = yield* handoff.pack({ cwd: laptop, handoffId: "h2", outDir });
325
326 // The box has its own commit on the same branch.
327 yield* sh(box, ["checkout", "--quiet", "-b", "fix/login"]);
328 yield* fileSystem.writeFileString(path.join(box, "box.ts"), "export const mine = 1;\n");
329 yield* sh(box, ["add", "."]);
330 yield* sh(box, ["commit", "--quiet", "-m", "box-only work"]);
331 yield* sh(box, ["checkout", "--quiet", "main"]);
332 const boxBranch = yield* sh(box, ["rev-parse", "fix/login"]);
333 const worktreesBefore = yield* sh(box, ["worktree", "list", "--porcelain"]);
334
335 const refused = yield* handoff
336 .apply({
337 repoRoot: box,
338 worktreePath: path.join(root, "box-worktree"),
339 handoffId: "h2",
340 bundlePath: packed.bundlePath,
341 branch: packed.branch,
342 tip: packed.tip,
343 snapshot: packed.snapshot,
344 })
345 .pipe(Effect.flip);
346 assert.equal(refused._tag, "HandoffBranchDivergedError");
347 assert.equal(yield* sh(box, ["rev-parse", "fix/login"]), boxBranch);
348 assert.equal(yield* sh(box, ["worktree", "list", "--porcelain"]), worktreesBefore);
349 assert.equal(yield* sh(box, ["for-each-ref", "refs/t3code"]), "");
350 assert.isFalse(yield* fileSystem.exists(path.join(root, "box-worktree")));
351 }),
352 ),
353 );
354
355 it.effect("moves a branch that is behind forward, and undoes it when a later step fails", () =>
356 Effect.scoped(
357 Effect.gen(function* () {
358 const fileSystem = yield* FileSystem.FileSystem;
359 const path = yield* Path.Path;
360 const handoff = yield* HandoffGit.HandoffGit;
361 const { laptop, box, outDir, root } = yield* repos;
362 yield* workOnLaptop(laptop);
363 const packed = yield* handoff.pack({ cwd: laptop, handoffId: "h3", outDir });
364 // The box has the branch at main, behind the laptop's tip.
365 yield* sh(box, ["branch", "fix/login", "main"]);
366 const before = yield* sh(box, ["rev-parse", "fix/login"]);
367
368 // The worktree path is taken, so adding the worktree fails after the branch moved.
369 const taken = path.join(root, "taken");
370 yield* fileSystem.makeDirectory(taken);
371 yield* fileSystem.writeFileString(path.join(taken, "keep.txt"), "mine\n");
372 const failed = yield* handoff
373 .apply({
374 repoRoot: box,
375 worktreePath: taken,
376 handoffId: "h3",
377 bundlePath: packed.bundlePath,
378 branch: packed.branch,
379 tip: packed.tip,
380 snapshot: packed.snapshot,
381 })
382 .pipe(Effect.flip);
383 assert.equal(failed._tag, "HandoffGitStepError");
384 assert.equal(yield* sh(box, ["rev-parse", "fix/login"]), before);
385 assert.equal(yield* sh(box, ["for-each-ref", "refs/t3code"]), "");
386 assert.equal(yield* fileSystem.readFileString(path.join(taken, "keep.txt")), "mine\n");
387
388 // With a free path it moves forward and applies.
389 const applied = yield* handoff.apply({
390 repoRoot: box,
391 worktreePath: path.join(root, "box-worktree"),
392 handoffId: "h3",
393 bundlePath: packed.bundlePath,
394 branch: packed.branch,
395 tip: packed.tip,
396 snapshot: packed.snapshot,
397 });
398 assert.equal(applied.branch, "fix/login");
399 assert.equal(yield* sh(box, ["rev-parse", "fix/login"]), packed.tip);
400 }),
401 ),
402 );
403
404 it.effect("carries the whole working tree when the thread sits in a subdirectory", () =>
405 Effect.scoped(
406 Effect.gen(function* () {
407 const fileSystem = yield* FileSystem.FileSystem;
408 const path = yield* Path.Path;
409 const handoff = yield* HandoffGit.HandoffGit;
410 const { laptop, box, outDir, root } = yield* repos;
411 yield* workOnLaptop(laptop);
412 const packages = path.join(laptop, "packages");
413 yield* fileSystem.makeDirectory(packages);
414 yield* fileSystem.writeFileString(path.join(packages, "lib.ts"), "export const lib = 1;\n");
415
416 const packed = yield* handoff.pack({ cwd: packages, handoffId: "h6", outDir });
417 const worktree = path.join(root, "box-worktree");
418 yield* handoff.apply({
419 repoRoot: box,
420 worktreePath: worktree,
421 handoffId: "h6",
422 bundlePath: packed.bundlePath,
423 branch: packed.branch,
424 tip: packed.tip,
425 snapshot: packed.snapshot,
426 });
427 // Edits above the subdirectory travel too, not only those under it.
428 assert.deepEqual(yield* status(worktree), [
429 " D old.ts",
430 " M app.ts",
431 "?? .gitignore",
432 "?? new.ts",
433 "?? packages/",
434 ]);
435 }),
436 ),
437 );
438
439 it.effect("runs no repository hooks, and its undo keeps a branch someone moved since", () =>
440 Effect.scoped(
441 Effect.gen(function* () {
442 const handoff = yield* HandoffGit.HandoffGit;
443 const { laptop, box, outDir } = yield* repos;
444 yield* workOnLaptop(laptop);
445 const packed = yield* handoff.pack({ cwd: laptop, handoffId: "h7", outDir });
446 // A checkout hook would run with this machine's rights on content another one sent.
447 const hooks = yield* sh(box, [
448 "rev-parse",
449 "--path-format=absolute",
450 "--git-path",
451 "hooks",
452 ]);
453 const fileSystem = yield* FileSystem.FileSystem;
454 const path = yield* Path.Path;
455 const ran = path.join(path.dirname(box), "hook-ran");
456 const hook = path.join(hooks, "post-checkout");
457 yield* fileSystem.makeDirectory(hooks, { recursive: true });
458 yield* fileSystem.writeFileString(hook, `#!/bin/sh\ntouch "${ran}"\nexit 1\n`);
459 yield* fileSystem.chmod(hook, 0o755);
460
461 const applied = yield* handoff.apply({
462 repoRoot: box,
463 worktreePath: path.join(path.dirname(box), "box-worktree"),
464 handoffId: "h7",
465 bundlePath: packed.bundlePath,
466 branch: packed.branch,
467 tip: packed.tip,
468 snapshot: packed.snapshot,
469 });
470 assert.isFalse(yield* fileSystem.exists(ran));
471
472 // Someone moves the branch the apply created; taking the apply back leaves it theirs.
473 const moved = yield* sh(box, ["rev-parse", "main"]);
474 yield* sh(box, ["update-ref", "refs/heads/fix/login", moved]);
475 yield* applied.undo;
476 assert.equal(yield* sh(box, ["rev-parse", "fix/login"]), moved);
477 }),
478 ),
479 );
480
481 it.effect("carries commits only another remote has, and takes the whole apply back", () =>
482 Effect.scoped(
483 Effect.gen(function* () {
484 const fileSystem = yield* FileSystem.FileSystem;
485 const path = yield* Path.Path;
486 const handoff = yield* HandoffGit.HandoffGit;
487 const { laptop, box, outDir, root } = yield* repos;
488 yield* workOnLaptop(laptop);
489 // Pushed to a fork the box has never heard of.
490 const fork = path.join(root, "fork.git");
491 yield* sh(root, ["init", "--quiet", "--bare", fork]);
492 yield* sh(laptop, ["remote", "add", "fork", fork]);
493 yield* sh(laptop, ["push", "--quiet", "fork", "fix/login"]);
494 yield* sh(laptop, ["fetch", "--quiet", "fork"]);
495
496 const packed = yield* handoff.pack({ cwd: laptop, handoffId: "h6", outDir });
497 const worktree = path.join(root, "box-worktree");
498 // A snapshot sent with a tip it was not made on is refused before any branch moves.
499 const mismatched = yield* handoff
500 .apply({
501 repoRoot: box,
502 worktreePath: worktree,
503 handoffId: "h6",
504 bundlePath: packed.bundlePath,
505 branch: packed.branch,
506 tip: yield* sh(box, ["rev-parse", "main"]),
507 snapshot: packed.snapshot,
508 })
509 .pipe(Effect.flip);
510 assert.equal(mismatched._tag, "HandoffGitStepError");
511 assert.equal(yield* sh(box, ["for-each-ref", "refs/heads/fix/login"]), "");
512 const applied = yield* handoff.apply({
513 repoRoot: box,
514 worktreePath: worktree,
515 handoffId: "h6",
516 bundlePath: packed.bundlePath,
517 branch: packed.branch,
518 tip: packed.tip,
519 snapshot: packed.snapshot,
520 });
521 assert.equal(yield* sh(worktree, ["rev-parse", "HEAD"]), packed.tip);
522
523 // A second apply aimed at the same path fails without touching the checkout there.
524 const occupied = yield* handoff
525 .apply({
526 repoRoot: box,
527 worktreePath: worktree,
528 handoffId: "h6",
529 bundlePath: packed.bundlePath,
530 branch: packed.branch,
531 tip: packed.tip,
532 snapshot: packed.snapshot,
533 })
534 .pipe(Effect.flip);
535 assert.equal(occupied._tag, "HandoffGitStepError");
536 assert.include(occupied.message, "already sits");
537 assert.equal(yield* sh(worktree, ["rev-parse", "HEAD"]), packed.tip);
538
539 // A caller whose own next step fails leaves neither the checkout nor the branch.
540 yield* applied.undo;
541 assert.isFalse(yield* fileSystem.exists(worktree));
542 assert.equal(yield* sh(box, ["for-each-ref", "refs/heads/fix/login"]), "");
543 }),
544 ),
545 );
546
547 it.effect("fetches the base a bundle builds on, and refuses work over the size limit", () =>
548 Effect.scoped(
549 Effect.gen(function* () {
550 const fileSystem = yield* FileSystem.FileSystem;
551 const path = yield* Path.Path;
552 const handoff = yield* HandoffGit.HandoffGit;
553 const { laptop, box, outDir, root } = yield* repos;
554 // The laptop's branch builds on a commit pushed after the box cloned.
555 yield* fileSystem.writeFileString(path.join(laptop, "pushed.ts"), "export const p = 1;\n");
556 yield* sh(laptop, ["add", "."]);
557 yield* sh(laptop, ["commit", "--quiet", "-m", "pushed later"]);
558 // Pushed through the remote, so the laptop knows origin has it and the
559 // bundle leaves it out: the box has to fetch it.
560 yield* sh(laptop, ["push", "--quiet", "origin", "main"]);
561 yield* workOnLaptop(laptop);
562 const packed = yield* handoff.pack({ cwd: laptop, handoffId: "h4", outDir });
563 assert.isFalse(
564 (yield* sh(packed.bundlePath.replace(/\/[^/]+$/, ""), [
565 "bundle",
566 "list-heads",
567 packed.bundlePath,
568 ])).includes(yield* sh(laptop, ["rev-parse", "main"])),
569 );
570 const applied = yield* handoff.apply({
571 repoRoot: box,
572 worktreePath: path.join(root, "box-worktree"),
573 handoffId: "h4",
574 bundlePath: packed.bundlePath,
575 branch: packed.branch,
576 tip: packed.tip,
577 snapshot: packed.snapshot,
578 });
579 assert.equal(applied.branch, "fix/login");
580 assert.isTrue(yield* fileSystem.exists(path.join(root, "box-worktree", "pushed.ts")));
581
582 // An untracked file bigger than a handoff carries, and incompressible.
583 const random = yield* SecureRandom.SecureRandom;
584 yield* fileSystem.writeFile(
585 path.join(laptop, "big.bin"),
586 yield* random.randomBytes(HandoffGit.MAX_HANDOFF_BUNDLE_BYTES + 1024).pipe(Effect.orDie),
587 );
588 const tooLarge = yield* handoff
589 .pack({ cwd: laptop, handoffId: "h5", outDir })
590 .pipe(Effect.flip);
591 assert.equal(tooLarge._tag, "HandoffTooLargeError");
592 assert.isFalse(yield* fileSystem.exists(path.join(outDir, "h5.bundle")));
593 }),
594 ),
595 );
596});