const { chromium } = require('playwright'); const assert = require('node:assert/strict'); (async () => { const browser = await chromium.launch({ headless: true, executablePath: process.env.CHROMIUM_PATH }); const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }); const errors = []; page.on('pageerror', e => errors.push(e.message)); if (process.env.PLOT_ASSET_ORIGIN) await page.route(/\/(?:css|js)\/plot-line-workspace\.(?:css|js)(?:\?.*)?$/, async r => r.fulfill({ response: await r.fetch({ url: process.env.PLOT_ASSET_ORIGIN + new URL(r.request().url()).pathname }) })); let healthLoads = 0; await page.route('**/PlotLineWorkspace/Health?**', async r => { healthLoads++; await r.fulfill({ response: await r.fetch({ url: 'http://127.0.0.1:5238/plot-map-fixture?healthDetail=true&focus=true' }) }); }); await page.route('**/PlotLineWorkspace/Inspector?**', r => r.fulfill({ body: '

Canonical contribution inspector

' })); await page.route('**/Scenes/SceneThreadsEditor?**', r => r.fulfill({ body: '
' })); await page.route('**/Scenes/AddThreadEvent', r => r.fulfill({ contentType: 'application/json', body: '{"success":true}' })); await page.route('**/plot-map-fixture*', async r => { if (r.request().headers()['x-plot-map'] === 'true') return r.fulfill({ response: await r.fetch({ url: 'http://127.0.0.1:5238/plot-map-fixture?health=true' }) }); return r.continue(); }); await page.goto('http://127.0.0.1:5238/plot-map-fixture?health=true'); assert.equal(healthLoads, 0, 'Verbose health detail must be lazy loaded'); assert.equal(await page.locator('.plot-horizontal-route').count(), 2); assert.equal(await page.locator('.plot-health-summary').count(), 2); assert.ok(await page.locator('.plot-health-position').count()); const clear = await page.locator('.plot-health-position').evaluateAll(markers => markers.every(marker => { const box = marker.getBoundingClientRect(); return Array.from(document.querySelectorAll('.plot-map-callout,.plot-thread-section,.plot-map-marker')).every(item => { const other = item.getBoundingClientRect(); return box.right <= other.left || box.left >= other.right || box.bottom <= other.top || box.top >= other.bottom; }); })); assert.ok(clear, 'Health annotations must not obscure cards, thread labels or contribution nodes'); await page.locator('.plot-health-summary[data-health-line="1"]').click(); await page.locator('[data-health-rule="H002"]').first().waitFor(); assert.equal(healthLoads, 1); assert.match(await page.locator('#plot-inspector-content').textContent(), /Stored author status:\s*Planned/); assert.match(await page.locator('#plot-inspector-content').textContent(), /Observed activity:/); assert.match(await page.locator('[data-health-rule="H002"]').first().textContent(), /10 scenes/); assert.ok(await page.locator('a[href*="PlotThreads/Edit/11"]').count()); await page.locator('[data-health-rule="H002"] [data-scene-inspector]').first().click(); await page.locator('#plot-inspector-content h2').filter({ hasText: 'Canonical contribution inspector' }).waitFor(); await page.keyboard.press('Escape'); await page.locator('[data-map-mode="associate"]').click(); assert.equal(await page.locator('.plot-health-position').first().evaluate(el => getComputedStyle(el).pointerEvents), 'none'); const drag = await page.evaluateHandle(() => new DataTransfer()); await page.locator('[data-associate-scene="2"]').dispatchEvent('dragstart', { dataTransfer: drag }); await page.locator('.plot-horizontal-route[data-drop-line="1"]').dispatchEvent('dragover', { dataTransfer: drag }); assert.ok(await page.locator('.plot-horizontal-route[data-drop-line="1"]').evaluate(el => el.classList.contains('is-drop-target'))); await page.locator('.plot-horizontal-route[data-drop-line="1"]').dispatchEvent('drop', { dataTransfer: drag }); await page.locator('#plot-association-dialog form').waitFor(); await page.locator('#plot-association-dialog [type="submit"]').click(); await page.getByText('Association saved. Continue adding scenes.').waitFor(); assert.ok(await page.locator('#plot-association-strip').isVisible()); assert.equal(await page.locator('.plot-health-summary').count(), 2); await page.locator('[data-map-mode="view"]').click(); await page.goto('http://127.0.0.1:5238/plot-map-fixture?health=true&focus=true'); assert.equal(await page.locator('.plot-health-summary').count(), 1); for (const theme of ['modern-dark', 'warm-dark', 'modern-light']) { await page.evaluate(theme => document.documentElement.dataset.appTheme = theme, theme); await page.locator('.plot-health-summary').click(); await page.locator('[data-health-rule="H002"]').first().waitFor(); await page.waitForTimeout(240); await page.screenshot({ path: `/tmp/plot-health-${theme}.png` }); await page.keyboard.press('Escape'); } assert.deepEqual(errors, []); await browser.close(); console.log('PASS: restrained lazy health inspector, evidence navigation, Focus/Weave, marker clearance, three themes and association refresh/drop preservation'); })().catch(e => { console.error(e); process.exit(1); });