fix: close workspace ownership and API escapes

This commit is contained in:
2026-08-11 15:39:27 +02:00
parent 1b24337a98
commit ca37156a56
12 changed files with 202 additions and 77 deletions
+15 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it, afterEach } from "vitest";
import { mkdtempSync, renameSync, mkdirSync, rmSync, statSync, chmodSync, symlinkSync } from "node:fs";
import { mkdtempSync, renameSync, mkdirSync, rmSync, statSync, chmodSync, symlinkSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { WorkspaceFsAtV1 } from "../src/workspaces/workspace-fs-at.js";
import { VerifiedWorkspaceLockRootLeaseFactory } from "../src/workspaces/workspace-lock-root-lease.js";
@@ -27,4 +27,18 @@ describe("retained canonical workspace root", () => {
const parent = mkdtempSync(join(process.cwd(), "thoth-root-")); roots.push(parent); const f = factory(parent); const a = await f.acquireOrProvision(f.canonicalInput("aaa-workspace")); const b = await f.acquireOrProvision(f.canonicalInput("bbb-workspace"));
const { runUnderOrderedWorkspaceWriterLocks } = await import("../src/workspaces/preprocessing-state.js"); await runUnderOrderedWorkspaceWriterLocks([a, b], async set => { expect(set.workspaceIds).toEqual(["aaa-workspace", "bbb-workspace"]); }); await expect(b.close()).resolves.toBeUndefined();
});
it("rejects writer pathname replacement without admitting a concurrent writer", async () => {
const parent = mkdtempSync(join(process.cwd(), "thoth-root-")); roots.push(parent);
const f = factory(parent); const first = await f.acquireOrProvision(f.canonicalInput("abc-workspace"));
const second = await f.acquireOrProvision(f.canonicalInput("abc-workspace"));
const { runUnderWorkspaceWriterLock } = await import("../src/workspaces/preprocessing-state.js");
const outcome = runUnderWorkspaceWriterLock(first, async () => {
renameSync(join(parent, "abc-workspace", "writer.lock"), join(parent, "abc-workspace", "writer.lock.old"));
writeFileSync(join(parent, "abc-workspace", "writer.lock"), "", { mode: 0o600 });
await expect(runUnderWorkspaceWriterLock(second, async () => "entered")).rejects.toThrow(/preprocessing/);
return "done";
});
await expect(outcome).rejects.toThrow(/preprocessing/);
});
});