Doubao-powered voice input for Linux, Wayland and Omarchy
fix(reports): support Midscene 1.13.0 directory-mode screenshots
quanru873a9c22ee47
diff --git a/scripts/build-pages-report.mjs b/scripts/build-pages-report.mjsindex c491151..a00f11e 100644--- a/scripts/build-pages-report.mjs+++ b/scripts/build-pages-report.mjs@@ -205,7 +205,7 @@ function collectAssertionResults(run) {return { passed, total };}-function buildReportEntry({+async function buildReportEntry({includeCaseReportPath = false,label,previewPath,@@ -215,9 +215,12 @@ function buildReportEntry({role,}) {const status = report.run?.status ?? 'unknown';- const cases = reportCases(report.run, project, {- reportHtml: report.html,- }).map((testCase) => ({+ const cases = (+ await reportCases(report.run, project, {+ reportHtml: report.html,+ reportFile: report.file,+ })+ ).map((testCase) => ({caseId: testCase.caseId,name: testCase.name,status: testCase.status,@@ -248,15 +251,17 @@ function buildReportEntry({};}-function buildReportGroup({ label, reports, role }) {- const reportEntries = reports.map((item) =>- item.fallbackEntry ??- buildReportEntry({- ...item,- includeCaseReportPath: true,- label,- role,- }),+async function buildReportGroup({ label, reports, role }) {+ const reportEntries = await Promise.all(+ reports.map((item) =>+ item.fallbackEntry ??+ buildReportEntry({+ ...item,+ includeCaseReportPath: true,+ label,+ role,+ }),+ ),);const sum = (field, nested) =>reportEntries.reduce((total, entry) => total + entry[field][nested], 0);@@ -707,19 +712,29 @@ export async function buildPagesReport(options) {throw new Error('Site output directory must be empty');}- const reportCandidates = await Promise.all(- (await findHtmlFiles(reportDirectory)).map(async (file) => ({- file,- html: await readFile(file, 'utf8'),- })),- );+ const reportCandidates = (+ await Promise.all(+ (await findHtmlFiles(reportDirectory)).map(async (file) => ({+ file,+ html: await readFile(file, 'utf8'),+ })),+ )+ ).map((report) => ({+ ...report,+ run: testRunDump(report.html),+ }))+ // Midscene Test 1.13.0 writes its HTML to midscene-e2e-<run>/ instead of+ // the legacy test-run-* location, so findHtmlFiles also returns the+ // standalone computer-*.html agent reports. Those carry no runner dump;+ // only Midscene Test reports participate in aggregation.+ .filter((report) => report.run !== null);const latestByProject = new Map();for (const report of reportCandidates) {- report.run = testRunDump(report.html);report.startedAt = Date.parse(report.run?.startedAt ?? '') || 0;- const projectKey =- report.run?.projects?.map((project) => project.name).join(',') ||- path.basename(report.file);+ const projectKey = report.run?.projects+ ?.map((project) => project.name)+ .join(',');+ if (!projectKey) continue;const previous = latestByProject.get(projectKey);if (!previous || report.startedAt >= previous.startedAt) {latestByProject.set(projectKey, report);@@ -773,7 +788,9 @@ export async function buildPagesReport(options) {selectedReports = groupedReports.flatMap((group) =>group.reports.map((item) => item.report).filter(Boolean),);- entries = groupedReports.map((group) => buildReportGroup(group));+ entries = await Promise.all(+ groupedReports.map((group) => buildReportGroup(group)),+ );reportCopies = groupedReports.flatMap((group) =>group.reports.filter((item) => item.report).flatMap((item) => [{@@ -821,28 +838,30 @@ export async function buildPagesReport(options) {primaryNativeReport,`${reportPrefix}/report-preview.png`,];- entries = [- buildReportEntry({- role: 'primary',- project: primaryProject,- label: primaryReportLabel,- report: primaryReport,- reportPath: primaryNativeReport,- previewPath: `${reportPrefix}/report-preview.png`,- }),- ...(auxiliaryReport- ? [- buildReportEntry({- role: 'auxiliary',- project: auxiliaryProject,- label: auxiliaryReportLabel,- report: auxiliaryReport,- reportPath: auxiliaryNativeReport,- previewPath: `${reportPrefix}/auxiliary-report-preview.png`,- }),- ]- : []),- ];+ entries = await Promise.all(+ [+ buildReportEntry({+ role: 'primary',+ project: primaryProject,+ label: primaryReportLabel,+ report: primaryReport,+ reportPath: primaryNativeReport,+ previewPath: `${reportPrefix}/report-preview.png`,+ }),+ ...(auxiliaryReport+ ? [+ buildReportEntry({+ role: 'auxiliary',+ project: auxiliaryProject,+ label: auxiliaryReportLabel,+ report: auxiliaryReport,+ reportPath: auxiliaryNativeReport,+ previewPath: `${reportPrefix}/auxiliary-report-preview.png`,+ }),+ ]+ : []),+ ],+ );reportCopies = [{source: primaryReport.file,@@ -867,6 +886,36 @@ export async function buildPagesReport(options) {];}const selectedFiles = new Set(selectedReports.map((report) => report.file));+ // Midscene 1.13.0 keeps native-report screenshots in a sibling+ // screenshots/ directory instead of inlining them in the HTML. The+ // published native reports load screenshots/<id>.jpeg relatively, so+ // publish the directory next to the flattened report files. File names are+ // screenshot UUIDs (content-addressed), so a name shared by reports is+ // published once.+ const screenshotCopies = [];+ const seenScreenshotNames = new Set();+ for (const report of selectedReports) {+ const screenshotDirectory = path.join(+ path.dirname(report.file),+ 'screenshots',+ );+ let screenshotNames = [];+ try {+ screenshotNames = await readdir(screenshotDirectory);+ } catch (error) {+ if (error.code !== 'ENOENT') throw error;+ continue;+ }+ for (const name of screenshotNames.sort()) {+ if (seenScreenshotNames.has(name)) continue;+ seenScreenshotNames.add(name);+ screenshotCopies.push({+ source: path.join(screenshotDirectory, name),+ destination: `screenshots/${name}`,+ });+ }+ }+ reportCopies.push(...screenshotCopies);const declaredProjects = new Set(reportGroups ? reportGroups.flatMap((group) => group.projects) : [],);@@ -899,7 +948,12 @@ export async function buildPagesReport(options) {const casePreviewFiles = entries.flatMap((entry) =>entry.cases.map((testCase) => testCase.previewPath),);- const files = [...new Set([...baseFiles, ...casePreviewFiles])];+ const screenshotFiles = screenshotCopies.map(+ (copy) => `${reportPrefix}/${copy.destination}`,+ );+ const files = [+ ...new Set([...baseFiles, ...casePreviewFiles, ...screenshotFiles]),+ ];const current = {runId,generatedAt,@@ -930,7 +984,9 @@ export async function buildPagesReport(options) {const source =reportCopy.source ??(await findUniqueFile(reportDirectory, reportCopy.sourceName));- await copyFile(source, path.join(currentDirectory, reportCopy.destination));+ const destination = path.join(currentDirectory, reportCopy.destination);+ await mkdir(path.dirname(destination), { recursive: true });+ await copyFile(source, destination);}for (const fallback of generatedFallbacks) {const [testCase] = fallback.entry.cases;diff --git a/scripts/omarchy-shell-evidence.mjs b/scripts/omarchy-shell-evidence.mjsindex ad83fd2..230c833 100644--- a/scripts/omarchy-shell-evidence.mjs+++ b/scripts/omarchy-shell-evidence.mjs@@ -115,16 +115,64 @@ export async function findLatestTestReport(return latest;}-export function extractShellEvidence(html, { allowIncomplete = false } = {}) {+const INLINE_REPORT_IMAGE_RE =+ /<script\s+type=["']midscene-image["']\s+data-id=["']([^"']+)["'][^>]*>\s*data:image\/(jpeg|png|webp);base64,([A-Za-z0-9+/=]+)\s*<\/script>/g;++const REPORT_IMAGE_EXTENSIONS = new Set(['jpg', 'jpeg', 'png', 'webp']);++// Midscene reports embed screenshots as inline scripts until 1.12.x;+// 1.13.0 writes them to a sibling `screenshots/` directory instead+// (data-screenshot-mode="directory"). Load both so either report shape works.+export async function loadReportImages(html, reportFile) {const images = new Map();- for (const match of html.matchAll(- /<script\s+type=["']midscene-image["']\s+data-id=["']([^"']+)["'][^>]*>\s*data:image\/(png|jpeg);base64,([A-Za-z0-9+/=]+)\s*<\/script>/g,- )) {+ for (const match of html.matchAll(INLINE_REPORT_IMAGE_RE)) {images.set(match[1], {- extension: match[2] === 'jpeg' ? 'jpg' : 'png',+ extension: match[2] === 'jpeg' ? 'jpg' : match[2],bytes: Buffer.from(match[3], 'base64'),});}+ if (!reportFile) return images;+ const screenshotDirectory = path.join(path.dirname(reportFile), 'screenshots');+ let entries = [];+ try {+ entries = await readdir(screenshotDirectory);+ } catch (error) {+ if (error.code !== 'ENOENT') throw error;+ }+ for (const entryName of entries.sort()) {+ const extension = entryName.split('.').pop()?.toLowerCase();+ const id = entryName.slice(0, entryName.lastIndexOf('.'));+ if (+ !id ||+ !REPORT_IMAGE_EXTENSIONS.has(extension) ||+ images.has(id)+ ) {+ continue;+ }+ images.set(id, {+ extension: extension === 'jpeg' ? 'jpg' : extension,+ bytes: await readFile(path.join(screenshotDirectory, entryName)),+ });+ }+ return images;+}++export function extractShellEvidence(+ html,+ { allowIncomplete = false, images = null } = {},+) {+ const imageMap =+ images ??+ (() => {+ const inline = new Map();+ for (const match of html.matchAll(INLINE_REPORT_IMAGE_RE)) {+ inline.set(match[1], {+ extension: match[2] === 'jpeg' ? 'jpg' : match[2],+ bytes: Buffer.from(match[3], 'base64'),+ });+ }+ return inline;+ })();const finished = [];for (const dump of reportDumps(html)) {@@ -143,7 +191,7 @@ export function extractShellEvidence(html, { allowIncomplete = false } = {}) {return { ...check, passed: false, screenshot: null, missing: true };throw new Error(`Missing finished Omarchy assertion: ${check.label}`);}- const screenshot = images.get(task.uiContext?.screenshot?.id);+ const screenshot = imageMap.get(task.uiContext?.screenshot?.id);if (!screenshot) {if (allowIncomplete)return { ...check, passed: false, screenshot: null, missing: true };@@ -158,7 +206,13 @@ export async function findShellReport(directory) {const html = await readFile(file, 'utf8');const run = testRunDump(html);if (run?.projects?.some((project) => project.name === 'omarchy-shell')) {- return { file, html, checks: extractShellEvidence(html) };+ return {+ file,+ html,+ checks: extractShellEvidence(html, {+ images: await loadReportImages(html, file),+ }),+ };}}throw new Error('No Omarchy shell Midscene HTML report found');diff --git a/scripts/report-cases.mjs b/scripts/report-cases.mjsindex b7ebcbe..7c3e6ea 100644--- a/scripts/report-cases.mjs+++ b/scripts/report-cases.mjs@@ -1,4 +1,7 @@-import { normalizeJsonControlCharacters } from './omarchy-shell-evidence.mjs';+import {+ loadReportImages,+ normalizeJsonControlCharacters,+} from './omarchy-shell-evidence.mjs';function allAttemptSteps(attempt) {return [@@ -43,9 +46,8 @@ function scriptAttributes(source) {return attributes;}-function embeddedReportData(reportHtml) {+async function embeddedReportData(reportHtml, reportFile) {const dumps = [];- const images = new Map();for (const match of reportHtml.matchAll(/<script\s+([^>]*\btype=["']midscene_web_dump["'][^>]*)>\s*(\{[\s\S]*?)<\/script>/g,)) {@@ -58,14 +60,7 @@ function embeddedReportData(reportHtml) {dump: JSON.parse(normalizeJsonControlCharacters(match[2].trim())),});}- for (const match of reportHtml.matchAll(- /<script\s+type=["']midscene-image["']\s+data-id=["']([^"']+)["'][^>]*>\s*data:image\/(jpeg|png|webp);base64,([A-Za-z0-9+/=]+)\s*<\/script>/g,- )) {- images.set(match[1], {- extension: match[2] === 'jpeg' ? 'jpg' : match[2],- bytes: Buffer.from(match[3], 'base64'),- });- }+ const images = await loadReportImages(reportHtml, reportFile);return { dumps, images };}@@ -152,13 +147,19 @@ function evidenceForStep(step, embedded) {};}-export function reportCases(run, projectName, { reportHtml } = {}) {+export async function reportCases(+ run,+ projectName,+ { reportHtml, reportFile } = {},+) {const project = run?.projects?.find((item) => item.name === projectName);if (!project) {throw new Error(`Project ${projectName} is absent from the runner dump`);}- const embedded = reportHtml ? embeddedReportData(reportHtml) : null;+ const embedded = reportHtml+ ? await embeddedReportData(reportHtml, reportFile)+ : null;return (project.documents ?? []).flatMap((document) =>(document.cases ?? []).map((testCase) => {const attempt = testCase.attempts?.at(-1);diff --git a/scripts/verify-pages-report.mjs b/scripts/verify-pages-report.mjsindex 036ebb7..664d6fd 100644--- a/scripts/verify-pages-report.mjs+++ b/scripts/verify-pages-report.mjs@@ -25,7 +25,8 @@ function required(options, name) {function expectedContentType(file) {if (file.endsWith('.html')) return 'text/html';if (file.endsWith('.png')) return 'image/png';- if (file.endsWith('.jpg')) return 'image/jpeg';+ if (file.endsWith('.jpg') || file.endsWith('.jpeg'))+ return 'image/jpeg';if (file.endsWith('.webp')) return 'image/webp';if (file.endsWith('.svg')) return 'image/svg+xml';throw new Error(`No expected Content-Type is defined for ${file}`);diff --git a/tests/contracts/test_pages_report_history.mjs b/tests/contracts/test_pages_report_history.mjsindex 679f036..9694546 100644--- a/tests/contracts/test_pages_report_history.mjs+++ b/tests/contracts/test_pages_report_history.mjs@@ -136,6 +136,7 @@ function runnerScript({project,status = 'success',startedAt,+ screenshotMode = 'inline',}) {const attempts =assertionAttempts ??@@ -212,15 +213,23 @@ function runnerScript({},],};- return `<script type="midscene_web_dump" data-report-id="${reportId}">${JSON.stringify({ executions })}</script>-${attempts- .flatMap((statuses, attemptIndex) =>- statuses.map(- (_stepStatus, stepIndex) =>- `<script type="midscene-image" data-id="screenshot-${attemptIndex}-${stepIndex}">data:image/jpeg;base64,/9j/2Q==</script>`,- ),- )- .join('\n')}+ return `<script type="midscene_web_dump" data-report-id="${reportId}"${+ screenshotMode === 'directory'+ ? ' data-screenshot-mode="directory"'+ : ''+ }>${JSON.stringify({ executions })}</script>+${+ screenshotMode === 'inline'+ ? attempts+ .flatMap((statuses, attemptIndex) =>+ statuses.map(+ (_stepStatus, stepIndex) =>+ `<script type="midscene-image" data-id="screenshot-${attemptIndex}-${stepIndex}">data:image/jpeg;base64,/9j/2Q==</script>`,+ ),+ )+ .join('\n')+ : ''+}<script type="midscene_test_run_dump">${JSON.stringify(run)}</script>`;}@@ -358,6 +367,78 @@ test('simulates a first deployment when Pages returns 404', async (context) => {);});+test('publishes 1.13.0 directory-mode screenshots next to the native report', async (context) => {+ const root = await mkdtemp(path.join(os.tmpdir(), 'pages-directory-'));+ const reportRoot = path.join(root, 'artifact');+ const htmlDirectory = path.join(+ reportRoot,+ 'report',+ 'midscene-e2e-20260921045854-d9ab4bd0',+ );+ await mkdir(path.join(htmlDirectory, 'screenshots'), {+ recursive: true,+ });+ const html = runnerScript({+ project: 'ubuntu',+ startedAt: '2026-09-15T12:00:00Z',+ screenshotMode: 'directory',+ });+ await writeFile(path.join(htmlDirectory, 'index.html'), html);+ await writeFile(+ path.join(htmlDirectory, 'screenshots', 'screenshot-0-0.jpeg'),+ 'directory screenshot bytes',+ );+ // 1.13.0 also writes standalone computer-*.html agent reports without a+ // runner dump; they must not be treated as undeclared report projects.+ await writeFile(+ path.join(reportRoot, 'report', 'computer-2026-09-21_04-58-55.html'),+ '<html>standalone computer agent report</html>',+ );+ await writeFile(+ path.join(reportRoot, 'report-preview.png'),+ 'preview',+ );+ await writeFile(+ path.join(reportRoot, 'case-preview-ubuntu-case-ubuntu.jpg'),+ 'ubuntu case preview',+ );+ const siteDirectory = path.join(root, 'site');+ const server = await startServer((_request, response) => {+ response.writeHead(404).end();+ });+ context.after(server.close);++ const manifest = await buildPagesReport(+ options(reportRoot, siteDirectory, server.url),+ );++ assert.equal(+ await readFile(+ path.join(+ siteDirectory,+ 'reports',+ '200',+ 'screenshots',+ 'screenshot-0-0.jpeg',+ ),+ 'utf8',+ ),+ 'directory screenshot bytes',+ );+ assert.ok(+ manifest.reports[0].files.includes(+ 'reports/200/screenshots/screenshot-0-0.jpeg',+ ),+ );+ assert.deepEqual(manifest.reports[0].files, [+ 'reports/200/index.html',+ 'reports/200/native-report.html',+ 'reports/200/report-preview.png',+ 'reports/200/case-preview-ubuntu-case-ubuntu.jpg',+ 'reports/200/screenshots/screenshot-0-0.jpeg',+ ]);+});+test('combines independently executed shards into one report table', async (context) => {const root = await mkdtemp(path.join(os.tmpdir(), 'pages-shards-'));const reportDirectory = path.join(root, 'bundle');@@ -1140,7 +1221,7 @@ test('renders singular failure copy for one available report', () => {assert.match(summary, /Each image is the original page screenshot/);});-test('selects the last screenshot for success and first failed screenshot for failure', () => {+test('selects the last screenshot for success and first failed screenshot for failure', async () => {const run = {projects: [{@@ -1184,7 +1265,9 @@ test('selects the last screenshot for success and first failed screenshot for fa};assert.deepEqual(- reportCases(run, 'ubuntu').map(({ caseId, stepId, selection }) => ({+ (+ await reportCases(run, 'ubuntu')+ ).map(({ caseId, stepId, selection }) => ({caseId,stepId,selection,@@ -1204,14 +1287,16 @@ test('selects the last screenshot for success and first failed screenshot for fa);});-test('pairs an original node screenshot with its AI text or error', () => {+test('pairs an original node screenshot with its AI text or error', async () => {const successHtml = runnerScript({project: 'ubuntu',startedAt: '2026-09-15T12:00:00Z',});- const success = reportCases(testRunDump(successHtml), 'ubuntu', {- reportHtml: successHtml,- })[0];+ const success = (+ await reportCases(testRunDump(successHtml), 'ubuntu', {+ reportHtml: successHtml,+ })+ )[0];assert.equal(success.descriptionKind, 'ai');assert.equal(success.description, 'AI explanation 0-0');assert.deepEqual(success.screenshot.bytes, Buffer.from('/9j/2Q==', 'base64'));@@ -1221,9 +1306,11 @@ test('pairs an original node screenshot with its AI text or error', () => {startedAt: '2026-09-15T12:00:00Z',status: 'failed',});- const failure = reportCases(testRunDump(failureHtml), 'ubuntu', {- reportHtml: failureHtml,- })[0];+ const failure = (+ await reportCases(testRunDump(failureHtml), 'ubuntu', {+ reportHtml: failureHtml,+ })+ )[0];assert.equal(failure.descriptionKind, 'error');assert.equal(failure.description, 'Fixture error 0-0');assert.deepEqual(failure.screenshot.bytes, Buffer.from('/9j/2Q==', 'base64'));@@ -1252,6 +1339,77 @@ test('finds Omarchy evidence by project instead of assertion wording', async ());});+test('reads Midscene Test 1.13.0 node screenshots from the screenshots directory', async () => {+ const root = await mkdtemp(path.join(os.tmpdir(), 'directory-shots-'));+ const reportDirectory = path.join(+ root,+ 'report',+ 'midscene-e2e-20260921045854-d9ab4bd0',+ );+ await mkdir(path.join(reportDirectory, 'screenshots'), {+ recursive: true,+ });+ const html = runnerScript({+ project: 'ubuntu',+ startedAt: '2026-09-21T12:00:00Z',+ screenshotMode: 'directory',+ });+ const reportFile = path.join(reportDirectory, 'index.html');+ await writeFile(reportFile, html);+ await writeFile(+ path.join(reportDirectory, 'screenshots', 'screenshot-0-0.jpeg'),+ Buffer.from('/9j/2Q==', 'base64'),+ );++ const [testCase] = await reportCases(testRunDump(html), 'ubuntu', {+ reportHtml: html,+ reportFile,+ });+ assert.equal(testCase.descriptionKind, 'ai');+ assert.equal(testCase.description, 'AI explanation 0-0');+ assert.equal(testCase.screenshot.extension, 'jpg');+ assert.deepEqual(+ testCase.screenshot.bytes,+ Buffer.from('/9j/2Q==', 'base64'),+ );+});++test('reads 1.13.0 shell screenshots from the screenshots directory', async () => {+ const root = await mkdtemp(path.join(os.tmpdir(), 'shell-directory-'));+ const reportDirectory = path.join(root, 'report');+ await mkdir(path.join(reportDirectory, 'screenshots'), {+ recursive: true,+ });+ const html = shellFixtureHtml.replace(+ /<script\s+type=["']midscene-image["'][^>]*>[\s\S]*?<\/script>/g,+ '',+ );+ await writeFile(+ path.join(reportDirectory, 'test-run-shell.html'),+ html,+ );+ for (const index of [0, 1, 2]) {+ await writeFile(+ path.join(reportDirectory, 'screenshots', `image-${index}.jpeg`),+ Buffer.from('/9j/2Q==', 'base64'),+ );+ }++ const report = await findShellReport(root);+ assert.deepEqual(+ report.checks.map(({ key, passed, screenshot }) => ({+ key,+ passed,+ hasScreenshot: screenshot !== null,+ })),+ [+ { key: 'shutdown', passed: true, hasScreenshot: true },+ { key: 'focus', passed: true, hasScreenshot: true },+ { key: 'bar', passed: true, hasScreenshot: true },+ ],+ );+});+test('verifies every file and its expected content type', async () => {const requested = [];const manifest = {@@ -1264,6 +1422,7 @@ test('verifies every file and its expected content type', async () => {'reports/200/report-preview.png','reports/200/auxiliary-report-preview.png','reports/200/case-preview-ubuntu-case-ubuntu.jpg',+ 'reports/200/screenshots/node-shot-1.jpeg',],},],@@ -1279,7 +1438,8 @@ test('verifies every file and its expected content type', async () => {headers: {'content-type': url.pathname.endsWith('.png')? 'image/png'- : url.pathname.endsWith('.jpg')+ : url.pathname.endsWith('.jpg') ||+ url.pathname.endsWith('.jpeg')? 'image/jpeg': 'text/html; charset=utf-8',},@@ -1294,5 +1454,6 @@ test('verifies every file and its expected content type', async () => {'https://example.test/doubao-say/reports/200/report-preview.png','https://example.test/doubao-say/reports/200/auxiliary-report-preview.png','https://example.test/doubao-say/reports/200/case-preview-ubuntu-case-ubuntu.jpg',+ 'https://example.test/doubao-say/reports/200/screenshots/node-shot-1.jpeg',]);});diff --git a/tests/e2e/capture-report-preview.mjs b/tests/e2e/capture-report-preview.mjsindex 62a2e6a..a0530ba 100644--- a/tests/e2e/capture-report-preview.mjs+++ b/tests/e2e/capture-report-preview.mjs@@ -138,6 +138,7 @@ try {for (const testCase of reportCases(runnerDump, projectName, {reportHtml: report.html,+ reportFile: report.file,})) {const caseOutput = path.join(reportDirectory, testCase.previewFile);await writeFile(caseOutput, testCase.screenshot.bytes);