"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateTestExecutor = void 0;
exports.validateTestExecutor = {
    needsFind: () => false,
    getStepType: () => 'validate-test',
    execute: async (payload, _stateProvider, _eventHandler, logger) => {
        if (!payload.validateTest) {
            logger.error('validateTest callback not available on payload');
            return {
                success: false,
                errorMessage: 'Test validation is not available in this execution context',
                errorCause: 'UnexpectedError',
            };
        }
        const toolParams = payload.toolCall.toolParams;
        logger.info('Starting test validation in fresh browser');
        const { screenshotImages, ...validationResultJson } = await payload.validateTest({
            url: toolParams?.url,
            stop_on_first_failure: toolParams?.stop_on_first_failure,
        });
        if (validationResultJson.error) {
            return {
                success: false,
                errorMessage: validationResultJson.error,
                errorCause: 'UnexpectedError',
                validation_result: validationResultJson,
                imageContentItems: screenshotImages,
            };
        }
        return {
            success: validationResultJson.success,
            errorMessage: validationResultJson.success
                ? undefined
                : `Validation failed: ${validationResultJson.stepResults.filter((r) => r.status === 'fail')
                    .length} step(s) failed`,
            validation_result: validationResultJson,
            imageContentItems: screenshotImages,
        };
    },
};
