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,21 +1,48 @@
import { beforeEach, describe, expect, it } from 'bun:test';
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
import { RedisCache } from '../src/redis-cache';
import type { CacheOptions } from '../src/types';
import type { CacheOptions, RedisConfig } from '../src/types';
const hasTestRedis = Boolean(process.env.BACKTEST_TEST_REDIS_URL);
const testRedisUrl = process.env.BACKTEST_TEST_REDIS_URL;
describe.skipIf(!hasTestRedis)('RedisCache', () => {
function parseTestRedisConfig(rawUrl: string): RedisConfig {
const parsed = new URL(rawUrl);
if (parsed.pathname !== '/15') {
throw new Error('BACKTEST_TEST_REDIS_URL must point to dedicated Redis database /15');
}
return {
host: parsed.hostname,
port: parsed.port ? Number(parsed.port) : 6379,
db: 15,
...(parsed.username ? { username: decodeURIComponent(parsed.username) } : {}),
...(parsed.password ? { password: decodeURIComponent(parsed.password) } : {}),
};
}
if (!testRedisUrl) {
process.stderr.write(
'Skipping RedisCache integration tests: set BACKTEST_TEST_REDIS_URL to a dedicated Redis fixture using database /15\n'
);
}
describe.skipIf(!testRedisUrl)('RedisCache', () => {
let cache: RedisCache;
let redisConfig: RedisConfig;
beforeEach(() => {
redisConfig = parseTestRedisConfig(testRedisUrl!);
const options: CacheOptions = {
keyPrefix: 'test:',
ttl: 3600,
redisConfig: { host: 'localhost', port: 6379 },
shared: false,
redisConfig,
};
cache = new RedisCache(options);
});
afterEach(async () => {
await cache?.disconnect().catch(() => {});
});
describe('Core functionality', () => {
it('should create cache instance', () => {
expect(cache).toBeDefined();
@ -148,16 +175,21 @@ describe.skipIf(!hasTestRedis)('RedisCache', () => {
// Force an error by using invalid JSON
const badCache = new RedisCache({
keyPrefix: 'bad:',
redisConfig: { host: 'localhost', port: 6379 },
shared: false,
redisConfig,
});
// This would normally throw but should return null
const result = await badCache.get('non-existent');
expect(result).toBeNull();
try {
// This would normally throw but should return null
const result = await badCache.get('non-existent');
expect(result).toBeNull();
// Check stats updated
const stats = badCache.getStats();
expect(stats.misses).toBe(1);
// Check stats updated
const stats = badCache.getStats();
expect(stats.misses).toBe(1);
} finally {
await badCache.disconnect().catch(() => {});
}
});
});