Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/features/perfsweep.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { LINKS } from '../config.js';

export const EVERY_MS = 5 * 60_000;
// No slash command: bot.js maps every feature's `commands`, so a missing list crashed Kira at start.
export const commands = [];

// Returns how many captures the site deleted, or null when no token is set.
export async function sweep({ token = process.env.PERF_SWEEP_TOKEN, fetchImpl = fetch } = {}) {
Expand Down
11 changes: 11 additions & 0 deletions test/perfsweep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ test('the sweep posts to the site with the token, and does nothing without one',
assert.equal(calls[0].options.headers.Authorization, 'Bearer s3cret');
await assert.rejects(sweep({ token: 's3cret', fetchImpl: async () => ({ ok: false, status: 403 }) }), /HTTP 403/);
});

test('every feature bot.js loads exports a commands list (a missing one crashed Kira at start)', async () => {
const src = (await import('node:fs')).readFileSync(new URL('../src/bot.js', import.meta.url), 'utf8');
const list = src.match(/const FEATURES = \[([^\]]+)\]/)[1].split(',').map((s) => s.trim());
for (const name of list) {
const file = src.match(new RegExp(`import \\* as ${name} from '\\./features/([\\w-]+)\\.js'`))?.[1];
if (!file) continue;
const m = await import(`../src/features/${file}.js`);
assert.ok(Array.isArray(m.commands), `${file}.js exports no commands array`);
}
});
Loading