import { rootPath } from "../src/lib/paths.ts"; type BenchFile = { readonly target_keys: readonly string[]; readonly iterations: number; readonly results: readonly { readonly name: string; readonly duration_ms: number; readonly consumed: number; readonly errors: number; }[]; }; const benchPath = rootPath("results", "selectors_bench.json"); let bench: BenchFile | null = null; try { bench = JSON.parse(await Deno.readTextFile(benchPath)) as BenchFile; } catch { bench = null; } const rows = bench?.results.map((result) => { const operations = bench.iterations * bench.target_keys.length; return `| ${result.name} | ${result.duration_ms.toFixed(2)} | ${ (result.duration_ms / operations).toFixed(4) } | ${result.consumed} | ${result.errors} |`; }).join("\n") ?? "| not-run | n/a | n/a | n/a | n/a |"; const report = `# Live selector validation report This report is generated by \`deno task report\` after running the test and benchmark harness. ## What this harness validates - CSS selector generation and validation in a real Chromium DOM. - XPath generation and validation with browser-native \`document.evaluate()\`. - Accessibility selector extraction through role/name semantics. - CSS parser compatibility through \`postcss-selector-parser\`. - Selector behavior when classes are renamed, ids are removed, accessible names change, hidden elements are encountered, and values require CSS escaping. - Feature-flag validation for enabling/disabling selector families. - JSONL corruption handling and artifact integrity checks for missing, truncated, and hash-corrupted evidence files. ## Benchmark summary | Scenario | Total ms | ms/op | Consumed length | Errors | |---|---:|---:|---:|---:| ${rows} ## Interpretation Use CSS selectors for browser replay, XPath for structural/source traceability, and accessibility selectors for agent-facing semantic references. The tests intentionally prove that no single selector family survives every mutation. Removed ids can break id-based CSS while accessibility references keep semantic identity. Renamed accessible names can break role/name locators while stable data/href selectors continue to resolve. Class renames should not break stable selectors when better attributes exist. ## Replication \`\`\`bash npm install npm exec --yes --package deno@2.9.1 -- deno task verify npm exec --yes --package deno@2.9.1 -- deno task report \`\`\` Set \`CHROMIUM_PATH\` if Chromium is not available at a common Linux path. `; await Deno.mkdir(rootPath("results"), { recursive: true }); await Deno.writeTextFile(rootPath("results", "selector-validation-report.md"), report); console.log(rootPath("results", "selector-validation-report.md"));