Nouveautés dans l'app, et « Tout effacer » synchronisé : cet appareil ou partout (2d)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
0ea0ea109f
commit
8ebdca0c30
@@ -144,3 +144,35 @@ test("limite de requêtes : par adresse, en fenêtre, et non contournable par un
|
||||
await s.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("relais : « Tout effacer partout » vide le journal, et le dit aux autres appareils (410)", async () => {
|
||||
const s = await startServer();
|
||||
try {
|
||||
await push(s, ID, TOKEN, [blob(1), blob(2)]);
|
||||
let r = await s.fetch(`/api/journals/${ID}/events`, { method: "DELETE", headers: auth("mauvaise-cle") });
|
||||
assert.equal(r.status, 403, "une autre clé ne peut pas effacer");
|
||||
r = await s.fetch(`/api/journals/${ID}/events`, { method: "DELETE", headers: auth(TOKEN) });
|
||||
assert.equal(r.status, 200);
|
||||
assert.deepEqual(await r.json(), { erased: true });
|
||||
r = await s.fetch(`/api/journals/${ID}/events`, { headers: auth(TOKEN) });
|
||||
assert.equal(r.status, 410, "lecture : effacé");
|
||||
assert.equal((await r.json()).error, "erased");
|
||||
r = await push(s, ID, TOKEN, [blob(3)]);
|
||||
assert.equal(r.status, 410, "un autre appareil ne recrée pas le journal");
|
||||
r = await s.fetch(`/api/journals/${ID}/events`, { method: "DELETE", headers: auth(TOKEN) });
|
||||
assert.equal(r.status, 200, "effacer deux fois ne change rien");
|
||||
} finally {
|
||||
await s.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("relais : un journal effacé le reste après redémarrage, et n'est plus « possédé »", async () => {
|
||||
const dir = tmp();
|
||||
const relay = createRelay(dir);
|
||||
await relay.append(ID, TOKEN, [blob(1)]);
|
||||
await relay.erase(ID, TOKEN);
|
||||
const again = createRelay(dir);
|
||||
await assert.rejects(again.read(ID, TOKEN, 0), (e) => /** @type {any} */ (e).status === 410);
|
||||
assert.equal(await again.owns(ID, TOKEN), false);
|
||||
assert.equal(fs.readFileSync(path.join(dir, "journals", ID + ".jsonl"), "utf8").split("\n").filter(Boolean).length, 1, "seul l'en-tête reste");
|
||||
});
|
||||
|
||||
@@ -104,3 +104,26 @@ test("erreurs : réseau absent, clé d'accès refusée ; un seul sync() à la fo
|
||||
await a;
|
||||
assert.equal(calls, 2, "une lecture, un envoi");
|
||||
});
|
||||
|
||||
test("« Tout effacer partout » : l'autre appareil reçoit « erased », et oublier permet de tout relire", async () => {
|
||||
const s = await startServer();
|
||||
try {
|
||||
const syncKey = generateSyncKey();
|
||||
const pc = memoryStore();
|
||||
const phone = memoryStore();
|
||||
await pc.add([weight("pc", "2026-11-01", 80)]);
|
||||
const syncPc = createSync({ store: pc, syncKey, baseUrl: s.base });
|
||||
const syncPhone = createSync({ store: phone, syncKey, baseUrl: s.base });
|
||||
await syncPc.sync();
|
||||
await syncPhone.sync();
|
||||
await syncPc.erase();
|
||||
await assert.rejects(syncPhone.sync(), (e) => e instanceof SyncError && e.code === "erased");
|
||||
// Oublier : une clé réactivée relirait tout depuis le début.
|
||||
const { journalId } = await deriveKeys(syncKey);
|
||||
assert.ok(phone.meta.get("sync:" + journalId));
|
||||
await syncPhone.forget();
|
||||
assert.equal(phone.meta.get("sync:" + journalId), null);
|
||||
} finally {
|
||||
await s.close();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user