fix(companion): validate runtime and heartbeat loop options

This commit is contained in:
William Valentin
2026-02-16 18:47:43 -08:00
parent 873dc1ad5b
commit a5c5a320ca
5 changed files with 52 additions and 3 deletions
+10
View File
@@ -37,6 +37,16 @@ describe('CompanionHeartbeatLoop', () => {
loop.stop();
});
it('validates constructor options', () => {
const publisher = { publishHeartbeat: vi.fn(async () => buildStatusResult()) };
expect(() => new CompanionHeartbeatLoop(publisher, { intervalMs: 0 })).toThrow(
'intervalMs must be a positive number',
);
expect(() => new CompanionHeartbeatLoop(publisher, { maxConsecutiveFailures: 0 })).toThrow(
'maxConsecutiveFailures must be >= 1 when specified',
);
});
it('supports delayed first run when runImmediately=false', async () => {
const publishHeartbeat = vi.fn(async () => buildStatusResult());
const loop = new CompanionHeartbeatLoop({ publishHeartbeat }, { intervalMs: 500 });