Files
Dragan Spiridonov 65457ccc84 fix: add kill switches, missing tests, and log redirect for CC-internals (IMP-00–10)
Address verification findings from user-perspective review of IMP-00 through IMP-10:

- Implement 8 missing env var kill switches (AQE_MICROCOMPACT, AQE_RETRY_DISABLED,
  AQE_SESSION_DURABILITY, AQE_PROMPT_CACHE_LATCH, AQE_FAST_PATHS,
  AQE_HOOKS_SSRF_DISABLED, AQE_COMPACTION_DISABLED, AQE_PLUGINS_DISABLED)
- Add 5 missing test files: parallel-prefetch, session-durability-middleware,
  and plugin sources (local, github, npm) — 40 new tests
- Add kill switch test coverage for all 8 env vars — 10 new tests
- Fix stdout log leak: redirect [ParserRegistry], [ContinueGateIntegration],
  timestamped logs, and other internal prefixes to stderr
- Update plan doc verification matrix with correct test file names (37 files)
- Add user-perspective verification report

466 tests pass across 37 IMP test files. Build clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 06:46:57 +00:00

78 lines
2.8 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { parallelPrefetch, type PrefetchResult } from '../../src/boot/parallel-prefetch';
describe('parallelPrefetch', () => {
it('should run all tasks and return completed list', async () => {
const result = await parallelPrefetch([
{ name: 'task-a', fn: async () => {} },
{ name: 'task-b', fn: async () => {} },
]);
expect(result.completedTasks).toEqual(['task-a', 'task-b']);
expect(result.failedTasks).toEqual([]);
expect(result.totalTimeMs).toBeGreaterThanOrEqual(0);
});
it('should isolate failures — one failing task does not block others', async () => {
const result = await parallelPrefetch([
{ name: 'ok', fn: async () => {} },
{ name: 'fail', fn: async () => { throw new Error('boom'); } },
{ name: 'also-ok', fn: async () => {} },
]);
expect(result.completedTasks).toEqual(['ok', 'also-ok']);
expect(result.failedTasks).toHaveLength(1);
expect(result.failedTasks[0].name).toBe('fail');
expect(result.failedTasks[0].error).toBe('boom');
});
it('should handle all tasks failing', async () => {
const result = await parallelPrefetch([
{ name: 'a', fn: async () => { throw new Error('err-a'); } },
{ name: 'b', fn: async () => { throw new Error('err-b'); } },
]);
expect(result.completedTasks).toEqual([]);
expect(result.failedTasks).toHaveLength(2);
});
it('should handle empty task list', async () => {
const result = await parallelPrefetch([]);
expect(result.completedTasks).toEqual([]);
expect(result.failedTasks).toEqual([]);
expect(result.totalTimeMs).toBeGreaterThanOrEqual(0);
});
it('should run tasks concurrently (not sequentially)', async () => {
const start = performance.now();
const result = await parallelPrefetch([
{ name: 'slow-a', fn: () => new Promise(r => setTimeout(r, 50)) },
{ name: 'slow-b', fn: () => new Promise(r => setTimeout(r, 50)) },
]);
const elapsed = performance.now() - start;
expect(result.completedTasks).toEqual(['slow-a', 'slow-b']);
// If sequential, would be >=100ms; parallel should be ~50ms
expect(elapsed).toBeLessThan(90);
});
it('should capture error message from non-Error throws', async () => {
const result = await parallelPrefetch([
{ name: 'string-throw', fn: async () => { throw 'raw string'; } },
]);
expect(result.failedTasks[0].error).toBe('raw string');
});
it('should report totalTimeMs accurately', async () => {
const result = await parallelPrefetch([
{ name: 'quick', fn: async () => {} },
]);
expect(typeof result.totalTimeMs).toBe('number');
expect(result.totalTimeMs).toBeGreaterThanOrEqual(0);
expect(result.totalTimeMs).toBeLessThan(1000); // should be very fast
});
});