mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-15 07:36:50 +03:00
* feat(live): manual text-edit panel + Astro inject + stale-lockfile reap Adds a manual text-edit popover under the live-mode bar so users can retype copy directly without going through generate. The footer's "Apply edits" button fires a manual_edits event; the server writes the changes back to source via the new live-edit.mjs deterministic file mutator. Mirrors the wrap+accept flow but skips variant generation. New scripts: - skill/scripts/live-edit.mjs: writes manual_edits back to source - skill/scripts/live-text-rows.js: browser walker that surfaces every pure-text descendant of the picked element as an editable row Touched scripts: - skill/scripts/live-browser.js: text panel UI, CONFIGURING state hook - skill/scripts/live-poll.mjs: manual_edits routing - skill/scripts/live-server.mjs: manual_edits endpoint + handler - skill/scripts/live-wrap.mjs: small adjustments to support the flow Docs + tests: - skill/reference/live.md: manual-edit section - tests/live-edit.test.mjs, tests/live-text-rows.test.mjs Also bundles two live-mode reliability fixes that surfaced during manual testing of the feature: 1. live-inject now emits is:inline when the inject target is a .astro file. Astro otherwise processes the <script> tag and rewrites src to its own bundled URL, so the literal live.js never loads. 2. readLiveServerInfo now probes the lockfile PID with kill(pid, 0) and unlinks the stale lock if dead. Previously a crashed helper left server.json with a dead PID and live-poll reported "Live server not running" forever. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(live): inline contenteditable text editing Replace the text-edit popover panel with inline contenteditable activation. When an element is picked in CONFIGURING, every pure-text descendant becomes contenteditable="true" directly on the page. Each blur-event fires a single-op manual_edits save to source. Esc restores original text and stays in CONFIGURING; successful save exits to PICKING. If Go is clicked while a save is in-flight, the save completes before generate fires. Deleted ~340 lines of panel UI (initTextPanel, openTextPanel, closeTextPanel, renderTextRow, buildTextFooter, etc.). Added enableInlineEdit, disableInlineEdit, onInlineBlur. Server contract unchanged; live-edit.mjs handles per-op saves as before. Tests: 186 pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(live): hide annotation overlay during inline edit Annotation overlay's click handler was intercepting clicks on contenteditable text elements. Hide the overlay when inline-edit is enabled to allow text selection and editing. Restore it when exiting inline-edit (if still in CONFIGURING). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(live): edit content badge mode with batched saves Replace automatic inline contenteditable on element pick with an explicit "Edit content" badge. The badge appears at the element's top-right corner when an element is picked. Clicking the badge enters a new EDITING state where: - The contextual bar hides - The annotation overlay hides - The badge morphs to show Cancel + Apply buttons - Text descendants become contenteditable inline Edits are held in memory (input event tracking) until Apply is clicked, which fires a single batched manual_edits event with all ops. Cancel discards drafts without saving. This eliminates the annotation overlay interference that prevented clicking on text elements. The EDITING state integrates with the main state machine and handles all exits (Esc, click-outside, teardown) cleanly. All 186 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(live): use row.el.tagName for tag in applyEditing op The applyEditing function was trying to use row.tag which doesn't exist on the row object. The tag should be the tagName of the text element itself (row.el.tagName.toLowerCase()). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(live): Edit content badge styling + auto-focus + separate buttons - Edit content button now matches Go button styling (BP.accent background, BP.mark text, FONT, transitions, hover effects) - Auto-focus first editable element when entering editing mode (50ms timeout) - Separate Cancel and Apply buttons with 8px gap (no divider) - Cancel uses muted styling (BP.hairline background, BP.textDim text) - Apply keeps brand accent styling - Remove all focus rings and outlines on edit badge buttons (no blue ring/outline in EDITING mode) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> * feat(live): Subtle button UI + cursor positioning + better copy - Change badge buttons to use impeccable-button aesthetic (ink background, surface text, hover to accent) - Removes aggressive styling conflict with Go button - No animations; simple 150ms background transition - Matches site design language (padding 0.625rem 1.5rem, 0.8125rem font, letter-spacing 0.03em) - Shorter, clearer button copy: "Edit" instead of "Edit content", "Save" instead of "Apply" - Fix cursor positioning: cursor now appears at END of text, not beginning - Use Selection API to collapse cursor to end of contenteditable element - Improves UX for immediate continuation of text - Update live.md documentation to reflect new button labels Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> * fix(live): Use site design system colors for edit badge buttons - Edit/Save buttons: oklch(10% 0 0) background → oklch(60% 0.25 350) on hover - Cancel button: oklch(55% 0 0) background → oklch(65% 0 0) on hover - All buttons: 6px border-radius (matches Go button), oklch(98% 0 0) text - Smooth transition: 0.3s cubic-bezier(0.16, 1, 0.3, 1) (--ease-out) - Uses site color palette instead of live-overlay constants Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> * fix(live): Match slop-callout style for edit badge buttons - Use exact .slop-callout aesthetic: paper background, accent border + text, uppercase 10px (0.625rem) - 600 weight, 0.06em letter-spacing, 4px 8px padding, 6px border-radius - Box-shadow: 0 2px 8px rgba(0,0,0,0.1) matches site callouts - Hover: inverts to filled background (accent fill, paper text) - Cancel uses ash color variant for muted state, Save uses accent - Smooth 0.3s cubic-bezier(0.16, 1, 0.3, 1) transition on background and color Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(live): Pill-shaped edit badge buttons, 2px padding, no uppercase - Border-radius: 999px (pill shape) - Padding: 2px 8px (more compact) - Removed text-transform: uppercase Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(live): Cancel button uses mist border + ash text - Border: 1px solid oklch(92% 0 0) (--color-mist) - Color: oklch(55% 0 0) (--color-ash) - Hover: inverts to ash background with paper text Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(live): Remove blue focus outline from contenteditable elements in EDITING mode - Add inline outline: none on each row's element when contenteditable activates - Inject [data-impeccable-editable] CSS rule to override browser default focus ring - Use !important to win against site styles that re-apply focus outlines - Cleanup restores outline/data-attribute on disable Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(live): Decouple manual edits from agent/poll pipeline Manual text edits now POST directly to a new /manual-edit endpoint that runs live-edit.mjs synchronously and returns the result. The event is never enqueued, never reaches the poll loop, never reaches the agent. Why: every Save was costing an LLM turn. The poll script would dequeue the manual_edits event, run live-edit.mjs deterministically, post a completion ack, then print the event JSON to stdout. The Claude agent would read that output and decide "loop and re-poll". Zero real work for the agent but every Save burned context. Changes: - live-server.mjs: new POST /manual-edit handler that runs live-edit.mjs synchronously and returns the result. Does not enqueue, does not log to session store. Defense-in-depth: /events rejects manual_edits. - live-browser.js: applyEditing() POSTs to /manual-edit instead of sendEvent({type: 'manual_edits'}). - live-poll.mjs: removed manual_edits handler branch (dead code now). - reference/live.md: removed "Handle manual_edits" section; replaced with a one-line note that manual edits are server-direct. The HMR-triggered page reload remains (dev server detects source file change) but that is a separate dev-server behavior, not our pipeline. resumeSession() already restores variants and selection after reload. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(live): Stash manual edits server-side; commit via AI on request Decouples manual-edit Save from source file writes. Save now stashes to .impeccable/live/pending-manual-edits.json with no HMR refresh. The user explicitly asks the AI to commit when ready. Why: even with the prior /manual-edit fix, every Save still wrote to source and triggered the dev server's HMR/full reload. The page flash was the actual user pain. Now there's zero source touch on Save, and the user controls when the dev server reloads. Server (live-server.mjs): - /manual-edit-stash POST: append to buffer file. Returns {ok, pendingCount, totalCount, perPage}. - /manual-edit-stash GET: query counts by page for counter UI. - /manual-edit-discard POST: drop entries (all if no pageUrl). - Old /manual-edit returns 410 Gone (defense in depth). - Buffer ops merge by (pageUrl, ref): keep first originalText, update newText. CLIs: - live-commit-manual-edits.mjs: read buffer, shell out to live-edit.mjs per entry, truncate succeeded entries, surface failures. - live-discard-manual-edits.mjs: truncate buffer (optionally scoped by page). - Both take optional --page-url=<url>. Browser (live-browser.js): - applyEditing() POSTs to /manual-edit-stash, no source write. - Pending pill (• N staged) + trash icon next to Exit in global bar. - One-time onboarding toast on first Save: "Saved. Tell the AI to commit when ready." - Counter persists across reloads via GET /manual-edit-stash on init. - Trash icon: confirm dialog scoped to current page, then POST /manual-edit-discard. Variant pipeline interaction: - live-wrap.mjs: when wrapping an element, apply pending manual edits to the source range so the wrap block's "original" variant reflects the user's edited DOM (their pre-Go view), not the raw source. - live-accept.mjs: after accept writes the variant to source, scrub buffer ops whose originalText no longer appears in that file. The accept embodies the manual edit; the pending op is consumed. - Variant discard does NOT touch the buffer. Reference docs: - reference/live.md: full commit/discard contract, trigger guidance (narrow action-verb intent), do-not-auto-commit rule. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(live): Staged-edits pill becomes an "Apply" button Click the "• N staged" pill → confirm dialog "Apply N staged edits to source? The page will reload." → POST /manual-edit-commit on the server, which shells out to live-commit-manual-edits.mjs. Same path the AI uses, just triggered from the overlay. Trash icon stays for discard. The AI-driven commit path also stays (useful for inspecting failures or scripting). The pill is now the primary apply affordance because it removes the chat-context-switch for the common case. Pill styling: pointer cursor, accent border + text at rest, fills on hover (accent bg, paper text). Tooltip: "Click to apply staged edits to source". First-save toast updated: "Saved. Click the 'staged' badge to apply, or ask the AI." Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * chore(live): gitignore pending-manual-edits.json runtime buffer Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: drop stray site/ test edits from PR Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(live): Pill label reads "Apply N staged" Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(live): Manual edit ops use the leaf element's locator, not parent's Multi-row inline editing captures each contenteditable leaf (row.el) but the op was being built with selectedElement.id / classList — i.e. the parent card, not the editable text node. live-edit.mjs then searched source for the parent's class on the leaf's tag (e.g. <span class= "foundation-card">), found nothing, and silently failed. Use row.el's own id / classList instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(live): Climb to nearest classed ancestor when leaf has no locator A bare <em>/<strong>/etc. with no id or class produced ops the CLI rejected with insufficient_locator. Prefer the leaf's own id/class; if neither exists, walk up to the nearest ancestor with one and adopt its tag + locator. Text-replace still works because the CLI narrows by originalText inside the matched element's source range. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(live): Make mixed-content paragraphs editable The text-rows walker skips elements with mixed children (text + element + text), so paragraphs like "Some text <code>x</code> more text" or "Body text · <a>link</a>" exposed zero rows for the surrounding copy. At edit time, wrap each non-whitespace direct text-node child in a marker span so the walker emits a row for it. Unwrap on save/cancel. The locator climbs to the parent's class as before, and live-edit narrows by originalText inside that parent's source range. hasTextRows now uses a lightweight subtree check that matches the new wrap+walk path so the edit affordance shows up on mixed-content elements. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(live): Address Cursor Bugbot findings (CB-2 through CB-6) CB-2 - Escape reverted DOM text but inlineEditDrafts retained the pre-revert value; clicking Apply afterwards committed the undone edit. Clear the draft entry when restoring innerText. CB-3 - The scrub gate !result.handled || result.handled !== false was a tautology that ran the scrub regardless of accept outcome. Use the intended result.handled !== false. CB-4 - The buffer-aware "original" content step in live-wrap iterated every entry in the buffer with no pageUrl filter, so an edit on /a could leak into a wrap call on /b. Add --page-url to the CLI; filter by it; skip the buffer-aware step entirely when omitted. live.md updated. CB-5 - removeEntries returned entry count while truncateBuffer returned op count, causing the discard CLI and HTTP endpoint to report mixed units. Make removeEntries return ops removed. CB-6 - applyTextReplace used string truthiness to gate prepending content above the edit, which silently dropped a leading empty line when the file started with '\n'. Gate on the line index instead, and mirror the fix on the trailing-empty-line side. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(live): A3+A4 data-integrity guards, A6 test coverage A3 — applyTextReplace refuses with text_ambiguous_in_block when originalText appears more than once in the matched element block. Refusing is safer than picking the first indexOf hit when we can't tell which leaf the user edited; user can rephrase one occurrence. A4 — newText is rejected if it contains <, >, {, }, or a backtick. Two layers: server-side validator in /manual-edit-stash returns 400, CLI-side guard in applyTextReplace returns invalid_chars_in_newText. Browser surfaces the specific reason via toast. The shared char list lives in live-edit.mjs (validateNewTextChars). reference/live.md documents the rule. A6 — New test files cover the orchestration gap: - live-manual-edits-buffer.test.mjs (17 tests across read/stage/ remove/find/count/truncate; pins removeEntries returns OPS count) - live-wrap-buffer-aware.test.mjs (3 tests; CB-4 regression test) - live-commit-manual-edits.test.mjs (4 tests; partial-failure, --page-url scope, no_pending_edits) - live-discard-manual-edits.test.mjs (3 tests; CB-5 unit consistency) - live-accept-scrub.test.mjs (4 tests; keep/drop/prune) Plus 2 new cases in live-edit.test.mjs for A3 and A4. Side-effect refactors: - scrubManualEditsAgainstFile accepts cwd for unit-testing and is exported. - Failed-op entries in live-edit.mjs now propagate forbidden and occurrences fields so callers can surface specifics. 41 tests across the 6 affected files pass; full suite green at 186/186. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: drop .claude/pr-review.md from PR Local review notes belong in the working tree, not the PR diff. Kept in the file system; just untracked. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: drop stray site/ test edits from PR (round 2) Live-inject script tag and the "Impeccable Works!" / "WHAT'S INCLUDED IN THE BOX" / "Wow Impeccable. ---- " strings were test edits that slipped back into the branch. Restore both files to match main. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(live): Disable Edit badge while variants are generating Clicking Edit during GENERATING would open inline text editing on the same DOM region the variant wrapper is about to land in, racing the HMR and the mutation observer. The badge now switches to an 'idle-disabled' rendering (ash + mist, not-allowed cursor, disabled attribute, tooltip) the moment state transitions into GENERATING. Returns to 'idle' on the normal CONFIGURING re-entry paths. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(live): live-wrap refuses without --page-url when buffer has pending edits When a manual edit is staged ("Impeccable Works!") but not yet committed, the buffer holds the user's edited DOM while source still has the un- edited text ("Impeccable"). live-wrap's buffer-aware step exists to rewrite the wrap block's <div data-impeccable-variant="original"> to match the staged DOM, but per CB-4 it is gated by --page-url. When the agent invoking live-wrap omits --page-url, the buffer-aware step silently no-op'd and the variant authoring saw stale source — the user's manual edit appeared lost. Make the silent no-op a loud error: when buffer.entries.length > 0 and --page-url is missing, exit 1 with { error: 'missing_page_url_with_pending_edits', pendingEntries, hint }. Empty buffer = no risk = no requirement, so existing flows without pending edits keep working. Updated reference/live.md to flag --page-url as required when the buffer has entries. Added regression test in live-wrap-buffer-aware.test.mjs. live-wrap.test.mjs gained a buffer- clear hook so any leftover .impeccable/live/pending-manual-edits.json from local dev doesn't trip the new check. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * change back * chore: drop stray site/ test edits from PR (round 3) Live-inject script tag in Base.astro slipped back in via git add -A while a local live server was running. Restore both site/ files to main. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Fix live manual edit staging * Rename live edit copy badge * Use sentence case for live edit copy badge * Move copy edit apply control outside live bar * Improve live copy edit apply flow * Clean up live copy edit AI apply flow * Polish live copy edit docs and toast * Fix staged copy edit review issues * Fix CI jsdom dependency * Fix Cursor Bot live edit findings * Fix remaining live edit review issues * Fix Bugbot staged edit edge cases * Fix latest Bugbot live edit edges * Fix remaining Bugbot wrap and discard issues * Fix live copy edit safety contracts * Fix copy edit rollback coverage * Fix live manual copy edit apply flow * Adjust live pending dock offset * feat(live): route manual-edit Apply through the chat agent Make the staged copy-edit Apply work when no CLI AI runner is authenticated by routing the batch through the active chat session, and surface runner failures clearly instead of opaque exit codes. - live-poll: add --reply --data '<json>' so the chat agent can return a structured manual_edit_apply result (the documented flag was missing, so the server resolved with an empty object) - live-server: manual_edit_apply event + deferred map, chat-vs-subprocess dispatch in /manual-edit-commit, resolve the deferred from the ack - live-copy-edit-agent: chat provider, extractRunnerErrorMessage and commandAuthed pre-flight, diagnostic describeNoProviderError; drop the stale CLAUDE_CODE_SIMPLE and --no-session-persistence flags so headless CLAUDE_CODE_OAUTH_TOKEN auth works - live-browser: clear pendingApplyInFlight on commit_done and add a watchdog so a missed signal can no longer freeze element picking - reference/live.md: tight Handle manual_edit_apply handler plus a separate diagnostics reference section; advertise the event in the opening contract and dispatch table Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Add live manual edit apply coverage * Fix manual edit apply review issues * Fix manual edit review follow-ups * Fix manual apply poll acknowledgements * Fix manual apply failed-entry rollback * Clarify manual apply LLM prompt * Fix stale manual apply discard events * Fix manual apply dynamic source edits * Fix large manual apply chunks * Clarify manual edit apply is first-class work * Clarify manual apply resume flow * Compact live manual apply evidence * Reject malformed manual apply replies * Recover legacy manual apply summaries * Fix Astro live script injection * Add live manual edit apply coverage * Slim live manual apply flow * Slim manual edit test dependencies * Stabilize real browser LLM smoke * Generalize manual edit LLM prompt examples * Remove retired live edit wrapper * Inline live text row walker * Slim manual edit prompts * Drop AGENTS doc churn * Stabilize live manual apply prompts * Stabilize manual apply visible Haiku flow * Add hard framework manual edit coverage * Stabilize manual edit LLM retries * Fix manual apply transaction rollback * Fix live shader text capture * Clean up manual apply runtime artifacts * Fix live manual edit apply reliability * Clean up manual apply coverage * Slim manual apply test cleanup * Fix manual edit prompt contract test * Align manual edit cancel hover * Fix live loading shader capture * Fix manual apply review findings * Restore live e2e tests for CI * Fix live loading shader halftone * Tune live loading shader dots * Restore main live shader behavior * Fix manual apply review findings * Fix manual apply bot follow-ups * Clarify manual apply rollback changes * Fix manual apply state naming * Address PR review cleanup * Fix manual apply review follow-ups * Fix multiline manual apply verification * Restore inline drafts when hiding live bar --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
361 lines
16 KiB
JavaScript
361 lines
16 KiB
JavaScript
/**
|
|
* Static-source regression guards for live-browser.js.
|
|
*
|
|
* `skill/scripts/live-browser.js` is a self-contained
|
|
* IIFE served directly to user pages by live-server.mjs (no bundle step,
|
|
* no module exports). That makes its internal helpers untestable via
|
|
* normal import — but a few behaviors have failed in real-world live
|
|
* sessions in ways that are easy to express as "this exact code shape
|
|
* MUST NOT come back." This file pins those down.
|
|
*
|
|
* Add a guard whenever a bug we fix has a one-line "anti-pattern" cause
|
|
* that's easy to reintroduce on an unrelated edit.
|
|
*/
|
|
|
|
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const LIVE_BROWSER = path.resolve(
|
|
__dirname,
|
|
'..',
|
|
'skill/scripts/live-browser.js',
|
|
);
|
|
const SOURCE = fs.readFileSync(LIVE_BROWSER, 'utf-8');
|
|
|
|
describe('live-browser.js regression guards', () => {
|
|
it('resolveCanvasBackground does not fall back to `getComputedStyle(...).backgroundColor || ...`', () => {
|
|
// The browser returns the literal string `"rgba(0, 0, 0, 0)"` for an
|
|
// unset body/html background. That string is non-empty and truthy, so a
|
|
// `||` chain short-circuits to transparent-black, which modern-screenshot
|
|
// hands to its WebGL shader as the canvas color and the screenshot
|
|
// overlay flashes solid black during loading on any page that doesn't
|
|
// explicitly set its own background. Forbid the pattern outright; the
|
|
// correct fallback is a literal `'#ffffff'` (the browser's default
|
|
// canvas color).
|
|
const buggy =
|
|
/getComputedStyle\(document\.(?:body|documentElement)\)\.backgroundColor\s*\|\|/;
|
|
assert.ok(
|
|
!buggy.test(SOURCE),
|
|
'live-browser.js must not chain `getComputedStyle(...).backgroundColor || ...` — that returns transparent-black for default-bg pages and renders the screenshot overlay as solid black during loading. Use a literal fallback (`#ffffff`) instead.',
|
|
);
|
|
});
|
|
|
|
it('detectPageTheme honors alpha when reading body / html backgroundColor', () => {
|
|
// Equivalent trap: `rgba(0, 0, 0, 0)` parsed naively as `(0,0,0)` makes
|
|
// a perfectly white default page register as "dark," which flips the
|
|
// chrome to the wrong palette. The fix introduced an alpha guard
|
|
// (function readOpaque) — keep that signature in source.
|
|
assert.match(
|
|
SOURCE,
|
|
/function detectPageTheme\b[\s\S]{0,1500}?function readOpaque\b/,
|
|
'detectPageTheme must keep its readOpaque helper that filters out fully-transparent backgrounds before computing luminance',
|
|
);
|
|
});
|
|
|
|
it('locks every global bar mode toggle while manual Apply is in flight', () => {
|
|
assert.match(
|
|
SOURCE,
|
|
/const controlsLocked = pendingApplyInFlight === true;[\s\S]{0,120}?\[pickToggle, insertToggle, detectToggle, designToggle\]\.forEach/,
|
|
'pending manual Apply must visually disable Pick, Insert, Detect, and Design together',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function toggleInsert\(\) \{[\s\S]{0,120}?if \(pendingApplyInFlight\) \{ showManualApplyBusyToast\(\); return; \}/,
|
|
'Insert must have the same in-flight Apply guard as the other mode toggles',
|
|
);
|
|
});
|
|
|
|
it('exits inline editing directly on outside click', () => {
|
|
assert.match(
|
|
SOURCE,
|
|
/function cancelEditingToPicking\(\) \{[\s\S]{0,600}?state = 'PICKING';/,
|
|
'outside-click editing cancel should avoid rebuilding configure UI before hiding it',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/state === 'EDITING'[\s\S]{0,180}?cancelEditingToPicking\(\);[\s\S]{0,40}?return;/,
|
|
'outside-click handler should leave EDITING directly',
|
|
);
|
|
});
|
|
|
|
it('restores unsaved inline edit drafts before hideBar tears editing down', () => {
|
|
assert.match(
|
|
SOURCE,
|
|
/function hideBar\(\) \{[\s\S]{0,360}?if \(state === 'EDITING'\) restoreInlineEditDrafts\(\);[\s\S]{0,80}?disableInlineEdit\(\);/,
|
|
'hideBar should not leave unsaved contenteditable drafts in the DOM when an external event hides the bar',
|
|
);
|
|
});
|
|
|
|
it('does not shadow the global live state when storing Apply state', () => {
|
|
assert.doesNotMatch(
|
|
SOURCE,
|
|
/function readStoredManualApplyState\(\)[\s\S]{0,240}?const state = JSON\.parse\(raw\);/,
|
|
'stored manual Apply JSON should not shadow the outer UI state variable',
|
|
);
|
|
assert.doesNotMatch(
|
|
SOURCE,
|
|
/function writeManualApplyState\(state\)/,
|
|
'stored manual Apply object should not shadow the outer UI state variable',
|
|
);
|
|
});
|
|
|
|
it('handleServerLost preserves the current recoverable phase', () => {
|
|
assert.doesNotMatch(
|
|
SOURCE,
|
|
/state\s*=\s*currentSessionId\s*\?\s*['"]GENERATING['"]\s*:\s*['"]IDLE['"]/,
|
|
'event=live_browser.server_lost_phase actor=browser operation=sse_disconnect risk=cycling_or_saving_session_saved_as_generating expected=preserve current phase actual=forced generating',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function handleServerLost\(\)[\s\S]{0,300}?const recoveryState = currentSessionId \? state : 'IDLE';[\s\S]{0,1200}?state = recoveryState;[\s\S]{0,120}?if \(currentSessionId\) saveSession\(\);/,
|
|
'server-lost cleanup should keep the current session phase in local recovery state instead of rewriting it to GENERATING',
|
|
);
|
|
});
|
|
|
|
it('source reinjection preserves the visible variant after cycling', () => {
|
|
assert.doesNotMatch(
|
|
SOURCE,
|
|
/Replace the live element[\s\S]{0,900}?visibleVariant\s*=\s*1;\s*showVariantInDOM\(sessionId,\s*1\);/,
|
|
'event=live_browser.visible_variant_reset actor=browser operation=hmr_source_reinject risk=late_hmr_accepts_variant_1_after_user_cycles expected=preserve visible variant actual=reset_to_first',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/previousVisibleVariant[\s\S]{0,900}?savedVisibleVariant[\s\S]{0,500}?showVariantInDOM\(sessionId, visibleVariant\);/,
|
|
'source reinjection should preserve the in-memory or saved visible variant instead of always showing variant 1',
|
|
);
|
|
});
|
|
|
|
it('global bar includes expandable page chat affordance', () => {
|
|
assert.match(
|
|
SOURCE,
|
|
/function initPageChat\(/,
|
|
'live-browser must mount a page-level chat control in the global bar',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/pageChatEl\.id = PREFIX \+ '-page-chat'/,
|
|
'page chat container needs a stable id for future wiring and tests',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function syncPageChatFocus\(reason\)[\s\S]{0,220}?if \(state === 'CONFIGURING'\) focusConfigureInput\(reason\);[\s\S]{0,120}?else if \(shouldSteerAutoFocus\(\)\) focusSteerChat\(reason\);/,
|
|
'focus configure input while configuring; steer auto-focus unless page text is selected',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function steerFocusLog\(reason, extra\)/,
|
|
'steer focus attempts should be logged for debugging before adding retries',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function submitSteerMessage\(\)[\s\S]{0,1200}?type: 'steer'/,
|
|
'steer submit must post a steer event to the live poller',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/case 'steer_done':[\s\S]{0,80}?maybeCompleteSteer\(msg\)/,
|
|
'steer_done SSE must unlock the chat bar',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function toggleSteerVoice\(\)/,
|
|
'steer voice must toggle Web Speech recognition from the mic button',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/webkitSpeechRecognition|SpeechRecognition/,
|
|
'steer voice must use the Web Speech API',
|
|
);
|
|
assert.doesNotMatch(
|
|
SOURCE,
|
|
/Voice mode coming soon/,
|
|
'steer voice placeholder toast must not ship once voice is wired',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function isEmbeddedPreviewBrowser\(\)/,
|
|
'steer voice must detect embedded preview browsers (Cursor/Electron)',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/steerVoiceUnavailableMessage\(\)/,
|
|
'steer voice must explain when preview browsers cannot reach speech services',
|
|
);
|
|
assert.doesNotMatch(
|
|
SOURCE,
|
|
/Handing off|pageChatHint\.textContent = 'Working'/,
|
|
'steer processing state should use dots-only animation, not truncated text',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function syncAgentPollingUi\(/,
|
|
'global bar brand must reflect agent poll connectivity',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/case 'agent_polling':/,
|
|
'browser must listen for agent_polling SSE updates',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function showAgentPollTooltip\(/,
|
|
'disconnected agent state must use an instant custom tooltip on brand hover',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function scheduleSteerFocusRecover\(reason\)/,
|
|
'steer focus must reschedule after page clicks once selection/pause gates clear',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/steer-blur-recover/,
|
|
'steer blur should recover focus for type-to-steer when not selecting page text',
|
|
);
|
|
});
|
|
|
|
it('pick mode preference persists in localStorage', () => {
|
|
assert.match(
|
|
SOURCE,
|
|
/const INTERACTION_PREFS_KEY = 'impeccable-live-interaction';[\s\S]{0,3000}?function saveInteractionPrefs\(\)/,
|
|
'pick/insert interaction prefs must persist in localStorage',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function togglePick\(\)[\s\S]{0,200}?saveInteractionPrefs\(\);/,
|
|
'togglePick must persist interaction prefs',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function toggleInsert\(\)[\s\S]{0,800}?saveInteractionPrefs\(\);/,
|
|
'toggleInsert must persist interaction prefs',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/if \(state === 'IDLE' && \(pickActive \|\| insertActive\)\) state = 'PICKING';/,
|
|
'SSE connected must arm insert mode when saved preference has insert on',
|
|
);
|
|
});
|
|
|
|
it('insert mode UI and generate payload guards', () => {
|
|
assert.match(SOURCE, /function toggleInsert\(\)/, 'global bar must expose insert toggle');
|
|
assert.match(SOURCE, /PREFIX \+ '-insert-toggle'/, 'insert toggle needs stable id');
|
|
assert.match(SOURCE, /function buildInsertConfigureRow\(\)/, 'insert configure bar required');
|
|
assert.match(SOURCE, /function handleInsertCreate\(\)/, 'insert create handler required');
|
|
assert.match(SOURCE, /mode: 'insert'/, 'insert generate must set mode insert');
|
|
assert.match(SOURCE, /function syncInsertCreateButton\(btn, input\)/, 'Create button must reflect prompt/annotation gate');
|
|
assert.match(
|
|
SOURCE,
|
|
/syncInsertCreateButton\(create, input\)/,
|
|
'Create gate must sync before the row is attached to the document',
|
|
);
|
|
assert.match(SOURCE, /function showInsertCreateTooltip\(/, 'Create disabled state uses a custom hover tooltip');
|
|
assert.match(
|
|
SOURCE,
|
|
/function buildCyclingRow\(\)[\s\S]*?background: C\.brand, color: C\.ink/,
|
|
'Accept button uses lacquer-deep text on kinpaku gold',
|
|
);
|
|
assert.match(SOURCE, /insertCreateDisabledReason/, 'disabled Create hover must explain why');
|
|
assert.match(SOURCE, /data-impeccable-insert-placeholder/, 'placeholder element must be marked');
|
|
assert.match(
|
|
SOURCE,
|
|
/showHighlight\(el\)[\s\S]{0,120}?data-impeccable-insert-placeholder/,
|
|
'pick highlight must not stack on insert placeholder',
|
|
);
|
|
assert.match(SOURCE, /border: '2px dotted ' \+ BP\.accent/, 'placeholder border matches insert line (dotted)');
|
|
assert.match(
|
|
SOURCE,
|
|
/function syncPageInteractionCursor\(\)[\s\S]{0,280}?cursorForInsertAxis/,
|
|
'insert picking cursor follows row/column axis',
|
|
);
|
|
assert.match(SOURCE, /function hitSiblingInsertGap\(/, 'insert mode detects gaps between siblings');
|
|
assert.match(SOURCE, /function resolveInsertHover\(/, 'insert hover resolves axis-aware boundaries');
|
|
assert.match(SOURCE, /data-impeccable-placeholder-resize/, 'placeholder edge handles on annotation overlay');
|
|
assert.match(SOURCE, /resizeEdge && configureKind === 'insert'/, 'resize takes priority over draw');
|
|
assert.match(SOURCE, /cursorForPlaceholderEdge\(spec\.edge\)/, 'edge handles use resize cursors');
|
|
assert.match(
|
|
SOURCE,
|
|
/create\.id = PREFIX \+ '-insert-create'/,
|
|
'Create button id must be set on the element, not passed to el() styles',
|
|
);
|
|
assert.doesNotMatch(
|
|
SOURCE,
|
|
/buildInsertConfigureRow[\s\S]{0,1200}?toggleActionPicker/,
|
|
'insert configure bar must not include action picker',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/buildInsertConfigureRow[\s\S]*?const count = el\('button', \{[\s\S]{0,320}?height: '28px'/,
|
|
'insert count toggle must match input height',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/buildInsertConfigureRow[\s\S]*?const create = el\('button', \{[\s\S]{0,320}?height: '28px'/,
|
|
'insert Create button must match input height',
|
|
);
|
|
assert.match(SOURCE, /function resolveBarAnchor\(\)/, 'bar positions from a connected anchor');
|
|
assert.match(SOURCE, /function finalizeInsertSession\(\)/, 'insert placeholder outlives capture');
|
|
assert.match(SOURCE, /function placeholderSizing\(/, 'insert placeholder picks implicit vs explicit width');
|
|
assert.match(SOURCE, /applyPlaceholderSizingStyles\(placeholder, sizing\)/, 'placeholder width styles applied by kind');
|
|
assert.match(
|
|
SOURCE,
|
|
/function createInsertPlaceholder[\s\S]*?applyPlaceholderSizingStyles\(placeholder, sizing\)/,
|
|
'createInsertPlaceholder must not always set parent pixel width',
|
|
);
|
|
assert.doesNotMatch(
|
|
SOURCE,
|
|
/sendEvent\(screenshotPath[\s\S]{0,200}?removeInsertPlaceholder/,
|
|
'capture must not remove insert placeholder before variants land',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function setVariantShown\(el, shown\)[\s\S]{0,200}?removeAttribute\('hidden'\)/,
|
|
'variant cycling must clear the hidden attribute, not only style.display',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/count > 0 \? pickVariantContent\(wrapper, visibleVariant \|\| 1\) : null/,
|
|
'insert HMR re-anchor must not drop placeholder until variants exist',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function ensureInsertPlaceholder\(\)/,
|
|
'insert generating must recreate placeholder after scaffold HMR',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/insertPlaceholder: insertPlaceholderSnapshot/,
|
|
'insert placeholder snapshot must persist across HMR resume',
|
|
);
|
|
});
|
|
|
|
it('handleAccept reads the visible DOM variant before sending accept', () => {
|
|
assert.match(
|
|
SOURCE,
|
|
/function readVisibleVariantFromDOM\(sessionId\)[\s\S]{0,900}?isVariantShown\(variant\)[\s\S]{0,500}?return idx;/,
|
|
'live-browser should be able to derive the accepted variant from the currently visible DOM node',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/function handleAccept\(\)[\s\S]{0,180}?const domVisibleVariant = readVisibleVariantFromDOM\(currentSessionId\);[\s\S]{0,120}?if \(domVisibleVariant > 0\) visibleVariant = domVisibleVariant;[\s\S]{0,160}?variantId: String\(visibleVariant\)/,
|
|
'event=live_browser.accept_stale_visible_variant actor=browser operation=accept_after_hmr risk=accept_sends_variant_1_after_user_cycles_to_2 expected=read_dom_visible_variant actual=stale_state_variable',
|
|
);
|
|
});
|
|
|
|
it('editing focus timeout does not read a stale inline edit row', () => {
|
|
assert.doesNotMatch(
|
|
SOURCE,
|
|
/setTimeout\(\(\) => \{\s*const el = inlineEditRows\[0\]\.el;/,
|
|
'event=live_browser.stale_edit_focus actor=browser operation=edit_mode_focus_timeout risk=post_apply_or_accept_pageerror expected=capture editable element before timeout and guard state actual=reads inlineEditRows[0].el after rows can be cleared',
|
|
);
|
|
assert.match(
|
|
SOURCE,
|
|
/const firstEditable = inlineEditRows\[0\] && inlineEditRows\[0\]\.el;[\s\S]{0,120}?setTimeout\(\(\) => \{[\s\S]{0,120}?if \(!el \|\| !el\.isConnected \|\| state !== 'EDITING'\) return;/,
|
|
'edit-mode delayed focus should capture the element before scheduling and no-op if editing ended before the timeout fires',
|
|
);
|
|
});
|
|
});
|