audit follow-up: reduce warning hotspots in automation and gateway tests
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest';
|
||||
import { HeartbeatMonitor, parseInterval } from './heartbeat.js';
|
||||
import type { HeartbeatDeps } from './heartbeat.js';
|
||||
import type { HeartbeatConfig } from '../config/schema.js';
|
||||
import type { ChannelAdapter } from '../channels/types.js';
|
||||
|
||||
function makeConfig(overrides?: Partial<HeartbeatConfig>): HeartbeatConfig {
|
||||
return {
|
||||
@@ -21,8 +22,8 @@ function makeDeps(overrides?: Partial<HeartbeatDeps>): HeartbeatDeps {
|
||||
modelRouter: { getTier: () => 'default' },
|
||||
channelLister: {
|
||||
list: () => [
|
||||
{ name: 'telegram', status: 'connected' } as any,
|
||||
{ name: 'webchat', status: 'connected' } as any,
|
||||
makeChannelAdapter('telegram', 'connected'),
|
||||
makeChannelAdapter('webchat', 'connected'),
|
||||
],
|
||||
},
|
||||
memoryDir: '/tmp/flynn-test-memory',
|
||||
@@ -32,6 +33,17 @@ function makeDeps(overrides?: Partial<HeartbeatDeps>): HeartbeatDeps {
|
||||
};
|
||||
}
|
||||
|
||||
function makeChannelAdapter(name: string, status: ChannelAdapter['status']): ChannelAdapter {
|
||||
return {
|
||||
name,
|
||||
status,
|
||||
connect: async () => {},
|
||||
disconnect: async () => {},
|
||||
send: async () => {},
|
||||
onMessage: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
describe('parseInterval', () => {
|
||||
it('parses seconds', () => {
|
||||
expect(parseInterval('60s')).toBe(60000);
|
||||
@@ -150,8 +162,8 @@ describe('HeartbeatMonitor', () => {
|
||||
|
||||
const lastResult = monitor.getLastResult();
|
||||
expect(lastResult).toBeDefined();
|
||||
expect(lastResult!.checks).toHaveLength(1);
|
||||
expect(lastResult!.timestamp).toBeGreaterThan(0);
|
||||
expect(lastResult?.checks).toHaveLength(1);
|
||||
expect(lastResult?.timestamp ?? 0).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('notification sent after failure_threshold consecutive failures', async () => {
|
||||
@@ -294,7 +306,8 @@ describe('HeartbeatMonitor', () => {
|
||||
monitor = new HeartbeatMonitor(deps);
|
||||
|
||||
const result = await monitor.runChecks();
|
||||
const check = result.checks.find((c) => c.name === 'model')!;
|
||||
const check = result.checks.find((c) => c.name === 'model');
|
||||
if (!check) {throw new Error('Expected model check result');}
|
||||
expect(check.healthy).toBe(true);
|
||||
expect(check.message).toContain('fast');
|
||||
});
|
||||
@@ -307,7 +320,8 @@ describe('HeartbeatMonitor', () => {
|
||||
monitor = new HeartbeatMonitor(deps);
|
||||
|
||||
const result = await monitor.runChecks();
|
||||
const check = result.checks.find((c) => c.name === 'model')!;
|
||||
const check = result.checks.find((c) => c.name === 'model');
|
||||
if (!check) {throw new Error('Expected model check result');}
|
||||
expect(check.healthy).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -318,15 +332,16 @@ describe('HeartbeatMonitor', () => {
|
||||
config: makeConfig({ checks: ['channels'] }),
|
||||
channelLister: {
|
||||
list: () => [
|
||||
{ name: 'telegram', status: 'connected' } as any,
|
||||
{ name: 'webchat', status: 'disconnected' } as any,
|
||||
makeChannelAdapter('telegram', 'connected'),
|
||||
makeChannelAdapter('webchat', 'disconnected'),
|
||||
],
|
||||
},
|
||||
});
|
||||
monitor = new HeartbeatMonitor(deps);
|
||||
|
||||
const result = await monitor.runChecks();
|
||||
const check = result.checks.find((c) => c.name === 'channels')!;
|
||||
const check = result.checks.find((c) => c.name === 'channels');
|
||||
if (!check) {throw new Error('Expected channels check result');}
|
||||
expect(check.healthy).toBe(true);
|
||||
expect(check.message).toContain('1/2 connected');
|
||||
expect(check.message).toContain('webchat');
|
||||
@@ -337,14 +352,15 @@ describe('HeartbeatMonitor', () => {
|
||||
config: makeConfig({ checks: ['channels'] }),
|
||||
channelLister: {
|
||||
list: () => [
|
||||
{ name: 'telegram', status: 'disconnected' } as any,
|
||||
makeChannelAdapter('telegram', 'disconnected'),
|
||||
],
|
||||
},
|
||||
});
|
||||
monitor = new HeartbeatMonitor(deps);
|
||||
|
||||
const result = await monitor.runChecks();
|
||||
const check = result.checks.find((c) => c.name === 'channels')!;
|
||||
const check = result.checks.find((c) => c.name === 'channels');
|
||||
if (!check) {throw new Error('Expected channels check result');}
|
||||
expect(check.healthy).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -358,7 +374,8 @@ describe('HeartbeatMonitor', () => {
|
||||
monitor = new HeartbeatMonitor(deps);
|
||||
|
||||
const result = await monitor.runChecks();
|
||||
const check = result.checks.find((c) => c.name === 'memory')!;
|
||||
const check = result.checks.find((c) => c.name === 'memory');
|
||||
if (!check) {throw new Error('Expected memory check result');}
|
||||
expect(check.healthy).toBe(true);
|
||||
expect(check.message).toContain('disabled');
|
||||
});
|
||||
@@ -371,7 +388,8 @@ describe('HeartbeatMonitor', () => {
|
||||
monitor = new HeartbeatMonitor(deps);
|
||||
|
||||
const result = await monitor.runChecks();
|
||||
const check = result.checks.find((c) => c.name === 'memory')!;
|
||||
const check = result.checks.find((c) => c.name === 'memory');
|
||||
if (!check) {throw new Error('Expected memory check result');}
|
||||
expect(check.healthy).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -385,7 +403,8 @@ describe('HeartbeatMonitor', () => {
|
||||
monitor = new HeartbeatMonitor(deps);
|
||||
|
||||
const result = await monitor.runChecks();
|
||||
const check = result.checks.find((c) => c.name === 'disk')!;
|
||||
const check = result.checks.find((c) => c.name === 'disk');
|
||||
if (!check) {throw new Error('Expected disk check result');}
|
||||
expect(check.healthy).toBe(true);
|
||||
expect(check.message).toContain('MB available');
|
||||
});
|
||||
@@ -398,7 +417,8 @@ describe('HeartbeatMonitor', () => {
|
||||
monitor = new HeartbeatMonitor(deps);
|
||||
|
||||
const result = await monitor.runChecks();
|
||||
const check = result.checks.find((c) => c.name === 'disk')!;
|
||||
const check = result.checks.find((c) => c.name === 'disk');
|
||||
if (!check) {throw new Error('Expected disk check result');}
|
||||
expect(check.healthy).toBe(false);
|
||||
expect(check.message).toContain('Low disk space');
|
||||
});
|
||||
@@ -411,7 +431,8 @@ describe('HeartbeatMonitor', () => {
|
||||
monitor = new HeartbeatMonitor(deps);
|
||||
|
||||
const result = await monitor.runChecks();
|
||||
const check = result.checks.find((c) => c.name === 'disk')!;
|
||||
const check = result.checks.find((c) => c.name === 'disk');
|
||||
if (!check) {throw new Error('Expected disk check result');}
|
||||
expect(check.healthy).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user