T-16: M0.1b — Make repo-wide bun test green: fix queue, shutdown-signal and research-workflow test failures

This commit is contained in:
Studio 2026-11-27 12:01:06 -05:00
parent 890761e0d5
commit 9c4e87cdfd
17 changed files with 366 additions and 266 deletions

View file

@ -1,4 +1,4 @@
import { describe, expect, it } from 'bun:test';
import { afterEach, describe, expect, it } from 'bun:test';
import { createServiceCache, ServiceCache } from '../src/service-cache';
import {
generateCachePrefix,
@ -78,39 +78,40 @@ describe('Service Utilities', () => {
});
describe('ServiceCache', () => {
it('should create service cache', () => {
const mockRedisConfig = {
host: 'localhost',
port: 6379,
};
// Use a non-QA isolated loopback port and non-shared clients so unit tests never touch QA Dragonfly (localhost:6379)
const mockRedisConfig = {
host: '127.0.0.1',
port: 16379,
maxRetriesPerRequest: 1,
retryDelay: 50,
};
const createdCaches: ServiceCache[] = [];
// Since ServiceCache constructor internally creates a real cache,
// we can't easily test it without mocking the createCache function
// For now, just test that the function exists and returns something
const serviceCache = createServiceCache('myservice', mockRedisConfig);
afterEach(async () => {
await Promise.all(createdCaches.splice(0).map(cache => cache.disconnect().catch(() => {})));
});
it('should create service cache', () => {
const serviceCache = createServiceCache('myservice', mockRedisConfig, { shared: false });
createdCaches.push(serviceCache);
expect(serviceCache).toBeDefined();
expect(serviceCache).toBeInstanceOf(ServiceCache);
});
it('should handle cache prefix correctly', () => {
const mockRedisConfig = {
host: 'localhost',
port: 6379,
};
const serviceCache = createServiceCache('webApi', mockRedisConfig);
const serviceCache = createServiceCache('webApi', mockRedisConfig, { shared: false });
createdCaches.push(serviceCache);
expect(serviceCache).toBeDefined();
// The prefix is set internally as cache:web-api
expect(serviceCache.getKey('test')).toBe('cache:web-api:test');
});
it('should support global cache option', () => {
const mockRedisConfig = {
host: 'localhost',
port: 6379,
};
const globalCache = createServiceCache('myservice', mockRedisConfig, { global: true });
const globalCache = createServiceCache('myservice', mockRedisConfig, {
global: true,
shared: false,
});
createdCaches.push(globalCache);
expect(globalCache).toBeDefined();
// Global cache uses a different prefix
expect(globalCache.getKey('test')).toBe('stock-bot:shared:test');
@ -120,16 +121,16 @@ describe('ServiceCache', () => {
describe('Batch Processing', () => {
it('should handle batch job data types', () => {
const batchJob: BatchJobData = {
items: [1, 2, 3],
options: {
batchSize: 10,
concurrency: 2,
},
payloadKey: 'batch:payload:1',
batchIndex: 0,
totalBatches: 3,
itemCount: 10,
totalDelayHours: 1,
};
expect(batchJob.items).toHaveLength(3);
expect(batchJob.options.batchSize).toBe(10);
expect(batchJob.options.concurrency).toBe(2);
expect(batchJob.payloadKey).toBe('batch:payload:1');
expect(batchJob.totalBatches).toBe(3);
expect(batchJob.itemCount).toBe(10);
});
it('should process batch results', () => {