- Distinguish hypervisor launch disabled (hypervisor_off) from BIOS/UEFI virtualization disabled (no_hypervisor) via unprivileged Win32 & DeviceGuard probes without spawning background PowerShell/BCD processes - Add default-off `enable_hypervisor_switch` preference in Settings -> General with confirmation modal, active VM/task guards, HVCI notice, same-boot undo, and single-UAC System32 execution without auto-restarting Windows - Update Engine page, first-run Setup, `reims-go doctor`, and VM startprep diagnostics for `hypervisor_off` and pending boot states
132 lines
5.2 KiB
JavaScript
132 lines
5.2 KiB
JavaScript
import assert from 'node:assert/strict'
|
||
import test from 'node:test'
|
||
import { loadTestModule } from './load-test-module.mjs'
|
||
|
||
const {
|
||
buildHypervisorSettingsView,
|
||
describeHostWHPX,
|
||
hasHypervisorBlockingWork,
|
||
t,
|
||
} = await loadTestModule(`export * from './lib/hypervisor'; export { t } from './i18n'`)
|
||
|
||
test('hypervisor switch gate is off and collapsed by default to preserve existing UX', () => {
|
||
const view = buildHypervisorSettingsView(
|
||
'zh-CN',
|
||
{ whpx: 'ready', pending_hypervisor_boot: '', hvci_enabled: false, vbs_running: false },
|
||
{},
|
||
false,
|
||
)
|
||
assert.equal(view.supported, true)
|
||
assert.equal(view.gateEnabled, false)
|
||
assert.equal(view.expanded, false)
|
||
})
|
||
|
||
test('unlocked hypervisor settings reflect active, off, pending, undo, and HVCI states', () => {
|
||
const active = buildHypervisorSettingsView(
|
||
'en-US',
|
||
{ whpx: 'ready', pending_hypervisor_boot: '', hvci_enabled: true, vbs_running: true },
|
||
{ enable_hypervisor_switch: true },
|
||
false,
|
||
)
|
||
assert.equal(active.expanded, true)
|
||
assert.equal(active.badgeClass, 'badge-ok')
|
||
assert.equal(active.targetEnable, false)
|
||
assert.equal(active.isUndo, false)
|
||
assert.equal(active.actionVariant, 'secondary')
|
||
assert.equal(active.disableBlockedByVMs, false)
|
||
assert.equal(active.showHVCINotice, true)
|
||
|
||
const blocked = buildHypervisorSettingsView(
|
||
'en-US',
|
||
{ whpx: 'ready', pending_hypervisor_boot: '', hvci_enabled: false, vbs_running: false },
|
||
{ enable_hypervisor_switch: true },
|
||
true,
|
||
)
|
||
assert.equal(blocked.disableBlockedByVMs, true)
|
||
|
||
const pendingOff = buildHypervisorSettingsView(
|
||
'en-US',
|
||
{ whpx: 'ready', pending_hypervisor_boot: 'off', hvci_enabled: false, vbs_running: false },
|
||
{ enable_hypervisor_switch: true },
|
||
false,
|
||
)
|
||
assert.equal(pendingOff.isUndo, true)
|
||
assert.equal(pendingOff.targetEnable, true)
|
||
assert.equal(pendingOff.badgeClass, 'badge-warn')
|
||
|
||
const hvOff = buildHypervisorSettingsView(
|
||
'en-US',
|
||
{ whpx: 'hypervisor_off', pending_hypervisor_boot: '', hvci_enabled: false, vbs_running: false },
|
||
{ enable_hypervisor_switch: true },
|
||
true, // running VMs check should never block enabling Hyper-V
|
||
)
|
||
assert.equal(hvOff.targetEnable, true)
|
||
assert.equal(hvOff.actionVariant, 'primary')
|
||
assert.equal(hvOff.disableBlockedByVMs, false)
|
||
assert.equal(hvOff.showHVCINotice, false)
|
||
})
|
||
|
||
test('hasHypervisorBlockingWork detects running/transitioning VMs and vm-create tasks only', () => {
|
||
assert.equal(hasHypervisorBlockingWork([{ name: 'a', state: 'stopped' }], {}, []), false)
|
||
assert.equal(hasHypervisorBlockingWork([{ name: 'a', state: 'suspended' }], {}, []), false)
|
||
assert.equal(hasHypervisorBlockingWork([{ name: 'a', state: 'running' }], {}, []), true)
|
||
assert.equal(hasHypervisorBlockingWork([{ name: 'a', state: 'stopped' }], { a: 'starting' }, []), true)
|
||
assert.equal(
|
||
hasHypervisorBlockingWork(
|
||
[{ name: 'a', state: 'stopped' }],
|
||
{},
|
||
[{ id: 't1', kind: 'installer-download', status: 'running' }],
|
||
),
|
||
false,
|
||
)
|
||
assert.equal(
|
||
hasHypervisorBlockingWork(
|
||
[{ name: 'a', state: 'stopped' }],
|
||
{},
|
||
[{ id: 't2', kind: 'vm-create', status: 'running' }],
|
||
),
|
||
true,
|
||
)
|
||
})
|
||
|
||
test('describeHostWHPX distinguishes hypervisor_off from BIOS no_hypervisor and pending states', () => {
|
||
const ready = describeHostWHPX('zh-CN', { whpx: 'ready', pending_hypervisor_boot: '' })
|
||
assert.equal(ready.tone, 'ok')
|
||
assert.equal(ready.canEnable, false)
|
||
|
||
const hvOff = describeHostWHPX('zh-CN', { whpx: 'hypervisor_off', pending_hypervisor_boot: '' })
|
||
assert.equal(hvOff.tone, 'warn')
|
||
assert.equal(hvOff.canEnable, true)
|
||
|
||
const noHv = describeHostWHPX('zh-CN', { whpx: 'no_hypervisor', pending_hypervisor_boot: '' })
|
||
assert.equal(noHv.tone, 'warn')
|
||
assert.equal(noHv.canEnable, false)
|
||
|
||
const pendingOn = describeHostWHPX('zh-CN', { whpx: 'hypervisor_off', pending_hypervisor_boot: 'auto' })
|
||
assert.equal(pendingOn.tone, 'warn')
|
||
assert.equal(pendingOn.canEnable, false)
|
||
|
||
// When WHPX is currently ready and pending === 'off', the hint must clarify
|
||
// that WHPX is still active right now and will turn off after restarting Windows.
|
||
const pendingOffZh = describeHostWHPX('zh-CN', { whpx: 'ready', pending_hypervisor_boot: 'off' })
|
||
assert.equal(pendingOffZh.tone, 'warn')
|
||
assert.equal(pendingOffZh.canEnable, false)
|
||
assert.notEqual(pendingOffZh.hint, pendingOn.hint)
|
||
assert.match(pendingOffZh.hint, /当前可用/)
|
||
|
||
const pendingOffEn = describeHostWHPX('en-US', { whpx: 'ready', pending_hypervisor_boot: 'off' })
|
||
assert.match(pendingOffEn.hint, /Active now/i)
|
||
})
|
||
|
||
test('hypervisor action buttons and short notices follow design-guidelines copy rules', () => {
|
||
for (const key of ['hypervisorActionDisable', 'hypervisorActionEnable', 'hypervisorActionUndo', 'hypervisorOpenCoreIsolation', 'hypervisorConfirmDisableBtn', 'hypervisorConfirmEnableBtn']) {
|
||
const zh = t('zh-CN', key)
|
||
const en = t('en-US', key)
|
||
assert.ok(zh.length >= 2 && zh.length <= 5, `zh-CN button ${key}="${zh}" must be 2–5 chars`)
|
||
assert.doesNotMatch(zh, /[。!!请您]|成功/, `zh-CN button ${key}="${zh}" violates copy rules`)
|
||
assert.doesNotMatch(en, /[.!]$/, `en-US button ${key}="${en}" must not end with punctuation`)
|
||
}
|
||
})
|
||
|
||
|