Files
thedotmack__claude-mem/tests/server/runtime/active-queue-manager.test.ts
Alex Newman 2a0a407340 chore: remove over-engineering findings from repo-wide ponytail audit (wave 1)
Cuts verified dead code, duplication, and speculative abstractions across
14 disjoint areas of the tree: sqlite layer, worker HTTP routes, search
pipeline, server, chroma sync, viewer UI, npx-cli, MCP server, shared/utils,
telemetry/infra, integrations, scripts, tests, and stale plans/evals docs.

Also unifies the Chroma search pipeline onto SearchOrchestrator/strategies
and ports dual-project (merged_into_project) scoping plus dateRange
filtering into ChromaSearchStrategy, which corpus builds need but had
silently lost.

Full audit trail: 65-agent verification workflow wf_160a7862-1a6, 14-agent
execution wf_c7e48c0f-164, 6-agent fixup wf_865f86a4-c6b.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-02 20:49:27 -07:00

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');
});
});