Stop orphan game links from blocking global imports
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:
parent
98c442a9cd
commit
d030c3f59f
9 changed files with 137 additions and 9 deletions
|
|
@ -185,3 +185,31 @@ test("a stale toolbox replacement shows a conflict and reloads the confirmed ver
|
|||
expect(confirmed.toolboxes.find((toolbox) => toolbox.name === "Version distante")).toBeTruthy();
|
||||
expect(confirmed.toolboxes.find((toolbox) => toolbox.name === "Version locale")).toBeFalsy();
|
||||
});
|
||||
|
||||
test("deleting a toolbox also removes game links written by another tab", async ({ page, context }) => {
|
||||
await resetSokkoStorage(page);
|
||||
const otherPage = await context.newPage();
|
||||
await otherPage.goto("/");
|
||||
const toolbox = (id) => ({ id, name: id, modules: [] });
|
||||
const empty = { toolboxes: [], links: {}, moduleData: {} };
|
||||
const both = { toolboxes: [toolbox("a"), toolbox("b")], links: {}, moduleData: {} };
|
||||
expect(await runMutation(page, empty, both)).toEqual({ ok: true });
|
||||
|
||||
// L'autre onglet associe un jeu à « a » ; cet onglet supprime « a » sans avoir vu l'association.
|
||||
expect(await runMutation(otherPage, both, { ...both, links: { game: "a", other: "b" } })).toEqual({ ok: true });
|
||||
expect(await runMutation(page, both, { ...both, toolboxes: [toolbox("b")] })).toEqual({ ok: true });
|
||||
|
||||
const links = await page.evaluate(async () => (await import("/src/utils/indexedDbStorage.js")).getLinks());
|
||||
expect(links).toEqual({ other: "b" });
|
||||
});
|
||||
|
||||
test("orphan game links already stored are removed from IndexedDB", async ({ page }) => {
|
||||
await resetSokkoStorage(page);
|
||||
const result = await page.evaluate(async () => {
|
||||
const db = await import("/src/utils/indexedDbStorage.js");
|
||||
await db.setToolboxSnapshot([{ id: "kept", modules: [] }], { mhwilds: "deleted", diablo4: "kept" }, {});
|
||||
const removed = await db.removeOrphanLinks();
|
||||
return { removed, links: await db.getLinks(), again: await db.removeOrphanLinks() };
|
||||
});
|
||||
expect(result).toEqual({ removed: 1, links: { diablo4: "kept" }, again: 0 });
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue