Share uploads now reserve their slot, bytes and per-IP count before the disk check, so simultaneous uploads can no longer exceed the limits. Writes to a share's metadata run one after another, and a revocation can no longer be undone by a pending read count. The TCG page ignores a state reload that started before or during a mutation, the last mutation wins, and returning to the page triggers a single reload. The card cache confirms writes only once the IndexedDB transaction completes and shows only the current player's copy. The administration panel loads on demand, which shrinks the TCG chunk from 311.6 to 191.8 kB. A new /api/health route answers 503 when the cards or shares API failed to start. The deploy script ships the commit's production dependencies with the build, waits up to 30 s for a healthy server instead of trusting systemctl is-active, and restores node_modules on rollback. Both Forgejo workflows check the route on the public site. The updated script applies once reinstalled on the server. Unused helpers, the ignored join role and duplicate button selectors are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
2 KiB
JavaScript
39 lines
2 KiB
JavaScript
// Rôle : vérifie que les métadonnées d'un envoi de toolbox restent justes sur disque quand plusieurs lectures ou une révocation se croisent.
|
|
import assert from "node:assert/strict";
|
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { test } from "node:test";
|
|
import { ShareStore } from "../services/shares/store.js";
|
|
|
|
const ID = "AAAAAAAAAAAAAAAAAAAAAA";
|
|
|
|
async function storeWithShare(t) {
|
|
const dir = await mkdtemp(join(tmpdir(), "sokko-share-store-"));
|
|
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
const now = Date.UTC(2026, 10, 20, 12);
|
|
const store = new ShareStore({ dir, now: () => now });
|
|
await writeFile(store.partPath(ID), Buffer.alloc(64, 1));
|
|
await store.commit(ID, { createdAt: now, expiresAt: now + 60_000, size: 64, singleUse: false, reads: 0, deleteTokenHash: "00" });
|
|
return { dir, store, now };
|
|
}
|
|
|
|
test("simultaneous reads of a reusable share all reach the file on disk", async (t) => {
|
|
const { dir, store, now } = await storeWithShare(t);
|
|
const results = await Promise.allSettled(Array.from({ length: 10 }, () => store.recordRead(ID)));
|
|
assert.deepEqual(results.filter(({ status }) => status === "rejected").map(({ reason }) => reason.code), []);
|
|
assert.equal(JSON.parse(readFileSync(store.metaPath(ID), "utf8")).reads, 10);
|
|
assert.deepEqual(readdirSync(dir).filter((name) => name.endsWith(".tmp")), []);
|
|
assert.equal(new ShareStore({ dir, now: () => now }).get(ID).reads, 10);
|
|
});
|
|
|
|
test("a revocation is not undone by a read still being written", async (t) => {
|
|
const { dir, store, now } = await storeWithShare(t);
|
|
const reads = [store.recordRead(ID), store.recordRead(ID)];
|
|
await store.remove(ID);
|
|
await Promise.all(reads);
|
|
assert.equal(existsSync(store.metaPath(ID)), false);
|
|
assert.equal(existsSync(store.binPath(ID)), false);
|
|
assert.equal(new ShareStore({ dir, now: () => now }).count, 0);
|
|
});
|