Files
Reims-Go/frontend/scripts/test-guest-drivers.mjs
T
YXC0915 577b2f73ed
Windows CI / verify (push) Successful in 6m28s
Merge GitHub client updates into the Gitea mainline
2026-12-07 03:33:06 +08:00

55 lines
3.0 KiB
JavaScript

import assert from 'node:assert/strict'
import test from 'node:test'
import { loadTestModule } from './load-test-module.mjs'
const { defaultGuestDriver, eligibleGuestDrivers, hasRestoreImagePicker, needsRuntimeSetup, restoreImageField } = await loadTestModule(`export * from './lib/guestDrivers'`)
const mac = { os: 'darwin', arch: 'arm64' }
const win = { os: 'windows', arch: 'amd64' }
const restore = { type: 'string', 'x-filePattern': '*.ipsw' }
const create_schema = { properties: { restore_path: restore } }
const native = { id: 'example.native', runtime_kind: 'external', builtin: true, create_schema }
const thirdParty = { id: 'example.additional', runtime_kind: 'external', create_schema }
const legacy = { id: 'builtin.driver.reims-macos', runtime_kind: 'reims-vgpu', builtin: true }
test('Apple Silicon skips portable runtime setup, but Windows still offers it when missing', () => {
assert.equal(needsRuntimeSetup(mac, false), false)
assert.equal(needsRuntimeSetup(win, false), true)
assert.equal(needsRuntimeSetup(win, true), false)
assert.equal(needsRuntimeSetup({ os: 'darwin', arch: 'amd64' }, false), true)
})
test('a host-provided external driver can create without a portable runtime', () => {
const eligible = eligibleGuestDrivers([legacy, native, thirdParty], false)
assert.deepEqual(eligible, [native, thirdParty])
assert.equal(defaultGuestDriver(eligible, mac), native)
assert.equal(defaultGuestDriver([thirdParty, native], mac), thirdParty)
assert.equal(defaultGuestDriver(eligible, mac, 'offline'), undefined)
assert.equal(defaultGuestDriver([thirdParty, legacy], win), legacy)
assert.equal(defaultGuestDriver([thirdParty, legacy], win, 'online'), legacy)
assert.deepEqual(eligibleGuestDrivers([legacy, native], true), [legacy, native])
})
test('Windows exposes only the managed drivers with their matching runtime', () => {
const arm = { id: 'builtin.driver.stambha', runtime_kind: 'stambha-hosted', builtin: true }
const drivers = [legacy, arm]
assert.deepEqual(eligibleGuestDrivers(drivers, false, true), [arm])
assert.equal(defaultGuestDriver([arm], win), arm)
assert.deepEqual(eligibleGuestDrivers(drivers, true, false), [legacy])
assert.deepEqual(eligibleGuestDrivers(drivers, true, true), drivers)
})
test('cached IPSW routes only to the trusted native restore driver', () => {
assert.equal(defaultGuestDriver([thirdParty, legacy, native], mac, 'ipsw'), native)
assert.equal(defaultGuestDriver([thirdParty, legacy], mac, 'ipsw'), undefined)
assert.equal(defaultGuestDriver([legacy, native], win, 'ipsw'), undefined)
assert.equal(restoreImageField(native, mac), 'restore_path')
})
test('only a host-trusted create schema can add the IPSW picker', () => {
assert.equal(hasRestoreImagePicker(native, restore), true)
assert.equal(hasRestoreImagePicker(thirdParty, restore), false)
assert.equal(hasRestoreImagePicker(native, { ...restore, 'x-filePattern': '*.ipsw;*' }), false)
assert.equal(hasRestoreImagePicker(native, { ...restore, type: 'integer' }), false)
})