scripts/replay.mjs
Commit 01f96e7. All files · Download the tarball.
#!/usr/bin/env node
// Replay the bundled sample usage through Tripwire's detection and alert formatting. No Admin key needed.
// node scripts/replay.mjs print the Slack payloads that would be sent
// node scripts/replay.mjs --discord print Discord payloads instead
// node scripts/replay.mjs --post <webhook-url> also POST them to a Slack/Discord test webhook
// WORK_HOURS=08:00-15:00 TIMEZONE=UTC node scripts/replay.mjs (try other settings via env vars)
import { replaySample } from "../src/sample.js";
const args = process.argv.slice(2);
const postIdx = args.indexOf("--post");
const post = postIdx >= 0;
const webhookUrl = post ? args[postIdx + 1] : args.includes("--discord") ? "https://discord.com/api/webhooks/0/sample" : undefined;
if (post && !webhookUrl) { console.error("usage: --post <slack-or-discord-webhook-url>"); process.exit(2); }
const VARS = ["SPIKE_MULTIPLIER", "BASELINE_MINUTES", "MIN_TOKENS_PER_MINUTE", "COOLDOWN_MINUTES", "TIMEZONE", "WORK_HOURS", "WORK_DAYS", "OFF_HOURS_MIN_TOKENS", "ALERT_NEW_KEYS", "ALERT_NEW_MODELS", "WATCH_KEY_LIST", "PRICES_JSON"];
const vars = Object.fromEntries(VARS.filter((k) => process.env[k] !== undefined).map((k) => [k, process.env[k]]));
try {
const r = await replaySample({ webhookUrl, post, vars });
for (const p of r.payloads) {
console.log(`--- ${p.phase === "seed" ? "first run (baseline seeded)" : "check run"}: ${r.kind} payload${post ? " (posted)" : ""} ---`);
console.log(JSON.stringify(p.payload, null, 2));
}
if (!r.runs.check.ok) { console.error("check failed:", r.runs.check.error); process.exit(1); }
} catch (e) { console.error(e.message); process.exit(1); }