A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Keep a user's .asar file when a download takes its name
AdamPlatin123272cedae56c4
diff --git a/app/src/downloads.mjs b/app/src/downloads.mjsindex c762e333..ba905726 100644--- a/app/src/downloads.mjs+++ b/app/src/downloads.mjs@@ -6,10 +6,15 @@// download starts into a staging folder of its own, and moves to the chosen file once both the// answer and the download are in. A cancelled picker cancels the download.import { randomUUID } from 'node:crypto'-import { constants, copyFileSync, existsSync, mkdirSync, renameSync, rmSync } from 'node:fs'+import * as nodeFs from 'node:fs'import { homedir as osHomedir } from 'node:os'import { basename, dirname, extname, join } from 'node:path'+// In Electron's main process node:fs takes every path that ends in .asar for an archive: a real+// file of that name with other content reads as missing, and a staged one cannot be copied.+// original-fs sees plain files; it exists only in Electron.+const { constants, copyFileSync, existsSync, mkdirSync, renameSync, rmSync } = process.getBuiltinModule('original-fs') ?? nodeFs+/*** @param {{* window: any,diff --git a/app/test/downloads.test.mjs b/app/test/downloads.test.mjsindex 95bff0fd..57ba8b4f 100644--- a/app/test/downloads.test.mjs+++ b/app/test/downloads.test.mjs@@ -3,7 +3,8 @@// cancelled picker cancels it; other contents' downloads pass through. Temp folders only.import assert from 'node:assert/strict'import { EventEmitter } from 'node:events'-import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'+import nodeFs, { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'+import { syncBuiltinESMExports } from 'node:module'import { tmpdir } from 'node:os'import { dirname, join } from 'node:path'import { after, test } from 'node:test'@@ -40,9 +41,9 @@ const event = () => ({ prevented: false, preventDefault() { this.prevented = truconst settle = () => new Promise(resolve => setImmediate(resolve))const until = async (check) => { for (let turn = 0; turn < 50 && !check(); turn += 1) await settle() }-function saver(at, ask, extra = {}) {+function saver(at, ask, { saverOf = downloadSaver, ...extra } = {}) {const contents = {}- const save = downloadSaver({ window: { webContents: contents }, ask, staging: () => at.staging, getPath: name => ({ downloads: at.downloads, home: at.home })[name], log: { warn: () => {} }, ...extra })+ const save = saverOf({ window: { webContents: contents }, ask, staging: () => at.staging, getPath: name => ({ downloads: at.downloads, home: at.home })[name], log: { warn: () => {} }, ...extra })return { contents, save }}@@ -258,3 +259,62 @@ test('two downloads of one name without a picker each keep their own file', asynconst texts = names.map(name => readFileSync(name, 'utf8')).sort()assert.deepEqual(texts, ['one', 'two'], 'each download kept its own bytes')})++// Electron's main process, for a .asar file that is no archive: node:fs says it is missing and+// cannot copy it, and original-fs, which plain Node does not have, sees the file. The app's test+// job has no Electron binary. `run` gets a fresh downloads.mjs that loaded under these rules.+async function inElectron(run, both = {}) {+ const plain = { ...nodeFs, ...both }+ const { copyFileSync: copy, existsSync: exists } = nodeFs+ const patched = {+ ...both,+ existsSync: path => !String(path).endsWith('.asar') && exists(path),+ copyFileSync(from, ...rest) {+ if (String(from).endsWith('.asar')) throw Object.assign(new Error('Invalid package'), { code: 'ENOENT' })+ copy(from, ...rest)+ },+ }+ const kept = Object.fromEntries(Object.keys(patched).map(name => [name, nodeFs[name]]))+ const { getBuiltinModule } = process+ process.getBuiltinModule = name => (name === 'original-fs' ? plain : getBuiltinModule(name))+ Object.assign(nodeFs, patched)+ syncBuiltinESMExports()+ try {+ await run(await import(`../src/downloads.mjs?electron=${String(runs)}`))+ } finally {+ process.getBuiltinModule = getBuiltinModule+ Object.assign(nodeFs, kept)+ syncBuiltinESMExports()+ }+}++test('a .asar file of the user\'s stays whole when a download of that name gets a free name', async () => {+ const at = place()+ const mine = join(at.downloads, 'mine.asar')+ writeFileSync(mine, 'mine')+ await inElectron(async ({ downloadSaver: electronSaver }) => {+ const { contents, save } = saver(at, async () => undefined, { saverOf: electronSaver })+ const download = item('mine.asar')+ save(event(), download, contents)+ download.finish('new')+ await until(() => readdirSync(at.downloads).length === 2)+ })+ assert.equal(readFileSync(mine, 'utf8'), 'mine')+ assert.equal(readFileSync(join(at.downloads, 'mine (2).asar'), 'utf8'), 'new')+})++test('a cross-drive move can copy a staged .asar file', async () => {+ const at = place()+ const staged = join(at.staging, 'held', 'tool.asar')+ mkdirSync(dirname(staged), { recursive: true })+ writeFileSync(staged, 'new')+ const target = join(at.downloads, 'tool.asar')+ const rename = nodeFs.renameSync+ const crossDrive = (from, to) => {+ if (from === staged) throw Object.assign(new Error('cross-device link not permitted'), { code: 'EXDEV' })+ rename(from, to)+ }+ await inElectron(({ move: electronMove }) => { electronMove(staged, target) }, { renameSync: crossDrive })+ assert.equal(readFileSync(target, 'utf8'), 'new')+ assert.deepEqual(readdirSync(at.downloads), ['tool.asar'], 'no temp file is left next to the target')+})