Skip to content

Commit 4073185

Browse files
igorcostaAutohand Evolve
andcommitted
Keep native MCP readiness tests independent of hook latency
Exercise immediate and delayed pre-tool hooks while an unrelated MCP readiness promise remains unresolved. Bound the ordering assertion with five seconds instead of including normal hook and filesystem work in a 100ms deadline. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
1 parent 51c7f86 commit 4073185

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎tests/core/agent/AgentDependencyComposer.outcomes.test.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,21 @@ describe('AgentDependencyComposer typed tool outcomes', () => {
603603
expect(result.output).toBe('Found 1 window(s).\n{"windows":[{"window_id":280,"pid":6844,"title":"Spotify Free"}]}');
604604
});
605605

606-
it('dispatches a ready native tool while an unrelated MCP server is still starting', async () => {
606+
it.each([0, 150])('dispatches a ready native tool while an unrelated MCP server is still starting (hook delay %dms)', async hookDelay => {
607607
const { internals } = createAgent();
608608
const tool = 'mcp__autohand-computer-use__list_windows' as AgentAction['type'];
609609
internals.toolManager.register({ name: tool, description: 'List windows', parameters: { type: 'object', properties: {} } });
610610
let release!: () => void;
611611
internals.mcpReady = new Promise<void>(resolve => { release = resolve; });
612612
internals.mcpManager.callTool = vi.fn().mockResolvedValue({ content: [{ type: 'text', text: 'Spotify' }] });
613-
internals.hookManager.executeHooks = vi.fn().mockResolvedValue([]);
613+
internals.hookManager.executeHooks = vi.fn(async () => {
614+
if (hookDelay) await new Promise<void>(resolve => setTimeout(resolve, hookDelay));
615+
return [];
616+
});
614617
internals.telemetryManager.trackToolUse = vi.fn().mockResolvedValue(undefined);
615618
const pending = internals.toolManager.execute([{ id: 'windows', tool, args: {} }]);
616619
try {
617-
await vi.waitFor(() => expect(internals.mcpManager.callTool).toHaveBeenCalledOnce(), { timeout: 100 });
620+
await vi.waitFor(() => expect(internals.mcpManager.callTool).toHaveBeenCalledOnce(), { timeout: 5_000 });
618621
} finally {
619622
release();
620623
await pending;

0 commit comments

Comments
 (0)