import assert from "node:assert/strict"; import { test } from "node:test"; // The sweep of 2026-10-30 (issue 774): a refused admin password was said every 30 s, forever. Now it is said once with // its cause, asked again hourly, and its end is said; any other error is still said each time. test("a refused credential is said once, asked again hourly, and its end said", async () => { const { Refusal, AskAgainRefusedMs } = await import("../refused.ts"); const r = new Refusal(); const refused = new Error('Grafana API /api/prometheus/grafana/api/v1/alerts: 401 {"message":"Invalid username or password"}'); const rows: [number, Error | undefined, boolean, RegExp | undefined][] = [ // at, error of the ask, due before it, what is said [0, refused, true, /refuses the vault's admin password.*reset-admin-password/], [30_000, undefined, false, undefined], [AskAgainRefusedMs, refused, true, undefined], [AskAgainRefusedMs + 1, new Error("Grafana API /api/health: 502 bad gateway"), false, undefined], [2 * AskAgainRefusedMs, undefined, true, /accepts the vault's admin password again/], [2 * AskAgainRefusedMs + 30_000, new Error("Grafana API /x: 502 bad gateway"), true, /502 bad gateway/], [2 * AskAgainRefusedMs + 60_000, new Error("Grafana API /x: 502 bad gateway"), true, /502 bad gateway/], ]; for (const [i, [at, err, due, said]] of rows.entries()) { assert.equal(r.due(at), due, `row ${i}: due`); if (!due) continue; const line = r.after(at, err); if (said) assert.match(line ?? "", said, `row ${i}`); else assert.equal(line, undefined, `row ${i}`); } });