A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Resolve download roots on each download
Fei24112c5b56764294
diff --git a/app/src/bot-views.mjs b/app/src/bot-views.mjsindex c00370a9..1ebb1a51 100644--- a/app/src/bot-views.mjs+++ b/app/src/bot-views.mjs@@ -209,8 +209,15 @@ export class BotViews {#allowedDownloadPath(botId, requested) {if (typeof requested !== 'string' || !isAbsolute(requested)) return undefinedconst target = resolve(requested)- const roots = (this.#downloadRoots.get(botId) ?? []).filter(root =>- containsPath(root.path, target) || (root.realPath !== undefined && containsPath(root.realPath, target)))+ const roots = this.#downloadRoots.get(botId) ?? []+ const allowedByRoot = roots.some(root => {+ if (containsPath(root, target)) return true+ try {+ return containsPath(realpathSync(root), target)+ } catch {+ return false+ }+ })const temporaryRoot = resolve(tmpdir())let temporaryRealRoottry {@@ -218,12 +225,16 @@ export class BotViews {} catch {}const isArtifact = temporaryRealRoot !== undefined && [temporaryRoot, temporaryRealRoot].some(root =>isDirectChild(root, target) && basename(target).startsWith(PLAYWRIGHT_ARTIFACT_PREFIX))- if (roots.length === 0 && !isArtifact) return undefined+ if (!allowedByRoot && !isArtifact) return undefinedtry {mkdirSync(target, { recursive: true })const realTarget = realpathSync(target)const inRoot = roots.some(root => {- return root.realPath !== undefined && containsPath(root.realPath, realTarget)+ try {+ return containsPath(realpathSync(root), realTarget)+ } catch {+ return false+ }})const inArtifacts = isArtifact && temporaryRealRoot !== undefined&& isDirectChild(temporaryRealRoot, realTarget)@@ -298,13 +309,7 @@ export class BotViews {if (!Array.isArray(downloadRoots) || downloadRoots.length > 4 || !Array.from(downloadRoots).every(root => typeof root === 'string' && isAbsolute(root))) {throw new Error('Invalid browser download roots.')}- this.#downloadRoots.set(botId, [...new Set(downloadRoots.map(root => resolve(root)))].map(path => {- try {- return { path, realPath: realpathSync(path) }- } catch {- return { path, realPath: undefined }- }- }))+ this.#downloadRoots.set(botId, [...new Set(downloadRoots.map(root => resolve(root)))])this.#downloadPaths.delete(botId)for (const entry of this.#views.values()) if (entry.botId === botId) entry.downloadPath = undefined}diff --git a/app/test/bot-views.test.mjs b/app/test/bot-views.test.mjsindex a2cf00f0..b3ad9777 100644--- a/app/test/bot-views.test.mjs+++ b/app/test/bot-views.test.mjs@@ -201,6 +201,33 @@ test('CDP download behavior saves to the Bot path and emits download events', asassert.equal(sessionId.length > 0, true)})+test('CDP accepts a download root created after endpoint setup', async t => {+ const { manager, handlers, views } = fixture()+ t.after(() => manager.dispose())+ const parentPath = mkdtempSync(join(tmpdir(), 'bot-views-download-late-root-'))+ const rootPath = join(parentPath, 'downloads-root')+ t.after(() => rmSync(parentPath, { recursive: true, force: true }))+ const entry = manager.create('a')+ const socket = await openSocket(await manager.endpoint('a', { downloadRoots: [rootPath] }))+ t.after(() => socket.close())+ assert.equal(existsSync(rootPath), false)+ await request(socket, 1, 'Target.attachToTarget', { targetId: entry.tabId, flatten: true })+ const downloadPath = join(rootPath, 'downloads')+ const response = await request(socket, 2, 'Browser.setDownloadBehavior', { behavior: 'allowAndName', downloadPath })+ assert.deepEqual(response.result, {})+ let savePath+ const item = Object.assign(new EventEmitter(), {+ setSavePath(path) { savePath = path; writeFileSync(path, 'download') },+ getURL() { return 'https://example.com/file' },+ getFilename() { return 'report.pdf' },+ })+ let prevented = false+ handlers.get('bot:a')({ preventDefault() { prevented = true } }, item, views[0].webContents)+ assert.equal(prevented, false)+ assert.equal(existsSync(savePath), true)+ assert.equal(readFileSync(savePath, 'utf8'), 'download')+})+test('download roots are isolated per Bot', async t => {const { manager, handlers, views } = fixture()t.after(() => manager.dispose())