refactor(skills): simplify checkpoint locking

This commit is contained in:
jb
2026-09-04 15:16:51 -04:00
parent c257f31c21
commit ebbf3c3d19
3 changed files with 8 additions and 57 deletions
@@ -175,36 +175,6 @@ test("serializes concurrent updates with an exclusive per-target lock", async ()
assert.equal(await exists(`${target}.lock`), false);
});
test("does not remove a lock pathname replaced before cleanup", async () => {
const directory = await temporaryDirectory();
const target = join(directory, "record.md");
const lock = `${target}.lock`;
const replacement = "replacement lock";
let replaced = false;
const io = {
...defaultIo,
open: async (path, flags, mode) => {
const handle = await defaultIo.open(path, flags, mode);
if (path !== lock || flags !== "wx") return handle;
return {
stat: (...args) => handle.stat(...args),
close: async () => {
await handle.close();
await fs.unlink(lock);
await fs.writeFile(lock, replacement, { mode: 0o600 });
replaced = true;
},
};
},
};
await checkpointRecord({ target, input: record(), io });
assert.equal(replaced, true);
assert.equal(await fs.readFile(lock, "utf8"), replacement);
assert.equal(await fs.readFile(target, "utf8"), record());
});
test("fails closed on a pre-existing stale lock and leaves it for recovery", async () => {
const directory = await temporaryDirectory();
const target = join(directory, "record.md");