/** * heal-test.ts * * Implements the pwpilot_heal_test MCP tool. * * When a test step fails, this tool attempts to find a working alternative * locator for the failing element. It operates in two phases: * * Phase 1 — Local healing (zero AI tokens): * Delegates to HealingEngine which tries stored ElementContext metadata, * semantic role/text matching, and accessibility label scanning. * * Phase 2 — AI escalation (only if local healing fails): * Builds a compact, token-optimized prompt for Claude using only the * elements nearby the failure in the DOM snapshot (not the full DOM). * Returns the prompt as claudeHealingPrompt for the caller to use. * * Role in the overall flow: * pwpilot_execute_test (step fails) → user calls pwpilot_heal_test * → healTest() → HealingEngine (local) → HealingResult * → claudeHealingPrompt (if local fails) */ import { z } from 'zod'; import { Page } from 'playwright'; import { HealingResult, TestIntent } from '../../types'; import { HealingEngine } from '../../ai/healing-engine'; import { ScreenshotManager } from '../../artifacts/screenshot-manager'; import { PageObserver } from '../../browser/page-observer'; import { MetadataManager } from '../../artifacts/metadata-manager'; import { StepContextManager } from '../../execution/step-context-manager'; /** * Zod schema for validating the input to heal_test. */ export declare const HealTestSchema: z.ZodObject<{ testName: z.ZodString; stepIndex: z.ZodNumber; stepDescription: z.ZodString; failureReason: z.ZodString; }, "strip", z.ZodTypeAny, { testName: string; stepIndex: number; stepDescription: string; failureReason: string; }, { testName: string; stepIndex: number; stepDescription: string; failureReason: string; }>; /** Input type inferred from HealTestSchema. */ export type HealTestInput = z.infer; /** * Output returned to the MCP server after a healing attempt. */ export interface HealTestOutput { /** The result of the local healing attempt. */ result: HealingResult; /** Path to the screenshot captured at the time of healing. */ screenshotPath: string; /** * If local healing failed, this is a compact prompt for Claude to produce * a corrected locator. Only present when result.success is false. */ claudeHealingPrompt?: string; } /** * Attempt to heal a failed test step. * * Takes a screenshot, captures nearby DOM context, loads any stored element * metadata, runs local healing strategies, and (if those fail) builds a compact * AI prompt for Claude to suggest a corrected locator. * * @param input - Validated input: test name, step index, description, and failure reason. * @param page - The live Playwright page at the time of healing. * @param intent - The TestIntent being healed (used for context in the healing prompt). * @param healingEngine - Runs local healing strategies against the live page. * @param screenshotManager - Captures the current page state as a PNG. * @param pageObserver - Reads the full DOM snapshot. * @param metadataManager - Saves the healing log to disk. * @param contextManager - Optional; loads the stored StepContext to find saved ElementContext. * @returns A HealTestOutput with the healing result, screenshot path, and optional AI prompt. */ export declare function healTest(input: HealTestInput, page: Page, intent: TestIntent, healingEngine: HealingEngine, screenshotManager: ScreenshotManager, pageObserver: PageObserver, metadataManager: MetadataManager, contextManager?: StepContextManager): Promise; //# sourceMappingURL=heal-test.d.ts.map