A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Offer a new version on the failure page's banner, not in a box
AdamPlatin1230c10fe9b76db
diff --git a/app/src/main.mjs b/app/src/main.mjsindex 37cc37ac..07a0619f 100644--- a/app/src/main.mjs+++ b/app/src/main.mjs@@ -66,7 +66,7 @@ const frameFile = join(app.getPath('userData'), 'start-frame.json')let BotBrowserGuests, partitionOf, BotViews, isBotId, importFromBrowser, listSources, applyCookies, CookieImports, parseCookieFilelet downloadSaver, chooseLocations, defaultPlaces, pickRoot, programFolder, saveLocations, teamIn, teamsAt, tx, HostProcesslet copySessions, findTeam, importTeam, 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.@@ -95,6 +95,8 @@ let proposedlet moveTo// Takes the answer of the card that askCard() put up.let answering+// The new version that the failure page's update banner offers.+let offered// A retry or a start over is stopping the old engine: no second one starts meanwhile.let restarting = false// The first run's answer to the import; only the first boot copies.@@ -183,6 +185,7 @@ if (canonical !== undefined) {if (answering !== undefined) { answering(value); return }(startWindow.kind === 'later' ? moveAnswer(value) : placeAnswer(value)).catch(fail)},+ onUpdate: (name) => { updateAct(name) },})// A second launch shows the window that is showing: the start window until the hand-off// (also after a failed start), then the team window, built anew when it is gone.@@ -269,7 +272,7 @@ async function loadModules() {;({ copySessions, findTeam, importTeam, 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 })@@ -1241,9 +1244,7 @@ function openOutside(url) {}// The start window shows the failure page and stays. A new version may fix what keeps this one-// from starting; until the page has its update row, a box on it says what comes: the release-// page opens (macOS, a Linux deb), or the version that installs itself does so once it is-// downloaded, unless the user has tried again meanwhile.+// from starting: the page's update banner offers it.async function fail(error) {console.error(error)if (failed || stopping) return@@ -1252,12 +1253,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: 'DeepSeek 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)+ 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 --git a/app/src/start-window.mjs b/app/src/start-window.mjsindex cdab43e8..e9fc0564 100644--- a/app/src/start-window.mjs+++ b/app/src/start-window.mjs@@ -41,6 +41,9 @@ const ACT_VIEWS = {// (「会放在…」, a place that cannot be used).pick: ['boot', 'card', 'watchdog'],answer: ['card'],+ // The failure page's update banner: 〔下载〕 or 〔重试〕 on it, and 「手动下载」.+ installUpdate: ['failed'],+ manualDownload: ['failed'],openLogs: null,copyDetails: null,}@@ -236,6 +239,7 @@ export function startSnapshot(state, now) {if (state.card !== undefined) snapshot.card = { ...state.card }if (state.failure !== undefined) snapshot.failure = { reason: state.failure.reason, log: [...state.failure.log] }if (state.landing !== undefined) snapshot.landing = { ...state.landing }+ if (state.update !== undefined) snapshot.update = { ...state.update }return snapshot}@@ -283,11 +287,13 @@ export class StartWindow {* mainWindow: () => any,* onRetry: () => void, onReload: () => void, onClose: () => void,* onPick?: (value?: string) => void, onAnswer?: (value?: string) => void,+ * onUpdate?: (name: 'installUpdate' | 'manualDownload') => void,* }} options `lang` is asked at each open; `program` names the folders of the app's own files;* `onClose` runs when the user closes the start window before the hand-off; `onPick` when* the page asks for the folder picker ('changePlace' from its place line, nothing from a* card's 〔重新选〕; on a later start the line's button moves the data), `onAnswer` with a- * card's answer ('use' for 〔继续〕 on 「会放在…」).+ * card's answer ('use' for 〔继续〕 on 「会放在…」), `onUpdate` with a button of the failure+ * page's update banner.*/constructor(options) {this.#o = options@@ -440,7 +446,7 @@ export class StartWindow {this.#watchAt = WATCHDOG_MSthis.#phaseAt = Date.now()this.#clear('teamView')- this.#update({ view: 'boot', done: [], card: undefined, failure: undefined, celebrate: true, clock: { base: 0, from: Date.now(), running: true } })+ this.#update({ view: 'boot', done: [], card: undefined, failure: undefined, update: undefined, celebrate: true, clock: { base: 0, from: Date.now(), running: true } })}/**@@ -570,6 +576,17 @@ export class StartWindow {if (emptied) this.#window.webContents.reload()}+ /**+ * The failure page's update banner (start-window §7), or none: a new version that may fix what+ * keeps this one from starting. A retry takes it away.+ * @param {{ state: 'available' | 'downloading' | 'installing' | 'failed', version: string, page?: boolean, percent?: number, received?: number, total?: number } | undefined} update+ * `page`: the version installs from its release page, not by itself; `received` and `total` in MB+ */+ update(update) {+ if (!this.#open() || this.#state.view !== 'failed') return+ this.#update({ update: update === undefined ? undefined : { ...update } })+ }+/** The team window's rect: centred on the start window, inside that display's work area. */mainBounds() {const { screen } = this.#o.electron@@ -632,7 +649,7 @@ export class StartWindow {view: start === 'moving' ? 'moving' : 'boot',done: [], explain: this.#explain, celebrate: start === 'first',clock: { base: 0, from: now, running: true },- hint: undefined, place: undefined, card: undefined, failure: undefined,+ hint: undefined, place: undefined, card: undefined, failure: undefined, update: undefined,}this.#refresh()}@@ -684,6 +701,7 @@ export class StartWindow {else if (name === 'copyDetails') this.#copyDetails()else if (name === 'pick') this.#o.onPick?.(valueOf(payload))else if (name === 'answer') this.#o.onAnswer?.(valueOf(payload))+ else if (name === 'installUpdate' || name === 'manualDownload') this.#o.onUpdate?.(name)return true}@@ -696,7 +714,7 @@ export class StartWindow {this.#holdsOff()this.#watchAt = WATCHDOG_MSthis.#phaseAt = Date.now()- this.#update({ view: 'boot', failure: undefined, celebrate: true, done: this.#state.done.filter(phase => phase !== 'team'), clock: { base: 0, from: Date.now(), running: true } })+ this.#update({ view: 'boot', failure: undefined, update: undefined, celebrate: true, done: this.#state.done.filter(phase => phase !== 'team'), clock: { base: 0, from: Date.now(), running: true } })this.#o.onRetry()}diff --git a/app/src/start/start.html b/app/src/start/start.htmlindex c623d275..5df7d57c 100644--- a/app/src/start/start.html+++ b/app/src/start/start.html@@ -45,7 +45,7 @@<section class="card" data-kind="newer" hidden><div class="card-scroll"><h2 class="card-title" data-t="say.newer"></h2><p class="lead" data-t="card.newer.lead"></p></div><div class="card-actions"><button class="btn" data-look="primary" data-act="answer" data-detail="startWithout" data-t="btn.startWithout"></button><p class="foot" data-t="note.copyAgain"></p></div></section><section class="card" data-kind="importFailed" hidden><div class="card-scroll"><p class="lead" data-t="card.importFailed.lead"></p><div class="card-actions"><button class="btn" data-look="primary" data-act="retry" data-t="btn.retry"></button><button class="btn" data-look="soft" data-act="answer" data-detail="startWithout" data-t="btn.startWithout"></button><button class="btn" data-look="soft" data-act="copyDetails" data-t="btn.copyDetails"></button><button class="btn disclose" data-look="link" data-act="toggleDetails" aria-expanded="false"><span data-t="btn.details"></span><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4.5 6.2 8 9.7l3.5-3.5"/></svg></button></div><div class="log" hidden><pre></pre></div></div></section><section class="card" data-kind="watchdog" hidden><div class="card-actions"><button class="btn" data-look="primary" data-act="wait" data-t="btn.wait"></button><button class="btn" data-look="soft" data-act="retry" data-t="btn.retry"></button><button class="btn" data-look="soft" data-act="openLogs" data-t="btn.openLogs"></button></div></section>-<section class="card" data-kind="failed" hidden><div class="card-scroll"><p class="lead" data-t="reason.start.{reason}"></p><div class="banner" hidden><div class="banner-row"><p class="lead" data-t="card.update.available"></p><button class="btn" data-look="primary" data-act="installUpdate" data-u="available" data-t="btn.install"></button></div><div class="banner-down" data-u="downloading"><p class="small banner-line"><span data-t="card.update.downloading"></span><span class="slow"><span data-t="card.update.slow"></span><button class="btn" data-look="link" data-act="manualDownload" data-t="btn.manualDownload"></button></span></p><div class="bar"><span class="bar-fill"></span></div></div><p class="small" data-u="installing" data-t="card.update.installing"></p><div class="banner-fail" data-u="failed"><p class="small danger" data-t="card.update.failed"></p><button class="btn" data-look="small" data-act="installUpdate" data-t="btn.retry"></button><button class="btn" data-look="small" data-act="manualDownload" data-t="btn.manualDownload"></button></div></div><div class="card-actions"><button class="btn" data-look="primary" data-act="retry" data-main data-t="btn.retry"></button><button class="btn" data-look="soft" data-act="pick" data-detail="changePlace" data-places data-t="btn.changePlace" hidden></button><button class="btn" data-look="soft" data-act="freshStart" data-places data-t="btn.freshStart" hidden></button><button class="btn" data-look="soft" data-act="openLogs" data-t="btn.openLogs"></button><button class="btn" data-look="soft" data-act="copyDetails" data-t="btn.copyDetails"></button><button class="btn disclose" data-look="link" data-act="toggleDetails" aria-expanded="false"><span data-t="btn.details"></span><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4.5 6.2 8 9.7l3.5-3.5"/></svg></button></div><div class="log" hidden><pre></pre></div></div></section>+<section class="card" data-kind="failed" hidden><div class="card-scroll"><p class="lead" data-t="reason.start.{reason}"></p><div class="banner" hidden><div class="banner-row"><p class="lead" data-t="card.update.available"></p><button class="btn" data-look="primary" data-act="installUpdate" data-u="available" data-t="btn.download"></button></div><div class="banner-down" data-u="downloading"><p class="small banner-line"><span data-t="card.update.downloading"></span><span class="slow"><span data-t="card.update.slow"></span><button class="btn" data-look="link" data-act="manualDownload" data-t="btn.manualDownload"></button></span></p><div class="bar"><span class="bar-fill"></span></div></div><p class="small" data-u="installing" data-t="card.update.installing"></p><div class="banner-fail" data-u="failed"><p class="small danger" data-t="card.update.failed"></p><button class="btn" data-look="small" data-act="installUpdate" data-t="btn.retry"></button><button class="btn" data-look="small" data-act="manualDownload" data-t="btn.manualDownload"></button></div></div><div class="card-actions"><button class="btn" data-look="primary" data-act="retry" data-main data-t="btn.retry"></button><button class="btn" data-look="soft" data-act="pick" data-detail="changePlace" data-places data-t="btn.changePlace" hidden></button><button class="btn" data-look="soft" data-act="freshStart" data-places data-t="btn.freshStart" hidden></button><button class="btn" data-look="soft" data-act="openLogs" data-t="btn.openLogs"></button><button class="btn" data-look="soft" data-act="copyDetails" data-t="btn.copyDetails"></button><button class="btn disclose" data-look="link" data-act="toggleDetails" aria-expanded="false"><span data-t="btn.details"></span><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4.5 6.2 8 9.7l3.5-3.5"/></svg></button></div><div class="log" hidden><pre></pre></div></div></section><section class="card" data-kind="viewFailed" hidden><div class="card-actions"><button class="btn" data-look="primary" data-act="reloadView" data-t="btn.reload"></button><button class="btn" data-look="soft" data-act="openLogs" data-t="btn.openLogs"></button><button class="btn" data-look="soft" data-act="copyDetails" data-t="btn.copyDetails"></button></div></section></div></section>diff --git a/app/src/start/text.mjs b/app/src/start/text.mjsindex e8bcca1c..9bbb3820 100644--- a/app/src/start/text.mjs+++ b/app/src/start/text.mjs@@ -118,7 +118,6 @@ export const TEXT = {'btn.copyDetails': '复制详细信息','btn.copied': '已复制','btn.details': '详细信息',- 'btn.install': '下载并安装','btn.manualDownload': '手动下载','btn.reload': '重新载入','btn.move': '移动并重启',@@ -273,7 +272,6 @@ export const TEXT = {'btn.copyDetails': 'Copy details','btn.copied': 'Copied','btn.details': 'Details',- 'btn.install': 'Download and install','btn.manualDownload': 'Download manually','btn.reload': 'Reload','btn.move': 'Move and restart',diff --git a/app/src/updates.mjs b/app/src/updates.mjsindex a70fc341..4aa6ccac 100644--- a/app/src/updates.mjs+++ b/app/src/updates.mjs@@ -4,6 +4,9 @@const CHECK_EVERY_MS = 4 * 60 * 60_000export const RELEASES_URL = 'https://api.github.com/repos/Fei2411/DS-Bot/releases?per_page=20'+// Where a user downloads the newest version by hand.+export const RELEASE_PAGE = 'https://github.com/Fei2411/DS-Bot/releases/latest'+const MB = 1024 * 1024function parseVersion(version) {if (typeof version !== 'string') return null@@ -156,13 +159,14 @@ export function watchReleases({ current, arch, fetch = globalThis.fetch, ask, op* stop: () => void,* latest: () => Promise<{ version: string, downloaded: Promise<boolean> } | null>,* install: () => Promise<void>,- * state: () => { phase: string, version?: string, page?: string },+ * state: () => { phase: string, version?: string, page?: string, percent?: number, received?: number, total?: number },* subscribe: (listener: (state: { phase: string }) => void) => () => void,* check: () => void,* }} `latest` is what the newest check found: the version and whether its download finished.* `install` stops the Host and runs the installer, which opens the app again. `state` is- * the phase the About row shows; `check` runs the same check the timer does and does- * nothing while a check, a download or a ready install is on.+ * the phase the About row shows, with the download's per cent and MB while it downloads;+ * `check` runs the same check the timer does and does nothing while a check, a download or a+ * ready install is on.*/export function watchUpdates({ updater, beforeInstall, ask, feed, log = console }) {updater.autoDownload = true@@ -177,6 +181,13 @@ export function watchUpdates({ updater, beforeInstall, ask, feed, log = consoleupdater.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`)holder.set({ phase: 'downloaded', version })diff --git a/app/test/main-fail-update.test.mjs b/app/test/main-fail-update.test.mjsnew file mode 100644index 00000000..16b0ded0--- /dev/null+++ b/app/test/main-fail-update.test.mjs@@ -0,0 +1,62 @@+// 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 { 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')+})diff --git a/app/test/start-window.test.mjs b/app/test/start-window.test.mjsindex 956bd921..9ac0fe9a 100644--- a/app/test/start-window.test.mjs+++ b/app/test/start-window.test.mjs@@ -116,7 +116,7 @@ test('only a missing file of the app\'s own says that the install is incomplete'})test('the main process takes only its own acts, each in its own views', () => {- assert.deepEqual([...START_ACTS].sort(), ['answer', 'copyDetails', 'handoffDone', 'handoffShow', 'openLogs', 'pick', 'reloadView', 'retry', 'wait'])+ assert.deepEqual([...START_ACTS].sort(), ['answer', 'copyDetails', 'handoffDone', 'handoffShow', 'installUpdate', 'manualDownload', 'openLogs', 'pick', 'reloadView', 'retry', 'wait'])assert.equal(acceptsAct('handoffShow', 'handoff'), true)// 「换个位置…」 while the start boots and 〔重新选〕 on its cards; a card's answer only on a card.assert.equal(acceptsAct('pick', 'boot'), true)@@ -136,12 +136,17 @@ test('the main process takes only its own acts, each in its own views', () => {assert.equal(acceptsAct('wait', 'failed'), false)assert.equal(acceptsAct('reloadView', 'viewFailed'), true)assert.equal(acceptsAct('reloadView', 'failed'), false)+ // The failure page's update banner.+ for (const name of ['installUpdate', 'manualDownload']) {+ assert.equal(acceptsAct(name, 'failed'), true)+ for (const view of ['boot', 'card', 'viewFailed', 'watchdog', 'handoff', 'moving']) assert.equal(acceptsAct(name, view), false, `${name} in ${view}`)+ }for (const view of ['boot', 'failed', 'viewFailed', 'watchdog', 'handoff', 'moving']) {assert.equal(acceptsAct('openLogs', view), true)assert.equal(acceptsAct('copyDetails', view), true)}// The cards of later pull requests, and names that are not acts at all.- for (const name of ['reload', 'toggleDetails', 'freshStart', 'installUpdate', 'manualDownload', 'stopCopy', 'keepCopying', 'importModel', 'importOption', '__proto__', 'constructor', 'toString', '']) {+ for (const name of ['reload', 'toggleDetails', 'freshStart', 'stopCopy', 'keepCopying', 'importModel', 'importOption', '__proto__', 'constructor', 'toString', '']) {assert.equal(acceptsAct(name, 'failed'), false, name)}assert.equal(acceptsAct(undefined, 'failed'), false)@@ -314,13 +319,13 @@ function startWindow(t) {t.mock.method(console, 'log', () => {})const fake = fakeElectron()const main = new fake.electron.BrowserWindow({ show: false })- const calls = { retry: 0, reload: 0, close: 0, pick: [], answer: [] }+ const calls = { retry: 0, reload: 0, close: 0, pick: [], answer: [], update: [] }const start = new StartWindow({electron: fake.electron, page: join(tmpdir(), 'start', 'start.html'), preload: 'preload.cjs', icon: 'icon.ico', mica: false, devTools: false,lang: () => 'en', motion: 'normal', version: '0.0.0', program: [], log: { dir: 'logs', tail: () => ['a log line'] },mainWindow: () => main,onRetry: () => { calls.retry += 1 }, onReload: () => { calls.reload += 1 }, onClose: () => { calls.close += 1 },- onPick: (value) => { calls.pick.push(value) }, onAnswer: (value) => { calls.answer.push(value) },+ onPick: (value) => { calls.pick.push(value) }, onAnswer: (value) => { calls.answer.push(value) }, onUpdate: (name) => { calls.update.push(name) },})const win = () => fake.windows.at(-1)const page = () => ({ sender: win().webContents, senderFrame: win().webContents.mainFrame })@@ -749,6 +754,27 @@ test('a move from a later start turns the start window into the move\'s and dropassert.equal('card' in m.state(), false)})+test('the failure page carries the update banner until a retry', (t) => {+ const u = startWindow(t)+ u.start.open('first')+ // Not before the failure page.+ u.start.done('data')+ u.start.update({ state: 'available', version: '9.9.9', page: true })+ assert.equal('update' in u.state(), false)+ u.start.fail(new Error('the Host did not start'), 'first')+ u.start.update({ state: 'downloading', version: '9.9.9', percent: 37, received: 78, total: 212 })+ assert.deepEqual(u.state().update, { state: 'downloading', version: '9.9.9', percent: 37, received: 78, total: 212 })+ u.start.update({ state: 'installing', version: '9.9.9' })+ assert.deepEqual(u.state().update, { state: 'installing', version: '9.9.9' })+ assert.equal(u.act('installUpdate'), true)+ assert.equal(u.act('manualDownload'), true)+ assert.deepEqual(u.calls.update, ['installUpdate', 'manualDownload'])+ assert.equal(u.act('retry'), true)+ assert.equal('update' in u.state(), false)+ assert.equal(u.act('manualDownload'), false)+ assert.deepEqual(u.calls.update, ['installUpdate', 'manualDownload'])+})+test('a card shows only while the start boots or the data moves', (t) => {const c = startWindow(t)c.start.open('first')diff --git a/app/test/updates.test.mjs b/app/test/updates.test.mjsindex 6aa47e87..f739663f 100644--- a/app/test/updates.test.mjs+++ b/app/test/updates.test.mjs@@ -514,6 +514,29 @@ describe('watchUpdates', () => {assert.deepEqual(updates.state(), { phase: 'downloaded', version: '0.1.9' })})+ test('the download reports its per cent and MB, once per whole per cent', (t) => {+ const updater = new FakeUpdater()+ const updates = watchUpdates({ updater, beforeInstall: async () => {}, log: quietLog() })+ t.after(updates.stop)+ const seen = []+ updates.subscribe(state => seen.push(state))+ // No download, no progress.+ updater.emit('download-progress', { percent: 5, transferred: 1, total: 2 })+ assert.deepEqual(seen, [])+ updater.emit('update-available', { version: '0.1.9' })+ const MB = 1024 * 1024+ updater.emit('download-progress', { percent: 37.4, transferred: 78.2 * MB, total: 212 * MB })+ updater.emit('download-progress', { percent: 37.9, transferred: 79 * MB, total: 212 * MB })+ updater.emit('download-progress', { percent: 38.1, transferred: 80.6 * MB, total: 212 * MB })+ updater.emit('download-progress', { percent: Number.NaN })+ assert.deepEqual(seen.slice(1), [+ { phase: 'downloading', version: '0.1.9', percent: 37, received: 78, total: 212 },+ { phase: 'downloading', version: '0.1.9', percent: 38, received: 81, total: 212 },+ ])+ updater.emit('update-downloaded', { version: '0.1.9' })+ assert.deepEqual(updates.state(), { phase: 'downloaded', version: '0.1.9' })+ })+test('a failed check or download reports failed, unless an update is already downloaded', (t) => {const updater = new FakeUpdater()const updates = watchUpdates({ updater, beforeInstall: async () => {}, log: quietLog() })