diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index f424a62..9a963eb 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -439,3 +439,4 @@ {"id":"int-7f32d0d3d8541f3309c009c7ac8c077d","kind":"field_change","created_at":"2026-11-20T18:21:11.286693487Z","actor":"Shinuwa","issue_id":"sokko-g-eecb.8","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Corrigé avec tests de régression (échec vérifié sur l'ancien code pour F01/F02/F04) ; npm run check:full réussi le 2026-11-20."}} {"id":"int-f75cefa76d1475da43d7744c088a4b87","kind":"field_change","created_at":"2026-11-20T18:21:23.188596174Z","actor":"Shinuwa","issue_id":"sokko-g-eecb.1","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Côté dépôt : node_modules livré avec dist (npm prune --omit=dev), route /api/health et attente de santé dans le script et les workflows, retour arrière de node_modules. Réinstallation du script sur le serveur suivie dans sokko-g-6vjw."}} {"id":"int-48d5d2077d92a245d65c3b067eabf51b","kind":"field_change","created_at":"2026-11-20T18:21:36.31133937Z","actor":"Shinuwa","issue_id":"sokko-g-eecb.6","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"AdminPanel chargé à la demande : chunk CardsPage 311,6 → 191,8 ko (77,6 → 47,8 ko gzip). Séparation configuration/catalogue non faite : 30 ko gzip une fois la compression active (sokko-g-6vjw)."}} +{"id":"int-94dfd02acf23d34d6e65722cbb2386e4","kind":"field_change","created_at":"2026-11-21T09:02:20.762620584Z","actor":"Shinuwa","issue_id":"sokko-g-9r25","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"dev-auth limit is now the devAuthRateLimit option (default 10); the cards E2E server raises it like apiRateLimit. Full cards suite 14/14 locally."}} diff --git a/scripts/start-cards-e2e-server.mjs b/scripts/start-cards-e2e-server.mjs index b7bbdef..9bc2e1a 100644 --- a/scripts/start-cards-e2e-server.mjs +++ b/scripts/start-cards-e2e-server.mjs @@ -60,12 +60,13 @@ function now() { const { startServer } = await import("../server.mjs"); const draws = [0.999, 0, 0.999, 0.999, 0.999, 0]; let drawIndex = 0; -// Tous les parcours et leurs deux comptes partagent la même adresse IP : la limite par minute les ferait échouer au hasard. +// Tous les parcours et leurs deux comptes partagent la même adresse IP : les limites par minute, connexion de développement +// comprise, les feraient échouer au hasard. // Alertes Discord sans bot : chaque message est écrit dans ce fichier, une ligne JSON par alerte. const alertsFile = join(tmpdir(), "sokkog-cards-e2e-alerts.jsonl"); writeFileSync(alertsFile, ""); const sendAlert = async (discordId, content) => appendFileSync(alertsFile, `${JSON.stringify({ discordId, content })}\n`); -const server = startServer({ cardsApiOptions: { allowProductionDevAuth: true, apiRateLimit: 100_000, now, sendAlert, random: (max) => Math.min(max - 1, Math.floor(draws[drawIndex++ % draws.length] * max)) } }); +const server = startServer({ cardsApiOptions: { allowProductionDevAuth: true, apiRateLimit: 100_000, devAuthRateLimit: 100_000, now, sendAlert, random: (max) => Math.min(max - 1, Math.floor(draws[drawIndex++ % draws.length] * max)) } }); let stopping = false; function stop() { diff --git a/services/cards/api.js b/services/cards/api.js index 2f70775..89cebc2 100644 --- a/services/cards/api.js +++ b/services/cards/api.js @@ -114,6 +114,8 @@ export function createCardsApiHandler({ fetchImpl = fetch, devPerks = false, apiRateLimit = 60, + // Connexions de développement par minute et par adresse ; les parcours E2E en enchaînent davantage. + devAuthRateLimit = 10, // Envoi des alertes Discord ; par défaut, la route palico-bot de CARDS_DISCORD_ALERTS_URL avec la clé CARDS_DISCORD_ALERTS_KEY. sendAlert = null } = {}) { @@ -269,7 +271,7 @@ export function createCardsApiHandler({ if (req.method === "POST" && url.pathname === "/api/cards/auth/dev") { if (!devAuth) throw Object.assign(new Error("Connexion de développement indisponible."), { status: 404, code: "NOT_FOUND" }); - rateLimit(req, "dev-auth", 10); + rateLimit(req, "dev-auth", devAuthRateLimit); const player = service.upsertPlayer({ discordId: DEV_DISCORD_ID, displayName: "Version développement", isAdmin: true }); const created = service.createSession(player.id); res.setHeader("Set-Cookie", sessionCookie(created.token, secureCookies)); diff --git a/tests/nebula-cards-api.test.mjs b/tests/nebula-cards-api.test.mjs index a0c280e..7680cc2 100644 --- a/tests/nebula-cards-api.test.mjs +++ b/tests/nebula-cards-api.test.mjs @@ -377,6 +377,19 @@ test("the reserve route answers visitors without an account and returns the play assert.equal(reserve.json.recharge.nextOpeningAt, state.json.recharge.nextOpeningAt); }); +test("development logins stay limited per minute unless the limit is raised", async (t) => { + const limited = createCardsApiHandler({ projectRoot: resolve("."), enabled: true, devAuth: true, databasePath: ":memory:", env: { NODE_ENV: "test" }, now: () => 1_000 }); + const raised = createCardsApiHandler({ projectRoot: resolve("."), enabled: true, devAuth: true, databasePath: ":memory:", env: { NODE_ENV: "test" }, now: () => 1_000, devAuthRateLimit: 20 }); + t.after(() => { limited.close(); raised.close(); }); + const statuses = async (handler) => { + const result = []; + for (let index = 0; index < 11; index += 1) result.push((await call(handler, { method: "POST", path: "/api/cards/auth/dev" })).status); + return result; + }; + assert.deepEqual(await statuses(limited), [...Array(10).fill(200), 429]); + assert.deepEqual(await statuses(raised), Array(11).fill(200)); +}); + test("menu reserve reads do not use up the game's request limit", async (t) => { const handler = createCardsApiHandler({ projectRoot: resolve("."), enabled: true, devAuth: true, databasePath: ":memory:", env: { NODE_ENV: "test" }, apiRateLimit: 2 }); t.after(() => handler.close());