"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const filterFailingTests_1 = require("../../../src/commands/eval/filterFailingTests");
const types_1 = require("../../../src/types");
const util_1 = require("../../../src/util");
jest.mock('../../../src/util', () => {
    return {
        ...jest.requireActual('../../../src/util'),
        readOutput: jest.fn(),
    };
});
describe('filterFailingTests', () => {
    const varsSuccess = { successKey: 'value' };
    const varsFailure = { failureKey: 'value' };
    const sucessTest = { vars: varsSuccess };
    const failureTest = { vars: varsFailure };
    const testSuite = {
        tests: [sucessTest, failureTest],
    };
    const outputPath = 'outputPath.json';
    const restResult = {
        prompt: {
            raw: 'prompt',
            label: 'prompt',
        },
        score: 0.5,
        latencyMs: 1000,
        namedScores: {},
    };
    beforeEach(() => {
        jest.mocked(util_1.readOutput).mockResolvedValue({
            results: {
                version: 2,
                timestamp: '2024-01-01T00:00:00.000Z',
                results: [
                    {
                        ...restResult,
                        success: true,
                        failureReason: types_1.ResultFailureReason.NONE,
                        provider: { id: 'provider1' },
                        vars: varsSuccess,
                        promptIdx: 0,
                        testIdx: 0,
                        testCase: {},
                        promptId: 'foo',
                    },
                    {
                        ...restResult,
                        success: false,
                        failureReason: types_1.ResultFailureReason.NONE,
                        provider: { id: 'provider2' },
                        vars: varsFailure,
                        promptIdx: 0,
                        testIdx: 0,
                        testCase: {},
                        promptId: 'foo',
                    },
                ],
                table: {},
                stats: {},
            },
        });
    });
    afterEach(jest.clearAllMocks);
    it('can filter using vars', async () => {
        const result = await (0, filterFailingTests_1.filterFailingTests)(testSuite, outputPath);
        expect(result).toStrictEqual([failureTest]);
    });
    it('can filter using test provider', async () => {
        const failureTest1 = { provider: 'provider1', vars: varsFailure };
        const failureTest2 = { provider: 'provider2', vars: varsFailure };
        const testSuite = {
            tests: [failureTest1, failureTest2],
        };
        const result = await (0, filterFailingTests_1.filterFailingTests)(testSuite, outputPath);
        expect(result).toStrictEqual([failureTest2]);
    });
    it('returns empty array when no failing tests', async () => {
        jest.mocked(util_1.readOutput).mockResolvedValue({
            results: {
                version: 2,
                timestamp: '2024-01-01T00:00:00.000Z',
                results: [
                    {
                        success: true,
                        failureReason: types_1.ResultFailureReason.NONE,
                        provider: { id: 'provider1' },
                        vars: varsSuccess,
                        prompt: {
                            raw: 'prompt',
                            label: 'prompt',
                        },
                        score: 0.5,
                        latencyMs: 1000,
                        namedScores: {},
                        promptIdx: 0,
                        testIdx: 0,
                        testCase: {},
                        promptId: 'foo',
                    },
                ],
                table: {},
                stats: {},
            },
        });
        const result = await (0, filterFailingTests_1.filterFailingTests)(testSuite, outputPath);
        expect(result).toStrictEqual([]);
    });
});
//# sourceMappingURL=filterFailingTests.test.js.map