Stop orphan game links from blocking global imports
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 20m13s
Validate and deploy Sokko G / deploy (push) Successful in 11s

A game link could outlive its toolbox when one tab linked a game while
another tab, unaware of that link, deleted the toolbox. Auto-backups and
manual exports then copied the orphan link, and the global import
rejected the whole file.

- Drop links to missing toolboxes inside the IndexedDB transaction.
- Remove orphan links already stored when the page loads.
- Ignore a link request to a toolbox that no longer exists.
- Leave orphan links out of exports and skip them on global import, so
  older backups import again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-11 15:12:34 +01:00
parent 98c442a9cd
commit d030c3f59f
9 changed files with 137 additions and 9 deletions

View file

@ -171,7 +171,7 @@ test("orphan storage, space and business references are rejected", () => {
assert.throws(() => validateToolboxImportPayload(memos), /identifiant dupliqué/);
});
test("global imports reject duplicate toolboxes, orphan module keys and orphan game links", () => {
test("global imports reject duplicate toolboxes and orphan module keys", () => {
const toolbox = sourceToolbox();
const payload = createGlobalExportPayload([toolbox], { game: toolbox.id }, sourceModuleData());
validateToolboxImportPayload(payload, "global");
@ -185,8 +185,37 @@ test("global imports reject duplicate toolboxes, orphan module keys and orphan g
assert.throws(() => validateToolboxImportPayload(moduleData, "global"), /ne correspond à aucun outil déclaré/);
const link = clone(payload);
link.links.game = "missing";
assert.throws(() => validateToolboxImportPayload(link, "global"), /links\.game référence l'identifiant absent/);
link.links.game = 3;
assert.throws(() => validateToolboxImportPayload(link, "global"), /links\.game doit être une chaîne non vide/);
});
test("a global export drops game links whose toolbox no longer exists", () => {
const toolbox = sourceToolbox();
const payload = createGlobalExportPayload([toolbox], { game: toolbox.id, removed: "deleted-toolbox" }, sourceModuleData());
assert.deepEqual(payload.links, { game: toolbox.id });
});
test("a global import skips orphan game links from older backups instead of failing", async () => {
const toolbox = sourceToolbox();
const payload = JSON.parse(JSON.stringify(createGlobalExportPayload([toolbox], { game: toolbox.id }, sourceModuleData())));
payload.links.removed = "deleted-toolbox";
let state = { toolboxes: [], links: {}, moduleData: {} };
const actions = useToolboxActions({
store: {
ready: true,
links: { removed: "existing" },
persistToolboxSnapshot: async (updater) => {
state = { ...state, ...updater(state) };
return true;
}
},
notify() {},
setConfirmModal: (value) => assert.fail(value.message)
});
assert.equal(await actions.importAllToolboxes({ text: async () => JSON.stringify(payload) }), true);
assert.deepEqual(Object.keys(state.links), ["game"]);
assert.equal(state.links.game, state.toolboxes[0].id);
});
test("a global import remaps toolbox, game and planner references together", async () => {