mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-15 07:36:50 +03:00
Add DeepSeek live E2E adapter (#163)
* Add DeepSeek live E2E adapter * Fix DeepSeek live E2E review issues * Harden live-e2e helpers against silent failures - htmlToJsx: match multi-line inline style attributes ([\s\S]*?) - readCliOption: throw when --flag value is missing or another --flag - llm-agent: echo parsed payload (first 500 chars) in schema-error throws * Bind hoisted inline styles to their owning tag normalizeVariantOutput previously hoisted every stripped style attribute onto a selector derived from the variant's first tag, so a style on a nested <span> landed on <h1>. Now walks each opening tag and emits one rule per styled element with a descendant combinator so nested-element styles target the correct node. Also fixes the duplicated multi-line style regex bug (.*?) -> ([\s\S]*?) that survived the previous round. Extracts parseVariantResponse from llm-agent for direct schema-throw testing, and lifts readCliOption into its own module so its new missing-value throws can be unit-tested. Adds tests for: - multi-line style hoisting - nested-element tag binding and per-tag rule emission - astro-global-prefixed selector shape - no-op identity-return path - opts.config short-circuit in createLlmAgent - all four parseVariantResponse schema previews + JSON-parse failure - readCliOption value/throw matrix * Hoist inline styles via data attribute, not tag name Two bugs in normalizeVariantOutput that Bugbot flagged: 1. Hoisted rules like `:scope span` matched every same-tag descendant of the variant wrap, so a style on one of several <span>s leaked onto its siblings. 2. The opening-tag scan used `[^>]*` for attributes, so a literal `>` inside a quoted attribute value (e.g. `aria-label="x > y"`) terminated the match early and the trailing `style="..."` was never seen. stripInlineStylesPerElement now walks each opening tag character by character respecting quoted attribute values, and tags every styled element with `data-impeccable-hoist-id="N"`. Rules select on the attribute so they bind to exactly the one element they came from. The attribute is stripped during carbonize cleanup so it does not survive into the final source. * Harden live E2E variant CSS normalization * Fix Radix tests * Harden live E2E pick clicks
This commit is contained in:
+52
-7
@@ -13,6 +13,7 @@
|
||||
const BAR_ID = '#impeccable-live-bar';
|
||||
const GLOBAL_BAR_ID = '#impeccable-live-global-bar';
|
||||
const PICKER_ID = '#impeccable-live-picker';
|
||||
const PICK_TOGGLE_ID = '#impeccable-live-pick-toggle';
|
||||
|
||||
/**
|
||||
* Wait for the live handshake to complete:
|
||||
@@ -43,13 +44,24 @@ export async function waitForHandshake(page, { timeout = 20_000 } = {}) {
|
||||
*/
|
||||
export async function pickElement(page, selector) {
|
||||
const el = await page.waitForSelector(selector, { timeout: 5_000 });
|
||||
await el.hover();
|
||||
// Tiny settle: live-browser updates `hoveredElement` on mousemove, and the
|
||||
// click handler reads from it.
|
||||
await page.waitForTimeout(50);
|
||||
await el.click();
|
||||
// Per-element bar mounts on click → wait for it.
|
||||
await page.waitForSelector(BAR_ID, { state: 'visible', timeout: 5_000 });
|
||||
for (let attempt = 0; attempt < 2; attempt++) {
|
||||
await ensurePickerActive(page);
|
||||
await el.hover();
|
||||
// Tiny settle: live-browser updates `hoveredElement` on mousemove, and the
|
||||
// click handler reads from it.
|
||||
await page.waitForTimeout(50);
|
||||
await clickPickTarget(page, el);
|
||||
// Per-element bar mounts on click → wait for it. Dialog fixtures can
|
||||
// briefly hide the global live chrome while preActions open a portal, so
|
||||
// retry once after explicitly re-arming picker mode.
|
||||
const visible = await page
|
||||
.waitForSelector(BAR_ID, { state: 'visible', timeout: 5_000 })
|
||||
.then(() => true, () => false);
|
||||
if (visible) break;
|
||||
if (attempt === 1) {
|
||||
await page.waitForSelector(BAR_ID, { state: 'visible', timeout: 1 });
|
||||
}
|
||||
}
|
||||
// Wait specifically for the Configure-row Go button to be in the bar.
|
||||
// pickElement returning before that race-conditions with clickGo on
|
||||
// fixtures whose framework re-renders right after pick (modal open, tab
|
||||
@@ -68,6 +80,39 @@ export async function pickElement(page, selector) {
|
||||
);
|
||||
}
|
||||
|
||||
async function clickPickTarget(page, el) {
|
||||
const box = await el.boundingBox();
|
||||
if (box) {
|
||||
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
||||
return;
|
||||
}
|
||||
await el.evaluate((node) => node.click());
|
||||
}
|
||||
|
||||
async function ensurePickerActive(page) {
|
||||
await page.waitForSelector(GLOBAL_BAR_ID, { timeout: 5_000 });
|
||||
const active = await page
|
||||
.locator(PICK_TOGGLE_ID)
|
||||
.evaluate((el) => el.dataset.active === 'true')
|
||||
.catch(() => false);
|
||||
if (active) return;
|
||||
|
||||
const clicked = await page.evaluate((sel) => {
|
||||
const btn = document.querySelector(sel);
|
||||
if (!btn) return false;
|
||||
btn.click();
|
||||
return true;
|
||||
}, PICK_TOGGLE_ID);
|
||||
if (!clicked) {
|
||||
await page.locator(PICK_TOGGLE_ID).click({ timeout: 5_000 });
|
||||
}
|
||||
await page.waitForFunction(
|
||||
(sel) => document.querySelector(sel)?.dataset.active === 'true',
|
||||
PICK_TOGGLE_ID,
|
||||
{ timeout: 5_000 },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the variant count by clicking the count button (cycles 2 → 3 → 4 → 2).
|
||||
* Default is 3. If the desired count is already showing, this is a no-op.
|
||||
|
||||
Reference in New Issue
Block a user