Skip to content

Commit 3cd10de

Browse files
committed
test(session): harden latest symlink race test with readlink + tmp-stray assertions
1 parent c0e433e commit 3cd10de

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/session/session-dir.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { afterEach, beforeEach, expect, test } from "bun:test";
2-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
2+
import { mkdir, readFile, readdir, readlink, rm, writeFile } from "node:fs/promises";
33
import { existsSync } from "node:fs";
4-
import { join } from "node:path";
4+
import { dirname, join } from "node:path";
55
import { tmpdir } from "node:os";
66
import { execFileSync } from "node:child_process";
77

@@ -89,6 +89,15 @@ test("concurrent initSessionDir does not throw on latest symlink race", async ()
8989
expect(dir).toBe(sessionDir(cwd, ids[i] as string, home));
9090
expect(existsSync(join(dir, "context"))).toBe(true);
9191
}
92+
// The winning `latest` symlink must resolve to one of the raced ids.
93+
const projectRoot = dirname(dirs[0] as string);
94+
const latestTarget = await readlink(join(projectRoot, "latest"));
95+
expect(ids).toContain(latestTarget);
96+
// No temp-symlink strays (`latest.<pid>.<rand>.tmp`) may be left behind.
97+
const entries = await readdir(projectRoot);
98+
expect(
99+
entries.filter((e) => e.startsWith("latest.") && e.endsWith(".tmp")),
100+
).toEqual([]);
92101
});
93102

94103
test("migrateLegacySessionIfNeeded does not migrate main-repo .agent-state from a worktree cwd", async () => {

0 commit comments

Comments
 (0)