Files
Reims-Go/frontend/scripts/test-endpoints.mjs
T
千川白浪 e0ff794b0e feat: add experimental macOS desktop support on Apple Silicon (#207)
* feat: add experimental Apple Silicon support with Nivfold

Integrate the standalone Nivfold protocol 1 runner; tested against Nivfold f436fb6. The Windows Reims vGPU runtime remains independent.

* fix: open QQ invites and VM SSH on macOS

* fix: move VM, View and Help to the macOS menu bar

* feat(macos): add resumable Apple restore image downloads

Expose the compatible restore image in the VM wizard and Images page, validate downloads before caching, and fix macOS memory reporting and plugin SVG rendering.

* fix(macos): localize the native application menu

* fix(macos): address native desktop review findings
2026-12-06 00:47:07 +08:00

170 lines
7.6 KiB
JavaScript

import assert from 'node:assert/strict'
import test from 'node:test'
import { loadTestModule } from './load-test-module.mjs'
const lib = await loadTestModule(`export * from './lib/endpoints'`)
const ep = (kind, ready = true, extra = {}) => ({ kind, ready, ...extra })
test('guest family comes from the driver, else the builtin macOS driver, else unknown', () => {
assert.equal(lib.guestFamilyOf({ driver_id: 'acme.linux', guest_os: { family: 'linux' } }), 'linux')
assert.equal(lib.guestFamilyOf({ driver_id: 'builtin.driver.reims-macos' }), 'macos')
assert.equal(lib.guestFamilyOf({ driver_id: '' }), 'macos')
assert.equal(lib.guestFamilyOf({ driver_id: 'acme.other' }), '')
assert.equal(lib.guestFamilyOf({ driver_id: 'acme.other', guest_os: { family: 'plan9' } }), '')
assert.equal(lib.guestFamilyOf(undefined), '')
})
test('capability helpers read the capability list only', () => {
assert.equal(lib.hasCap(['qmp', 'ssh'], 'qmp'), true)
assert.equal(lib.hasCap(['qmp'], 'ssh'), false)
assert.equal(lib.hasCap(undefined, 'qmp'), false)
assert.equal(lib.isHosted(['hosted', 'rdp']), true)
assert.equal(lib.isHosted(['qmp']), false)
})
test('the primary endpoint is the highest-priority ready one', () => {
assert.deepEqual([...lib.ENDPOINT_PRIORITY], ['vmconnect', 'rdp', 'wsl', 'ssh', 'adb'])
const all = [ep('adb'), ep('ssh'), ep('wsl'), ep('rdp'), ep('vmconnect')]
const { primary, rest } = lib.splitEndpoints(all)
assert.equal(primary.kind, 'vmconnect')
assert.deepEqual(rest.map((e) => e.kind), ['rdp', 'wsl', 'ssh', 'adb'])
})
test('a not-ready endpoint never becomes primary and stays in the rest', () => {
const { primary, rest } = lib.splitEndpoints([ep('vmconnect', false), ep('ssh'), ep('rdp', false)])
assert.equal(primary.kind, 'ssh')
assert.deepEqual(rest.map((e) => e.kind), ['vmconnect', 'rdp'])
})
test('without a ready endpoint there is no primary and nothing is dropped', () => {
const none = lib.splitEndpoints([ep('ssh', false), ep('adb', false)])
assert.equal(none.primary, undefined)
assert.deepEqual(none.rest.map((e) => e.kind), ['ssh', 'adb'])
assert.deepEqual(lib.splitEndpoints(undefined), { rest: [] })
assert.deepEqual(lib.splitEndpoints(null), { rest: [] })
})
test('the primary endpoint is never repeated in the rest, even with several of one kind', () => {
const first = ep('ssh', true, { port: 22 })
const second = ep('ssh', true, { port: 2222 })
const { primary, rest } = lib.splitEndpoints([first, second])
assert.equal(primary, first)
assert.equal(rest.length, 1)
assert.equal(rest[0], second)
})
test('an unknown endpoint kind is kept last and is never primary', () => {
const { primary, rest } = lib.splitEndpoints([ep('serial'), ep('adb')])
assert.equal(primary.kind, 'adb')
assert.deepEqual(rest.map((e) => e.kind), ['serial'])
assert.deepEqual(lib.endpointActions('serial'), [])
})
test('the endpoint list is ordered by priority with unknown kinds last', () => {
const ordered = lib.orderEndpoints([ep('serial'), ep('adb'), ep('vmconnect', false), ep('ssh')])
assert.deepEqual(ordered.map((e) => e.kind), ['vmconnect', 'ssh', 'adb', 'serial'])
assert.deepEqual(lib.orderEndpoints(undefined), [])
})
test('every kind lists its actions with the default first', () => {
assert.deepEqual(lib.endpointActions('ssh'), ['terminal', 'vscode', 'config'])
assert.deepEqual(lib.endpointActions('wsl'), ['terminal', 'vscode'])
assert.deepEqual(lib.endpointActions('rdp'), ['open'])
assert.deepEqual(lib.endpointActions('vmconnect'), ['open', 'edit'])
assert.deepEqual(lib.endpointActions('adb'), ['shell', 'copy'])
assert.equal(lib.defaultEndpointAction('vmconnect'), 'open')
assert.deepEqual(lib.secondaryEndpointActions('vmconnect'), ['edit'])
assert.deepEqual(lib.secondaryEndpointActions('rdp'), [])
})
test('macOS VMs keep every action; other VMs follow their capabilities', () => {
const mac = lib.vmFeatures({ driver_id: 'builtin.driver.reims-macos', capabilities: [] })
assert.deepEqual(
Object.entries(mac).filter(([k, v]) => k !== 'hosted' && v === false), [],
)
const plain = lib.vmFeatures({ driver_id: 'acme.linux', capabilities: ['snapshot', 'qmp'] })
assert.equal(plain.snapshot, true)
assert.equal(plain.clone, false)
assert.equal(plain.resize, false)
assert.equal(plain.affinity, false)
assert.equal(plain.screenshot, true)
assert.equal(plain.sendText, true)
assert.equal(plain.suspend, false)
assert.equal(plain.fullscreen, true)
assert.equal(plain.window, true)
const withAffinity = lib.vmFeatures({ driver_id: 'acme.linux', capabilities: ['affinity', 'cow_clone', 'resize', 'suspend'] })
assert.equal(withAffinity.affinity, true)
assert.equal(withAffinity.clone, true)
assert.equal(withAffinity.resize, true)
assert.equal(withAffinity.suspend, true)
assert.equal(withAffinity.screenshot, false)
})
test('hosted VMs without a window or console do not offer process or display controls', () => {
const hosted = lib.vmFeatures({
driver_id: 'acme.wsl',
capabilities: ['hosted', 'affinity', 'qmp', 'snapshot'],
})
assert.equal(hosted.hosted, true)
assert.equal(hosted.window, false)
assert.equal(hosted.fullscreen, false)
assert.equal(hosted.affinity, false)
assert.equal(hosted.screenshot, false)
assert.equal(hosted.sendText, false)
assert.equal(hosted.snapshot, true)
})
test('a hosted native window takes priority over ready endpoints', () => {
const windowed = lib.vmFeatures({ driver_id: 'example.native', capabilities: ['hosted', 'window', 'affinity'] })
const ssh = ep('ssh')
assert.equal(windowed.window, true)
assert.equal(windowed.fullscreen, false)
assert.equal(windowed.affinity, false)
assert.deepEqual(lib.primaryVMAccess(windowed, [ssh]), { kind: 'window' })
assert.deepEqual(lib.primaryVMAccess(windowed, []), { kind: 'window' })
const endpointOnly = lib.vmFeatures({ driver_id: 'example.wsl', capabilities: ['hosted'] })
assert.deepEqual(lib.primaryVMAccess(endpointOnly, [ssh]), { kind: 'endpoint', endpoint: ssh })
assert.equal(lib.primaryVMAccess(endpointOnly, [ep('ssh', false)]), undefined)
})
test('a hosted VM offers screenshots and typing only when its driver serves a console', () => {
const withConsole = lib.vmFeatures({ driver_id: 'acme.wsl', capabilities: ['hosted', 'console'] })
assert.equal(withConsole.screenshot, true)
assert.equal(withConsole.sendText, true)
assert.equal(withConsole.window, false)
assert.equal(withConsole.fullscreen, false)
const without = lib.vmFeatures({ driver_id: 'acme.wsl', capabilities: ['hosted'] })
assert.equal(without.screenshot, false)
assert.equal(without.sendText, false)
})
test('the live VM info takes volatile fields from the polled list entry', () => {
const item = {
name: 'dev', driver_id: 'acme.wsl', dir: '', state: 'running',
capabilities: ['hosted'], ready: false, phase: 'installer', endpoints: [ep('ssh')],
}
const info = {
name: 'dev', driver_id: 'acme.wsl', state: 'stopped', cpus: 4, memory: '8G',
ready: true, endpoints: [ep('rdp')], capabilities: ['hosted', 'snapshot'],
}
const merged = lib.liveVMInfo(item, info)
assert.equal(merged.state, 'running')
assert.equal(merged.cpus, 4)
assert.equal(merged.ready, false)
assert.equal(merged.phase, 'installer')
assert.deepEqual(merged.endpoints.map((e) => e.kind), ['ssh'])
assert.deepEqual(merged.capabilities, ['hosted'])
const noDetail = lib.liveVMInfo(item, null)
assert.equal(noDetail.name, 'dev')
assert.equal(noDetail.cpus, undefined)
assert.equal(noDetail.ready, false)
const other = lib.liveVMInfo(item, { ...info, driver_id: 'acme.other' })
assert.equal(other.cpus, undefined)
})