diff --git a/docs/DEVLOG.md b/docs/DEVLOG.md index ab37c6c..0356fa6 100644 --- a/docs/DEVLOG.md +++ b/docs/DEVLOG.md @@ -6,6 +6,23 @@ Newest entries first. --- +## 2026-11-05 — live mode names the missing VoiceOver settings download + +From Guidepup 0.36, VoiceOver starts with a settings file (a disk image) that +`npx @guidepup/setup install` downloads, one per macOS version. On a Mac that +moved to macOS 27 the cache still held only the macOS 26 file, so Guidepup +stopped with "Failed to mount Guidepup preferences" — and our message sent +people to automation permissions, which were not involved. An afternoon went +to `@guidepup/setup setup` and privacy settings. + +Now the pre-check looks for the exact file Guidepup will mount (same rule as +Guidepup, read from the manifest it ships) and, if it is missing, prints the +download command with the `cd` it needs: `setup install` reads the manifest of +whichever Guidepup it finds from the folder it runs in, so run anywhere else +it downloads the wrong files or none. + +--- + ## 2026-10-17 — 0.13.0: the page's security policy stays on A page can tell the browser which scripts it may run, with a diff --git a/src/live-bridge.js b/src/live-bridge.js index d16decb..5e7b69f 100644 --- a/src/live-bridge.js +++ b/src/live-bridge.js @@ -1,5 +1,9 @@ import fs from "node:fs"; import os from "node:os"; +import path from "node:path"; +import { createRequire } from "node:module"; + +const require = createRequire(import.meta.url); /** * Live screen reader bridge — drives real VoiceOver (macOS) or NVDA (Windows) @@ -27,7 +31,7 @@ export function detectReader() { if (process.platform === "darwin") return "voiceover"; if (process.platform === "win32") return "nvda"; throw new Error( - `Unsupported platform: ${process.platform}. Live mode requires macOS (VoiceOver) or Windows (NVDA).` + `Unsupported platform: ${process.platform}. Live mode requires macOS (VoiceOver) or Windows (NVDA).`, ); } @@ -116,7 +120,7 @@ export async function createLiveBridge(readerName) { const command = reader.keyboardCommands[commandKey]; if (!command) { throw new Error( - `Unknown command: ${commandKey}. Available: ${Object.keys(reader.keyboardCommands).join(", ")}` + `Unknown command: ${commandKey}. Available: ${Object.keys(reader.keyboardCommands).join(", ")}`, ); } await reader.perform(command); @@ -174,20 +178,107 @@ export function preflightLiveMode({ platform = process.platform, release = os.release(), exists = (p) => fs.existsSync(p), + guidepup = loadGuidepupManifest(), + cachePath = guidepupCachePath(), } = {}) { if (platform !== "darwin") return { ok: true }; const launcher = voiceOverLauncher(release); - if (exists(launcher)) return { ok: true }; - return { - ok: false, - reason: - `Live mode cannot start VoiceOver on this machine (Darwin ${release}).\n\n` + - `This is not a permissions problem. The screen-reader driver launches\n` + - `VoiceOver through a path that does not exist here:\n` + - ` ${launcher}\n\n` + - `Report it with that path: https://github.com/Elizabeth1979/screen-reader-cli/issues\n\n` + - STILL_WORKS, - }; + if (!exists(launcher)) { + return { + ok: false, + reason: + `Live mode cannot start VoiceOver on this machine (Darwin ${release}).\n\n` + + `This is not a permissions problem. The screen-reader driver launches\n` + + `VoiceOver through a path that does not exist here:\n` + + ` ${launcher}\n\n` + + `Report it with that path: https://github.com/Elizabeth1979/screen-reader-cli/issues\n\n` + + STILL_WORKS, + }; + } + const prefs = voiceOverPreferencesFile({ release, guidepup, cachePath }); + if (prefs && !exists(prefs)) { + return { + ok: false, + reason: + `Live mode cannot start VoiceOver yet: a one-time download is missing.\n\n` + + `The screen-reader driver (Guidepup) needs its VoiceOver settings file\n` + + `for this macOS (Darwin ${release}), and it is not on this machine:\n` + + ` ${prefs}\n\n` + + `This is not a permissions problem. Download it with:\n` + + ` ${installCommand(guidepup)}\n\n` + + STILL_WORKS, + }; + } + return { ok: true }; +} + +// From Guidepup 0.36, VoiceOver starts with a settings file (a disk image) that +// `@guidepup/setup install` downloads into a cache, one per macOS version. Its +// absence surfaces only as "Failed to mount Guidepup preferences", which the +// start wrapper below used to send to automation permissions. The rule here +// copies Guidepup's own (resolveCachePath + getManifestAsset + resolveDmgPath), +// read from the manifest Guidepup ships, so the two cannot disagree. + +/** Guidepup's manifest and where it lives, or null for a Guidepup without one. */ +export function loadGuidepupManifest() { + try { + const manifestPath = require.resolve("@guidepup/guidepup/manifest.json"); + return { + manifestPath, + manifest: JSON.parse(fs.readFileSync(manifestPath, "utf8")), + }; + } catch { + return null; + } +} + +/** Where Guidepup caches screen-reader assets on macOS. */ +export function guidepupCachePath(env = process.env, home = os.homedir()) { + return env.GUIDEPUP_SCREEN_READERS_PATH + ? path.resolve(env.GUIDEPUP_SCREEN_READERS_PATH) + : path.resolve(home, "Library", "Caches", "guidepup"); +} + +/** + * The settings file Guidepup will mount on this Darwin release, or null when + * there is nothing to check (an older Guidepup, or a release its manifest does + * not list — Guidepup then refuses on its own with "not supported"). + */ +export function voiceOverPreferencesFile({ release, guidepup, cachePath }) { + const assets = guidepup?.manifest?.screenReaders?.find( + ({ id }) => id === "voiceover", + )?.assets; + const major = release.split(".", 1)[0]; + const asset = assets?.find( + ({ platformVersion }) => platformVersion === major, + ); + if (!asset) return null; + return path.join( + cachePath, + "voiceover", + asset.platformVersion, + asset.version, + asset.asset, + ); +} + +/** + * The download command. `@guidepup/setup install` reads the manifest of the + * Guidepup it finds from the folder it runs in, so it must run from the folder + * that holds this tool's Guidepup — run anywhere else, it fetches files for a + * different Guidepup, or none. + */ +export function installCommand(guidepup) { + const base = "npx @guidepup/setup install voiceover"; + if (!guidepup?.manifestPath) return base; + // .../node_modules/@guidepup/guidepup/manifest.json → the folder above node_modules + const root = path.resolve( + path.dirname(guidepup.manifestPath), + "..", + "..", + "..", + ); + return `cd "${root}" && ${base}`; } /** @@ -205,6 +296,36 @@ export function explainStartFailure(err, env = {}) { const platform = env.platform ?? process.platform; const release = env.release ?? os.release(); const raw = [err?.message, err?.cause?.message].filter(Boolean).join(" — "); + if ( + platform === "darwin" && + /Failed to mount Guidepup preferences/i.test(raw) + ) { + // Most often the per-macOS settings file was never downloaded (the + // preflight catches that case first). Name the download, not automation. + const guidepup = "guidepup" in env ? env.guidepup : loadGuidepupManifest(); + // Guidepup nests the real reason (an EPERM from symlink) a level deeper. + const chain = []; + for (let e = err; e && chain.length < 5; e = e.cause) + chain.push(String(e.message ?? e)); + if (chain.some((m) => /EPERM|operation not permitted/i.test(m))) { + return ( + `${raw}\n\n` + + `macOS blocked the screen-reader driver from writing into VoiceOver's\n` + + `settings folder (~/Library/Group Containers/group.com.apple.VoiceOver).\n` + + `This is macOS privacy protection, not a missing download. Give Full Disk\n` + + `Access to the app this terminal runs in (System Settings > Privacy &\n` + + `Security > Full Disk Access), quit and reopen that app, then run again.` + ); + } + return ( + `${raw}\n\n` + + `The screen-reader driver could not load its VoiceOver settings file.\n` + + `Download it for this macOS (Darwin ${release}) with:\n` + + ` ${installCommand(guidepup)}\n` + + `If that file is already there, the terminal may be blocked from VoiceOver's\n` + + `settings folder (~/Library/Group Containers/group.com.apple.VoiceOver).` + ); + } const unsupported = /not supported|no such file|VoiceOverStarter/i.test(raw); if (platform === "darwin" && unsupported) { // Deliberately no Darwin-to-macOS conversion: the offset changed when Apple diff --git a/test/live.test.js b/test/live.test.js index 1f705fd..f7c24b1 100644 --- a/test/live.test.js +++ b/test/live.test.js @@ -17,7 +17,10 @@ function run(...args) { describe("live command — CLI registration", () => { it("shows help for live command", () => { const output = run("live", "--help"); - assert.ok(output.includes("Drive a real screen reader"), "should show live description"); + assert.ok( + output.includes("Drive a real screen reader"), + "should show live description", + ); assert.ok(output.includes("open"), "should list open subcommand"); assert.ok(output.includes("read"), "should list read subcommand"); assert.ok(output.includes("test"), "should list test subcommand"); @@ -66,7 +69,7 @@ describe("live-bridge module", () => { await assert.rejects( () => createLiveBridge("jaws"), /Unknown screen reader/, - "should reject unsupported reader" + "should reject unsupported reader", ); }); }); @@ -122,11 +125,19 @@ describe("enterWebArea", () => { // The dangerous case: VoiceOver was already inside the page, so these are // real content. Discarding them would be the very bug being fixed. const { enterWebArea } = await import("../src/commands/live.js"); - const pageContent = ["heading level 1, Test page", "list 2 items", "First item"]; + const pageContent = [ + "heading level 1, Test page", + "list 2 items", + "First item", + ]; const b = fakeBridge("voiceover", pageContent); const r = await enterWebArea(b); assert.equal(r.entered, false); - assert.equal(b.calls.interact, 0, "must not interact when no boundary was found"); + assert.equal( + b.calls.interact, + 0, + "must not interact when no boundary was found", + ); assert.deepEqual(r.skipped, pageContent, "content is returned, not lost"); }); @@ -209,10 +220,19 @@ describe("walkBackward", () => { const { walkBackward } = await import("../src/commands/live.js"); const b = directionalBridge( [], - ["c", "b", "a", "Test page web content. You are currently on a web content"], + [ + "c", + "b", + "a", + "Test page web content. You are currently on a web content", + ], ); const r = await walkBackward(b, { maxSteps: 50 }); - assert.deepEqual(r.phrases, ["c", "b", "a"], "browser chrome is not part of the page log"); + assert.deepEqual( + r.phrases, + ["c", "b", "a"], + "browser chrome is not part of the page log", + ); assert.match(r.reason, /web area|boundary/i); }); @@ -251,7 +271,9 @@ describe("compareDirections", () => { const { compareDirections } = await import("../src/commands/live.js"); const r = compareDirections( ["list 2 items. You are currently on a list, inside of web content."], - ["list 2 items. To move between items in this list, press Control-Option-Right Arrow."], + [ + "list 2 items. To move between items in this list, press Control-Option-Right Arrow.", + ], ); assert.equal(r.onlyForward.length, 0); assert.equal(r.onlyBackward.length, 0); @@ -267,7 +289,10 @@ describe("explainStartFailure", () => { const { explainStartFailure } = await import("../src/live-bridge.js"); const err = new Error("VoiceOver cannot be started"); err.cause = new Error("macOS version not supported: 28"); - const msg = explainStartFailure(err, { platform: "darwin", release: "28.0.0" }); + const msg = explainStartFailure(err, { + platform: "darwin", + release: "28.0.0", + }); assert.match(msg, /not a permissions problem/i); assert.match(msg, /Darwin 28\.0\.0/); assert.match(msg, /scan|audit/i, "must say what still works"); @@ -276,7 +301,9 @@ describe("explainStartFailure", () => { it("still catches a missing launcher binary", async () => { const { explainStartFailure } = await import("../src/live-bridge.js"); const msg = explainStartFailure( - new Error("VoiceOver cannot be started\nCommand failed: .../VoiceOverStarter: No such file or directory"), + new Error( + "VoiceOver cannot be started\nCommand failed: .../VoiceOverStarter: No such file or directory", + ), { platform: "darwin", release: "27.0.0" }, ); assert.match(msg, /not a permissions problem/i); @@ -302,7 +329,9 @@ describe("explainStartFailure — platform", () => { // and the tests themselves failed the moment CI ran them. const { explainStartFailure } = await import("../src/live-bridge.js"); const msg = explainStartFailure( - new Error("VoiceOver cannot be started\nCommand failed: .../VoiceOverStarter: No such file or directory"), + new Error( + "VoiceOver cannot be started\nCommand failed: .../VoiceOverStarter: No such file or directory", + ), { platform: "linux", release: "6.1.0" }, ); assert.doesNotMatch(msg, /not a permissions problem/i); @@ -312,13 +341,22 @@ describe("explainStartFailure — platform", () => { describe("voiceOverLauncher — the same rule Guidepup uses", () => { it("opens VoiceOver.app from Darwin 27, where VoiceOverStarter is gone", async () => { const { voiceOverLauncher } = await import("../src/live-bridge.js"); - assert.equal(voiceOverLauncher("27.0.0"), "/System/Library/CoreServices/VoiceOver.app"); - assert.equal(voiceOverLauncher("28.1.0"), "/System/Library/CoreServices/VoiceOver.app"); + assert.equal( + voiceOverLauncher("27.0.0"), + "/System/Library/CoreServices/VoiceOver.app", + ); + assert.equal( + voiceOverLauncher("28.1.0"), + "/System/Library/CoreServices/VoiceOver.app", + ); }); it("runs VoiceOverStarter before Darwin 27", async () => { const { voiceOverLauncher } = await import("../src/live-bridge.js"); - assert.match(voiceOverLauncher("25.4.0"), /Contents\/MacOS\/VoiceOverStarter$/); + assert.match( + voiceOverLauncher("25.4.0"), + /Contents\/MacOS\/VoiceOverStarter$/, + ); }); }); @@ -331,7 +369,11 @@ describe("preflightLiveMode — check before taking over the machine", () => { const r = preflightLiveMode({ platform: "darwin", release: "27.0.0", - exists: (p) => (checked.push(p), p === "/System/Library/CoreServices/VoiceOver.app"), + exists: (p) => ( + checked.push(p), + p === "/System/Library/CoreServices/VoiceOver.app" + ), + guidepup: null, }); assert.equal(r.ok, true); assert.deepEqual(checked, ["/System/Library/CoreServices/VoiceOver.app"]); @@ -343,6 +385,7 @@ describe("preflightLiveMode — check before taking over the machine", () => { platform: "darwin", release: "24.0.0", exists: (p) => p.endsWith("/VoiceOverStarter"), + guidepup: null, }); assert.equal(r.ok, true); }); @@ -356,16 +399,156 @@ describe("preflightLiveMode — check before taking over the machine", () => { }); assert.equal(r.ok, false); assert.match(r.reason, /not a permissions problem/i); - assert.match(r.reason, /VoiceOver\.app/, "must name the path it looked for"); + assert.match( + r.reason, + /VoiceOver\.app/, + "must name the path it looked for", + ); assert.match(r.reason, /scan|audit/i, "must say what still works"); }); it("does not block on platforms this check does not cover", async () => { const { preflightLiveMode } = await import("../src/live-bridge.js"); assert.equal( - preflightLiveMode({ platform: "win32", release: "10", exists: () => false }).ok, + preflightLiveMode({ + platform: "win32", + release: "10", + exists: () => false, + }).ok, true, "NVDA on Windows has nothing to do with a macOS launcher path", ); }); }); + +describe("preflightLiveMode — VoiceOver settings file (Guidepup 0.36+)", () => { + // A manifest shaped like the one Guidepup ships. Injected so the test does + // not depend on which Guidepup is installed, or on the host's cache. + const guidepup = { + manifestPath: "/opt/tool/node_modules/@guidepup/guidepup/manifest.json", + manifest: { + version: 1, + screenReaders: [ + { + id: "voiceover", + assets: [ + { + version: "0.0.1-VoiceOver4", + platformVersion: "25", + asset: "prefs-26.dmg", + }, + { + version: "0.1.0-VoiceOver4", + platformVersion: "27", + asset: "prefs-27.dmg", + }, + ], + }, + ], + }, + }; + const APP = "/System/Library/CoreServices/VoiceOver.app"; + const PREFS_27 = "/cache/voiceover/27/0.1.0-VoiceOver4/prefs-27.dmg"; + + it("refuses with the download command when the file for this macOS is missing", async () => { + // The real case: the cache held only the Darwin 25 file, the machine was + // on Darwin 27, and Guidepup said "Failed to mount Guidepup preferences", + // which the old message sent to automation permissions. + const { preflightLiveMode } = await import("../src/live-bridge.js"); + const r = preflightLiveMode({ + platform: "darwin", + release: "27.2.0", + exists: (p) => p === APP, + guidepup, + cachePath: "/cache", + }); + assert.equal(r.ok, false); + assert.match(r.reason, /not a permissions problem/i); + assert.ok(r.reason.includes(PREFS_27), "must name the file it looked for"); + assert.ok( + r.reason.includes( + 'cd "/opt/tool" && npx @guidepup/setup install voiceover', + ), + "must run install from the folder holding this tool's Guidepup", + ); + }); + + it("passes when the file is there", async () => { + const { preflightLiveMode } = await import("../src/live-bridge.js"); + const r = preflightLiveMode({ + platform: "darwin", + release: "27.2.0", + exists: (p) => p === APP || p === PREFS_27, + guidepup, + cachePath: "/cache", + }); + assert.equal(r.ok, true); + }); + + it("does not block on a release the manifest does not list", async () => { + // Guidepup refuses that itself with "not supported"; explainStartFailure + // already names it. Guessing a file name here would be a false refusal. + const { preflightLiveMode } = await import("../src/live-bridge.js"); + const r = preflightLiveMode({ + platform: "darwin", + release: "29.0.0", + exists: (p) => p === APP, + guidepup, + cachePath: "/cache", + }); + assert.equal(r.ok, true); + }); + + it("follows GUIDEPUP_SCREEN_READERS_PATH like Guidepup does", async () => { + const { guidepupCachePath } = await import("../src/live-bridge.js"); + assert.equal( + guidepupCachePath({ GUIDEPUP_SCREEN_READERS_PATH: "/x/y" }, "/home/u"), + "/x/y", + ); + assert.equal( + guidepupCachePath({}, "/Users/u"), + "/Users/u/Library/Caches/guidepup", + ); + }); +}); + +describe("explainStartFailure — preferences mount", () => { + it("points at the download, not at automation", async () => { + const { explainStartFailure } = await import("../src/live-bridge.js"); + const err = new Error("VoiceOver cannot be started"); + err.cause = new Error( + "Failed to mount Guidepup preferences\n\nPlease ensure you have run: ...", + ); + const msg = explainStartFailure(err, { + platform: "darwin", + release: "27.2.0", + guidepup: { + manifestPath: "/opt/tool/node_modules/@guidepup/guidepup/manifest.json", + }, + }); + assert.ok( + msg.includes('cd "/opt/tool" && npx @guidepup/setup install voiceover'), + ); + assert.doesNotMatch(msg, /automation is permitted/); + }); + + it("names Full Disk Access when macOS blocks the settings folder", async () => { + // Real chain on macOS 27: start -> mount -> EPERM symlink into + // ~/Library/Group Containers/group.com.apple.VoiceOver (privacy protection). + const { explainStartFailure } = await import("../src/live-bridge.js"); + const eperm = new Error( + "EPERM: operation not permitted, symlink '/Volumes/...' -> '...portable.scrd'", + ); + const mount = new Error("Failed to mount Guidepup preferences", { + cause: eperm, + }); + const err = new Error("VoiceOver cannot be started", { cause: mount }); + const msg = explainStartFailure(err, { + platform: "darwin", + release: "27.2.0", + guidepup: null, + }); + assert.match(msg, /Full Disk Access/); + assert.doesNotMatch(msg, /setup install/); + }); +});