"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetPlanRunTestRunsToolDefinition = exports.getPlanRunTestRunsResponseSchema = exports.failurePatternSchema = exports.testRunInfoSchema = exports.getPlanRunTestRunsParamsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var agentToolNames_js_1 = require("../shared/agentToolNames.js");
/**
 * GetPlanRunTestRunsDefinition - Tool definition for fetching all test runs within a plan run.
 */
exports.getPlanRunTestRunsParamsSchema = zod_1.z.object({
    plan_run_id: zod_1.z.string().meta({
        description: "Required. Plan run ID to fetch test runs for. To compare another run, pass that run's plan_run_id from get_related_plan_runs. When analyzing deployments, use plan_run_id from get_deployment_event_plan_runs results.",
    }),
    filter_status: zod_1.z.enum(['all', 'passed', 'failed', 'skipped']).optional().meta({
        description: 'Filter test runs by status. Default: all',
    }),
    limit: zod_1.z.number().optional().meta({
        description: 'Maximum number of test runs to return. Default: 50',
    }),
});
// Schema for individual test run info
exports.testRunInfoSchema = zod_1.z.object({
    testRunId: zod_1.z.string().meta({ description: 'Test run ID' }),
    testName: zod_1.z.string().optional().meta({ description: 'Name of the test' }),
    testId: zod_1.z.string().optional().meta({ description: 'Test ID (journey_id)' }),
    status: zod_1.z.enum(['passed', 'failed', 'skipped', 'running', 'queued']).meta({ description: 'Status of the test run' }),
    durationMs: zod_1.z.number().optional().meta({ description: 'Duration in milliseconds' }),
    browser: zod_1.z.string().optional().meta({ description: 'Browser used for the test' }),
    failureReason: zod_1.z.string().optional().meta({ description: 'Failure reason if test failed' }),
    stageIndex: zod_1.z.number().optional().meta({ description: 'Execution stage index within the plan' }),
});
// Schema for failure pattern analysis
exports.failurePatternSchema = zod_1.z.object({
    reason: zod_1.z.string().meta({ description: 'The failure reason' }),
    count: zod_1.z.number().meta({ description: 'Number of tests with this failure reason' }),
    testNames: zod_1.z.array(zod_1.z.string()).meta({ description: 'Names of tests with this failure reason' }),
});
exports.getPlanRunTestRunsResponseSchema = zod_1.z.object({
    testRuns: zod_1.z.array(exports.testRunInfoSchema).meta({ description: 'List of test runs in the plan run' }),
    summary: zod_1.z
        .object({
        total: zod_1.z.number().meta({ description: 'Total number of test runs' }),
        passed: zod_1.z.number().meta({ description: 'Number of passed test runs' }),
        failed: zod_1.z.number().meta({ description: 'Number of failed test runs' }),
        skipped: zod_1.z.number().meta({ description: 'Number of skipped test runs' }),
        running: zod_1.z.number().meta({ description: 'Number of running test runs' }),
    })
        .meta({ description: 'Summary of test run statuses' }),
    failurePatterns: zod_1.z.array(exports.failurePatternSchema).optional().meta({
        description: 'Analysis of failure patterns (grouped by failure reason)',
    }),
});
exports.GetPlanRunTestRunsToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.GetPlanRunTestRuns,
    description: "Retrieves all test runs within a plan run with their status, duration, and failure information.\n\nUse this tool to:\n- See which tests passed and which failed\n- Understand failure reasons for failed tests\n- Identify patterns in test failures\n- Get test run IDs for fetching screenshots or more details\n- Analyze test execution timing within the plan",
    argumentsSchema: exports.getPlanRunTestRunsParamsSchema,
    responseSchema: exports.getPlanRunTestRunsResponseSchema,
});
//# sourceMappingURL=GetPlanRunTestRunsDefinition.js.map