The merge combined old callers with newer lifecycle and update modules. It also dropped native handlers while keeping their preload methods. Type declarations alone could not repair those runtime failures. Restore bounded backend teardown and retain failed-stop ownership. Use API-only passive checkout checks with a daily disk cache, and pass manual refresh requests through the updater strategy. Keep the shared About UI and restore onboarding, feature flags, and notification wiring. Verified all workspace typechecks, lint on the changed desktop files, focused UI and Electron tests, and the development bundle. A headless Electron smoke test exercised the real main process, preload, and native IPC. A separate test exercised update checks with a linked git worktree, loopback HTTP, and the disk cache. The full repository suite was not run.
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { statSync } from 'node:fs'
|
|
import * as os from 'node:os'
|
|
|
|
import { beforeEach, expect, it, vi } from 'vitest'
|
|
|
|
const host = vi.hoisted(() => ({
|
|
getGPUInfo: vi.fn(),
|
|
getLocale: vi.fn((): string => 'fr-CA'),
|
|
handle: vi.fn()
|
|
}))
|
|
|
|
vi.mock('electron', () => ({
|
|
app: { getGPUInfo: host.getGPUInfo, getLocale: host.getLocale },
|
|
ipcMain: { handle: host.handle }
|
|
}))
|
|
|
|
import type { MachineProfile } from './machine-profile'
|
|
import { registerMachineProfile } from './machine-profile'
|
|
|
|
beforeEach((): void => {
|
|
host.handle.mockReset()
|
|
host.getGPUInfo.mockReset()
|
|
host.getLocale.mockClear()
|
|
})
|
|
|
|
function handler(): () => Promise<MachineProfile> {
|
|
registerMachineProfile()
|
|
const registration = host.handle.mock.calls.find(([channel]): boolean => channel === 'hermes:machine:profile')
|
|
expect(registration).toBeDefined()
|
|
|
|
return registration![1] as () => Promise<MachineProfile>
|
|
}
|
|
|
|
it('registers the renderer channel and reports native machine facts with the OS locale and GPU', async (): Promise<void> => {
|
|
host.getGPUInfo.mockResolvedValue({ gpuDevice: [{ vendorId: 0x8086 }, { vendorId: 0x10de }] })
|
|
const result = await handler()()
|
|
const { birthtimeMs } = statSync(os.homedir())
|
|
|
|
expect(result).toMatchObject({
|
|
ageDays: birthtimeMs > 0 ? Math.max(0, Math.floor((Date.now() - birthtimeMs) / 86_400_000)) : null,
|
|
arch: process.arch,
|
|
locale: 'fr-CA',
|
|
nvidia: true,
|
|
platform: process.platform,
|
|
release: os.release(),
|
|
username: os.userInfo().username
|
|
})
|
|
expect(typeof result.model).toBe('string')
|
|
expect(host.getGPUInfo).toHaveBeenCalledWith('basic')
|
|
})
|
|
|
|
it('keeps machine facts available when Chromium cannot enumerate GPUs', async (): Promise<void> => {
|
|
host.getGPUInfo.mockRejectedValue(new Error('GPU info unavailable'))
|
|
const result = await handler()()
|
|
|
|
expect(result.nvidia).toBe(false)
|
|
expect(result.platform).toBe(process.platform)
|
|
expect(result.locale).toBe('fr-CA')
|
|
})
|