fix: make workspace registry lock process-bound

This commit is contained in:
2026-08-03 22:42:57 +02:00
parent 553bb41138
commit e2d1117614
3 changed files with 128 additions and 67 deletions
+16 -4
View File
@@ -6,6 +6,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { promisify } from "node:util";
import { afterEach, expect, test } from "vitest";
import { WorkspaceRepositoryLock } from "../src/workspaces/git-repository.js";
import { WorkspaceRegistry } from "../src/workspaces/registry.js";
import type { WorkspaceRegistryConfig } from "../src/workspaces/types.js";
@@ -113,14 +114,25 @@ test("keeps the last valid snapshot when a pulled commit has invalid YAML", asyn
});
});
test("does not bypass an existing advisory repository lock", async () => {
test("does not bypass an existing live advisory repository lock", async () => {
const remote = await fixture();
const root = join(remote.root, "registry");
const registry = new WorkspaceRegistry(config(root, remote.remote));
mkdirSync(join(root, "locks"), { recursive: true });
writeFileSync(join(root, "locks", "repository.lock"), "held");
const lock = new WorkspaceRepositoryLock(join(root, "locks"));
let release!: () => void;
let started!: () => void;
const held = lock.run(async () => {
started();
await new Promise<void>((resolve) => { release = resolve; });
});
await new Promise<void>((resolve) => { started = resolve; });
await expect(registry.bootstrap()).rejects.toMatchObject({ code: "workspace_stale" });
try {
await expect(registry.bootstrap()).rejects.toMatchObject({ code: "workspace_stale" });
} finally {
release();
await held;
}
});
test("rejects a symbolic-link registry root before creating a lock below it", async () => {