From 2e480d99b7a80305a14bb0f20022a40de0e51119 Mon Sep 17 00:00:00 2001 From: YXC0915 Date: Fri, 4 Dec 2026 21:23:18 +0800 Subject: [PATCH] fix(logs): classify successful Metal precision notes as info Ignore the Metal selector when a QEMU message reports a successful precision note. Reuse the same severity for log rows and the unread-error badge. --- frontend/scripts/test-logs.mjs | 31 +++++++++++++++++++++++++++++++ frontend/src/App.tsx | 8 ++++---- frontend/src/lib/logs.ts | 11 +++++++---- 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 frontend/scripts/test-logs.mjs diff --git a/frontend/scripts/test-logs.mjs b/frontend/scripts/test-logs.mjs new file mode 100644 index 0000000..d567ab0 --- /dev/null +++ b/frontend/scripts/test-logs.mjs @@ -0,0 +1,31 @@ +import assert from 'node:assert/strict' +import test from 'node:test' +import { loadTestModule } from './load-test-module.mjs' + +const { createLogLine } = await loadTestModule(`export * from './lib/logs'`) + +const renderSelector = 'newRenderPipelineStateWithDescriptor:error:' +const computeSelector = 'newComputePipelineStateWithDescriptor:options:reflection:error:' +const precisionNote = (selector, code) => + `[QEMU] reims-vgpu: ${selector}: metal2vulkan-runtime made it with a precision note (metal2vulkan-degrade-${code}): its answers there can differ from Metal's on this device; the first of its kind, each make that carries it counted` + +test('successful render and compute precision notes keep their text as informational logs', () => { + for (const line of [ + precisionNote(renderSelector, 'device-denormals'), + precisionNote(computeSelector, 'simdgroup-access-order'), + ]) { + const row = createLogLine({ line }) + assert.equal(row.level, 'info') + assert.equal(row.line, line) + } +}) + +test('pipeline refusals and fatal errors retain their error level', () => { + for (const line of [ + `[QEMU] reims-vgpu: platform call ${renderSelector}: the runtime refused it`, + '[QEMU] reims-vgpu: fatal: Vulkan device was lost', + `${precisionNote(renderSelector, 'device-denormals')}; error: failed to submit the command buffer`, + ]) { + assert.equal(createLogLine({ line }).level, 'error') + } +}) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 4087668..26b8852 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -16,7 +16,7 @@ import { buildFallbackChain, I18nKey, localeDir, locText, parseAppError, resolve import { defaultGuestLang, recommendedMemoryGB, recommendedResolution } from './lib/format' import { isMacOSDriver, liveVMInfo, splitEndpoints, vmFeatures } from './lib/endpoints' import { resolveFullscreenHotkey } from './lib/fullscreenHotkey' -import { LogLine, appendLog } from './lib/logs' +import { LogLine, appendLog, createLogLine } from './lib/logs' import { macOSMajor } from './macos/macosRelease' import { currentTask, finishedTaskTTL, isActiveInstallerTask, pruneFinishedTasks, upsertTask } from './lib/tasks' import { applyActiveLocaleFonts, applyActiveTheme, disposeActiveThemeAndLocaleFonts, notifyInteractiveThemeState } from './lib/themeEngine' @@ -200,11 +200,11 @@ export const App: React.FC = () => { // Logs never pop the panel open (see docs/design-guidelines.md); errors only bump a badge. const offLog = events.onLog((entry) => { if (!entry || typeof entry !== 'object') return - const lineText = typeof entry.line === 'string' ? entry.line : String(entry.line ?? '') - if (!logsOpenRef.current && /\b(error|failed|fatal|panic)\b/i.test(lineText)) { + const line = createLogLine(entry) + if (!logsOpenRef.current && line.level === 'error') { setUnseenErrors((n) => n + 1) } - setLogLines((prev) => appendLog(prev, entry)) + setLogLines((prev) => appendLog(prev, line)) }) // Tasks: seed from the backend, then follow events. api.GetTasks().then((list) => { diff --git a/frontend/src/lib/logs.ts b/frontend/src/lib/logs.ts index 8751240..91ef084 100644 --- a/frontend/src/lib/logs.ts +++ b/frontend/src/lib/logs.ts @@ -14,18 +14,21 @@ const MAX_LOG_LINES = 2000 // backend tags them explicitly. const ERROR_RE = /\b(error|failed|fatal|panic)\b/i const WARN_RE = /\bwarn(ing)?\b/i +// Successful vGPU precision notes include the Metal selector's error: argument. +const PRECISION_NOTE_PREFIX = /^(?:\[QEMU\] )?reims-vgpu: [\w:]+: metal2vulkan-runtime made it with a precision note \(metal2vulkan-degrade-[a-z0-9-]+\): / let nextId = 1 -function classify(entry: LogEntry): LogLine { +export function createLogLine(entry: LogEntry): LogLine { const ts = typeof entry?.ts === 'string' ? entry.ts : '' const source = typeof entry?.source === 'string' ? entry.source : '' const line = typeof entry?.line === 'string' ? entry.line : String(entry?.line ?? '') - const level: LogLevel = ERROR_RE.test(line) ? 'error' : WARN_RE.test(line) ? 'warn' : 'info' + const message = line.replace(PRECISION_NOTE_PREFIX, '') + const level: LogLevel = ERROR_RE.test(message) ? 'error' : WARN_RE.test(message) ? 'warn' : 'info' return { ts, source, line, id: nextId++, level } } -export function appendLog(prev: LogLine[], entry: LogEntry): LogLine[] { - const next = [...prev, classify(entry)] +export function appendLog(prev: LogLine[], line: LogLine): LogLine[] { + const next = [...prev, line] return next.length > MAX_LOG_LINES ? next.slice(next.length - MAX_LOG_LINES) : next }