Files
MaashkinoozheandClaude Opus 5.5 b2bb34174c Fold the sentinel into the scraper and drop the sentinel service (BL-0046)
The stall watchdog now runs inside the scraper (ScraperService.checkStalls,
every 30 s from the work loop): same rule as before, one checkpoint-safe
restart, quarantine on the second stall, missing checkpoint is no evidence,
and paused time no longer counts. Stalls are recorded as scraper incidents
(failure.kind 'stall'). The private /api/recovery endpoint is gone.

Dropped with the service: reader/scraper-unreachable incidents (supervisor
and Docker handle crashes; the health page shows "Scraper: unreachable"),
duplicate job-failure incidents and the unused /metrics endpoint.
The stack is now reader + scraper (+ optional peer-gateway).
The supervisor test moved to runtime/test (npm run test:runtime stays).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 22:58:03 +02:00

29 lines
2.0 KiB
JavaScript

'use strict';
const test = require('node:test'), assert = require('node:assert/strict');
const fs = require('fs'), os = require('os'), path = require('path'), { EventEmitter } = require('events');
const { Supervisor } = require('../supervisor');
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
test('supervisor isolates a child crash and persists its bounded restart budget', async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'mc-supervisor-')), file = path.join(dir, 'runtime.json');
let starts = 0;
const spawn = () => { const child = new EventEmitter(); child.pid = ++starts; child.kill = () => { child.emit('exit', 0); child.emit('close', 0); }; return child; };
const supervisor = new Supervisor('reader', { file, spawn, retryBaseMs: 1 });
try {
supervisor.start();
for (let n = 0; n < 3; n++) {
supervisor.child.emit('close', 1, null);
for (let i = 0; i < 50 && supervisor.state.status === 'retry_wait'; i++) await delay(2);
}
assert.equal(starts, 3); assert.equal(supervisor.state.status, 'parked'); assert.equal(supervisor.child, null);
const restored = new Supervisor('reader', { file, spawn, retryBaseMs: 1 }); restored.start();
assert.equal(starts, 3); assert.equal(restored.state.status, 'parked'); await restored.close();
} finally { await supervisor.close(); fs.rmSync(dir, { recursive: true, force: true }); }
});
test('intentional supervisor shutdown does not consume the crash budget', async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'mc-supervisor-stop-'));
const child = new EventEmitter(); child.pid = 1; child.kill = () => { child.emit('exit', 0); child.emit('close', 0); };
const supervisor = new Supervisor('scraper', { file: path.join(dir, 'runtime.json'), spawn: () => child });
try { supervisor.start(); await supervisor.close(); assert.equal(supervisor.state.status, 'stopped'); assert.equal(supervisor.state.failures.length, 0); }
finally { await supervisor.close(); fs.rmSync(dir, { recursive: true, force: true }); }
});