Skip to content

Commit dcb5811

Browse files
committed
test(server): cover racy review diffs with split indexes
1 parent 2714602 commit dcb5811

1 file changed

Lines changed: 42 additions & 34 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,40 +1320,48 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
13201320
}),
13211321
);
13221322

1323-
for (const timestamp of [1_700_000_000, 1_700_000_000.9999]) {
1324-
it.effect(`preserves same-size edits with a racy review index (${timestamp})`, () =>
1325-
Effect.gen(function* () {
1326-
const cwd = yield* makeTmpDir();
1327-
yield* initRepoWithCommit(cwd);
1328-
const driver = yield* GitVcsDriver.GitVcsDriver;
1329-
const fileSystem = yield* FileSystem.FileSystem;
1330-
const path = yield* Path.Path;
1331-
const filePath = path.join(cwd, "tracked.txt");
1332-
const indexPath = path.join(cwd, ".git", "index");
1333-
// Reproduce a same-timestamp edit without relying on filesystem clock resolution.
1334-
yield* git(cwd, ["config", "core.trustctime", "false"]);
1335-
yield* writeTextFile(cwd, "tracked.txt", "before\n");
1336-
yield* fileSystem.utimes(filePath, timestamp, timestamp);
1337-
yield* git(cwd, ["add", "tracked.txt"]);
1338-
yield* git(cwd, ["commit", "-m", "record racy file"]);
1339-
yield* fileSystem.utimes(indexPath, timestamp, timestamp);
1340-
const originalIndex = yield* fileSystem.readFile(indexPath);
1341-
const originalIndexMtime = (yield* fileSystem.stat(indexPath)).mtime;
1342-
yield* writeTextFile(cwd, "tracked.txt", "after!\n");
1343-
yield* fileSystem.utimes(filePath, timestamp, timestamp);
1344-
yield* writeTextFile(cwd, "untracked.txt", "new\n");
1345-
1346-
const preview = yield* driver.getReviewDiffPreview({ cwd });
1347-
const dirty = preview.sources.find((source) => source.kind === "working-tree")!;
1348-
assert.deepStrictEqual(dirty.files, [
1349-
{ path: "tracked.txt", previousPath: null, additions: 1, deletions: 1 },
1350-
{ path: "untracked.txt", previousPath: null, additions: 1, deletions: 0 },
1351-
]);
1352-
assert.include(dirty.diff, "-before");
1353-
assert.include(dirty.diff, "+after!");
1354-
assert.deepStrictEqual(yield* fileSystem.readFile(indexPath), originalIndex);
1355-
assert.deepStrictEqual((yield* fileSystem.stat(indexPath)).mtime, originalIndexMtime);
1356-
}),
1323+
for (const [timestamp, splitIndex] of [
1324+
[1_700_000_000, false],
1325+
[1_700_000_000.9999, false],
1326+
[1_700_000_000, true],
1327+
[1_700_000_000.9999, true],
1328+
] as const) {
1329+
it.effect(
1330+
`preserves same-size edits with a racy review index (${timestamp}, split: ${splitIndex})`,
1331+
() =>
1332+
Effect.gen(function* () {
1333+
const cwd = yield* makeTmpDir();
1334+
yield* initRepoWithCommit(cwd);
1335+
const driver = yield* GitVcsDriver.GitVcsDriver;
1336+
const fileSystem = yield* FileSystem.FileSystem;
1337+
const path = yield* Path.Path;
1338+
const filePath = path.join(cwd, "tracked.txt");
1339+
const indexPath = path.join(cwd, ".git", "index");
1340+
// Reproduce a same-timestamp edit without relying on filesystem clock resolution.
1341+
yield* git(cwd, ["config", "core.trustctime", "false"]);
1342+
yield* writeTextFile(cwd, "tracked.txt", "before\n");
1343+
yield* fileSystem.utimes(filePath, timestamp, timestamp);
1344+
yield* git(cwd, ["add", "tracked.txt"]);
1345+
yield* git(cwd, ["commit", "-m", "record racy file"]);
1346+
if (splitIndex) yield* git(cwd, ["update-index", "--split-index"]);
1347+
yield* fileSystem.utimes(indexPath, timestamp, timestamp);
1348+
const originalIndex = yield* fileSystem.readFile(indexPath);
1349+
const originalIndexMtime = (yield* fileSystem.stat(indexPath)).mtime;
1350+
yield* writeTextFile(cwd, "tracked.txt", "after!\n");
1351+
yield* fileSystem.utimes(filePath, timestamp, timestamp);
1352+
yield* writeTextFile(cwd, "untracked.txt", "new\n");
1353+
1354+
const preview = yield* driver.getReviewDiffPreview({ cwd });
1355+
const dirty = preview.sources.find((source) => source.kind === "working-tree")!;
1356+
assert.deepStrictEqual(dirty.files, [
1357+
{ path: "tracked.txt", previousPath: null, additions: 1, deletions: 1 },
1358+
{ path: "untracked.txt", previousPath: null, additions: 1, deletions: 0 },
1359+
]);
1360+
assert.include(dirty.diff, "-before");
1361+
assert.include(dirty.diff, "+after!");
1362+
assert.deepStrictEqual(yield* fileSystem.readFile(indexPath), originalIndex);
1363+
assert.deepStrictEqual((yield* fileSystem.stat(indexPath)).mtime, originalIndexMtime);
1364+
}),
13571365
);
13581366
}
13591367

0 commit comments

Comments
 (0)