-
-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathreview-checkpoints.test.ts
More file actions
68 lines (58 loc) · 2.49 KB
/
Copy pathreview-checkpoints.test.ts
File metadata and controls
68 lines (58 loc) · 2.49 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
import { execFile } from "node:child_process";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { promisify } from "node:util";
import assert from "node:assert/strict";
import { createReviewCheckpointManager } from "./review-checkpoints.js";
const execFileAsync = promisify(execFile);
const root = await mkdtemp(join(tmpdir(), "devspace-review-checkpoints-test-"));
try {
await git(root, ["init"]);
await git(root, ["config", "user.email", "devspace@example.com"]);
await git(root, ["config", "user.name", "DevSpace Test"]);
await writeFile(join(root, "README.md"), "hello\n");
await git(root, ["add", "README.md"]);
await git(root, ["commit", "-m", "Initial commit"]);
const manager = createReviewCheckpointManager();
await manager.initializeWorkspace({ workspaceId: "ws_review", root });
const clean = await manager.reviewChanges({ workspaceId: "ws_review", root });
assert.equal(clean.summary.files, 0);
assert.equal(clean.patch, "");
assert.match(clean.result, /No changes/);
await writeFile(join(root, "README.md"), "hello\nworld\n");
await writeFile(join(root, "new.txt"), "new\n");
const firstReview = await manager.reviewChanges({
workspaceId: "ws_review",
root,
markReviewed: false,
});
assert.equal(firstReview.summary.files, 2);
assert.equal(firstReview.summary.additions, 2);
assert.equal(firstReview.summary.removals, 0);
assert.equal(firstReview.files.some((file) => file.path === "README.md"), true);
assert.equal(firstReview.files.some((file) => file.path === "new.txt"), true);
assert.match(firstReview.patch, /world/);
const restartedManager = createReviewCheckpointManager();
await restartedManager.initializeWorkspace({ workspaceId: "ws_review", root });
const afterRestart = await restartedManager.reviewChanges({
workspaceId: "ws_review",
root,
markReviewed: false,
});
assert.equal(afterRestart.summary.files, 2);
assert.match(afterRestart.patch, /world/);
const stillUnreviewed = await manager.reviewChanges({
workspaceId: "ws_review",
root,
markReviewed: true,
});
assert.equal(stillUnreviewed.summary.files, 2);
const afterReviewed = await manager.reviewChanges({ workspaceId: "ws_review", root });
assert.equal(afterReviewed.summary.files, 0);
} finally {
await rm(root, { recursive: true, force: true });
}
async function git(cwd: string, args: string[]): Promise<void> {
await execFileAsync("git", args, { cwd });
}