← back to Dw Gemini Skip TK11321
test/hourly-activation-count.test.js
20 lines
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const { countHourlyActivations } = require('../lib/hourly-activation-count');
const now = new Date('2026-09-09T18:10:00Z');
test('manual canaries and scheduled activations use the same hourly allowance', () => {
const rows = [{ ts: '2026-09-09T18:01:00Z', action: 'activated' }, { ts: '2026-09-09T18:05:00Z', action: 'activated' },
{ ts: '2026-09-09T18:06:00Z', action: 'dryrun-would-activate' }, { ts: '2026-09-09T18:07:00Z', action: 'activate-error' }];
assert.equal(countHourlyActivations(rows.map(JSON.stringify).join('\n'), now), 2);
});
test('hour boundaries are distinct and offsets normalize to UTC', () => {
const rows = [{ ts: '2026-09-09T17:59:59Z', action: 'activated' }, { ts: '2026-09-09T11:00:00-07:00', action: 'activated' }];
assert.equal(countHourlyActivations(rows.map(JSON.stringify).join('\n'), now), 1);
assert.equal(countHourlyActivations('', now), 0);
});
test('unreadable activation events cannot silently reset hourly usage', () => {
assert.throws(() => countHourlyActivations('{"action":"activated"', now));
assert.throws(() => countHourlyActivations('{"action":"activated","ts":"broken"}', now));
});