"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetDeploymentEventPlanRunsToolDefinition = exports.getDeploymentEventPlanRunsResponseSchema = exports.failurePatternSchema = exports.planRunInfoSchema = exports.testRunSummarySchema = exports.getDeploymentEventPlanRunsParamsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var agentToolNames_js_1 = require("../shared/agentToolNames.js");
/**
 * GetDeploymentEventPlanRunsDefinition - Tool definition for fetching all plan runs triggered by a deployment event.
 */
exports.getDeploymentEventPlanRunsParamsSchema = zod_1.z.object({
    deployment_event_id: zod_1.z.string().meta({
        description: 'Required. Deployment event ID.',
    }),
    filter_status: zod_1.z.enum(['all', 'passed', 'failed']).optional().meta({
        description: 'Filter plan runs by status. Default: all',
    }),
    include_test_details: zod_1.z.boolean().optional().meta({
        description: 'Whether to include individual test run details for each plan run. Default: false',
    }),
});
// Schema for test run summary within a plan run
exports.testRunSummarySchema = 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' }),
    status: zod_1.z.enum(['passed', 'failed', 'skipped', 'running', 'queued']).meta({ description: 'Test run status' }),
    failureReason: zod_1.z.string().optional().meta({ description: 'Failure reason if test failed' }),
    durationMs: zod_1.z.number().optional().meta({ description: 'Duration in milliseconds' }),
});
// Schema for individual plan run info
exports.planRunInfoSchema = zod_1.z.object({
    planRunId: zod_1.z.string().meta({ description: 'Plan run ID' }),
    planId: zod_1.z.string().optional().meta({ description: 'Plan ID' }),
    planName: zod_1.z.string().optional().meta({ description: 'Name of the plan' }),
    status: zod_1.z.enum(['passed', 'failed', 'running', 'cancelled', 'terminated']).meta({
        description: 'Status of the plan run',
    }),
    startTime: zod_1.z.string().optional().meta({ description: 'Start time as ISO string' }),
    endTime: zod_1.z.string().optional().meta({ description: 'End time as ISO string' }),
    durationMs: zod_1.z.number().optional().meta({ description: 'Duration in milliseconds' }),
    testCounts: zod_1.z
        .object({
        total: zod_1.z.number().meta({ description: 'Total number of tests' }),
        passed: zod_1.z.number().meta({ description: 'Number of passed tests' }),
        failed: zod_1.z.number().meta({ description: 'Number of failed tests' }),
        skipped: zod_1.z.number().meta({ description: 'Number of skipped tests' }),
    })
        .optional()
        .meta({ description: 'Test count statistics' }),
    passRate: zod_1.z.number().optional().meta({ description: 'Pass rate as a percentage (0-100)' }),
    failedTests: zod_1.z.array(exports.testRunSummarySchema).optional().meta({ description: 'Failed test runs (if any)' }),
});
// 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' }),
    planNames: zod_1.z.array(zod_1.z.string()).meta({ description: 'Names of plans with this failure reason' }),
});
exports.getDeploymentEventPlanRunsResponseSchema = zod_1.z.object({
    planRuns: zod_1.z.array(exports.planRunInfoSchema).meta({ description: 'List of plan runs triggered by this deployment' }),
    summary: zod_1.z
        .object({
        totalPlanRuns: zod_1.z.number().meta({ description: 'Total number of plan runs' }),
        passedPlanRuns: zod_1.z.number().meta({ description: 'Number of passed plan runs' }),
        failedPlanRuns: zod_1.z.number().meta({ description: 'Number of failed plan runs' }),
        runningPlanRuns: zod_1.z.number().meta({ description: 'Number of running plan runs' }),
        overallPassRate: zod_1.z.number().optional().meta({ description: 'Overall pass rate as a percentage' }),
        totalTestRuns: zod_1.z.number().optional().meta({ description: 'Total test runs across all plans' }),
        passedTestRuns: zod_1.z.number().optional().meta({ description: 'Passed test runs across all plans' }),
        failedTestRuns: zod_1.z.number().optional().meta({ description: 'Failed test runs across all plans' }),
    })
        .meta({ description: 'Summary of plan run statuses' }),
    failurePatterns: zod_1.z.array(exports.failurePatternSchema).optional().meta({
        description: 'Analysis of failure patterns across plan runs',
    }),
});
exports.GetDeploymentEventPlanRunsToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.GetDeploymentEventPlanRuns,
    description: "Retrieves all plan runs triggered by a deployment event with their status, duration, and test results.\n\n**Do not call without a real deployment_event_id** (same sources as **".concat(agentToolNames_js_1.AgentToolNames.GetDeploymentEventInfo, "** \u2014 context artifact, user, **").concat(agentToolNames_js_1.AgentToolNames.QueryWorkspaceDeploymentEvents, "**, or prior tool output).\n\nUse this tool to:\n- See which plans ran and their pass/fail status\n- Understand which specific plans failed and why\n- Identify patterns in test failures across plans\n- Get plan run IDs for deeper analysis\n- Analyze test execution timing within the deployment\n\nWith **include_test_details=true**, failed test rows include **testRunId**, **testName**, and per-test failure fields in addition to each plan run's **planRunId** and **planName**."),
    argumentsSchema: exports.getDeploymentEventPlanRunsParamsSchema,
    responseSchema: exports.getDeploymentEventPlanRunsResponseSchema,
});
//# sourceMappingURL=GetDeploymentEventPlanRunsDefinition.js.map