Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(desktop): refuse a link to a network share and an unreadable bundle check; never hang on open
AdityaUmale04cc1530c242
diff --git a/electron/save-file.mjs b/electron/save-file.mjsindex 01aeeded71..0a826c8b8b 100644--- a/electron/save-file.mjs+++ b/electron/save-file.mjs@@ -138,33 +138,38 @@ export async function revealInFolder(rawPath, { reveal, fsp = fs.promises, pathA}// shell.openPath runs whatever it is given, so only a plain folder may reach it: never a file, a Mac app bundle-// (Name.app, or a folder with Contents/Info.plist), or a link to either.+// (Name.app, or a folder with Contents/Info.plist), a network share, or a link to any of them.// A dead network mount can leave these checks pending: past checkMs the link falls back, and a late answer opens nothing.-export async function openFolder(rawPath, { open, fsp = fs.promises, pathApi = path, checkMs = 3_000 }) {+// xdg-open can stay running after the file manager shows the folder, so an open still pending after openMs counts as done.+export async function openFolder(rawPath, { open, fsp = fs.promises, pathApi = path, checkMs = 3_000, openMs = 10_000 }) {const target = localTarget(rawPath, pathApi);if (!target) return "invalid";- let timer;- const checked = await Promise.race([- plainFolder(target, fsp, pathApi),- new Promise((resolve) => { timer = setTimeout(() => resolve({ problem: "not-folder" }), checkMs); }),- ]).finally(() => clearTimeout(timer));+ const checked = await settleWithin(plainFolder(target, fsp, pathApi), checkMs, { problem: "not-folder" });if (checked.problem) return checked.problem;let error = "";- try { error = await open(checked.real); } catch (failure) { error = failure?.message ?? String(failure); }+ try { error = await settleWithin(Promise.resolve(open(checked.real)), openMs, ""); } catch (failure) { error = failure?.message ?? String(failure); }return error ? "failed" : "opened";}+async function settleWithin(promise, ms, fallback) {+ let timer;+ return Promise.race([promise, new Promise((resolve) => { timer = setTimeout(() => resolve(fallback), ms); })]).finally(() => clearTimeout(timer));+}++const absent = (error) => error?.code === "ENOENT" || error?.code === "ENOTDIR";+async function plainFolder(target, fsp, pathApi) {let real;let stats;try {real = await fsp.realpath(target);+ if (/^[\\/]{2}/.test(real)) return { problem: "not-folder" };stats = await fsp.stat(real);} catch {return { problem: "missing" };}if (!stats.isDirectory() || /.\.[^.]+$/.test(pathApi.basename(real))) return { problem: "not-folder" };- const bundle = await fsp.stat(pathApi.join(real, "Contents", "Info.plist")).then(() => true, () => false);+ const bundle = await fsp.stat(pathApi.join(real, "Contents", "Info.plist")).then(() => true, (error) => !absent(error));return bundle ? { problem: "not-folder" } : { real };}diff --git a/electron/save-file.node-test.mjs b/electron/save-file.node-test.mjsindex 5d1a67f102..4d8be8fa48 100644--- a/electron/save-file.node-test.mjs+++ b/electron/save-file.node-test.mjs@@ -344,6 +344,56 @@ describe("openFolder for a folder a chat links to", () => {await new Promise((resolve) => setTimeout(resolve, 10));assert.deepEqual(opened, []);});++ it("gives up on a link lookup that never answers and opens nothing when it answers late", async () => {+ const { opened, open } = shell();+ let answer;+ const fsp = {+ realpath: (target) => new Promise((resolve) => { answer = () => resolve(target); }),+ stat: async (target) => {+ if (target.endsWith("Info.plist")) throw Object.assign(new Error("gone"), { code: "ENOENT" });+ return { isFile: () => false, isDirectory: () => true };+ },+ };+ assert.equal(await openFolder("/Volumes/stale/Reports", { open, fsp, checkMs: 20 }), "not-folder");+ answer();+ await new Promise((resolve) => setTimeout(resolve, 10));+ assert.deepEqual(opened, []);+ });++ it("refuses a drive path that links to a network share", async () => {+ const { opened, open } = shell();+ const fsp = {+ realpath: async () => "\\\\server\\share\\Reports",+ stat: () => assert.fail("a network share must not be looked up"),+ };+ assert.equal(await openFolder("C:\\Users\\Maus\\Reports", { open, fsp, pathApi: path.win32 }), "not-folder");+ assert.deepEqual(opened, []);+ });++ it("treats a bundle check it can't make (no permission) as a bundle", async () => {+ const { opened, open } = shell();+ const fsp = {+ realpath: async (target) => target,+ stat: async (target) => {+ if (target.endsWith("Info.plist")) throw Object.assign(new Error("gone"), { code: "EACCES" });+ return { isFile: () => false, isDirectory: () => true };+ },+ };+ assert.equal(await openFolder("/Users/maus/Locked", { open, fsp }), "not-folder");+ assert.deepEqual(opened, []);+ });++ it("counts an open the system never answers as done", async () => {+ const fsp = {+ realpath: async (target) => target,+ stat: async (target) => {+ if (target.endsWith("Info.plist")) throw Object.assign(new Error("gone"), { code: "ENOENT" });+ return { isFile: () => false, isDirectory: () => true };+ },+ };+ assert.equal(await openFolder("/home/maus/Reports", { open: () => new Promise(() => {}), fsp, openMs: 20 }), "opened");+ });});describe("openLogsFolder", () => {