const fs = require('fs'); const crypto = require('crypto'); const path = require('path'); const { pathToFileURL } = require('url'); const { chromium } = require('playwright'); function assert(condition, message) { if (!condition) throw new Error(message); } function walk(root, skip = new Set(['tests', 'logs', 'node_modules', '.git'])) { const entries = []; for (const entry of fs.readdirSync(root, { withFileTypes: true })) { if (skip.has(entry.name)) continue; const absolute = path.join(root, entry.name); entries.push({ absolute, entry }); if (entry.isDirectory()) entries.push(...walk(absolute, skip)); } return entries; } // ENHANCED_CASE_1: remove the redundant directory completely without leaving executable imports to it. function caseFigmaCleanup(root) { const entries = walk(root); const redundantDirs = entries.filter(({ entry }) => entry.isDirectory() && entry.name.toLowerCase() === 'figma'); assert(redundantDirs.length === 0, 'the redundant figma directory must be absent'); for (const required of ['index.html', 'package.json']) { assert(fs.statSync(path.join(root, required)).isFile(), `${required} must remain after cleanup`); } const preserved = { 'index.html': '99f6e6fbc7d1acb64f46abaf69c52ae5caef0e888f36dbf77c9afdc506b7919f', 'src/app.js': 'efd825c0643d35e5fb14fa1bad0fe5ffc18f306b4fca0ac06fa3f77549fa30b2', 'package.json': '81c7353d98b36ad448f37d82ad7cb554d6a877efa2cb149bc513a8e3887cb76a' }; for (const [relative, expected] of Object.entries(preserved)) { const actual = crypto.createHash('sha256').update(fs.readFileSync(path.join(root, relative))).digest('hex'); assert(actual === expected, `only figma/ should be deleted; preserved file changed: ${relative}`); } const programFiles = entries .filter(({ entry }) => entry.isFile() && /\.(?:[cm]?js|jsx|ts|tsx|html)$/i.test(entry.name)); const staleImport = /(?:\bfrom\s*|\brequire\s*\(|\bimport\s*\()["'][^"']*(?:^|[/\\])figma(?:[/\\]|["'])/im; for (const { absolute } of programFiles) { assert(!staleImport.test(fs.readFileSync(absolute, 'utf8')), `stale figma import remains in ${path.relative(root, absolute)}`); } } // ENHANCED_CASE_2: the package entry keeps the fixture's public logic and boundary behavior unchanged. function caseModuleBehavior(root) { const manifest = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); assert(typeof manifest.main === 'string' && manifest.main.length > 0, 'preserved package configuration must identify its entry module'); const entry = path.resolve(root, manifest.main); assert(fs.existsSync(entry), 'package entry module must still exist'); delete require.cache[require.resolve(entry)]; const app = require(entry); assert(app && app.coreLogicVersion === 'demo-1001', 'core logic version must remain demo-1001'); assert(typeof app.sendPrompt === 'function', 'sendPrompt public behavior must remain available'); for (const [input, content] of [ [' plain ', 'plain'], [' 世界 & ', '世界 & '], ['', ''] ]) { const result = app.sendPrompt(input); assert(result && result.title === 'real title' && result.content === content, `sendPrompt behavior changed for ${JSON.stringify(input)}`); } } // ENHANCED_CASE_3: the preserved page still renders and performs its prompt-to-output interaction. async function caseRenderedPromptFlow(root) { const browser = await chromium.launch({ headless: true }); try { const page = await browser.newPage({ viewport: { width: 877, height: 613 } }); await page.goto(pathToFileURL(path.join(root, 'index.html')).href, { waitUntil: 'domcontentloaded' }); const parts = await page.evaluateHandle(() => { const visible = element => { const rect = element.getBoundingClientRect(); const style = getComputedStyle(element); return rect.width > 0 && rect.height > 0 && style.display !== 'none' && style.visibility !== 'hidden'; }; const inputs = [...document.querySelectorAll('input:not([type]), input[type="text"], textarea, [contenteditable="true"]')] .filter(visible).filter(element => !element.disabled && !element.readOnly); const actions = [...document.querySelectorAll('button, [role="button"], input[type="submit"], input[type="button"]')] .filter(visible).filter(element => !element.disabled); if (inputs.length !== 1 || actions.length !== 1) { throw new Error(`expected one prompt and one action, found ${inputs.length}/${actions.length}`); } return { input: inputs[0], action: actions[0] }; }); const input = await parts.getProperty('input'); const action = await parts.getProperty('action'); const sent = ' preserve & 世界 '; await input.fill(sent); await action.click(); const expected = sent.trim(); const rendered = await page.evaluate(expected => [...document.querySelectorAll('body *')].some(element => { const rect = element.getBoundingClientRect(); const style = getComputedStyle(element); return element.children.length === 0 && rect.width > 0 && rect.height > 0 && style.display !== 'none' && style.visibility !== 'hidden' && (element.textContent || '').includes(expected); }), expected); assert(rendered, 'prompt interaction must still render the submitted content'); fs.mkdirSync('/logs/verifier/visual-audit', {recursive: true}); await page.screenshot({path: '/logs/verifier/visual-audit/preserved-app.png', fullPage: true}); } finally { await browser.close(); } } (async () => { const root = process.cwd(); caseFigmaCleanup(root); caseModuleBehavior(root); await caseRenderedPromptFlow(root); console.log('enhanced cases passed for task 34'); })().catch(error => { console.error(error && error.stack || error); process.exit(1); });