Repository navigation
Expand file tree
/
Copy pathCheckpointStore.test.ts
More file actions
571 lines (532 loc) · 23.1 KB
/
Copy pathCheckpointStore.test.ts
File metadata and controls
571 lines (532 loc) · 23.1 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
// @effect-diagnostics nodeBuiltinImport:off
import * as NodePath from "node:path";
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { it } from "@effect/vitest";
import { CheckpointRef, ThreadId, type VcsError } from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as PlatformError from "effect/PlatformError";
import * as Scope from "effect/Scope";
import { describe, expect } from "vite-plus/test";
import * as Base64Url from "effect/encoding/Base64Url";
import { parseTurnDiffFilesFromNumstat } from "./Diffs.ts";
import * as CheckpointStore from "./CheckpointStore.ts";
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
import * as VcsProcess from "../vcs/VcsProcess.ts";
import * as ServerConfig from "../config.ts";
function checkpointRefForThreadTurn(threadId: ThreadId, turnCount: number): CheckpointRef {
return CheckpointRef.make(`refs/t3/checkpoints/${Base64Url.encode(threadId)}/turn/${turnCount}`);
}
const layerServerConfig = ServerConfig.ServerConfig.layerTest(process.cwd(), {
prefix: "t3-checkpoint-store-test-",
});
const layerVcsProcessTest = VcsProcess.layer.pipe(
Layer.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
);
const layerVcsDriverTest = VcsDriverRegistry.layer.pipe(Layer.provide(layerVcsProcessTest));
const layerCheckpointStoreTest = CheckpointStore.layer.pipe(
Layer.provideMerge(layerVcsDriverTest),
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
);
const layerTest = layerCheckpointStoreTest.pipe(
Layer.provideMerge(layerVcsProcessTest),
Layer.provideMerge(layerVcsDriverTest),
Layer.provideMerge(layerServerConfig),
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
);
function makeTmpDir(
prefix = "checkpoint-store-test-",
): Effect.Effect<string, PlatformError.PlatformError, FileSystem.FileSystem | Scope.Scope> {
return Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
return yield* fileSystem.makeTempDirectoryScoped({ prefix });
});
}
function writeTextFile(
filePath: string,
contents: string,
): Effect.Effect<void, PlatformError.PlatformError, FileSystem.FileSystem> {
return Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
yield* fileSystem.writeFileString(filePath, contents);
});
}
function git(
cwd: string,
args: ReadonlyArray<string>,
options: { readonly committedAt?: string; readonly allowNonZeroExit?: boolean } = {},
): Effect.Effect<string, VcsError, VcsProcess.VcsProcess> {
return Effect.gen(function* () {
const vcsProcess = yield* VcsProcess.VcsProcess;
const result = yield* vcsProcess.run({
operation: "CheckpointStore.test.git",
command: "git",
cwd,
args,
timeoutMs: 10_000,
...(options.committedAt === undefined
? {}
: { env: { ...process.env, GIT_COMMITTER_DATE: options.committedAt } }),
...(options.allowNonZeroExit === undefined
? {}
: { allowNonZeroExit: options.allowNonZeroExit }),
});
return result.stdout.trim();
});
}
function initRepoWithCommit(
cwd: string,
): Effect.Effect<
void,
VcsError | PlatformError.PlatformError,
VcsProcess.VcsProcess | FileSystem.FileSystem
> {
return Effect.gen(function* () {
yield* git(cwd, ["init"]);
yield* git(cwd, ["config", "user.email", "test@test.com"]);
yield* git(cwd, ["config", "user.name", "Test"]);
yield* writeTextFile(NodePath.join(cwd, "README.md"), "# test\n");
yield* git(cwd, ["add", "."]);
yield* git(cwd, ["commit", "-m", "initial commit"]);
});
}
function buildLargeText(lineCount = 5_000): string {
return Array.from({ length: lineCount }, (_, index) => `line ${String(index).padStart(5, "0")}`)
.join("\n")
.concat("\n");
}
it.layer(layerTest)("CheckpointStore.layer", (it) => {
it.effect("detects a nested workspace without its own .git entry", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
const fileSystem = yield* FileSystem.FileSystem;
const nested = NodePath.join(tmp, "packages", "nested");
yield* fileSystem.makeDirectory(nested, { recursive: true });
const checkpointStore = yield* CheckpointStore.CheckpointStore;
expect(yield* checkpointStore.isGitRepository(nested)).toBe(true);
}),
);
describe("diffCheckpoints", () => {
it.effect("returns full oversized checkpoint diffs without truncation", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("thread-checkpoint-store");
const fromCheckpointRef = checkpointRefForThreadTurn(threadId, 0);
const toCheckpointRef = checkpointRefForThreadTurn(threadId, 1);
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: fromCheckpointRef,
});
yield* writeTextFile(NodePath.join(tmp, "README.md"), buildLargeText());
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: toCheckpointRef,
});
const diff = yield* checkpointStore.diffCheckpoints({
cwd: tmp,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace: true,
});
expect(diff).toContain("diff --git");
expect(diff).not.toContain("[truncated]");
expect(diff).toContain("+line 04999");
}),
);
it.effect("keeps the patch format clients parse when the repository changes it", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
yield* git(tmp, ["config", "diff.noprefix", "true"]);
yield* git(tmp, ["config", "diff.suppressBlankEmpty", "true"]);
yield* git(tmp, ["config", "diff.submodule", "log"]);
const sub = NodePath.join(tmp, "sub");
yield* git(tmp, ["init", "sub"]);
yield* initRepoWithCommit(sub);
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("thread-checkpoint-store-noprefix");
const fromCheckpointRef = checkpointRefForThreadTurn(threadId, 0);
const toCheckpointRef = checkpointRefForThreadTurn(threadId, 1);
yield* writeTextFile(NodePath.join(tmp, "README.md"), "# test\n\nbefore\n");
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: fromCheckpointRef,
});
yield* writeTextFile(NodePath.join(tmp, "README.md"), "# test\n\nafter\n");
yield* git(sub, ["commit", "--allow-empty", "-m", "moved"]);
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: toCheckpointRef,
});
const diff = yield* checkpointStore.diffCheckpoints({
cwd: tmp,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace: false,
});
expect(diff).toContain("diff --git a/README.md b/README.md");
expect(diff).toContain(" # test\n \n-before\n+after\n");
expect(diff).toContain("diff --git a/sub b/sub");
expect(diff).toContain("+Subproject commit ");
}),
);
it.effect("can hide indentation churn when changes wrap existing lines", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("thread-checkpoint-store-whitespace");
const fromCheckpointRef = checkpointRefForThreadTurn(threadId, 0);
const toCheckpointRef = checkpointRefForThreadTurn(threadId, 1);
const componentPath = NodePath.join(tmp, "Component.tsx");
yield* writeTextFile(
componentPath,
[
"export function View() {",
" return (",
" <section>",
" <h1>Title</h1>",
" <p>Body</p>",
" </section>",
" );",
"}",
"",
].join("\n"),
);
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: fromCheckpointRef,
});
yield* writeTextFile(
componentPath,
[
"export function View() {",
" return (",
" <section>",
" {isReady ? (",
" <div>",
" <h1>Title</h1>",
" <p>Body</p>",
" </div>",
" ) : null}",
" </section>",
" );",
"}",
"",
].join("\n"),
);
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: toCheckpointRef,
});
const normalDiff = yield* checkpointStore.diffCheckpoints({
cwd: tmp,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace: false,
});
const whitespaceIgnoredDiff = yield* checkpointStore.diffCheckpoints({
cwd: tmp,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace: true,
});
expect(normalDiff).toContain("diff --git");
expect(normalDiff).toContain("- <h1>Title</h1>");
expect(normalDiff).toContain("+ <h1>Title</h1>");
expect(whitespaceIgnoredDiff).toContain("diff --git");
expect(whitespaceIgnoredDiff).toContain("+ {isReady ? (");
expect(whitespaceIgnoredDiff).toContain("+ <div>");
expect(whitespaceIgnoredDiff).not.toContain("- <h1>Title</h1>");
expect(whitespaceIgnoredDiff).not.toContain("+ <h1>Title</h1>");
for (const ignoreWhitespace of [false, true]) {
const numstat = yield* checkpointStore.diffCheckpoints({
cwd: tmp,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace,
format: "numstat",
});
expect(parseTurnDiffFilesFromNumstat(numstat)).toEqual([
{
path: "Component.tsx",
additions: ignoreWhitespace ? 4 : 6,
deletions: ignoreWhitespace ? 0 : 2,
},
]);
}
}),
);
});
describe("checkpoint file summaries", () => {
it.effect("counts changes whose full patch exceeds the output limit", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("large-checkpoint-summary");
const fromCheckpointRef = checkpointRefForThreadTurn(threadId, 0);
const toCheckpointRef = checkpointRefForThreadTurn(threadId, 1);
const filePath = NodePath.join(tmp, "README.md");
const lineCount = 20_000;
yield* writeTextFile(filePath, `${"before".repeat(50)}\n`.repeat(lineCount));
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef: fromCheckpointRef });
yield* writeTextFile(filePath, `${"after".repeat(60)}\n`.repeat(lineCount));
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef: toCheckpointRef });
const numstat = yield* checkpointStore.diffCheckpoints({
cwd: tmp,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace: false,
format: "numstat",
});
expect(parseTurnDiffFilesFromNumstat(numstat)).toEqual([
{ path: "README.md", additions: lineCount, deletions: lineCount },
]);
expect(numstat.length).toBeLessThan(100);
}),
);
it.effect("preserves file paths and turn ranges without changing the user index", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
yield* git(tmp, ["config", "diff.renames", "copies"]);
const fileSystem = yield* FileSystem.FileSystem;
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("checkpoint-summary-paths");
const baseline = checkpointRefForThreadTurn(threadId, 0);
const firstTurn = checkpointRefForThreadTurn(threadId, 1);
const secondTurn = checkpointRefForThreadTurn(threadId, 2);
const copiedText = Array.from({ length: 20 }, (_, index) => `copy line ${index}\n`).join(
"",
);
const platform = yield* HostProcess.Platform;
const renamedPath = platform === "win32" ? "renamed café.txt" : "renamed\tcafé\nname.txt";
const addedPath = platform === "win32" ? "new café.txt" : "new\tfile\n名.txt";
for (const [path, contents] of Object.entries({
"copy-source.txt": copiedText,
"deleted.txt": "delete me\n",
"rename-old.txt": "before\nkeep one\nkeep two\nkeep three\n",
"binary.bin": "\0before",
})) {
yield* writeTextFile(NodePath.join(tmp, path), contents);
}
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef: baseline });
yield* fileSystem.rename(
NodePath.join(tmp, "rename-old.txt"),
NodePath.join(tmp, renamedPath),
);
yield* fileSystem.remove(NodePath.join(tmp, "deleted.txt"));
for (const [path, contents] of Object.entries({
"copy-source.txt": `${copiedText}one more\n`,
"copied.txt": copiedText,
[renamedPath]: "after\nkeep one\nkeep two\nkeep three\n",
"binary.bin": "\0after",
"empty.txt": "",
[addedPath]: "first\nsecond\n",
})) {
yield* writeTextFile(NodePath.join(tmp, path), contents);
}
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef: firstTurn });
const userIndex = yield* fileSystem.readFile(NodePath.join(tmp, ".git/index"));
const input = {
cwd: tmp,
fromCheckpointRef: baseline,
toCheckpointRef: firstTurn,
ignoreWhitespace: false,
format: "numstat" as const,
};
const firstSummary = parseTurnDiffFilesFromNumstat(
yield* checkpointStore.diffCheckpoints(input),
);
const expectedFiles = [
{ path: "binary.bin", additions: 0, deletions: 0 },
{ path: "copied.txt", previousPath: "copy-source.txt", additions: 0, deletions: 0 },
{ path: "copy-source.txt", additions: 1, deletions: 0 },
{ path: "deleted.txt", additions: 0, deletions: 1 },
{ path: "empty.txt", additions: 0, deletions: 0 },
{ path: addedPath, additions: 2, deletions: 0 },
{ path: renamedPath, previousPath: "rename-old.txt", additions: 1, deletions: 1 },
].toSorted((left, right) => left.path.localeCompare(right.path));
expect(firstSummary).toEqual(expectedFiles);
yield* fileSystem.remove(NodePath.join(tmp, "empty.txt"));
yield* writeTextFile(NodePath.join(tmp, "copy-source.txt"), "replacement\n");
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef: secondTurn });
const secondSummary = parseTurnDiffFilesFromNumstat(
yield* checkpointStore.diffCheckpoints({
...input,
fromCheckpointRef: firstTurn,
toCheckpointRef: secondTurn,
}),
);
expect(secondSummary).toEqual([
{ path: "copy-source.txt", additions: 1, deletions: 21 },
{ path: "empty.txt", additions: 0, deletions: 0 },
]);
const inclusiveSummary = parseTurnDiffFilesFromNumstat(
yield* checkpointStore.diffCheckpoints({ ...input, toCheckpointRef: secondTurn }),
);
expect(inclusiveSummary).toEqual(
expectedFiles
.filter((file) => file.path !== "empty.txt")
.map((file) =>
file.path === "copy-source.txt" ? { ...file, additions: 1, deletions: 20 } : file,
),
);
expect(
yield* checkpointStore.diffCheckpoints({ ...input, toCheckpointRef: baseline }),
).toBe("");
expect(yield* fileSystem.readFile(NodePath.join(tmp, ".git/index"))).toEqual(userIndex);
}),
);
it.effect("uses HEAD for a missing baseline only when requested", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("checkpoint-summary-fallback");
const fromCheckpointRef = checkpointRefForThreadTurn(threadId, 0);
const toCheckpointRef = checkpointRefForThreadTurn(threadId, 1);
yield* writeTextFile(NodePath.join(tmp, "README.md"), "changed\n");
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef: toCheckpointRef });
const input = {
cwd: tmp,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace: false,
format: "numstat" as const,
};
const error = yield* Effect.flip(checkpointStore.diffCheckpoints(input));
expect(error._tag).toBe("VcsProcessExitError");
const numstat = yield* checkpointStore.diffCheckpoints({
...input,
fallbackFromToHead: true,
});
expect(parseTurnDiffFilesFromNumstat(numstat)).toEqual([
{ path: "README.md", additions: 1, deletions: 1 },
]);
}),
);
it.effect("reads repository paths from a subdirectory workspace under diff.relative", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
yield* git(tmp, ["config", "diff.relative", "true"]);
const fileSystem = yield* FileSystem.FileSystem;
const cwd = NodePath.join(tmp, "app");
yield* fileSystem.makeDirectory(cwd);
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("checkpoint-file-paths-subdirectory");
const refs = {
cwd,
fromCheckpointRef: checkpointRefForThreadTurn(threadId, 0),
toCheckpointRef: checkpointRefForThreadTurn(threadId, 1),
};
yield* checkpointStore.captureCheckpoint({ cwd, checkpointRef: refs.fromCheckpointRef });
yield* writeTextFile(NodePath.join(cwd, "kept.txt"), "kept\n");
yield* git(cwd, ["add", "kept.txt"]);
yield* git(cwd, ["commit", "-m", "kept"]);
yield* writeTextFile(NodePath.join(tmp, "README.md"), "# hidden\n");
yield* checkpointStore.captureCheckpoint({ cwd, checkpointRef: refs.toCheckpointRef });
const patch = yield* checkpointStore.diffCheckpoints({
...refs,
ignoreWhitespace: false,
filePaths: ["app/kept.txt"],
});
expect(patch).toContain("+++ b/app/kept.txt");
expect(patch).toContain("+kept");
expect(patch).not.toContain("hidden");
expect(yield* checkpointStore.listAuthoredPaths(refs)).toEqual(new Set(["app/kept.txt"]));
}),
);
});
describe("listAuthoredPaths", () => {
it.effect("leaves out paths that only a merged upstream changed", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("checkpoint-authored-paths");
const refs = {
cwd: tmp,
fromCheckpointRef: checkpointRefForThreadTurn(threadId, 0),
toCheckpointRef: checkpointRefForThreadTurn(threadId, 1),
};
const commitBeforeTurn = (file: string, contents: string) =>
Effect.gen(function* () {
yield* writeTextFile(NodePath.join(tmp, file), contents);
yield* git(tmp, ["add", "."]);
yield* git(tmp, ["commit", "-m", file], { committedAt: "2020-01-01T00:00:00Z" });
});
yield* git(tmp, ["checkout", "-b", "upstream"]);
yield* commitBeforeTurn("upstream.txt", "upstream\n");
yield* commitBeforeTurn("shared.txt", "upstream\n");
yield* git(tmp, ["checkout", "-"]);
yield* commitBeforeTurn("shared.txt", "ours\n");
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: refs.fromCheckpointRef,
});
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef: refs.toCheckpointRef });
expect(yield* checkpointStore.listAuthoredPaths(refs)).toBeNull();
yield* git(tmp, ["merge", "upstream", "--no-edit"], { allowNonZeroExit: true });
yield* writeTextFile(NodePath.join(tmp, "shared.txt"), "upstream\n");
yield* git(tmp, ["commit", "-am", "merge upstream"]);
yield* writeTextFile(NodePath.join(tmp, "README.md"), "# edited\n");
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef: refs.toCheckpointRef });
const numstat = yield* checkpointStore.diffCheckpoints({
...refs,
ignoreWhitespace: false,
format: "numstat",
});
expect(parseTurnDiffFilesFromNumstat(numstat).map((file) => file.path)).toEqual([
"README.md",
"shared.txt",
"upstream.txt",
]);
expect(yield* checkpointStore.listAuthoredPaths(refs)).toEqual(
new Set(["README.md", "shared.txt"]),
);
}),
);
it.effect("keeps paths from signed commits under log.showSignature", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
yield* initRepoWithCommit(tmp);
const signingKey = NodePath.join(yield* makeTmpDir("checkpoint-signing-key-"), "key");
yield* (yield* VcsProcess.VcsProcess).run({
operation: "CheckpointStore.test.sshKeygen",
command: "ssh-keygen",
cwd: tmp,
args: ["-q", "-t", "ed25519", "-N", "", "-f", signingKey],
timeoutMs: 10_000,
});
yield* git(tmp, ["config", "gpg.format", "ssh"]);
yield* git(tmp, ["config", "user.signingkey", `${signingKey}.pub`]);
yield* git(tmp, ["config", "log.showSignature", "true"]);
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("checkpoint-authored-paths-signed");
const refs = {
cwd: tmp,
fromCheckpointRef: checkpointRefForThreadTurn(threadId, 0),
toCheckpointRef: checkpointRefForThreadTurn(threadId, 1),
};
yield* checkpointStore.captureCheckpoint({
cwd: tmp,
checkpointRef: refs.fromCheckpointRef,
});
yield* writeTextFile(NodePath.join(tmp, "kept.txt"), "kept\n");
yield* git(tmp, ["add", "kept.txt"]);
yield* git(tmp, ["commit", "-S", "-m", "kept"]);
yield* checkpointStore.captureCheckpoint({ cwd: tmp, checkpointRef: refs.toCheckpointRef });
expect(yield* checkpointStore.listAuthoredPaths(refs)).toEqual(new Set(["kept.txt"]));
}),
);
});
});