|
1 | 1 | 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"; |
3 | 3 | import { existsSync } from "node:fs"; |
4 | | -import { join } from "node:path"; |
| 4 | +import { dirname, join } from "node:path"; |
5 | 5 | import { tmpdir } from "node:os"; |
6 | 6 | import { execFileSync } from "node:child_process"; |
7 | 7 |
|
@@ -89,6 +89,15 @@ test("concurrent initSessionDir does not throw on latest symlink race", async () |
89 | 89 | expect(dir).toBe(sessionDir(cwd, ids[i] as string, home)); |
90 | 90 | expect(existsSync(join(dir, "context"))).toBe(true); |
91 | 91 | } |
| 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([]); |
92 | 101 | }); |
93 | 102 |
|
94 | 103 | test("migrateLegacySessionIfNeeded does not migrate main-repo .agent-state from a worktree cwd", async () => { |
|
0 commit comments