fix(skills): preserve replaced checkpoint locks

This commit is contained in:
jb
2026-09-04 10:55:18 -04:00
parent 444483ade6
commit 52576c7556
2 changed files with 56 additions and 7 deletions
@@ -175,6 +175,36 @@ 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");