Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
import { mock } from 'jest-mock-extended';
|
|
import pLimit from 'p-limit';
|
|
|
|
import type { SimpleWorkflow } from '@/types/workflow';
|
|
|
|
import { runJudgePanel } from './judge-panel';
|
|
|
|
const mockEvaluateWorkflowPairwise = jest.fn();
|
|
|
|
jest.mock('./judge-chain', () => ({
|
|
evaluateWorkflowPairwise: (...args: unknown[]): unknown => mockEvaluateWorkflowPairwise(...args),
|
|
}));
|
|
|
|
function createMockWorkflow(name = 'Test Workflow'): SimpleWorkflow {
|
|
return { name, nodes: [], connections: {} };
|
|
}
|
|
|
|
describe('runJudgePanel()', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should respect llmCallLimiter concurrency', async () => {
|
|
let active = 0;
|
|
let maxActive = 0;
|
|
|
|
mockEvaluateWorkflowPairwise.mockImplementation(async () => {
|
|
active++;
|
|
maxActive = Math.max(maxActive, active);
|
|
await new Promise((r) => setTimeout(r, 20));
|
|
active--;
|
|
return { violations: [], passes: [], primaryPass: true, diagnosticScore: 1 };
|
|
});
|
|
|
|
const llm = mock<BaseChatModel>();
|
|
const workflow = createMockWorkflow();
|
|
|
|
await runJudgePanel(llm, workflow, { dos: 'Do X', donts: 'Do not Y' }, 5, {
|
|
llmCallLimiter: pLimit(2),
|
|
});
|
|
|
|
expect(maxActive).toBeLessThanOrEqual(2);
|
|
expect(mockEvaluateWorkflowPairwise).toHaveBeenCalledTimes(5);
|
|
});
|
|
});
|