fix(sitesmith): summarize nested (linkedNodes) nodes, explain dropped review ops, truly label-free bg placeholders
1. summarizeCanvas() walked only node.nodes, so everything inside Section/ColumnLayout/forms (linkedNodes) was missing and live self-reviews could only name top-level sections. It now walks nodes + linked slots (stable key order) and lists id, type and key props (text first, links, main style values as style.<key>, colour-like props) as key="value", within a documented budget (150 nodes, 6000 chars, 300 chars of props per line; detail is dropped before nodes; cuts happen at line boundaries -- a mid-line cut used to make the server refuse the whole review). HtmlBlock code is no longer summarised. applyPatch no longer counts an op with nothing left to set as a change; ops that did nothing are counted per reason. The self-review note and console say why ops were dropped (server and editor reasons, counts only). Real-browser test 8n builds a nested page, sends the real summary through the real WHP review lockdown (php) and checks the nested edit takes effect while link/text edits, unknown ids and deletes are dropped. 3. Background placeholders use ?text=%E2%80%8B (measured: placehold.co then draws no glyphs; the same-colour label left a 4-colour ghost in its PNG); the capture draws no <text> for a zero-width or same-colour label. Pixel test on the case-4 hero markup in both browsers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXgk6UunFCKyXqLe2Cq
This commit is contained in:
1 parent
615a20e25b
commit
4177e5015a
20 files changed
+449
-58
No files matched your search
@@ -1,6 +1,10 @@
|
||||
// Bundled by scripts/e2e-capture-fidelity.mjs and run in real Firefox + Chromium.
|
||||
import { captureHtml } from '../src/utils/self-review-capture';
|
||||
import { sanitizeCaptureHtml } from '../src/utils/sanitize-capture-html';
|
||||
import { cleanAiProps } from '../src/sitesmith/clean-ai-response';
|
||||
|
||||
/** Round 6: the background URL the editor really stores for an AI hero placeholder (apply-time cleaner). */
|
||||
(window as any).cleanedBgImage = (url: string) => cleanAiProps({ bgImage: url }, 'BackgroundSection').bgImage;
|
||||
|
||||
(window as any).sanitizeCaptureHtml = sanitizeCaptureHtml;
|
||||
/** Capture through the real path, then decode the JPEG and return RGB samples at the given points. */
|
||||
|
||||
@@ -135,6 +135,26 @@ async function run(name, launcher, exe) {
|
||||
check(name, label, hits >= 3, `(${hits} pixels near rgb(${want.join(',')}))`);
|
||||
}
|
||||
}
|
||||
// Round 6 (live case 4, Firefox): a background placeholder showed a faint "1920 x 1080" ghost label behind the
|
||||
// hero in the review render (the same-colour label still antialiased). The URL the editor stores for the live
|
||||
// case's hero, through the real capture path: every pixel of the box must be the box colour (max channel
|
||||
// deviation <= 2 for JPEG), over a dense grid that covers where the label was drawn.
|
||||
{
|
||||
const LIVE = 'https://placehold.co/1920x1080/101a2b/fbfaf7?text=Team+collaborating+in+a+modern+office';
|
||||
const bgUrl = await page.evaluate((u) => window.cleanedBgImage(u), LIVE);
|
||||
check(name, 'label-free background placeholder URL (zero-width label)', /^https:\/\/placehold\.co\/1920x1080\/101a2b\/101a2b\?text=%E2%80%8B$/.test(bgUrl), bgUrl);
|
||||
// the live case-4 hero as exported (BackgroundSection: quoted url(), cover, a same-colour overlay at 0.55)
|
||||
const hero = `<!doctype html><html><head><style>body{margin:0;background:#fff}</style></head><body><section style="position:relative;width:100%;min-height:200px;background-color:#ff0000;background-image:url('${bgUrl}');background-size:cover;background-position:center;padding-top:160px;padding-bottom:160px;padding-left:24px;padding-right:24px;text-align:left"><div style="position:absolute;inset:0;background-color:#101a2b;opacity:0.55"></div><div style="position:relative;height:400px"></div></section></body></html>`;
|
||||
const grid = [];
|
||||
for (let y = 16; y <= 704; y += 4) for (let x = 16; x <= 1264; x += 4) grid.push([x, y]);
|
||||
const r = await page.evaluate(([h, pts]) => window.captureAndSample(h, pts), [hero, grid]);
|
||||
check(name, 'label-free background placeholder captured', r.ok === true, r.ok ? '' : r.reason);
|
||||
if (r.ok) {
|
||||
let worst = 0; let at = null;
|
||||
r.samples.forEach((px, i) => { const d = Math.max(...px.map((v, k) => Math.abs(v - [0x10, 0x1a, 0x2b][k]))); if (d > worst) { worst = d; at = grid[i]; } });
|
||||
check(name, `label-free background placeholder: all ${grid.length} pixels are the box colour (no ghost label)`, worst <= 2, `(max deviation ${worst} at ${JSON.stringify(at)})`);
|
||||
}
|
||||
}
|
||||
for (const t of TALL) {
|
||||
const r = await page.evaluate(([h, pts]) => window.captureAndSample(h, pts), [t.html, t.pts.map((p) => [p[0], p[1]])]);
|
||||
check(name, `${t.label}: captured`, r.ok === true, r.ok ? `(${r.bytes} bytes, ${r.ms} ms)` : r.reason);
|
||||
|
||||
@@ -188,6 +188,8 @@ export async function createMockServer(o) {
|
||||
/** Queue the result of the next job (a bare response object, or a full {ok,...} result). */
|
||||
setNextResult(resp, notes) { const r = toResult(resp); if (notes) r.notes = notes; results.push(r); },
|
||||
clearResults() { results.length = 0; },
|
||||
/** Queue a function (start body) => result, for a job whose answer depends on what the editor sent. */
|
||||
setNextResultFn(fn) { results.push(fn); },
|
||||
setPhaseDelayMs(ms) { phaseDelayMs = ms; },
|
||||
setSlow(v) { slow = !!v; },
|
||||
setVision(v) { vision = !!v; },
|
||||
@@ -252,7 +254,8 @@ export async function createMockServer(o) {
|
||||
case 'start': {
|
||||
s.starts.push(body);
|
||||
for (const j of jobs.values()) if (j.status === 'running') return json(res, 409, { ok: false, error: 'job_in_progress', status: 'JOB_IN_PROGRESS', message: 'Sitesmith is already working on a request for this site.', job_id: j.id });
|
||||
const job = newJob();
|
||||
// a queued function computes the result from the start body (scenario 8n: the real WHP review lockdown)
|
||||
const job = newJob(typeof results[0] === 'function' ? toResult(results.shift()(body)) : undefined);
|
||||
activeJobId = job.id;
|
||||
history.push(msg('user', String(body.message ?? '')));
|
||||
return json(res, 200, { ok: true, job_id: job.id, status: 'running', phase: 'queued', created_at: job.created });
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Used by scripts/e2e-sitesmith.mjs (scenario 8n): runs the REAL WHP review lockdown on what the editor sent.
|
||||
* stdin {summary, proposed:[ops with alias ids]} -> stdout {summary: server-rebuilt summary | null, alias, ops, dropped}
|
||||
* (api/sitesmith.php sitesmith_review_rebuild_summary + Sitesmith::reviewFilterOps). Offline, no model call.
|
||||
* Usage: php e2e-sitesmith-review-backend.php <backend repo dir>
|
||||
*/
|
||||
ob_start();
|
||||
define('SITESMITH_API_LIBRARY_ONLY', true);
|
||||
$dir = rtrim($argv[1], '/');
|
||||
require_once $dir . '/web-files/libs/Sitesmith.php';
|
||||
require $dir . '/web-files/api/sitesmith.php';
|
||||
ob_end_clean();
|
||||
$in = json_decode(stream_get_contents(STDIN), true);
|
||||
$rb = sitesmith_review_rebuild_summary((string)($in['summary'] ?? ''));
|
||||
$f = $rb === null ? ['ops' => [], 'dropped' => []] : Sitesmith::reviewFilterOps((array)($in['proposed'] ?? []), $rb['alias']);
|
||||
echo json_encode(['summary' => $rb['summary'] ?? null, 'alias' => $rb['alias'] ?? null, 'ops' => $f['ops'], 'dropped' => (object)$f['dropped']], JSON_UNESCAPED_SLASHES);
|
||||
@@ -25,6 +25,7 @@ import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createMockServer, makePng } from './e2e-sitesmith-mock-server.mjs';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const distDir = path.resolve(process.env.SITESMITH_E2E_DIST || fs.mkdtempSync(path.join(os.tmpdir(), 'sitesmith-e2e-')));
|
||||
@@ -388,6 +389,61 @@ scenario('8', 'self-review round trip (one round)', async ({ page, name, ok }) =
|
||||
await modalShot(page, name, '08-self-review-done.png');
|
||||
}, { selfReview: true });
|
||||
|
||||
// Round 6 (live 2026.11.10): the review summary listed only top-level sections (children of Section/ColumnLayout live
|
||||
// in Craft linkedNodes), so every proposal was stripped. A NESTED page is built in the real editor, the real
|
||||
// summarizeCanvas() output goes through the REAL WHP review lockdown (php: sitesmith_review_rebuild_summary +
|
||||
// Sitesmith::reviewFilterOps, WHP_BACKEND_DIR), the "model" patches the nested heading by its server alias, and the
|
||||
// edit must take effect on the canvas while a link/text edit, an unknown id and a delete are dropped with reasons.
|
||||
const WHP_BACKEND_DIR = process.env.WHP_BACKEND_DIR || '/workspace/whp-wt-sitesmith-r6';
|
||||
scenario('8n', 'self-review patches a NESTED node through the real WHP review lockdown', async ({ page, name, ok }) => {
|
||||
const info = [];
|
||||
// console values as JSON (Firefox prints an object argument as "JSHandle@object" in text())
|
||||
page.on('console', async (m) => { if (m.type() === 'info') info.push((await Promise.all(m.args().map((x) => x.jsonValue().catch(() => null)))).map((v) => (typeof v === 'string' ? v : JSON.stringify(v))).join(' ')); });
|
||||
srv.setNextResult({ type: 'replace', scope: 'page', message: 'Built it.', pages: [{ name: 'Home', tree: el('Container', { node_id: 'nr-root', style: { padding: '0px' } }, [
|
||||
el('Section', { node_id: 'nr-sec', aiName: 'Hero', style: { backgroundColor: '#0f172a', paddingTop: '48px', paddingBottom: '48px' } }, [
|
||||
el('Heading', { node_id: 'nr-h', text: 'Nested review heading', level: 'h1', style: { color: '#ffffff', fontSize: '40px' } }),
|
||||
el('ColumnLayout', { node_id: 'nr-cols', columns: 2 }, [
|
||||
el('Container', { node_id: 'nr-c1' }, [el('ButtonLink', { node_id: 'nr-btn', text: 'Nested button', href: '/contact', style: { backgroundColor: '#fde047', color: '#0f172a' } })]),
|
||||
el('Container', { node_id: 'nr-c2' }, [el('TextBlock', { node_id: 'nr-t', text: 'Second column', style: { color: '#ffffff' } })]),
|
||||
]),
|
||||
]),
|
||||
]) }] });
|
||||
let backend = null;
|
||||
srv.setNextResultFn((body) => {
|
||||
const alias = (real) => Object.entries(backend?.alias ?? {}).find(([, r]) => r === real)?.[0] ?? 'missing';
|
||||
backend = JSON.parse(execFileSync('php', [path.join(root, 'scripts/e2e-sitesmith-review-backend.php'), WHP_BACKEND_DIR], { input: JSON.stringify({ summary: body.canvas_summary, proposed: [] }) }).toString());
|
||||
const proposed = [
|
||||
{ op: 'update_props', node_id: alias('nr-h'), props: { style: { color: '#fde047' } } },
|
||||
{ op: 'update_props', node_id: alias('nr-btn'), props: { href: 'https://evil.example/x', text: 'Hacked' } },
|
||||
{ op: 'update_props', node_id: 'n999', props: { style: { color: '#ff0000' } } },
|
||||
{ op: 'delete_node', node_id: alias('nr-t') },
|
||||
];
|
||||
const f = JSON.parse(execFileSync('php', [path.join(root, 'scripts/e2e-sitesmith-review-backend.php'), WHP_BACKEND_DIR], { input: JSON.stringify({ summary: body.canvas_summary, proposed }) }).toString());
|
||||
backend = { ...backend, filtered: f };
|
||||
return { ok: true, response: { type: 'patch', message: 'Recoloured the hero heading.', ops: f.ops }, review_ops: { proposed: proposed.length, kept: f.ops.length, dropped: f.dropped } };
|
||||
});
|
||||
await openModal(page);
|
||||
await sendMsg(page, 'Build my hero and check it');
|
||||
await page.waitForSelector('[data-testid=ss-review-note]', { timeout: 45000 });
|
||||
const note = (await page.textContent('[data-testid=ss-review-note]')) ?? '';
|
||||
const sent = srv.starts[1]?.canvas_summary ?? '';
|
||||
ok('the editor summary lists the NESTED nodes (heading, button, column text inside the Section)', /id=nr-h /.test(sent) && /id=nr-btn /.test(sent) && /id=nr-t /.test(sent), sent.slice(0, 600));
|
||||
const hLine = (backend?.summary ?? '').split('\n').find((l) => / id=n\d+ \{style\.color=#ffffff, style\.fontSize=40px, level=h1\}$/.test(l)) ?? '';
|
||||
ok('the WHP-rebuilt summary shows the heading indented under its Section, with its colour, without its text', /^ {4,}- Heading id=n\d+ /.test(hLine) && !/Nested review heading|Nested button|contact/.test(backend?.summary ?? ''), backend?.summary);
|
||||
ok('WHP kept exactly the nested heading edit, mapped back to its real id', JSON.stringify(backend?.filtered?.ops) === JSON.stringify([{ op: 'update_props', node_id: 'nr-h', props: { style: { color: '#fde047' } } }]), JSON.stringify(backend?.filtered));
|
||||
await page.waitForFunction(() => {
|
||||
const h = [...document.querySelectorAll('.canvas-device-frame h1')].find((e) => e.textContent.includes('Nested review heading'));
|
||||
return h && getComputedStyle(h).color === 'rgb(253, 224, 71)';
|
||||
}, null, { timeout: 10000 }).then(() => ok('the nested heading really changed colour on the canvas', true), (e) => ok('the nested heading really changed colour on the canvas', false, String(e).slice(0, 120)));
|
||||
const btn = await page.evaluate(() => { const a = [...document.querySelectorAll('.canvas-device-frame a')].find((e) => /Nested button|Hacked/.test(e.textContent)); return a ? { text: a.textContent.trim(), href: a.getAttribute('href') } : null; });
|
||||
ok('the button text and link were NOT changed (forbidden for a review)', btn?.text === 'Nested button' && btn?.href === '/contact', JSON.stringify(btn));
|
||||
ok('the column text was NOT deleted', (await canvasText(page)).includes('Second column'));
|
||||
ok('the note says it made fixes and why the rest were dropped', /made fixes/.test(note) && note.includes('3 did not pass the safety checks (1 named a part that is not on the page, 1 tried to change text, a link or an image, 1 tried to add, remove or replace a block)'), note);
|
||||
const logLine = info.find((t) => t.startsWith('[sitesmith] self-review dropped ops')) ?? '';
|
||||
ok('the console logs the drop counts, without any of the model\'s words', /unknown_id/.test(logLine) && !/evil|Hacked|Recoloured/.test(info.join(' ')), logLine);
|
||||
await modalShot(page, name, '08n-nested-review.png');
|
||||
}, { selfReview: true });
|
||||
|
||||
scenario('8b', 'self-review skipped when the upload fails', async ({ page, ok }) => {
|
||||
srv.setUploadFail(500);
|
||||
srv.setNextResult(pageResult('Kept first pass', { id: 'kp-h' }));
|
||||
|
||||
Reference in new issue
Block a user