import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
/**
 * GetPlanRunTestRunsDefinition - Tool definition for fetching all test runs within a plan run.
 */
export const getPlanRunTestRunsParamsSchema = z.object({
    plan_run_id: 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: z.enum(['all', 'passed', 'failed', 'skipped']).optional().meta({
        description: 'Filter test runs by status. Default: all',
    }),
    limit: z.number().optional().meta({
        description: 'Maximum number of test runs to return. Default: 50',
    }),
});
// Schema for individual test run info
export const testRunInfoSchema = z.object({
    testRunId: z.string().meta({ description: 'Test run ID' }),
    testName: z.string().optional().meta({ description: 'Name of the test' }),
    testId: z.string().optional().meta({ description: 'Test ID (journey_id)' }),
    status: z.enum(['passed', 'failed', 'skipped', 'running', 'queued']).meta({ description: 'Status of the test run' }),
    durationMs: z.number().optional().meta({ description: 'Duration in milliseconds' }),
    browser: z.string().optional().meta({ description: 'Browser used for the test' }),
    failureReason: z.string().optional().meta({ description: 'Failure reason if test failed' }),
    stageIndex: z.number().optional().meta({ description: 'Execution stage index within the plan' }),
});
// Schema for failure pattern analysis
export const failurePatternSchema = z.object({
    reason: z.string().meta({ description: 'The failure reason' }),
    count: z.number().meta({ description: 'Number of tests with this failure reason' }),
    testNames: z.array(z.string()).meta({ description: 'Names of tests with this failure reason' }),
});
export const getPlanRunTestRunsResponseSchema = z.object({
    testRuns: z.array(testRunInfoSchema).meta({ description: 'List of test runs in the plan run' }),
    summary: z
        .object({
        total: z.number().meta({ description: 'Total number of test runs' }),
        passed: z.number().meta({ description: 'Number of passed test runs' }),
        failed: z.number().meta({ description: 'Number of failed test runs' }),
        skipped: z.number().meta({ description: 'Number of skipped test runs' }),
        running: z.number().meta({ description: 'Number of running test runs' }),
    })
        .meta({ description: 'Summary of test run statuses' }),
    failurePatterns: z.array(failurePatternSchema).optional().meta({
        description: 'Analysis of failure patterns (grouped by failure reason)',
    }),
});
export const GetPlanRunTestRunsToolDefinition = defineTool({
    name: AgentToolNames.GetPlanRunTestRuns,
    description: `Retrieves all test runs within a plan run with their status, duration, and failure information.

Use this tool to:
- See which tests passed and which failed
- Understand failure reasons for failed tests
- Identify patterns in test failures
- Get test run IDs for fetching screenshots or more details
- Analyze test execution timing within the plan`,
    argumentsSchema: getPlanRunTestRunsParamsSchema,
    responseSchema: getPlanRunTestRunsResponseSchema,
});
//# sourceMappingURL=GetPlanRunTestRunsDefinition.js.map