#!/usr/bin/env node const fs = require('fs'); const path = require('path'); const repoRoot = path.resolve(__dirname, '..'); const runtimePath = path.join(repoRoot, 'rust/crates/mnote-web/browser/sidebar-page-ai-runtime.js'); const cssPath = path.join(repoRoot, 'rust/crates/mnote-web/src/ssr/styles/components/page-ai.css'); const runtime = fs.readFileSync(runtimePath, 'utf8'); const css = fs.readFileSync(cssPath, 'utf8'); const checks = [ ['opencode host switch', runtime.includes('mnote.page_ai.opencode_host')], ['opencode status api', runtime.includes('/api/page-ai/opencode/status')], ['opencode diff api', runtime.includes('/api/page-ai/opencode/diff?sessionId=')], ['opencode event api', runtime.includes('/api/page-ai/opencode/events') && runtime.includes('new EventSource')], ['opencode iframe route', runtime.includes('/page-ai/opencode/') && runtime.includes('src="about:blank"')], ['persistent binding source', runtime.includes('/api/page-ai/opencode/session') && !runtime.includes('sessionStorage.setItem(storageKey')], ['changed file opener', runtime.includes('__mnoteDocumentPaneRuntime.openResourceInActiveTab({ path: targetPath })')], ['current page refresh', runtime.includes('__mnoteDocumentPaneRuntime.refreshPrimaryDocument({ reason: \'page-ai-opencode-host\' })')], ['no interval polling', !/setInterval\s*\(/.test(runtime)], ['opencode css scope', css.includes('[data-page-ai-opencode-host="true"]')], ['opencode iframe css', css.includes('.wolai-page-ai-opencode-iframe')], ]; const failed = checks.filter(([, ok]) => !ok); if (failed.length) { console.error('Page AI opencode host static smoke failed:'); for (const [name] of failed) console.error(`- ${name}`); process.exit(1); } console.log('Page AI opencode host static smoke passed.');