All checks were successful
deploy / deploy (push) Successful in 26s
Proof: Runtime health sentinel, alert routing, and anomaly detection for stale/disconnected quote truth, truthful dashboard severity, webhook notifications, and safe executor containment. Assumptions: Existing control APIs remain the service-local truth surface; external notification stays as a generic webhook sink; executor disarm is an allowed non-fund-moving containment action; current dashboard/operator files in the worktree belong to this turn and are intended to ship together. Still fake: No live external receiver is configured; webhook delivery is implemented but unverified end-to-end in production; cluster rollout still depends on deploying the new image; no automatic deployment restart path was added.
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import http from 'node:http';
|
|
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { createAlertNotifier } from '../src/core/alert-notifier.mjs';
|
|
|
|
test('alert notifier dedupes repeated deliveries and records clear transitions separately', async () => {
|
|
const requests = [];
|
|
const server = http.createServer(async (req, res) => {
|
|
let body = '';
|
|
for await (const chunk of req) body += chunk;
|
|
requests.push(JSON.parse(body));
|
|
res.statusCode = 200;
|
|
res.end('{}');
|
|
});
|
|
|
|
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
const address = server.address();
|
|
const notifier = createAlertNotifier({
|
|
webhookUrl: `http://127.0.0.1:${address.port}/alerts`,
|
|
});
|
|
|
|
const raised = {
|
|
alert_code: 'near_intents_quotes_stale',
|
|
status: 'raised',
|
|
severity: 'critical',
|
|
service_scope: 'near-intents-ingest',
|
|
reason: 'quote truth stale',
|
|
pair: 'btc->eure',
|
|
raised_at: '2026-04-08T10:00:00.000Z',
|
|
cleared_at: null,
|
|
last_evaluated_at: '2026-04-08T10:00:00.000Z',
|
|
details: {},
|
|
};
|
|
const cleared = {
|
|
...raised,
|
|
status: 'cleared',
|
|
cleared_at: '2026-04-08T10:01:00.000Z',
|
|
};
|
|
|
|
const first = await notifier.notify(raised);
|
|
const second = await notifier.notify(raised);
|
|
const third = await notifier.notify(cleared);
|
|
|
|
assert.equal(first.ok, true);
|
|
assert.equal(second.deduped, true);
|
|
assert.equal(third.ok, true);
|
|
assert.equal(requests.length, 2);
|
|
assert.equal(requests[0].alert.status, 'raised');
|
|
assert.equal(requests[1].alert.status, 'cleared');
|
|
|
|
await new Promise((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
|
|
});
|