import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { EVIDENCE_FILENAME, REASONING_FILENAME, REPAIR_NOTES_FILENAME } from '../shared/constants.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
import { boundingBoxSchema } from '../shared/schemas.js';
export const resolveTestFailureArgumentsSchema = z.object({
    decision: z.enum(['fail', 'resume']).describe('Whether to fail the test or continue execution from the next step'),
    failure_summary: z.string().optional().describe('Summary of why the test failed (required if decision is fail)'),
    bounding_box: boundingBoxSchema
        .optional()
        .describe('Bounding box of the element that drove your recovery. Only provide it if you already have the coordinates from a prior recovery tool call (e.g., a previous click or text entry). Do NOT make additional tool calls to obtain it.'),
    test_needs_update: z
        .boolean()
        .optional()
        .describe(`Set to true when your investigation reveals the test definition itself is stale and a downstream test-editing agent should update it: a selector now binds to the wrong element, a step references a removed/renamed control, an assertion targets text that no longer exists, etc. Judge this independently of decision — set it whether you go on to resume or to fail. In particular, set decision=fail AND test_needs_update=true when you found the test is stale but could not safely recover (e.g. a required control was removed with no valid workaround). Leave false or omitted for (a) transient flakes (timing, network, race conditions) where the test definition is correct as-is — even if such a flake forced you to fail — and (b) real application bugs where the test is correct and should keep surfacing the bug. When true, your ${REPAIR_NOTES_FILENAME} is the only context the editor will receive: it must contain a URL line and a numbered list of step-level operations ("Replace step N: ...", "Insert between step N and N+1: ...", "Delete step N", "Change step N parameter X from Y to Z"), self-contained with no references to other files.`),
});
export const resolveTestFailureServerPrepareResultSchema = z.object({
    elementBoundingBox: boundingBoxSchema.optional(),
});
export const resolveTestFailureResponseSchema = z.object({
    acknowledged: z.boolean().describe('Whether the decision was acknowledged'),
});
export const ResolveTestFailureToolDefinition = defineTool({
    name: AgentToolNames.ResolveTestFailure,
    description: `Terminal tool - make the final decision on whether this test should fail or continue execution from the next step.

You MUST write ${EVIDENCE_FILENAME}, ${REASONING_FILENAME}, and ${REPAIR_NOTES_FILENAME} using ${AgentToolNames.WriteFile} before calling this tool. The tool will reject the call if any file is missing.

When decision is 'resume':
- You have performed the failed step's intended action and the app is ready for the next step
- If you already have coordinates for the element that drove your recovery, pass them as bounding_box. Do NOT call execute_javascript (or any other tool) just to obtain coordinates.

When decision is 'fail':
- Provide a clear failure_summary explaining why recovery is not possible`,
    argumentsSchema: resolveTestFailureArgumentsSchema,
    serverPrepareResultSchema: resolveTestFailureServerPrepareResultSchema,
    responseSchema: resolveTestFailureResponseSchema,
});
//# sourceMappingURL=ResolveFailureDefinition.js.map