Reserve the deleted marker for tombstones

Imports and uploads could carry deleted: false, which the loader took for
a tombstone on the next restart. The schemas now reject the property, and
the loader only treats deleted: true as a tombstone and strips the key from
entries already saved with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-18 19:53:36 +00:00
1 parent feb3253bec
commit 9ecd497f1e
4 files changed
+40 -12

No files matched your search

+22 -10
View File
@@ -208,23 +208,35 @@ describe("player_sync controller", function() {
await assert.rejects(set("stored", playerData("stored", 3)), acquiredError);
assert.equal((await saved()).get("stored").generation, 3);
});
// The link validates requests before the handler runs
const fromJSON = lib.Link.requestFromJSON(msg.SetPlayerDataRequest, "SetPlayerDataRequest");
async function setJSON(name, data) {
const request = fromJSON({ playerName: name, playerData: data });
return await handler(msg.SetPlayerDataRequest)(request);
}
it("should keep the stored data when an import fails validation", async function() {
// The link validates requests before the handler runs
const fromJSON = lib.Link.requestFromJSON(msg.SetPlayerDataRequest, "SetPlayerDataRequest");
async function setJSON(name, data) {
const request = fromJSON({ playerName: name, playerData: data });
return await handler(msg.SetPlayerDataRequest)(request);
}
await release("stored");
await setJSON("stored", playerData("stored", 0));
const before = (await saved()).get("stored");
assert.equal(before.epoch, 1);
await assert.rejects(
setJSON("stored", playerData("stored", 0, { crafting_queue: {} })),
{ message: "Request SetPlayerDataRequest failed validation" },
);
for (const extra of [{ crafting_queue: {} }, { deleted: false }, { deleted: true }]) {
await assert.rejects(
setJSON("stored", playerData("stored", 0, extra)),
{ message: "Request SetPlayerDataRequest failed validation" },
);
}
assert.deepEqual((await saved()).get("stored"), before);
});
it("should only load entries marked deleted: true as tombstones", async function() {
// Imports from before the marker was reserved could store deleted: false
const data = playerData("stored", 4, { epoch: 1 });
const entries = [["stored", { ...data, deleted: false }]];
await fs.writeFile(path.join(databaseDir, "player_sync.json"), JSON.stringify(entries));
controller = await load();
const response = await handler(msg.GetPlayerDataRequest)(new msg.GetPlayerDataRequest("stored"));
assert.deepEqual(response.playerData, data);
});
});
describe("DeletePlayerDataRequest", function() {