A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Merge feat/windows-onboarding-m5-03-place-line into feat/windows-onboarding-m5-04-update-banner
AdamPlatin1234a0de223b2d6
diff --cc app/src/main.mjsindex 07a0619f,523fde02..ad5e5c2a--- a/app/src/main.mjs+++ b/app/src/main.mjs@@@ -65,8 -68,8 +68,8 @@@ const frameFile = join(app.getPath('use// Loaded once the start window is up (loadModules).let BotBrowserGuests, partitionOf, BotViews, isBotId, importFromBrowser, listSources, applyCookies, CookieImports, parseCookieFilelet downloadSaver, chooseLocations, defaultPlaces, pickRoot, programFolder, saveLocations, teamIn, teamsAt, tx, HostProcess- let copySessions, findTeam, importTeam, teamInUse, userDshHome, copyData, copyReason, moveProblem, CHECK_PROFILE, PROFILE+ let copySessions, findTeam, importTeam, restoreSessions, teamInUse, userDshHome, copyData, copyReason, moveProblem, CHECK_PROFILE, PROFILE-let watchReleases, watchUpdates, getDshRuntimeVersion, electronUpdater+let watchReleases, watchUpdates, RELEASE_PAGE, getDshRuntimeVersion, electronUpdaterlet mainWindow// Settles once the hidden team window exists.@@@ -269,10 -273,10 +276,10 @@@ async function loadModules();({ downloadSaver } = downloads);({ chooseLocations, defaultPlaces, pickRoot, programFolder, saveLocations, teamIn, teamsAt, tx } = firstRun);({ HostProcess } = hostProcess)- ;({ copySessions, findTeam, importTeam, teamInUse, userDshHome } = imports)+ ;({ copySessions, findTeam, importTeam, restoreSessions, teamInUse, userDshHome } = imports);({ copyData, copyReason, moveProblem } = moves);({ CHECK_PROFILE, PROFILE } = profile)- ;({ watchReleases, watchUpdates } = updatesModule)+ ;({ watchReleases, watchUpdates, RELEASE_PAGE } = updatesModule);({ getDshRuntimeVersion } = boot)electronUpdater = updater.defaultbrowserGuests = new BotBrowserGuests({ session, origin: () => origin, devTools: !app.isPackaged })@@@ -1253,41 -1266,12 +1267,41 @@@ async function fail(error)startWindow.fail(error, startKind())// The failure page takes the place of a card that waited.answering?.(undefined)+ await offerUpdate(mine).catch((failure) => { console.error(failure) })+}++// The update banner of the failure page (start-window §7): 〔下载〕 opens the release page of a+// version that cannot install itself (macOS, a Linux deb); one that can is downloading already,+// and installs once it is downloaded, unless the user has tried again meanwhile.+async function offerUpdate(mine) {const found = await Promise.race([updates?.latest() ?? null, sleep(UPDATE_CHECK_WAIT_MS).then(() => null)])- if (!found || mine !== attempt) return- await dialog.showMessageBox(owner(), { type: 'info', title: 'DS Bot', message: tx(found.page ? 'dialog.update.onFailurePage' : 'dialog.update.onFailure', { version: found.version }) })- if (found.page) {- if (!process.env.DS_BOT_HOME) await electronShell.openExternal(found.page)+ const still = () => failed && mine === attempt+ offered = found ?? undefined+ if (!found || !still()) return+ const { version } = found+ if (found.page) { startWindow.update({ state: 'available', version, page: true }); return }+ const progress = (state) => {+ if (still() && state.phase === 'downloading') startWindow.update({ state: 'downloading', version, percent: state.percent ?? 0, received: state.received ?? 0, total: state.total ?? 0 })+ }+ progress(updates.state())+ const unsubscribe = updates.subscribe(progress)- const downloaded = await Promise.race([found.downloaded, sleep(UPDATE_DOWNLOAD_WAIT_MS).then(() => false)]).finally(unsubscribe)++ const downloaded = await Promise.race([found.downloaded, sleep(UPDATE_DOWNLOAD_WAIT_MS, undefined, { ref: false }).then(() => false)]).finally(unsubscribe)+ if (!still()) return+ if (!downloaded) { startWindow.update({ state: 'failed', version }); return }+ startWindow.update({ state: 'installing', version })+ await updates.install()+}++// The banner's buttons: 〔下载〕 and 「手动下载」 open the release page; 〔重试〕 after a failed+// download checks again.+function updateAct(name) {+ if (!failed) return+ if (name === 'manualDownload' || offered?.page) {+ const page = offered?.page ?? RELEASE_PAGE+ if (!process.env.DS_BOT_HOME) void electronShell.openExternal(page)return}- if (await Promise.race([found.downloaded, sleep(UPDATE_DOWNLOAD_WAIT_MS).then(() => false)]) && failed && mine === attempt) await updates.install()+ if (updates === undefined || updates.state().phase !== 'failed') return+ updates.check()+ void offerUpdate(attempt).catch((error) => { console.error(error) })}diff --cc app/src/updates.mjsindex 4aa6ccac,68db20e0..d6024854--- a/app/src/updates.mjs+++ b/app/src/updates.mjs@@@ -181,15 -177,8 +181,15 @@@ export function watchUpdates({ updaterupdater.on('checking-for-update', () => { holder.set({ phase: 'checking' }) })updater.on('update-not-available', () => { holder.set({ phase: 'current' }) })updater.on('update-available', (info) => { holder.set({ phase: 'downloading', version: info?.version }) })+ // The download's progress, for the failure page's update banner: once per whole per cent.+ updater.on('download-progress', (progress) => {+ const current = holder.state()+ const percent = Math.floor(Number(progress?.percent))+ if (current.phase !== 'downloading' || !Number.isFinite(percent) || percent === current.percent) return+ holder.set({ ...current, percent, received: Math.round(Number(progress.transferred) / MB) || 0, total: Math.round(Number(progress.total) / MB) || 0 })+ })updater.on('update-downloaded', ({ version }) => {- log.info(`DeepSeek Bot: update ${version} downloaded`)+ log.info(`DS Bot: update ${version} downloaded`)holder.set({ phase: 'downloaded', version })if (ask === undefined || asked === version) returnasked = versiondiff --cc app/test/main-fail-update.test.mjsindex 16b0ded0,00000000..d96588e4mode 100644,000000..100644--- a/app/test/main-fail-update.test.mjs+++ b/app/test/main-fail-update.test.mjs@@@ -1,62 -1,0 +1,69 @@@+// A start that fails while a new version downloads offers it on the failure page's update banner+// instead of a message box (start-window §7): the download's progress, 〔重试〕 after a failed+// download, 「手动下载」, then the install. The Electron parts are test doubles: no display, no+// DSH, no data of the user.+import assert from 'node:assert/strict'+import { test } from 'node:test'- import { state } from './helpers/fake-electron.mjs'++import { app, state } from './helpers/fake-electron.mjs'+import { state as hostState } from './helpers/fake-host-process.mjs'+import { state as updaterState, updater } from './helpers/fake-updater.mjs'+import { messageBoxes, startAct, startApp, startState, waitFor } from './helpers/app-harness.mjs'+import { installHooks } from './helpers/register.mjs'++await installHooks()++// Exercise the Windows installer on every runner; macOS and Linux debs open a release page.+Object.defineProperty(process, 'platform', { value: 'win32' })++const MB = 1024 * 1024++test('a failed start offers the downloading update on its banner and installs it', async () => {+ // Each check finds 9.9.9 and starts its download, which the test settles.+ const downloads = []+ updater.checkForUpdates = () => {+ updaterState.checks += 1+ const download = {}+ download.promise = new Promise((resolve, reject) => { Object.assign(download, { resolve, reject }) })+ downloads.push(download)+ return Promise.resolve({ isUpdateAvailable: true, updateInfo: { version: '9.9.9' }, downloadPromise: download.promise })+ }+ await startApp()+ await waitFor(() => updaterState.checks === 1, 'check for an update')+ updater.emit('download-progress', { percent: 37.4, transferred: 78 * MB, total: 212 * MB })++ // The Host does not start: the failure page, with the download on its banner.+ hostState.fail = true+ hostState.release()+ await waitFor(() => startState()?.view === 'failed', 'show the failure page')+ await waitFor(() => startState().update !== undefined, 'offer the update')+ assert.deepEqual(startState().update, { state: 'downloading', version: '9.9.9', percent: 37, received: 78, total: 212 })++ // The download fails: 〔重试〕 checks again, and the new download shows its progress.+ downloads[0].reject(new Error('download failed'))+ updater.emit('error', new Error('download failed'))+ await waitFor(() => startState().update?.state === 'failed', 'say that the download failed')+ assert.equal(await startAct('installUpdate'), true)+ await waitFor(() => updaterState.checks === 2, 'check again')+ updater.emit('update-available', { version: '9.9.9' })+ updater.emit('download-progress', { percent: 64.2, transferred: 136 * MB, total: 212 * MB })+ await waitFor(() => startState().update?.percent === 64, 'show the new download')+ assert.equal(startState().update.state, 'downloading')++ // 「手动下载」 opens the release page.+ assert.equal(await startAct('manualDownload'), true)+ await waitFor(() => (state.opened ?? []).length === 1, 'open the release page')+ assert.deepEqual(state.opened, ['https://github.com/Fei2411/DS-Bot/releases/latest'])++ // Downloaded: it installs, and the Host's stop comes first.+ downloads[1].resolve()+ await waitFor(() => updaterState.quitAndInstall.length === 1, 'install the update')+ assert.equal(startState().update.state, 'installing')+ assert.deepEqual(messageBoxes(), [], 'no message box on the way')+})++++test('the app ends after the update', async () => {++ let left = false++ app.once('will-quit', () => { left = true })++ app.quit()++ await waitFor(() => left, 'leave')++})