From bb1b97af3cb29a2c1cb99ee46559c983714920f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BA=B7?= Date: Tue, 17 Nov 2026 17:37:18 +0800 Subject: [PATCH] Fix preview fallback with canonical runtime paths on macOS --- scripts/pcb-preview.mjs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/pcb-preview.mjs b/scripts/pcb-preview.mjs index 2b46d3d..0935463 100644 --- a/scripts/pcb-preview.mjs +++ b/scripts/pcb-preview.mjs @@ -51,9 +51,12 @@ export function createPreviewHandler({ runtime = process.env.PCB_SESSION_ROOT || const cache = new Map(), pending = new Map(), captureAfter = new Map(); let capturing = false; async function preview(tid, kind) { - const task = JSON.parse(await readFile(resolve(runtime, 'tasks', tid, 'state.json'), 'utf8')); + // Canonicalize the configured root so OS aliases such as macOS /tmp do + // not look like task-owned symlinks to exportedFrame's containment check. + const runtimeRoot = await realpath(runtime); + const task = JSON.parse(await readFile(resolve(runtimeRoot, 'tasks', tid, 'state.json'), 'utf8')); let frame = null, reason = 'waiting_for_canvas'; - const savedPath = resolve(runtime, 'web-previews', `${tid}.json`); + const savedPath = resolve(runtimeRoot, 'web-previews', `${tid}.json`); if (task.approval && task.eda_session && task.state === 'running' && !capturing && Date.now() >= (captureAfter.get(tid) || 0)) { capturing = true; if (captureAfter.size > 100) captureAfter.delete(captureAfter.keys().next().value); @@ -63,7 +66,7 @@ export function createPreviewHandler({ runtime = process.env.PCB_SESSION_ROOT || reason = value.reason || ''; if (value.available && ['schematic', 'layout', '3d'].includes(value.kind) && /^data:image\/png;base64,/.test(value.image)) { frame = { kind: value.kind, capturedAt: Date.now(), source: 'canvas', image: value.image }; - await mkdir(resolve(runtime, 'web-previews'), { recursive: true }); + await mkdir(resolve(runtimeRoot, 'web-previews'), { recursive: true }); await writeFile(savedPath + '.tmp', JSON.stringify(frame)); await rename(savedPath + '.tmp', savedPath); } @@ -72,7 +75,7 @@ export function createPreviewHandler({ runtime = process.env.PCB_SESSION_ROOT || } else if (capturing) reason = 'eda_busy'; if (!frame) frame = await readFile(savedPath, 'utf8').then(JSON.parse).catch(() => null); if (frame && kind !== 'auto' && frame.kind !== kind) frame = null; - const exported = await exportedFrame(resolve(runtime, 'tasks', tid, 'workspace', 'artifacts'), kind).catch(() => null); + const exported = await exportedFrame(resolve(runtimeRoot, 'tasks', tid, 'workspace', 'artifacts'), kind).catch(() => null); if (exported && (!frame || exported.capturedAt > frame.capturedAt)) frame = exported; return { taskId: tid, frame, reason, refreshSeconds: 5 }; }