Files
deepseek-harness/apps/desktop/tests/installer-packaging.spec.ts
T
winewill 4745934683 feat(desktop): hide the window on close and confirm interruptible quits
Closing the main window hides it on macOS and Windows; the page and the
Host keep running and the next show resumes the same document. Windows
gets a permanent tray icon (open / quit) and a one-time notification the
first time the window is hidden after installation.

Every ordinary quit entry asks the Host over a new quit-inspection IPC
request for active tasks (same rule as the update restart check) and
armed scheduled reminders (schedule family of workspace/session-activity
for loaded sessions). Nothing to interrupt quits silently; otherwise a
native message box explains what stops, with Quit as the default and
Cancel on Esc. Inspection failure or a missed two-second deadline counts
as running tasks. The installer restart, fatal recovery, the development
restart command, and OS session end skip the confirmation.

Also: defer the downloaded-update confirmation while the window is hidden,
render the tray ICO from the vector icon, and point the installer's
running-application message at the tray.

Closes #4013
2026-09-24 14:24:39 +08:00

103 lines
5.8 KiB
TypeScript

import { tmpdir } from 'node:os'
import { readFileSync } from 'node:fs'
import { Arch, Platform } from 'electron-builder'
import { Packager } from 'app-builder-lib'
import { describe, expect, it, vi } from 'vitest'
const { execute } = vi.hoisted(() => ({ execute: vi.fn(async () => undefined) }))
vi.mock('node:child_process', async (importOriginal) => {
const original = await importOriginal<typeof import('node:child_process')>()
const { promisify } = await import('node:util')
return { ...original, execFile: Object.assign(vi.fn(), { [promisify.custom]: execute }) }
})
describe('installer preparation preserves application dependencies', () => {
it.each(['win32', 'darwin'] as const)('rejects a missing production policy before signing on %s', async (platform) => {
const { createElectronBuilderConfig } = await import('../scripts/electron-builder-config.mjs')
expect(() => createElectronBuilderConfig({ DSH_DESKTOP_APP_ID: 'com.example.installer',
DSH_DESKTOP_AUTO_UPDATE_ENV: 'production',
DSH_DESKTOP_MANDATORY_UPDATE_TEST_ORIGIN: 'https://test.example.com',
}, platform, 'x64')).toThrow('DSH_DESKTOP_MANDATORY_UPDATE_PROD_ORIGIN')
})
it.each(['win32', 'darwin'] as const)('keeps electron-builder responsible for node_modules on %s', async (platform) => {
execute.mockClear()
const env = {
DSH_DESKTOP_APP_ID: 'com.example.installer',
DSH_DESKTOP_MANDATORY_UPDATE_TEST_ORIGIN: 'https://policy.example.com',
DSH_DESKTOP_MANDATORY_UPDATE_CONFIG: JSON.stringify({ allowedAuthOrigins: ['https://login.example.com'] }),
DSH_DESKTOP_TARGET_PLATFORM: platform,
DSH_DESKTOP_TARGET_ARCH: 'x64',
DSH_DESKTOP_UNSIGNED: platform === 'win32' ? '1' : '0',
DSH_DESKTOP_MACOS_SIGNING_IDENTITY: 'Example Company (TEAMID1234)',
DSH_DESKTOP_MACOS_TEAM_ID: 'TEAMID1234',
APPLE_KEYCHAIN_PROFILE: 'installer-test',
DOWNLOAD_TEST_ORIGIN: 'https://desktop-updates.example.com', DOWNLOAD_TEST_RELEASE_ID: '0123456789abcdef0123456789abcdef',
}
for (const [name, value] of Object.entries(env)) vi.stubEnv(name, value)
try {
const { createElectronBuilderConfig } = await import('../electron-builder.config.mjs')
const config = createElectronBuilderConfig(env, platform, 'x64')
const aboutIcon = config.extraResources.find(resource => resource.to === 'icon.png')
expect(aboutIcon).toBeDefined()
expect(readFileSync(aboutIcon!.from)).toEqual(readFileSync(new URL('../resources/icon-windows.png', import.meta.url)))
// Only the Windows package carries the tray bitmaps; macOS keeps the Dock.
const trayIcon = config.extraResources.find(resource => resource.to === 'tray.ico')
if (platform === 'win32') {
expect(readFileSync(trayIcon!.from)).toEqual(readFileSync(new URL('../resources/tray-windows.ico', import.meta.url)))
} else {
expect(trayIcon).toBeUndefined()
}
const packager = new Packager({ projectDir: tmpdir() })
// A foreign source-build target avoids rebuilding modules; the real dependency ownership decision still runs.
Object.defineProperties(packager, {
config: { value: { beforeBuild: config.beforeBuild, buildDependenciesFromSource: true } },
framework: { value: { isNpmRebuildRequired: true, version: '42.0.0' } },
appInfo: { value: { type: 'module' } },
})
vi.spyOn(packager, 'getWorkspaceRoot').mockResolvedValue(tmpdir())
await packager.installAppDependencies(process.platform === 'win32' ? Platform.LINUX : Platform.WINDOWS, Arch.x64)
expect(packager.areNodeModulesHandledExternally).toBe(false)
expect(execute).toHaveBeenCalledTimes(platform === 'win32' ? 1 : 0)
} finally {
vi.unstubAllEnvs()
vi.restoreAllMocks()
}
})
it('names unsigned Windows artifacts so they cannot pass for release builds', async () => {
const { createElectronBuilderConfig } = await import('../scripts/electron-builder-config.mjs')
const config = createElectronBuilderConfig({
DSH_DESKTOP_APP_ID: 'com.example.installer',
DSH_DESKTOP_MANDATORY_UPDATE_TEST_ORIGIN: 'https://policy.example.com',
DSH_DESKTOP_MANDATORY_UPDATE_CONFIG: JSON.stringify({ allowedAuthOrigins: ['https://login.example.com'] }),
DSH_DESKTOP_TARGET_PLATFORM: 'win32',
DSH_DESKTOP_TARGET_ARCH: 'x64',
DSH_DESKTOP_UNSIGNED: '1',
}, 'win32', 'x64')
expect(config.artifactName).toBe('deepseek-harness-${version}-${os}-${arch}-unsigned.${ext}')
})
it('packages every preload entry point the shell loads', async () => {
const { readdirSync, readFileSync } = await import('node:fs')
const sourceDirectory = new URL('../src/', import.meta.url)
const referenced = new Set<string>()
for (const entry of readdirSync(sourceDirectory, { withFileTypes: true })) {
if (!entry.isFile()) continue
for (const match of readFileSync(new URL(entry.name, sourceDirectory), 'utf8').matchAll(/preload-[a-z-]+\.cjs/gu)) referenced.add(match[0])
}
expect(referenced.size).toBeGreaterThan(0)
const { createElectronBuilderConfig } = await import('../scripts/electron-builder-config.mjs')
const config = createElectronBuilderConfig({
DSH_DESKTOP_APP_ID: 'com.example.installer',
DSH_DESKTOP_AUTO_UPDATE_ENV: 'production',
DSH_DESKTOP_MANDATORY_UPDATE_TEST_ORIGIN: 'https://harness-test.deepseek.com',
DSH_DESKTOP_MANDATORY_UPDATE_PROD_ORIGIN: 'https://policy.example.com',
DSH_DESKTOP_MACOS_SIGNING_IDENTITY: 'Example Company (TEAMID1234)',
DSH_DESKTOP_MACOS_TEAM_ID: 'TEAMID1234',
APPLE_KEYCHAIN_PROFILE: 'installer-test',
}, 'darwin', 'arm64')
const packaged = new Set(config.files.filter((entry): entry is string => typeof entry === 'string'))
for (const name of referenced) expect(packaged.has(`lib/${name}`)).toBe(true)
})
})