f9447f8e5f
CI / typecheck · build · test · bundle-size (push) Failing after 1s
CI / clean-room dependency closure smoke (push) Failing after 1s
CI / server-runtime e2e (docker · pg + valkey) (push) Failing after 2s
Deploy Install Scripts / deploy (push) Failing after 2s
Windows / build (push) Has been cancelled
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
import { afterEach, describe, expect, it, mock } from 'bun:test';
|
|
import { ActiveServerQueueManager } from '../../../src/server/runtime/ActiveServerQueueManager.js';
|
|
import { ServerJobQueue } from '../../../src/server/jobs/ServerJobQueue.js';
|
|
import type {
|
|
ServerGenerationJobKind,
|
|
ServerGenerationJobPayload,
|
|
} from '../../../src/server/jobs/types.js';
|
|
import type { RedisQueueConfig } from '../../../src/server/queue/redis-config.js';
|
|
|
|
const bullmqConfig: RedisQueueConfig = {
|
|
engine: 'bullmq',
|
|
mode: 'managed',
|
|
url: null,
|
|
host: '127.0.0.1',
|
|
port: 6379,
|
|
prefix: 'cmem-test',
|
|
connection: { host: '127.0.0.1', port: 6379, lazyConnect: true },
|
|
};
|
|
|
|
const sqliteConfig: RedisQueueConfig = {
|
|
...bullmqConfig,
|
|
engine: 'sqlite',
|
|
};
|
|
|
|
function buildStubQueues(): {
|
|
queues: Map<ServerGenerationJobKind, ServerJobQueue<ServerGenerationJobPayload>>;
|
|
closedNames: string[];
|
|
} {
|
|
const closedNames: string[] = [];
|
|
const make = (name: string) => ({
|
|
name,
|
|
add: async () => {},
|
|
remove: async () => {},
|
|
getJob: async () => null,
|
|
getCounts: async () => ({ waiting: 0, active: 0, delayed: 0, failed: 0, completed: 0 }),
|
|
start: () => {},
|
|
isStarted: () => false,
|
|
close: async () => {
|
|
closedNames.push(name);
|
|
},
|
|
}) as unknown as ServerJobQueue<ServerGenerationJobPayload>;
|
|
|
|
const queues = new Map<ServerGenerationJobKind, ServerJobQueue<ServerGenerationJobPayload>>();
|
|
queues.set('event', make('event'));
|
|
queues.set('summary', make('summary'));
|
|
return { queues, closedNames };
|
|
}
|
|
|
|
describe('ActiveServerQueueManager', () => {
|
|
afterEach(() => {
|
|
mock.restore();
|
|
});
|
|
|
|
it('refuses construction when engine is not bullmq', () => {
|
|
expect(() => new ActiveServerQueueManager(sqliteConfig)).toThrow(/CLAUDE_MEM_QUEUE_ENGINE=bullmq/);
|
|
});
|
|
|
|
it('reports active health with both lanes when constructed against bullmq', () => {
|
|
const { queues } = buildStubQueues();
|
|
const manager = new ActiveServerQueueManager(bullmqConfig, queues);
|
|
const health = manager.getHealth();
|
|
expect(health.status).toBe('active');
|
|
expect(health.details?.engine).toBe('bullmq');
|
|
const lanes = health.details?.lanes as Array<{ kind: string; name: string }> | undefined;
|
|
expect(lanes?.map((l) => l.kind).sort()).toEqual(['event', 'summary']);
|
|
});
|
|
|
|
it('exposes per-kind queues via getQueue', () => {
|
|
const { queues } = buildStubQueues();
|
|
const manager = new ActiveServerQueueManager(bullmqConfig, queues);
|
|
expect(manager.getQueue('event')).toBe(queues.get('event'));
|
|
expect(manager.getQueue('summary')).toBe(queues.get('summary'));
|
|
});
|
|
|
|
it('closes every queue on close() and reports errored health afterwards', async () => {
|
|
const { queues, closedNames } = buildStubQueues();
|
|
const manager = new ActiveServerQueueManager(bullmqConfig, queues);
|
|
await manager.close();
|
|
expect(closedNames.sort()).toEqual(['event', 'summary']);
|
|
expect(manager.getHealth().status).toBe('errored');
|
|
});
|
|
});
|