test(agents): dedupe remaining tool and lock test scaffolds

This commit is contained in:
Peter Steinberger
2026-03-02 07:08:40 +00:00
parent c3948800f4
commit 45d77cac16
2 changed files with 112 additions and 203 deletions

View File

@@ -33,6 +33,20 @@ async function expectLockRemovedOnlyAfterFinalRelease(params: {
await expect(fs.access(params.lockPath)).rejects.toThrow();
}
async function expectCurrentPidOwnsLock(params: {
sessionFile: string;
timeoutMs: number;
staleMs?: number;
}) {
const { sessionFile, timeoutMs, staleMs } = params;
const lockPath = `${sessionFile}.lock`;
const lock = await acquireSessionWriteLock({ sessionFile, timeoutMs, staleMs });
const raw = await fs.readFile(lockPath, "utf8");
const payload = JSON.parse(raw) as { pid: number };
expect(payload.pid).toBe(process.pid);
await lock.release();
}
describe("acquireSessionWriteLock", () => {
it("reuses locks across symlinked session paths", async () => {
if (process.platform === "win32") {
@@ -90,12 +104,7 @@ describe("acquireSessionWriteLock", () => {
"utf8",
);
const lock = await acquireSessionWriteLock({ sessionFile, timeoutMs: 500, staleMs: 10 });
const raw = await fs.readFile(lockPath, "utf8");
const payload = JSON.parse(raw) as { pid: number };
expect(payload.pid).toBe(process.pid);
await lock.release();
await expectCurrentPidOwnsLock({ sessionFile, timeoutMs: 500, staleMs: 10 });
} finally {
await fs.rm(root, { recursive: true, force: true });
}
@@ -285,12 +294,7 @@ describe("acquireSessionWriteLock", () => {
"utf8",
);
const lock = await acquireSessionWriteLock({ sessionFile, timeoutMs: 500 });
const raw = await fs.readFile(lockPath, "utf8");
const payload = JSON.parse(raw) as { pid: number };
expect(payload.pid).toBe(process.pid);
await lock.release();
await expectCurrentPidOwnsLock({ sessionFile, timeoutMs: 500 });
} finally {
await fs.rm(root, { recursive: true, force: true });
}