import assert from 'node:assert/strict' import test from 'node:test' import { loadTestModule } from './load-test-module.mjs' const mod = await loadTestModule(` import './i18n/domains/settings.gen' import './i18n/domains/wizard.gen' export * from './i18n' export * from './lib/format' export * from './lib/displayResolution' `) const host4K150 = { primary_display: { width: 3840, height: 2160, scale_pct: 150, work_width: 3840, work_height: 2088, primary: true }, display_presets: [ { resolution: '3200x1800', label: '3200 × 1800', hidpi: true, recommended: true }, { resolution: '2880x1620', label: '2880 × 1620', hidpi: true }, { resolution: '2560x1440', label: '2560 × 1440', hidpi: false }, ], fullscreen_hidpi: true, recommended_gpu: { name: 'NVIDIA GeForce RTX 4070', kind: 'discrete' }, gpus: [{ name: 'NVIDIA GeForce RTX 4070', kind: 'discrete' }], } const host32K200 = { primary_display: { width: 3200, height: 2000, scale_pct: 200, work_width: 3200, work_height: 1904, primary: true }, display_presets: [ { resolution: '2880x1800', label: '2880 × 1800', hidpi: true, recommended: true }, { resolution: '2560x1600', label: '2560 × 1600', hidpi: true }, { resolution: '1920x1200', label: '1920 × 1200', hidpi: false }, ], fullscreen_hidpi: true, recommended_gpu: { name: 'Intel(R) Arc Graphics', kind: 'integrated' }, gpus: [{ name: 'Intel(R) Arc Graphics', kind: 'integrated' }], } test('resolveAutoDisplayPreset matches Go RecommendAutoResolution for 4K 16:9 and 3.2K 16:10', () => { // 4K 16:9 @ 150% const win4k = mod.resolveAutoDisplayPreset(host4K150, false, true) assert.equal(win4k.resolution, '3200x1800') assert.equal(win4k.hidpi, true) const fs4kFixed = mod.resolveAutoDisplayPreset(host4K150, true, true) assert.equal(fs4kFixed.resolution, '5120x2880') assert.equal(fs4kFixed.hidpi, true) assert.equal(fs4kFixed.scaleBadge, '1.5×') const fs4kNoFixed = mod.resolveAutoDisplayPreset(host4K150, true, false) assert.equal(fs4kNoFixed.resolution, '3840x2160') assert.equal(fs4kNoFixed.hidpi, true) assert.equal(fs4kNoFixed.native, true) // 3.2K 16:10 @ 200% (scale >= 175 -> native fullscreen even with fixedModeSupported) const win32k = mod.resolveAutoDisplayPreset(host32K200, false, true) assert.equal(win32k.resolution, '2880x1800') assert.equal(win32k.hidpi, true) const fs32kFixed = mod.resolveAutoDisplayPreset(host32K200, true, true) assert.equal(fs32kFixed.resolution, '3200x2000') assert.equal(fs32kFixed.hidpi, true) assert.equal(fs32kFixed.native, true) const fs32kNoFixed = mod.resolveAutoDisplayPreset(host32K200, true, false) assert.equal(fs32kNoFixed.resolution, '3200x2000') assert.equal(fs32kNoFixed.hidpi, true) assert.equal(fs32kNoFixed.native, true) }) test('resolveAutoDisplayPreset falls back safely to 1920x1080 non-HiDPI when host display is empty or invalid (#6)', () => { const emptyHost = {} const winEmpty = mod.resolveAutoDisplayPreset(emptyHost, false, true) assert.equal(winEmpty.resolution, '1920x1080') assert.equal(winEmpty.hidpi, false) for (const fixedModeSupported of [true, false]) { const fsEmpty = mod.resolveAutoDisplayPreset(emptyHost, true, fixedModeSupported) assert.equal(fsEmpty.resolution, '1920x1080') assert.equal(fsEmpty.label, '1920 × 1080') assert.equal(fsEmpty.hidpi, false) assert.equal(fsEmpty.native, true) assert.equal(fsEmpty.recommended, true) const zeroHeightHost = { primary_display: { width: 3200, height: 0, scale_pct: 150, primary: true }, fullscreen_hidpi: true, } const fsZeroHeight = mod.resolveAutoDisplayPreset(zeroHeightHost, true, fixedModeSupported) assert.equal(fsZeroHeight.resolution, '1920x1080') assert.equal(fsZeroHeight.label, '1920 × 1080') assert.equal(fsZeroHeight.hidpi, false) assert.equal(fsZeroHeight.native, true) } }) test('SettingsModal auto resolution never falls into custom or resBad across display and borderless switches', () => { // Auto mode with a resolution from 4K screen, now moved to 3.2K screen where 3200x1800 is not a preset const onLaptop = mod.deriveSettingsResolutionState({ form: { auto_resolution: true, resolution: '3200x1800', borderless: false }, displayProfile: host32K200, fixedModeSupported: true, forceCustomRes: false, }) assert.equal(onLaptop.presetHit, false) assert.equal(onLaptop.customRes, false) assert.equal(onLaptop.resValue, mod.AUTO_RESOLUTION_OPTION) assert.equal(onLaptop.resBad, false) assert.equal(onLaptop.autoPreset.resolution, '2880x1800') // Even empty or invalid resolution string must not trigger resBad while auto_resolution is on const emptyResAuto = mod.deriveSettingsResolutionState({ form: { auto_resolution: true, resolution: '', borderless: false }, displayProfile: host4K150, fixedModeSupported: true, forceCustomRes: true, }) assert.equal(emptyResAuto.customRes, false) assert.equal(emptyResAuto.resBad, false) assert.equal(emptyResAuto.resValue, mod.AUTO_RESOLUTION_OPTION) // Toggling borderless in auto mode keeps auto_resolution intact and refreshes autoPreset const borderlessPatch = mod.toggleSettingsBorderless({ borderless: true, form: { auto_resolution: true, resolution: '3200x1800' }, displayProfile: host4K150, targetDisplay: host4K150.primary_display, presets: onLaptop.presets, fsPresets: onLaptop.fsPresets, customRes: false, }) assert.deepEqual(borderlessPatch, { borderless: true }) const afterBorderless = mod.deriveSettingsResolutionState({ form: { auto_resolution: true, resolution: '3200x1800', borderless: true }, displayProfile: host4K150, fixedModeSupported: true, forceCustomRes: false, }) assert.equal(afterBorderless.resValue, mod.AUTO_RESOLUTION_OPTION) assert.equal(afterBorderless.autoPreset.resolution, '5120x2880') }) test('SettingsModal dirty count, save payload, reset, and custom blur snap-back behave consistently', () => { const baseFixed = { name: 'mac', auto_resolution: false, resolution: '3200x1800', borderless: false } const autoPreset = mod.resolveAutoDisplayPreset(host4K150, false, true) // Fixed -> Auto: keeps base.resolution so only auto_resolution is dirty (count = 1), save diff omits resolution const toAuto = mod.selectSettingsResolution({ value: mod.AUTO_RESOLUTION_OPTION, form: { resolution: '2560x1440' }, base: baseFixed, autoPreset, }) assert.equal(toAuto.forceCustomRes, false) assert.deepEqual(toAuto.patch, { auto_resolution: true, resolution: '3200x1800' }) assert.equal(mod.countChangedSettingsFields(['auto_resolution']), 1) assert.deepEqual( mod.buildSettingsSaveDiff('mac', ['auto_resolution', 'resolution'], { ...baseFixed, auto_resolution: true, resolution: '2560x1440' }), { name: 'mac', auto_resolution: true }, ) // Auto -> Fixed different resolution: both fields dirty, UI count = 1, save diff sends both assert.equal(mod.countChangedSettingsFields(['auto_resolution', 'resolution']), 1) assert.equal(mod.countChangedSettingsFields(['auto_resolution', 'resolution', 'borderless']), 2) assert.deepEqual( mod.buildSettingsSaveDiff('mac', ['auto_resolution', 'resolution'], { ...baseFixed, auto_resolution: false, resolution: '2560x1440' }), { name: 'mac', auto_resolution: false, resolution: '2560x1440' }, ) // Selecting custom disables auto_resolution and falls back to autoPreset when empty const toCustom = mod.selectSettingsResolution({ value: mod.CUSTOM_RESOLUTION_OPTION, form: { resolution: '' }, base: baseFixed, autoPreset, }) assert.equal(toCustom.forceCustomRes, true) assert.deepEqual(toCustom.patch, { auto_resolution: false, resolution: '3200x1800' }) // Typing a known preset in custom input snaps back to preset card on blur const typedPreset = mod.deriveSettingsResolutionState({ form: { auto_resolution: false, resolution: '3200x1800', borderless: false }, displayProfile: host4K150, fixedModeSupported: true, forceCustomRes: true, }) assert.equal(typedPreset.presetHit, true) assert.equal(typedPreset.customRes, true) assert.equal( mod.shouldExitCustomResOnBlur({ autoResolution: false, forceCustomRes: true, presetHit: typedPreset.presetHit }), true, ) // Typing an invalid custom resolution triggers resBad and does not snap back const typedInvalid = mod.deriveSettingsResolutionState({ form: { auto_resolution: false, resolution: 'not-a-res', borderless: false }, displayProfile: host4K150, fixedModeSupported: true, forceCustomRes: true, }) assert.equal(typedInvalid.presetHit, false) assert.equal(typedInvalid.resBad, true) assert.equal( mod.shouldExitCustomResOnBlur({ autoResolution: false, forceCustomRes: true, presetHit: typedInvalid.presetHit }), false, ) }) test('CreateWizard defaults to auto resolution and keeps preview resolution synced on borderless toggle', () => { const init = mod.initialWizardResolution(host4K150, true) assert.deepEqual(init, { auto_resolution: true, resolution: '3200x1800' }) const windowPresets = mod.windowDisplayPresets(host4K150, true) const fullscreenPresets = mod.fullscreenDisplayPresets(host4K150) // Toggling borderless ON in auto mode updates preview resolution to fullscreen auto preset const fsOnFixed = mod.toggleWizardBorderless({ borderless: true, opts: init, host: host4K150, fixedModeSupported: true, windowPresets, fullscreenPresets, }) assert.deepEqual(fsOnFixed, { borderless: true, auto_resolution: true, resolution: '5120x2880' }) const fsOnNoFixed = mod.toggleWizardBorderless({ borderless: true, opts: init, host: host4K150, fixedModeSupported: false, windowPresets, fullscreenPresets, }) assert.deepEqual(fsOnNoFixed, { borderless: true, auto_resolution: true, resolution: '3840x2160' }) // Selecting a fixed preset turns auto_resolution off const fixedChoice = mod.selectWizardResolution('2560x1440', mod.resolveAutoDisplayPreset(host4K150, false, true)) assert.deepEqual(fixedChoice, { auto_resolution: false, resolution: '2560x1440' }) // Selecting AUTO turns auto_resolution back on with current autoPreset const autoChoice = mod.selectWizardResolution(mod.AUTO_RESOLUTION_OPTION, mod.resolveAutoDisplayPreset(host4K150, true, true)) assert.deepEqual(autoChoice, { auto_resolution: true, resolution: '5120x2880' }) }) test('VM summary, formatResolutionLabel, and pendingChangeText format auto_resolution in zh-CN and en-US', () => { const trZh = (k, v) => mod.t('zh-CN', k, v) const trEn = (k, v) => mod.t('en-US', k, v) assert.equal(mod.formatResolutionLabel('3200x1800', true, trZh), '自动(3200 × 1800)') assert.equal(mod.formatResolutionLabel('3200x1800', true, trEn), 'Auto (3200 × 1800)') assert.equal(mod.formatResolutionLabel('3200x1800', false, trZh), '3200 × 1800') assert.equal(mod.formatResolutionLabel('', true, trEn), 'Auto') const autoDetail = { graphics: 'reims-vgpu', gpu: 'auto', resolution: '3200x1800', auto_resolution: true, displays: 1, } assert.equal(mod.graphicsLabel('zh-CN', autoDetail, host4K150), 'RTX 4070 · 自动(3200 × 1800)') assert.equal(mod.graphicsLabel('en-US', autoDetail, host4K150), 'RTX 4070 · Auto (3200 × 1800)') const fixedDetail = { ...autoDetail, auto_resolution: false } assert.equal(mod.graphicsLabel('en-US', fixedDetail, host4K150), 'RTX 4070 · 1800p') const pendingOnZh = mod.pendingChangeText('zh-CN', { field: 'auto_resolution', from: 'false', to: 'true' }, host4K150) const pendingOffEn = mod.pendingChangeText('en-US', { field: 'auto_resolution', from: 'true', to: 'false' }, host4K150) assert.equal(pendingOnZh, '自动分辨率 关闭 → 开启') assert.equal(pendingOffEn, 'Auto resolution On → Off') assert.ok(!pendingOnZh.includes('auto_resolution')) assert.ok(!pendingOffEn.includes('auto_resolution')) }) test('vmware-svga disables and hides auto resolution across wizard, settings, and summary (#5)', () => { // Wizard initialization: svga defaults to auto_resolution: false, reims-vgpu defaults to true assert.deepEqual(mod.initialWizardResolution(host4K150, true, 'vmware-svga'), { auto_resolution: false, resolution: '3200x1800', }) assert.deepEqual(mod.initialWizardResolution(host4K150, true, 'reims-vgpu'), { auto_resolution: true, resolution: '3200x1800', }) // Switching graphics in wizard disables auto on svga, and restores auto on reims-vgpu only if user did not pick a fixed preset const autoPreset = mod.resolveAutoDisplayPreset(host4K150, false, true) assert.deepEqual( mod.switchWizardGraphics({ graphics: 'vmware-svga', manualResolutionPicked: false, autoPreset }), { graphics: 'vmware-svga', auto_resolution: false }, ) assert.deepEqual( mod.switchWizardGraphics({ graphics: 'reims-vgpu', manualResolutionPicked: false, autoPreset }), { graphics: 'reims-vgpu', auto_resolution: true, resolution: '3200x1800' }, ) assert.deepEqual( mod.switchWizardGraphics({ graphics: 'reims-vgpu', manualResolutionPicked: true, autoPreset }), { graphics: 'reims-vgpu' }, ) // SettingsModal switching to svga only patches graphics and exits custom input (R2 #11) assert.deepEqual(mod.switchSettingsGraphics('vmware-svga'), { patch: { graphics: 'vmware-svga' }, forceCustomRes: false, }) const svgaState = mod.deriveSettingsResolutionState({ form: { graphics: 'vmware-svga', auto_resolution: true, resolution: 'not-a-res', borderless: false }, displayProfile: host4K150, fixedModeSupported: true, forceCustomRes: true, }) assert.notEqual(svgaState.resValue, mod.AUTO_RESOLUTION_OPTION) assert.equal(svgaState.customRes, false) assert.equal(svgaState.resBad, false) // R2 #2: SVGA never includes the AUTO resolution card in SettingsModal or CreateWizard options const activePresets = mod.windowDisplayPresets(host4K150, true) const settingsSvgaOpts = mod.buildResolutionOptions({ graphics: 'vmware-svga', autoPreset, activePresets, includeCustom: true, }) const wizardSvgaOpts = mod.buildResolutionOptions({ graphics: 'vmware-svga', autoPreset, activePresets, }) assert.equal(settingsSvgaOpts.some((o) => o.value === mod.AUTO_RESOLUTION_OPTION), false) assert.equal(wizardSvgaOpts.some((o) => o.value === mod.AUTO_RESOLUTION_OPTION), false) const settingsVgpuOpts = mod.buildResolutionOptions({ graphics: 'reims-vgpu', autoPreset, activePresets, includeCustom: true, }) const wizardVgpuOpts = mod.buildResolutionOptions({ graphics: 'reims-vgpu', autoPreset, activePresets, }) assert.equal(settingsVgpuOpts[0].value, mod.AUTO_RESOLUTION_OPTION) assert.equal(wizardVgpuOpts[0].value, mod.AUTO_RESOLUTION_OPTION) // Settings save diff never sends auto_resolution: true for vmware-svga assert.deepEqual( mod.buildSettingsSaveDiff('mac', ['graphics', 'auto_resolution'], { name: 'mac', graphics: 'vmware-svga', auto_resolution: true, resolution: '1920x1080', }), { name: 'mac', graphics: 'vmware-svga', auto_resolution: false }, ) // graphicsLabel never renders auto resolution label for vmware-svga const svgaDetail = { graphics: 'vmware-svga', gpu: 'auto', resolution: '3200x1800', auto_resolution: true, displays: 1, } assert.equal(mod.graphicsLabel('zh-CN', svgaDetail, host4K150), mod.t('zh-CN', 'softwareGraphics')) assert.equal(mod.graphicsLabel('en-US', svgaDetail, host4K150), mod.t('en-US', 'softwareGraphics')) }) test('installer wizard draft enables auto resolution by default while preserving user fixed drafts (#7)', () => { const installerDraftVgpu = mod.initialWizardResolution(host4K150, true, 'reims-vgpu') assert.deepEqual(installerDraftVgpu, { auto_resolution: true, resolution: '3200x1800' }) const installerDraftSvga = mod.initialWizardResolution(host4K150, true, 'vmware-svga') assert.deepEqual(installerDraftSvga, { auto_resolution: false, resolution: '3200x1800' }) // Returning from a failed create preserves explicit auto_resolution: false const failedFixedDraft = { name: 'macos-tahoe', graphics: 'reims-vgpu', auto_resolution: false, resolution: '2560x1440', borderless: false, } const effectiveFixed = mod.resolveEffectiveWizardOpts( failedFixedDraft, mod.resolveAutoDisplayPreset(host32K200, false, true), ) assert.equal(effectiveFixed.auto_resolution, false) assert.equal(effectiveFixed.resolution, '2560x1440') }) test('effective wizard opts track host screen changes in auto mode without mutating fixed mode (#8)', () => { const autoOptsFrom4K = { name: 'macos-tahoe', graphics: 'reims-vgpu', auto_resolution: true, resolution: '3200x1800', borderless: false, } // Host switches to 3.2K screen while wizard stays open or restores an auto draft const effectiveOn32K = mod.resolveEffectiveWizardOpts( autoOptsFrom4K, mod.resolveAutoDisplayPreset(host32K200, false, true), ) assert.equal(effectiveOn32K.auto_resolution, true) assert.equal(effectiveOn32K.resolution, '2880x1800') // Borderless auto mode on 4K updates to 5120x2880 const effectiveBorderless = mod.resolveEffectiveWizardOpts( { ...autoOptsFrom4K, borderless: true }, mod.resolveAutoDisplayPreset(host4K150, true, true), ) assert.equal(effectiveBorderless.resolution, '5120x2880') // Fixed mode keeps user-selected resolution even when host changes const fixedOpts = { ...autoOptsFrom4K, auto_resolution: false, resolution: '2560x1440' } const effectiveFixed = mod.resolveEffectiveWizardOpts( fixedOpts, mod.resolveAutoDisplayPreset(host32K200, false, true), ) assert.equal(effectiveFixed.auto_resolution, false) assert.equal(effectiveFixed.resolution, '2560x1440') }) test('custom resolution canonicalizes on blur and save diff to match Go validator (#9)', () => { assert.equal(mod.canonicalResolution('3200 × 1800'), '3200x1800') assert.equal(mod.canonicalResolution(' 3200X1800 '), '3200x1800') assert.equal(mod.canonicalResolution('2400 x 1500'), '2400x1500') assert.equal(mod.canonicalResolution(''), '') const presets = mod.windowDisplayPresets(host4K150, true) // Typing a known preset with × or uppercase X snaps back and writes canonical preset value assert.deepEqual( mod.resolveCustomResBlur({ resolution: '3200 × 1800', autoResolution: false, forceCustomRes: true, activePresets: presets, }), { exitCustom: true, nextResolution: '3200x1800' }, ) assert.deepEqual( mod.resolveCustomResBlur({ resolution: '3200X1800', autoResolution: false, forceCustomRes: true, activePresets: presets, }), { exitCustom: true, nextResolution: '3200x1800' }, ) // Typing a non-preset valid size canonicalizes without exiting custom input assert.deepEqual( mod.resolveCustomResBlur({ resolution: ' 2400 × 1500 ', autoResolution: false, forceCustomRes: true, activePresets: presets, }), { exitCustom: false, nextResolution: '2400x1500' }, ) // Save diff always canonicalizes resolution even if saved before blur assert.deepEqual( mod.buildSettingsSaveDiff('mac', ['auto_resolution', 'resolution'], { name: 'mac', graphics: 'reims-vgpu', auto_resolution: false, resolution: '3200 × 1800', }), { name: 'mac', auto_resolution: false, resolution: '3200x1800' }, ) }) test('background baseline refresh syncs untouched fields so saving memory never overwrites external auto_resolution (#11)', () => { const initialBase = { name: 'mac', memory: '8G', graphics: 'reims-vgpu', auto_resolution: true, resolution: '3200x1800', } // User only edits memory const touched = new Set(mod.expandTouchedSettingsFields(['memory'])) const editedForm = { ...initialBase, memory: '16G' } // External CLI disables auto_resolution and sets fixed 2560x1440; background poll refreshes base const refreshedBase = { ...initialBase, auto_resolution: false, resolution: '2560x1440', } const syncedForm = mod.syncUntouchedSettingsForm(editedForm, refreshedBase, touched) assert.equal(syncedForm.memory, '16G') assert.equal(syncedForm.auto_resolution, false) assert.equal(syncedForm.resolution, '2560x1440') // Only memory differs from refreshedBase, so save diff only sends memory const dirtyFields = ['memory', 'auto_resolution', 'resolution'].filter( (k) => syncedForm[k] !== refreshedBase[k], ) assert.deepEqual(dirtyFields, ['memory']) assert.deepEqual(mod.buildSettingsSaveDiff('mac', dirtyFields, syncedForm), { name: 'mac', memory: '16G', }) // Touching resolution pairs both resolution and auto_resolution so background refresh preserves user edits const resTouched = new Set(mod.expandTouchedSettingsFields(['resolution'])) assert.ok(resTouched.has('resolution')) assert.ok(resTouched.has('auto_resolution')) const editedResForm = { ...initialBase, auto_resolution: false, resolution: '1920x1080' } const syncedWhileEditingRes = mod.syncUntouchedSettingsForm(editedResForm, refreshedBase, resTouched) assert.equal(syncedWhileEditingRes.auto_resolution, false) assert.equal(syncedWhileEditingRes.resolution, '1920x1080') }) test('R2 #7: switching VMs resets settings draft to target VM baseline without leaking previous VM edits', () => { const baseA = { name: 'vm-a', graphics: 'reims-vgpu', auto_resolution: true, resolution: '3200x1800', memory: '8G', } const baseB = { name: 'vm-b', graphics: 'reims-vgpu', auto_resolution: true, resolution: '2880x1800', memory: '16G', } const touchedA = new Set(mod.expandTouchedSettingsFields(['resolution', 'memory'])) const editedA = { ...baseA, auto_resolution: false, resolution: '2560x1440', memory: '12G' } const switched = mod.reconcileSettingsFormOnBaseChange({ previousVMKey: 'builtin.driver.reims-macos:vm-a', nextVMKey: 'builtin.driver.reims-macos:vm-b', form: editedA, base: baseB, touchedFields: touchedA, }) assert.equal(switched.resetDraft, true) assert.deepEqual(switched.form, baseB) const dirtyB = Object.keys(baseB).filter((k) => switched.form[k] !== baseB[k]) assert.deepEqual(dirtyB, []) assert.deepEqual(mod.buildSettingsSaveDiff('vm-b', dirtyB, switched.form, baseB), { name: 'vm-b' }) }) test('R2 #5: internal digit spaces never match presets, keep custom input visible, and block save', () => { const hostWith1080 = { ...host4K150, display_presets: [ ...host4K150.display_presets, { resolution: '1920x1080', label: '1920 × 1080', hidpi: false }, ], } assert.equal(mod.canonicalResolution('1 920x1080'), '1 920x1080') assert.equal(mod.normalizeResolution('1 920x1080'), '1 920x1080') assert.equal(mod.isValidResolution('1 920x1080'), false) // Even when forceCustomRes is false (custom input opened automatically due to non-preset old value), // pasting "1 920x1080" must NOT match 1920x1080 preset, must keep input visible, and must set resBad = true. const badState = mod.deriveSettingsResolutionState({ form: { graphics: 'reims-vgpu', auto_resolution: false, resolution: '1 920x1080', borderless: false }, displayProfile: hostWith1080, fixedModeSupported: true, forceCustomRes: false, }) assert.equal(badState.presetHit, false) assert.equal(badState.customRes, true) assert.equal(badState.resBad, true) // Spaces around × or uppercase X still match preset and canonicalize to 3200x1800 assert.equal(mod.isValidResolution('3200 × 1800'), true) assert.equal(mod.isValidResolution('3200X1800'), true) const goodState = mod.deriveSettingsResolutionState({ form: { graphics: 'reims-vgpu', auto_resolution: false, resolution: '3200 × 1800', borderless: false }, displayProfile: hostWith1080, fixedModeSupported: true, forceCustomRes: false, }) assert.equal(goodState.presetHit, true) assert.equal(goodState.matchedPreset?.resolution, '3200x1800') assert.equal(goodState.resBad, false) assert.deepEqual( mod.resolveCustomResBlur({ resolution: '3200 × 1800', autoResolution: false, forceCustomRes: false, activePresets: goodState.activePresets, }), { exitCustom: true, nextResolution: '3200x1800' }, ) }) test('R2 #11: switching vGPU+auto to SVGA and resetting graphics leaves 0 changes; saving SVGA disables auto', () => { const base = { name: 'mac', graphics: 'reims-vgpu', auto_resolution: true, resolution: '3200x1800', } // Temporarily switch to SVGA const svgaSwitch = mod.switchSettingsGraphics('vmware-svga') assert.deepEqual(svgaSwitch, { patch: { graphics: 'vmware-svga' }, forceCustomRes: false }) const svgaForm = { ...base, ...svgaSwitch.patch } assert.equal(svgaForm.auto_resolution, true) // Resetting graphics row back to reims-vgpu restores clean form with 0 changes const resetForm = { ...svgaForm, graphics: base.graphics } const dirtyAfterReset = ['graphics', 'auto_resolution', 'resolution'].filter((k) => resetForm[k] !== base[k]) assert.deepEqual(dirtyAfterReset, []) assert.equal(mod.countChangedSettingsFields(dirtyAfterReset), 0) assert.deepEqual(mod.buildSettingsSaveDiff('mac', dirtyAfterReset, resetForm, base), { name: 'mac' }) // Saving SVGA directly sends graphics: 'vmware-svga' and turns off auto_resolution when base had it on const dirtyOnSvga = ['graphics', 'auto_resolution', 'resolution'].filter((k) => svgaForm[k] !== base[k]) assert.deepEqual(dirtyOnSvga, ['graphics']) assert.deepEqual(mod.buildSettingsSaveDiff('mac', dirtyOnSvga, svgaForm, base), { name: 'mac', graphics: 'vmware-svga', auto_resolution: false, }) // If base already had auto_resolution: false, saving SVGA only sends graphics const baseFixed = { ...base, auto_resolution: false } assert.deepEqual(mod.buildSettingsSaveDiff('mac', ['graphics'], { ...baseFixed, graphics: 'vmware-svga' }, baseFixed), { name: 'mac', graphics: 'vmware-svga', }) }) test('R2 #3: CreateWizard preserves manual fixed resolution across SVGA create failure and return to vGPU', () => { const autoPreset = mod.resolveAutoDisplayPreset(host4K150, false, true) // Step 1: User starts on vGPU and manually picks fixed 2560x1440 let opts = { name: 'macos-tahoe', graphics: 'reims-vgpu', ...mod.initialWizardResolution(host4K150, true, 'reims-vgpu'), borderless: false, } let manualResolutionPicked = true opts = { ...opts, ...mod.selectWizardResolution('2560x1440', autoPreset) } assert.equal(opts.auto_resolution, false) assert.equal(opts.resolution, '2560x1440') // Step 2: User switches to SVGA and submits; create fails and saves draft with manualResolution: true opts = { ...opts, ...mod.switchWizardGraphics({ graphics: 'vmware-svga', manualResolutionPicked, autoPreset }) } const failedDraft = { opts: mod.resolveEffectiveWizardOpts(opts, autoPreset), step: 5, manualResolution: manualResolutionPicked, } assert.equal(failedDraft.opts.graphics, 'vmware-svga') assert.equal(failedDraft.opts.auto_resolution, false) assert.equal(failedDraft.opts.resolution, '2560x1440') // Step 3: Reopen wizard from failed draft and switch back to vGPU const restoredManual = mod.initialWizardManualResolution(failedDraft) assert.equal(restoredManual, true) const backToVgpu = mod.switchWizardGraphics({ graphics: 'reims-vgpu', manualResolutionPicked: restoredManual, autoPreset, }) const restoredOpts = { ...failedDraft.opts, ...backToVgpu } assert.equal(restoredOpts.graphics, 'reims-vgpu') assert.equal(restoredOpts.auto_resolution, false) assert.equal(restoredOpts.resolution, '2560x1440') // Fallback behavior when draft.manualResolution is omitted assert.equal(mod.initialWizardManualResolution(null), false) assert.equal( mod.initialWizardManualResolution({ opts: { graphics: 'vmware-svga', auto_resolution: false } }), false, ) assert.equal( mod.initialWizardManualResolution({ opts: { graphics: 'reims-vgpu', auto_resolution: false } }), true, ) }) test('R3 #3 & #6: turning off auto includes fixed resolution; switching to SVGA omits hidden invalid resolution', () => { // R3 #3: switching from auto back to fixed card matching display-0 resolution still submits explicit resolution // so any per-display list (e.g. 3200x1800,2560x1440) is replaced uniformly. const baseAuto = { name: 'mac', graphics: 'reims-vgpu', auto_resolution: true, resolution: '3200x1800' } const formFixed = { ...baseAuto, auto_resolution: false, resolution: '3200x1800' } assert.deepEqual(mod.buildSettingsSaveDiff('mac', ['auto_resolution'], formFixed, baseAuto), { name: 'mac', auto_resolution: false, resolution: '3200x1800', }) // R3 #6: typing invalid custom resolution then switching to SVGA does not submit hidden invalid resolution const baseVgpu = { name: 'mac', graphics: 'reims-vgpu', auto_resolution: false, resolution: '2560x1440' } const formSvgaWithHiddenInvalid = { ...baseVgpu, graphics: 'vmware-svga', resolution: '1 920x1080', } assert.deepEqual( mod.buildSettingsSaveDiff('mac', ['graphics', 'resolution'], formSvgaWithHiddenInvalid, baseVgpu), { name: 'mac', graphics: 'vmware-svga', }, ) })