test: harden threaded channel follow-ups

This commit is contained in:
Peter Steinberger
2026-03-24 09:24:29 +00:00
parent 43131dcc08
commit b1b162fcdb
7 changed files with 87 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
export type { FileLockHandle, FileLockOptions } from "../plugin-sdk/file-lock.js";
export {
acquireFileLock,
drainFileLockStateForTest,
resetFileLockStateForTest,
withFileLock,
} from "../plugin-sdk/file-lock.js";

View File

@@ -40,6 +40,14 @@ function releaseAllLocksSync(): void {
}
}
async function drainAllLocks(): Promise<void> {
for (const [normalizedFile, held] of Array.from(HELD_LOCKS.entries())) {
HELD_LOCKS.delete(normalizedFile);
await held.handle.close().catch(() => undefined);
await fs.rm(held.lockPath, { force: true }).catch(() => undefined);
}
}
function rmLockPathSync(lockPath: string): void {
try {
fsSync.rmSync(lockPath, { force: true });
@@ -133,6 +141,10 @@ export function resetFileLockStateForTest(): void {
releaseAllLocksSync();
}
export async function drainFileLockStateForTest(): Promise<void> {
await drainAllLocks();
}
/** Acquire a re-entrant process-local file lock backed by a `.lock` sidecar file. */
export async function acquireFileLock(
filePath: string,

View File

@@ -1,7 +1,9 @@
import { drainSessionWriteLockStateForTest } from "../agents/session-write-lock.js";
import { clearSessionStoreCacheForTest } from "../config/sessions/store.js";
import { drainFileLockStateForTest } from "../infra/file-lock.js";
export async function cleanupSessionStateForTest(): Promise<void> {
clearSessionStoreCacheForTest();
await drainFileLockStateForTest();
await drainSessionWriteLockStateForTest();
}