/** * types/index.ts * * Central type definitions for the entire Playwright Pilot AI system. * * This file is the single source of truth for all shared data shapes. Every * major subsystem (execution, healing, skills, YAML, MCP tools) imports its * types from here rather than defining them locally. This keeps cross-system * contracts explicit and makes type changes easy to track. * * Sections: * - TestIntent / GeneratedTest — what a test is and what was generated * - ElementContext — rich element metadata stored in Page Objects for healing * - StepContext — per-step execution state written to disk * - Healing — HealingContext, HealingResult, HealingStrategy * - DOM analysis — DOMElement, PageAnalysis * - Config — FrameworkConfig, ExecutionReport * - Skills — SkillResult, SkillContext * - Compact page summary — CompactElement, CompactStep * - YAML test definition — YamlLocator, YamlAssertion, YamlStep, TestYaml, YamlStepResult, YamlExecutionReport * - CompactPageSummary — the minimal structure Claude needs to write a spec */ /** * Describes what a test should do: its name, the URL to visit, and an ordered * list of natural-language steps. Saved to disk after generation and loaded * at execution time. */ export interface TestIntent { /** Human-readable test name, e.g. "empty login validation". */ name: string; /** The original user prompt that triggered test generation. */ prompt: string; /** The URL under test. */ url: string; /** Ordered natural-language step descriptions, e.g. "click the Login button". */ intent: string[]; /** Additional metadata about when and how the test was generated. */ metadata: IntentMetadata; } /** Metadata recorded alongside a TestIntent at generation time. */ export interface IntentMetadata { /** ISO timestamp when the intent was created. */ generatedAt: string; /** The URL that was tested. */ url: string; /** Framework identifier, always "playwright-pilot-ai". */ framework: string; } /** * The full output of the test-generation process: the intent that drove it, * the generated TypeScript code, and where on disk it was saved. */ export interface GeneratedTest { intent: TestIntent; /** The full TypeScript source of the generated .spec.ts file. */ code: string; /** Absolute path where the spec file was written. */ filePath: string; } /** * Rich metadata about one interactive element, stored in the Page Object's * ELEMENT_CONTEXTS constant. Used by the HealingEngine to find alternative * locators when the original one fails. */ export interface ElementContext { /** Property name on the page object, e.g. "emailField" */ key: string; /** Plain English description, e.g. "email input field" */ description: string; /** HTML tag name, e.g. "input", "button". */ tag?: string; /** ARIA role, e.g. "button", "textbox". */ role?: string; /** Associated label text. */ label?: string; /** Placeholder text for input fields. */ placeholder?: string; /** Visible inner text of the element. */ text?: string; /** data-testid attribute value if present. */ testId?: string; /** Inferred interaction type — used by skill orchestrator and POM generator */ actionType?: 'click' | 'fill' | 'select' | 'check' | 'assert' | 'navigate'; /** Original locator expression used at generation time */ originalLocator: string; } /** * Records the execution state of one test step, written to disk before and * after every step so that healing and reporting have accurate, current data. */ export interface StepContext { /** Name of the test this step belongs to. */ testName: string; /** Zero-based position of this step in the test. */ stepIndex: number; /** Human-readable description of what this step does. */ stepDescription: string; /** Key into the page object's ELEMENT_CONTEXTS */ elementKey?: string; /** The full element context for this step's target element, if available. */ elementContext?: ElementContext; /** The locator expression that was used for this step. */ locatorUsed: string; /** Current execution status of this step. */ status: 'pending' | 'passed' | 'failed' | 'healed'; /** Error message if the step failed. */ error?: string; /** Path to the screenshot captured at failure time. */ screenshotPath?: string; /** Path to the DOM snapshot HTML file captured at failure time. */ domSnapshotPath?: string; /** Locator that healed the step, if healing succeeded */ healedLocator?: string; /** Name of the healing strategy that succeeded, e.g. "element-context". */ healingStrategy?: string; /** ISO timestamp when this context was last written. */ timestamp: string; } /** * All the information available to the HealingEngine when a step fails. */ export interface HealingContext { /** Zero-based step index. */ stepIndex: number; /** Human-readable description of the failed step. */ stepDescription: string; /** The error message from Playwright. */ failureReason: string; /** Path to the screenshot captured at failure time. */ screenshotPath: string; /** Full HTML snapshot of the page at failure time. */ domSnapshot: string; /** The test intent being executed. */ intent: TestIntent; /** Stored element metadata for the failing step, if available. */ elementContext?: ElementContext; } /** * The outcome of a healing attempt — whether it succeeded, what locator was * found (if any), and which strategy produced it. */ export interface HealingResult { /** True if a working alternative locator was found. */ success: boolean; /** The locator expression that was found to work. Present only when success is true. */ repairedLocator?: string; /** Which healing strategy produced this result. */ strategy: HealingStrategy; /** Human-readable explanation of the result. */ notes: string; } /** The strategies the HealingEngine tries, in order of preference. */ export type HealingStrategy = 'retry' | 'element-context' | 'semantic-text' | 'accessibility' | 'nearby-dom' | 'failed'; /** * A single interactive element extracted from the live page DOM. * All fields except tag and selector are optional because not every element * will have all attributes. */ export interface DOMElement { /** HTML tag name, e.g. "button", "input", "a". */ tag: string; /** ARIA role attribute value. */ role?: string; /** Accessible label (from aria-label or associated