"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const filterErrorTests_1 = require("../../../src/commands/eval/filterErrorTests");
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('filterErrorTests', () => {
    const varsSuccess = { successKey: 'value' };
    const varsError = { errorKey: 'value' };
    const successTest = { vars: varsSuccess };
    const errorTest = { vars: varsError };
    const testSuite = {
        tests: [successTest, errorTest],
    };
    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.ERROR,
                        provider: { id: 'provider2' },
                        vars: varsError,
                        promptIdx: 0,
                        testIdx: 0,
                        testCase: {},
                        promptId: 'foo',
                    },
                ],
                table: {},
                stats: {},
            },
        });
    });
    afterEach(jest.clearAllMocks);
    it('can filter using vars', async () => {
        const result = await (0, filterErrorTests_1.filterErrorTests)(testSuite, outputPath);
        expect(result).toStrictEqual([errorTest]);
    });
    it('can filter using test provider', async () => {
        const errorTest1 = { provider: 'provider1', vars: varsError };
        const errorTest2 = { provider: 'provider2', vars: varsError };
        const testSuite = {
            tests: [errorTest1, errorTest2],
        };
        const result = await (0, filterErrorTests_1.filterErrorTests)(testSuite, outputPath);
        expect(result).toStrictEqual([errorTest2]);
    });
    it('returns empty array when no error 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, filterErrorTests_1.filterErrorTests)(testSuite, outputPath);
        expect(result).toStrictEqual([]);
    });
});
//# sourceMappingURL=filterErrorTests.test.js.map