mirror of
https://github.com/proffesor-for-testing/agentic-qe.git
synced 2026-09-19 08:45:47 +08:00
65457ccc84
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>
131 lines
3.9 KiB
TypeScript
131 lines
3.9 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import { createSessionDurabilityMiddleware } from '../../../src/mcp/services/session-durability-middleware';
|
|
import type { ToolCallContext } from '../../../src/mcp/middleware/middleware-chain';
|
|
|
|
function createMockStore() {
|
|
return {
|
|
append: vi.fn(),
|
|
startSession: vi.fn(),
|
|
flush: vi.fn(),
|
|
getEntries: vi.fn().mockReturnValue([]),
|
|
};
|
|
}
|
|
|
|
function createContext(overrides?: Partial<ToolCallContext>): ToolCallContext {
|
|
return {
|
|
toolName: 'test_tool',
|
|
params: { key: 'value' },
|
|
timestamp: Date.now(),
|
|
metadata: {},
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('createSessionDurabilityMiddleware', () => {
|
|
beforeEach(() => {
|
|
delete process.env.AQE_SESSION_DURABILITY;
|
|
});
|
|
|
|
afterEach(() => {
|
|
delete process.env.AQE_SESSION_DURABILITY;
|
|
});
|
|
|
|
it('should return a middleware named "session-durability" at priority 50', () => {
|
|
const store = createMockStore();
|
|
const mw = createSessionDurabilityMiddleware(store as any);
|
|
|
|
expect(mw.name).toBe('session-durability');
|
|
expect(mw.priority).toBe(50);
|
|
});
|
|
|
|
it('preToolCall should append a tool_call entry', async () => {
|
|
const store = createMockStore();
|
|
const mw = createSessionDurabilityMiddleware(store as any);
|
|
const ctx = createContext();
|
|
|
|
const result = await mw.preToolCall!(ctx);
|
|
|
|
expect(result).toBe(ctx);
|
|
expect(store.append).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
type: 'tool_call',
|
|
toolName: 'test_tool',
|
|
state: 'running',
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('postToolResult should append a tool_result entry and pass through result', async () => {
|
|
const store = createMockStore();
|
|
const mw = createSessionDurabilityMiddleware(store as any);
|
|
const ctx = createContext();
|
|
const toolResult = { data: 'hello' };
|
|
|
|
const result = await mw.postToolResult!(ctx, toolResult);
|
|
|
|
expect(result).toBe(toolResult);
|
|
expect(store.append).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
type: 'tool_result',
|
|
toolName: 'test_tool',
|
|
state: 'idle',
|
|
result: toolResult,
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('onError should append an error entry with message and stack', async () => {
|
|
const store = createMockStore();
|
|
const mw = createSessionDurabilityMiddleware(store as any);
|
|
const ctx = createContext();
|
|
const error = new Error('something broke');
|
|
|
|
await mw.onError!(ctx, error);
|
|
|
|
expect(store.append).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
type: 'error',
|
|
toolName: 'test_tool',
|
|
state: 'requires_action',
|
|
result: expect.objectContaining({ message: 'something broke' }),
|
|
}),
|
|
);
|
|
});
|
|
|
|
describe('kill switch: AQE_SESSION_DURABILITY=false', () => {
|
|
it('preToolCall should be a no-op when disabled', async () => {
|
|
process.env.AQE_SESSION_DURABILITY = 'false';
|
|
const store = createMockStore();
|
|
const mw = createSessionDurabilityMiddleware(store as any);
|
|
const ctx = createContext();
|
|
|
|
const result = await mw.preToolCall!(ctx);
|
|
|
|
expect(result).toBe(ctx);
|
|
expect(store.append).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('postToolResult should pass through without logging when disabled', async () => {
|
|
process.env.AQE_SESSION_DURABILITY = 'false';
|
|
const store = createMockStore();
|
|
const mw = createSessionDurabilityMiddleware(store as any);
|
|
const ctx = createContext();
|
|
|
|
const result = await mw.postToolResult!(ctx, 'data');
|
|
|
|
expect(result).toBe('data');
|
|
expect(store.append).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('onError should be a no-op when disabled', async () => {
|
|
process.env.AQE_SESSION_DURABILITY = 'false';
|
|
const store = createMockStore();
|
|
const mw = createSessionDurabilityMiddleware(store as any);
|
|
|
|
await mw.onError!(createContext(), new Error('test'));
|
|
|
|
expect(store.append).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|