A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Check the desktop app's update in CI
Fei24112bff99faaa12
diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 6a506b42..867c4183 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -75,13 +75,15 @@ jobs:app-package:name: Desktop app package (Windows)runs-on: windows-latest- timeout-minutes: 30+ timeout-minutes: 45defaults:run:shell: bashworking-directory: appsteps:- uses: actions/checkout@v4+ with:+ fetch-depth: 0- uses: actions/setup-node@v4with:node-version: 24@@ -92,7 +94,7 @@ jobs:# The runner is a fresh machine, so the installer may run here. It must install for the# current user only, the installed app must pass the same check, and the uninstaller must# remove it again.- - name: Install, check and uninstall+ - name: Install and checkshell: pwshrun: |$ErrorActionPreference = 'Stop'@@ -110,6 +112,54 @@ jobs:if (Find-Entry 'HKLM:') { throw 'The installer installed for all users' }node scripts/check-packed.mjs $exeif ($LASTEXITCODE -ne 0) { throw 'The installed app failed its check' }++ # The update builds the app a second time, so it runs only for changes to the app or the+ # workflows. A build of the next version is the feed; the installed app downloads it, checks+ # its sha512, and installs it as it quits.+ - name: Does the change touch the app?+ id: scope+ run: |+ if [ "$GITHUB_EVENT_NAME" != pull_request ] || git diff --name-only "origin/$GITHUB_BASE_REF...HEAD" | grep -qE '^(app/|\.github/workflows/)'; then+ echo "update=true" >> "$GITHUB_OUTPUT"+ fi+ - name: Build the next version+ if: steps.scope.outputs.update == 'true'+ run: |+ next="$(node -p "const [a, b, c] = require('./package.json').version.split(/[.-]/u); [a, b, Number(c) + 1].join('.')")"+ echo "NEXT_VERSION=$next" >> "$GITHUB_ENV"+ npx electron-builder --publish never -c.extraMetadata.version="$next" -c.directories.output=dist-next+ - name: Update the installed app and check it+ if: steps.scope.outputs.update == 'true'+ shell: pwsh+ run: |+ $ErrorActionPreference = 'Stop'+ $exe = Join-Path $env:LOCALAPPDATA 'Programs\DeepSeek Bot\DeepSeek Bot.exe'+ node scripts/check-update.mjs $exe dist-next+ if ($LASTEXITCODE -ne 0) { throw 'The installed app did not take the update' }+ # The installer goes on after the app has quit.+ function Installed-Version {+ Get-ChildItem 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall' |+ ForEach-Object { Get-ItemProperty $_.PSPath } |+ Where-Object { $_.DisplayName -like 'DeepSeek Bot*' } |+ Select-Object -ExpandProperty DisplayVersion+ }+ $deadline = (Get-Date).AddSeconds(240)+ while ((Installed-Version) -ne $env:NEXT_VERSION -and (Get-Date) -lt $deadline) { Start-Sleep -Seconds 3 }+ if ((Installed-Version) -ne $env:NEXT_VERSION) { throw "The installed version is $(Installed-Version), not $env:NEXT_VERSION" }+ while ((Get-Process | Where-Object { $_.Path -like '*deepseek-bot-updater*' }) -and (Get-Date) -lt $deadline) { Start-Sleep -Seconds 2 }+ node scripts/check-packed.mjs $exe+ if ($LASTEXITCODE -ne 0) { throw 'The updated app failed its check' }++ - name: Uninstall+ shell: pwsh+ run: |+ $ErrorActionPreference = 'Stop'+ function Find-Entry($root) {+ Get-ChildItem "$root\Software\Microsoft\Windows\CurrentVersion\Uninstall" |+ Where-Object { (Get-ItemProperty $_.PSPath).DisplayName -like 'DeepSeek Bot*' }+ }+ $dir = Join-Path $env:LOCALAPPDATA 'Programs\DeepSeek Bot'+ $exe = Join-Path $dir 'DeepSeek Bot.exe'# The uninstaller removes the program only: the data location and the app's own data stay.$kept = foreach ($folder in (Join-Path $HOME '.ds-bot'), (Join-Path $env:APPDATA 'DeepSeek Bot')) {New-Item -ItemType Directory -Force $folder | Out-Nulldiff --git a/.gitignore b/.gitignoreindex baee991a..7ab1e5d9 100644--- a/.gitignore+++ b/.gitignore@@ -1,8 +1,10 @@node_modules/*.tgz-# The desktop app's window build (npm run build in app/) and its packages (npm run pack, npm run dist).+# The desktop app's window build (npm run build in app/), its packages (npm run pack, npm run dist)+# and the next version that checks its update (see app/README.md)./app/ui/dist//app/dist-pack/+/app/dist-next/# A DeepSeek Harness checkout for the tests and the test bench./deepseek-harness/diff --git a/app/scripts/check-update.mjs b/app/scripts/check-update.mjsnew file mode 100644index 00000000..a0c97690--- /dev/null+++ b/app/scripts/check-update.mjs@@ -0,0 +1,77 @@+// Check the update of a packaged app on Windows: serve a folder with a latest.yml and its+// installer, start the app on throwaway folders with that feed, and wait until the app has+// downloaded the update and checked its sha512. Then close the app as a user does, so that it+// installs the update as it quits, or with --kill end it at once, so that nothing is installed.+// Usage: node scripts/check-update.mjs <app executable> <feed folder> [--kill]+import { spawn, spawnSync } from 'node:child_process'+import { createReadStream, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync } from 'node:fs'+import { createServer } from 'node:http'+import { tmpdir } from 'node:os'+import { basename, join, resolve } from 'node:path'+import { setTimeout as sleep } from 'node:timers/promises'++const [executable, feedDir, mode] = process.argv.slice(2)+if (!executable || !feedDir || !existsSync(executable) || !existsSync(join(feedDir, 'latest.yml'))) {+ console.error('check-update: usage: node scripts/check-update.mjs <app executable> <feed folder with latest.yml> [--kill]')+ process.exit(2)+}+const version = /^version:\s*(\S+)/mu.exec(readFileSync(join(feedDir, 'latest.yml'), 'utf8'))?.[1]+const work = mkdtempSync(join(tmpdir(), 'ds-bot-update-'))+mkdirSync(join(work, 'home'))++const served = []+const server = createServer((request, response) => {+ const name = basename(decodeURIComponent(new URL(request.url, 'http://feed/').pathname))+ const file = join(feedDir, name)+ served.push(name)+ if (!existsSync(file) || !statSync(file).isFile()) { response.writeHead(404).end(); return }+ response.writeHead(200, { 'content-length': statSync(file).size })+ createReadStream(file).pipe(response)+})+await new Promise((done) => { server.listen(0, '127.0.0.1', done) })+const feed = `http://127.0.0.1:${String(server.address().port)}/`++let failed = false+let app+try {+ // A terminal inside an Electron-based editor may set ELECTRON_RUN_AS_NODE, which turns the app into plain Node.+ const { ELECTRON_RUN_AS_NODE: _runAsNode, ...env } = process.env+ Object.assign(env, { DS_BOT_HOME: join(work, 'home'), DS_BOT_SHELL_DATA: join(work, 'shell'), DS_BOT_UPDATE_URL: feed })+ app = spawn(resolve(executable), [], { env, stdio: ['ignore', 'pipe', 'pipe'] })+ const exited = new Promise((done) => { app.once('exit', (code) => { done(code) }) })+ let output = ''+ for (const stream of [app.stdout, app.stderr]) {+ stream.setEncoding('utf8')+ stream.on('data', (chunk) => { output += chunk; process.stdout.write(chunk) })+ }+ const downloaded = `DeepSeek Bot: update ${String(version)} downloaded`+ const end = Date.now() + 5 * 60_000+ while (!output.includes(downloaded)) {+ if (/DeepSeek Bot: update failed/u.test(output)) throw new Error('the app reported a failed update')+ if (app.exitCode !== null) throw new Error(`the app exited (code ${String(app.exitCode)}) before the update was downloaded`)+ if (Date.now() > end) throw new Error('the update was not downloaded within 5 minutes')+ await sleep(500)+ }+ console.log(`check-update: ${downloaded}; the feed served ${served.join(', ')}`)+ if (mode === '--kill') {+ spawnSync('taskkill', ['/pid', String(app.pid), '/T', '/F'], { stdio: 'ignore' })+ await exited+ console.log('check-update: ended the app, so nothing was installed')+ } else {+ // Without /F, taskkill asks the window to close, as a user closing it does.+ spawnSync('taskkill', ['/pid', String(app.pid)], { stdio: 'ignore' })+ const code = await Promise.race([exited, sleep(60_000).then(() => 'timeout')])+ if (code === 'timeout') throw new Error('the app did not exit after its window closed')+ if (code !== 0) throw new Error(`the app exited with code ${String(code)}, so it does not install the update`)+ console.log('check-update: the app closed; its installer runs now')+ }+ console.log('check-update: passed')+} catch (error) {+ failed = true+ console.error(`check-update: FAILED: ${error instanceof Error ? error.message : String(error)}`)+ if (app?.exitCode === null) spawnSync('taskkill', ['/pid', String(app.pid), '/T', '/F'], { stdio: 'ignore' })+}+server.close()+await sleep(500)+rmSync(work, { recursive: true, force: true, maxRetries: 10, retryDelay: 500 })+process.exit(failed ? 1 : 0)