import {test} from 'node:test' import assert from 'node:assert/strict' import {mkdtemp,rm,stat} from 'node:fs/promises' import {join} from 'node:path' import {tmpdir} from 'node:os' import {DesktopPreferences} from './preferences.mjs' test('background login remains opt-in and persists without changing system login permission',async()=>{ const home=await mkdtemp(join(tmpdir(),'yaoyao-desktop-preferences-')) try{ const preferences=new DesktopPreferences(home) assert.deepEqual(await preferences.load(),{backgroundAtLogin:false,hostOnly:false}) await preferences.setBackgroundAtLogin(true) assert.deepEqual(await new DesktopPreferences(home).load(),{backgroundAtLogin:true,hostOnly:false}) assert.equal((await stat(preferences.path)).mode&0o777,0o600) await preferences.setBackgroundAtLogin(false) assert.deepEqual(await new DesktopPreferences(home).load(),{backgroundAtLogin:false,hostOnly:false}) }finally{await rm(home,{recursive:true,force:true})} }) test('host-only mode persists independently of background login',async()=>{ const home=await mkdtemp(join(tmpdir(),'yaoyao-desktop-preferences-')) try{ const preferences=new DesktopPreferences(home) await preferences.load() await preferences.setHostOnly(true) assert.deepEqual(await new DesktopPreferences(home).load(),{backgroundAtLogin:false,hostOnly:true}) await preferences.setBackgroundAtLogin(true) assert.deepEqual(await new DesktopPreferences(home).load(),{backgroundAtLogin:true,hostOnly:true}) await preferences.setHostOnly(false) assert.deepEqual(await new DesktopPreferences(home).load(),{backgroundAtLogin:true,hostOnly:false}) }finally{await rm(home,{recursive:true,force:true})} })