Open-source Xbox-inspired desktop launcher for Xodus on Linux
TypeScript
fix(runtime): retain exact approved builds across family updates
domsvoboda5481ff313139
diff --git a/assets/locales/en.json b/assets/locales/en.jsonindex c3e716a..86b957c 100644--- a/assets/locales/en.json+++ b/assets/locales/en.json@@ -10,6 +10,8 @@"auth.sign_out_active_help": "Signs out active Store and player accounts and removes device registration. Saved Store accounts remain available until forgotten.","auth.active_signed_out": "Active accounts signed out. Saved Store accounts are retained.","auth.sign_out_all": "Sign out all accounts",+ "runtime.new_build_available": "Another runtime build is installed. Your approved build and its local saves remain selected until you choose another build.",+ "runtime.use_installed_build": "Use the newly installed build with a separate prefix","runtime.build_changed": "The installed runtime build changed or has not been approved. Review it and explicitly choose a new separate prefix. Existing local saves stay in the old prefix.","runtime.game_runtime": "Game runtime","runtime.use_default": "Use default runtime",diff --git a/src/main/runtime-families.test.ts b/src/main/runtime-families.test.tsindex 9419502..cfa9c10 100644--- a/src/main/runtime-families.test.ts+++ b/src/main/runtime-families.test.ts@@ -8,7 +8,7 @@ import {approvedRuntimeSettings} from './runtime-settings';import type {Game} from '../shared/types';import {prepareProtonRunner} from './proton';import {createHash} from 'node:crypto';-import {resolveRuntimeFamily,installedRuntimeFamilies,runtimeFamilyVerificationStats} from './runtime-families';+import {resolveRuntimeFamily,resolveRuntimeFamilyBuild,retainRuntimeFamilyBuild,installedRuntimeFamilies,runtimeFamilyVerificationStats} from './runtime-families';import {resolveGameRuntime,bindRuntimePrefix} from './runtime-prefix-binding';import {gameRuntimeSelection} from '../shared/runtime-selection';let root:string,release:string;@@ -262,3 +262,97 @@ it('requires a fresh transient approval and exact expected descriptor, and clearexpect(approved.runtimeBuild).toEqual(expected);expect(await approvedRuntimeSettings({...game,...approved},{runtime:'default'},root)).toEqual({runtime:'default',runtimeSeparatePrefix:false,runtimeBuild:undefined});});++async function installNextFixture() {+ const previous=release;+ const next='d'.repeat(64);release=path.join(root,'variants',family,'releases',next);+ await fs.cp(previous,release,{recursive:true});+ const manifestFile=path.join(release,'nexus-family.json');+ const manifest=JSON.parse(await fs.readFile(manifestFile,'utf8'));manifest.buildId=next;+ const bytes=JSON.stringify(manifest);await fs.writeFile(manifestFile,bytes);+ const pointer=JSON.parse(await fs.readFile(path.join(root,'variants',family,'current.json'),'utf8'));+ Object.assign(pointer,{buildId:next,manifestSha256:hash(bytes)});+ await fs.writeFile(path.join(root,'variants',family,'current.json'),JSON.stringify(pointer));+ return previous;+}+it('retains approved A across current B, and only explicit B approval creates a new prefix',async()=>{+ await fixture();const a=await approval();+ const options={runtimeRoot:root,dataRoot:root,gameId:'retained',selection:family,separatePrefix:true,defaultWine:'/default/wine',arch:'x64'};+ const old=await resolveGameRuntime({...options,approvedBuild:a});await bindRuntimePrefix(old);+ await fs.writeFile(path.join(old.compatibilityDataPath,'synthetic-save'),'A progress');+ await retainRuntimeFamilyBuild(root,family,'x64');await retainRuntimeFamilyBuild(root,family,'x64');+ await installNextFixture();+ const retained=await resolveGameRuntime({...options,approvedBuild:a});+ expect(retained.winePath).toBe(old.winePath);expect(retained.compatibilityDataPath).toBe(old.compatibilityDataPath);+ expect(await fs.readFile(path.join(retained.compatibilityDataPath,'synthetic-save'),'utf8')).toBe('A progress');+ const game={id:'retained',runtime:family,runtimeSeparatePrefix:true,runtimeBuild:a} as Game;+ const ordinary=await approvedRuntimeSettings(game,{},root);expect(ordinary.runtimeBuild).toEqual(a);+ const b=await approval();const patch=await approvedRuntimeSettings(game,{runtimeApproveBuild:true,runtimeExpectedBuild:b},root);+ const fresh=await resolveGameRuntime({...options,approvedBuild:patch.runtimeBuild});await bindRuntimePrefix(fresh);+ expect(fresh.compatibilityDataPath).not.toBe(old.compatibilityDataPath);+ expect(await fs.readdir(fresh.compatibilityDataPath)).toEqual(['.nexus-runtime-family.json']);+});+it('does not reconstruct missing A receipts from an approved identity or an existing release directory',async()=>{+ await fixture();const a=await approval();await installNextFixture();+ await expect(resolveRuntimeFamilyBuild(root,family,a,'x64')).rejects.toThrow();+});+it('keeps matching legacy current usable read-only, without fabricating retained receipts',async()=>{+ await fixture();expect((await resolveRuntimeFamilyBuild(root,family,await approval(),'x64')).buildId).toBe(buildId);+ await expect(fs.access(path.join(root,'variants',family,'receipts'))).rejects.toThrow();+});+it('fails closed for corrupt retained receipt even if matching current still exists',async()=>{+ await fixture();const a=await approval();await retainRuntimeFamilyBuild(root,family,'x64');+ const receipt=path.join(root,'variants',family,'receipts',buildId+'.json');+ await fs.writeFile(receipt,'{');await expect(resolveRuntimeFamilyBuild(root,family,a,'x64')).rejects.toThrow();+ await expect(retainRuntimeFamilyBuild(root,family,'x64')).rejects.toThrow('Conflicting');+ expect(await fs.readFile(receipt,'utf8')).toBe('{');+});+it('isolates retained cache from current and invalidates changed retained payload or receipt',async()=>{+ await fixture();const a=await approval();await retainRuntimeFamilyBuild(root,family,'x64');const previous=await installNextFixture();+ expect((await resolveRuntimeFamily(root,family,'x64')).buildId).not.toBe(buildId);+ expect((await resolveRuntimeFamilyBuild(root,family,a,'x64')).buildId).toBe(buildId);+ const receipt=path.join(root,'variants',family,'receipts',buildId+'.json');const original=await fs.readFile(receipt,'utf8');+ await fs.writeFile(receipt,original.replace(sourceRepository,'attacker/runtime'));+ await expect(resolveRuntimeFamilyBuild(root,family,a,'x64')).rejects.toThrow();+ await fs.writeFile(receipt,original);await resolveRuntimeFamilyBuild(root,family,a,'x64');+ await fs.appendFile(path.join(previous,'files/bin/wine'),'changed');+ await expect(resolveRuntimeFamilyBuild(root,family,a,'x64')).rejects.toThrow();+ expect((await resolveRuntimeFamily(root,family,'x64')).buildId).not.toBe(buildId);+});+it('rejects retained receipt and directory symlinks rather than falling back to current',async()=>{+ await fixture();const a=await approval();await retainRuntimeFamilyBuild(root,family,'x64');+ const directory=path.join(root,'variants',family,'receipts'),receipt=path.join(directory,buildId+'.json');+ await fs.unlink(receipt);await fs.symlink('../current.json',receipt);+ await expect(resolveRuntimeFamilyBuild(root,family,a,'x64')).rejects.toThrow();+ await expect(retainRuntimeFamilyBuild(root,family,'x64')).rejects.toThrow();+ await fs.unlink(receipt);await fs.rmdir(directory);await fs.symlink('.',directory);+ await expect(resolveRuntimeFamilyBuild(root,family,a,'x64')).rejects.toThrow();+ await expect(retainRuntimeFamilyBuild(root,family,'x64')).rejects.toThrow();+});+it('publishes no partial receipt when publication fails, and supports concurrent idempotent retention',async()=>{+ await fixture();const link=vi.spyOn(fs,'link').mockRejectedValueOnce(Object.assign(Error('synthetic full disk'),{code:'ENOSPC'}));+ await expect(retainRuntimeFamilyBuild(root,family,'x64')).rejects.toThrow('synthetic full disk');link.mockRestore();+ const directory=path.join(root,'variants',family,'receipts');expect(await fs.readdir(directory)).toEqual([]);+ const results=await Promise.all([retainRuntimeFamilyBuild(root,family,'x64'),retainRuntimeFamilyBuild(root,family,'x64')]);+ expect(results.map(item=>item.buildId)).toEqual([buildId,buildId]);+ expect(await fs.readdir(directory)).toEqual([buildId+'.json']);+ expect((await resolveRuntimeFamily(root,family,'x64')).buildId).toBe(buildId);+});+it('uses the same retained receipt contract for the standard managed family without changing legacy default',async()=>{+ await fixture();const directory=path.join(root,'variants','nexus');await fs.rename(path.join(root,'variants',family),directory);+ const manifestFile=path.join(directory,'releases',buildId,'nexus-family.json');+ const manifest=JSON.parse(await fs.readFile(manifestFile,'utf8'));Object.assign(manifest,{family:'nexus',sourceRepository:'domsvoboda/nexus-runtime'});+ const bytes=JSON.stringify(manifest);await fs.writeFile(manifestFile,bytes);+ const receipt=path.join(directory,'current.json');const pointer=JSON.parse(await fs.readFile(receipt,'utf8'));+ Object.assign(pointer,{family:'nexus',sourceRepository:'domsvoboda/nexus-runtime',manifestSha256:hash(bytes)});await fs.writeFile(receipt,JSON.stringify(pointer));+ await fs.writeFile(path.join(root,'current.json'),'legacy-default-pointer');+ const retained=await retainRuntimeFamilyBuild(root,'nexus','x64');await fs.unlink(receipt);+ expect((await resolveRuntimeFamilyBuild(root,'nexus',retained,'x64')).buildId).toBe(buildId);+ expect(await fs.readFile(path.join(root,'current.json'),'utf8')).toBe('legacy-default-pointer');+});+it('fails closed when retained A payload disappears while current B remains valid',async()=>{+ await fixture();const a=await approval();await retainRuntimeFamilyBuild(root,family,'x64');const previous=await installNextFixture();+ await fs.rm(previous,{recursive:true});+ await expect(resolveRuntimeFamilyBuild(root,family,a,'x64')).rejects.toThrow('default was not used');+ expect((await resolveRuntimeFamily(root,family,'x64')).buildId).not.toBe(buildId);+});diff --git a/src/main/runtime-families.ts b/src/main/runtime-families.tsindex 8ae9233..c2a3a73 100644--- a/src/main/runtime-families.ts+++ b/src/main/runtime-families.ts@@ -1,7 +1,7 @@import {constants,createReadStream,promises as fs} from 'node:fs';-import {createHash} from 'node:crypto';+import {createHash,randomUUID} from 'node:crypto';import path from 'node:path';-import {gameRuntimeSelection,runtimeFamilies,runtimeFamilyLabels,type RuntimeFamily,type InstalledRuntimeFamily} from '../shared/runtime-selection.js';+import {gameRuntimeSelection,runtimeFamilies,runtimeFamilyLabels,type RuntimeFamily,type InstalledRuntimeFamily,runtimeBuildApproval,sameRuntimeBuild,type RuntimeBuildApproval} from '../shared/runtime-selection.js';const repositories:Record<RuntimeFamily,string>={nexus:'domsvoboda/nexus-runtime','nexus-cachyos':'domsvoboda/nexus-runtime-cachyos'};const digest=(bytes:Buffer)=>createHash('sha256').update(bytes).digest('hex');async function fileDigest(file:string) {@@ -13,9 +13,24 @@ const within=(root:string,file:string)=>{const relative=path.relative(root,file)export interface ResolvedRuntimeFamily extends InstalledRuntimeFamily {readonly winePath:string;readonly root:string;readonly arch:'x64'|'arm64';readonly prefixSchema:1;readonly manifestSha256:string;}+/** Retained receipts live outside the fully inventoried payload. A directory+ * alone never authorizes a build. Existing current-only installs remain valid+ * only while current still identifies the exact approved build. */+async function receiptFile(runtimeRoot:string,id:RuntimeFamily,approved?:Readonly<RuntimeBuildApproval>):Promise<string> {+ const directory=path.join(runtimeRoot,'variants',id);+ if(approved) {+ const receipts=path.join(directory,'receipts'),file=path.join(receipts,approved.buildId+'.json');+ try {+ if(!(await fs.lstat(receipts)).isDirectory()||!within(await fs.realpath(directory),await fs.realpath(receipts)))throw Error('Invalid retained receipt directory');+ if(!(await fs.lstat(file)).isFile())throw Error('Retained receipt must be a regular file');+ return file;+ }catch(error){if((error as NodeJS.ErrnoException).code!=='ENOENT')throw error;}+ }+ return path.join(directory,'current.json');+}/** Read a receipt written by a verified managed installer, never a user-supplied* executable. A missing or damaged selected family cannot fall back to default. */-async function verifyRuntimeFamily(runtimeRoot:string,selection:unknown,arch:string=process.arch):Promise<Readonly<ResolvedRuntimeFamily>> {+async function verifyRuntimeFamily(runtimeRoot:string,selection:unknown,arch:string=process.arch,approved?:Readonly<RuntimeBuildApproval>):Promise<Readonly<ResolvedRuntimeFamily>> {const id=gameRuntimeSelection(selection);if(id==='default')throw Error('Default runtime resolution requires the existing global runtime.');if(!['x64','arm64'].includes(arch))throw Error('Unsupported runtime architecture.');@@ -23,7 +38,10 @@ async function verifyRuntimeFamily(runtimeRoot:string,selection:unknown,arch:strconst managedRoot=await fs.realpath(runtimeRoot);const directory=path.join(runtimeRoot,'variants',id);if(!within(managedRoot,await fs.realpath(directory)))throw Error('Family directory leaves managed root');- const pointer=JSON.parse(await fs.readFile(path.join(directory,'current.json'),'utf8'));+ const file=await receiptFile(runtimeRoot,id,approved);+ if(!(await fs.lstat(file)).isFile())throw Error('Receipt must be a regular file');+ const pointer=JSON.parse(await fs.readFile(file,'utf8'));+ if(approved&&!sameRuntimeBuild(approved,pointer))throw Error('Approved runtime receipt identity mismatch');if(pointer.schema!==1||pointer.family!==id||pointer.sourceRepository!==repositories[id]||!commit(pointer.sourceCommit)||!hash(pointer.manifestSha256)||!hash(pointer.buildId))throw Error('Invalid managed runtime receipt');const requestedRoot=path.join(directory,'releases',pointer.buildId);if(!(await fs.lstat(requestedRoot)).isDirectory())throw Error('Runtime root must be a real directory');@@ -82,14 +100,14 @@ const verified=new Map<string,{fingerprint:string;value:Readonly<ResolvedRuntimeconst inFlight=new Map<string,Promise<Readonly<ResolvedRuntimeFamily>>>();let fullPasses=0,cacheHits=0;export const runtimeFamilyVerificationStats=()=>Object.freeze({fullPasses,cacheHits});-async function runtimeFingerprint(runtimeRoot:string,id:RuntimeFamily):Promise<string> {+async function runtimeFingerprint(runtimeRoot:string,id:RuntimeFamily,approved?:Readonly<RuntimeBuildApproval>):Promise<string> {const hash=createHash('sha256');const add=(value:string)=>{hash.update(String(Buffer.byteLength(value)));hash.update(':');hash.update(value);};const root=await fs.realpath(runtimeRoot),directory=path.join(runtimeRoot,'variants',id);const canonical=await fs.realpath(directory);if(!within(root,canonical))throw Error('Family path leaves runtime root');add(root);add(canonical);- const pointerFile=path.join(directory,'current.json');+ const pointerFile=await receiptFile(runtimeRoot,id,approved);if(!(await fs.lstat(pointerFile)).isFile())throw Error('Receipt must be a regular file');const bytes=await fs.readFile(pointerFile);add(bytes.toString('utf8'));const pointer=JSON.parse(bytes.toString('utf8'));@@ -110,22 +128,22 @@ async function runtimeFingerprint(runtimeRoot:string,id:RuntimeFamily):Promise<sreturn hash.digest('hex');}const hashId=(value:unknown)=>typeof value==='string'&&/^[a-f0-9]{64}$/.test(value);-export async function resolveRuntimeFamily(runtimeRoot:string,selection:unknown,arch:string=process.arch):Promise<Readonly<ResolvedRuntimeFamily>> {+async function resolveVerifiedRuntimeFamily(runtimeRoot:string,selection:unknown,arch:string=process.arch,approved?:Readonly<RuntimeBuildApproval>):Promise<Readonly<ResolvedRuntimeFamily>> {const id=gameRuntimeSelection(selection);if(id==='default')throw Error('Default runtime resolution requires the existing global runtime.');- const key=JSON.stringify([path.resolve(runtimeRoot),id,arch]);+ const key=JSON.stringify([path.resolve(runtimeRoot),id,arch,approved]);const pending=inFlight.get(key);if(pending)return pending;const work=(async()=>{try {- const before=await runtimeFingerprint(runtimeRoot,id);+ const before=await runtimeFingerprint(runtimeRoot,id,approved);const previous=verified.get(key);if(previous?.fingerprint===before){- if(await runtimeFingerprint(runtimeRoot,id)!==before)throw Error('Runtime changed during cached verification.');+ if(await runtimeFingerprint(runtimeRoot,id,approved)!==before)throw Error('Runtime changed during cached verification.');cacheHits++;return previous.value;}verified.delete(key);fullPasses++;- const value=await verifyRuntimeFamily(runtimeRoot,id,arch);- if(await runtimeFingerprint(runtimeRoot,id)!==before)throw Error('Runtime changed during verification. Retry after installation finishes.');+ const value=await verifyRuntimeFamily(runtimeRoot,id,arch,approved);+ if(await runtimeFingerprint(runtimeRoot,id,approved)!==before)throw Error('Runtime changed during verification. Retry after installation finishes.');verified.set(key,{fingerprint:before,value});while(verified.size>8)verified.delete(verified.keys().next().value!);return value;@@ -134,6 +152,43 @@ export async function resolveRuntimeFamily(runtimeRoot:string,selection:unknown,inFlight.set(key,work);try{return await work;}finally{if(inFlight.get(key)===work)inFlight.delete(key);}}+/** Current build is for discovery and fresh explicit approval. */+export function resolveRuntimeFamily(runtimeRoot:string,selection:unknown,arch:string=process.arch) {+ return resolveVerifiedRuntimeFamily(runtimeRoot,selection,arch);+}+/** Launch an exact approved retained build, independently of current. */+export async function resolveRuntimeFamilyBuild(runtimeRoot:string,selection:unknown,approval:unknown,arch:string=process.arch) {+ return resolveVerifiedRuntimeFamily(runtimeRoot,selection,arch,runtimeBuildApproval(approval));+}+/** Future installers must call this BEFORE replacing current. Publish only a+ * fully verified current receipt, exclusively and outside the payload. Reads+ * never synthesize receipts or adopt arbitrary release directories. */+export async function retainRuntimeFamilyBuild(runtimeRoot:string,selection:unknown,arch:string=process.arch):Promise<Readonly<ResolvedRuntimeFamily>> {+ const value=await resolveRuntimeFamily(runtimeRoot,selection,arch);+ const directory=path.join(runtimeRoot,'variants',value.id),receipts=path.join(directory,'receipts');+ await fs.mkdir(receipts,{recursive:true,mode:0o700});+ if(!(await fs.lstat(receipts)).isDirectory()||!within(await fs.realpath(directory),await fs.realpath(receipts)))throw Error('Invalid retained receipt directory');+ const familyDirectory=await fs.open(directory,'r');+ try{await familyDirectory.sync();}finally{await familyDirectory.close();}+ const file=path.join(receipts,value.buildId+'.json');+ const record={schema:1,family:value.id,sourceRepository:repositories[value.id],buildId:value.buildId,manifestSha256:value.manifestSha256,sourceCommit:value.sourceCommit};+ const bytes=JSON.stringify(record)+'\n',temporary=path.join(receipts,'.receipt-'+randomUUID());+ try {+ const handle=await fs.open(temporary,'wx',0o600);+ try{await handle.writeFile(bytes);await handle.sync();}finally{await handle.close();}+ // Revalidate after staging; never bless a changed current installation.+ const latest=await resolveRuntimeFamily(runtimeRoot,selection,arch);+ if(!sameRuntimeBuild(value,latest))throw Error('Current runtime changed before retention');+ try{await fs.link(temporary,file);}catch(error){+ if((error as NodeJS.ErrnoException).code!=='EEXIST')throw error;+ if(!(await fs.lstat(file)).isFile()||await fs.readFile(file,'utf8')!==bytes)throw Error('Conflicting retained runtime receipt');+ }+ const handleDirectory=await fs.open(receipts,'r');+ try{await handleDirectory.sync();}finally{await handleDirectory.close();}+ await resolveRuntimeFamilyBuild(runtimeRoot,selection,value,arch);+ return value;+ }finally{await fs.unlink(temporary).catch(()=>undefined);}+}export async function installedRuntimeFamilies(runtimeRoot:string,arch:string=process.arch):Promise<InstalledRuntimeFamily[]> {const results=await Promise.all(runtimeFamilies.map(async id=>{try{const value=await resolveRuntimeFamily(runtimeRoot,id,arch);return {id:value.id,label:value.label,buildId:value.buildId,sourceCommit:value.sourceCommit,manifestSha256:value.manifestSha256};}catch{return undefined;}diff --git a/src/main/runtime-prefix-binding.ts b/src/main/runtime-prefix-binding.tsindex b66c154..124cbaa 100644--- a/src/main/runtime-prefix-binding.ts+++ b/src/main/runtime-prefix-binding.ts@@ -1,7 +1,7 @@import {promises as fs} from 'node:fs';import path from 'node:path';import {gameRuntimeSelection,sameRuntimeBuild,type GameRuntimeSelection} from '../shared/runtime-selection.js';-import {resolveRuntimeFamily,type ResolvedRuntimeFamily} from './runtime-families.js';+import {resolveRuntimeFamilyBuild,type ResolvedRuntimeFamily} from './runtime-families.js';export interface GameRuntimeContext {readonly selection:GameRuntimeSelection;readonly family:'default'|'nexus'|'nexus-cachyos';readonly winePath:string;readonly compatibilityDataPath:string;readonly legacyPrefixRoot:string;readonly dataRoot:string;@@ -22,7 +22,7 @@ export async function resolveGameRuntime(options:{runtimeRoot:string;dataRoot:stcompatibilityDataPath:path.join(options.dataRoot,'compatdata',options.gameId),legacyPrefixRoot:path.join(options.dataRoot,'prefixes',options.gameId)});}if(options.separatePrefix!==true)throw Error('Choose a separate runtime prefix before using this family. Existing local saves remain in the old prefix.');- const managed=await resolveRuntimeFamily(options.runtimeRoot,selection,options.arch);+ const managed=await resolveRuntimeFamilyBuild(options.runtimeRoot,selection,options.approvedBuild,options.arch).catch(error=>{throw Error('The selected runtime build changed, has not been approved or failed verification. Explicitly choose an installed build in Game settings. Existing prefix and local saves were preserved.',{cause:error});});if(!sameRuntimeBuild(options.approvedBuild,managed))throw Error('The selected runtime build changed or has not been approved. Explicitly choose the installed build in Game settings. Existing prefix and local saves were preserved.');const root=path.join(options.dataRoot,'runtime-prefixes',selection,managed.buildId,options.gameId);return Object.freeze({selection,family:selection,winePath:managed.winePath,dataRoot:options.dataRoot,managed,diff --git a/src/renderer/App.tsx b/src/renderer/App.tsxindex 6e3e6d7..6052a91 100644--- a/src/renderer/App.tsx+++ b/src/renderer/App.tsx@@ -649,7 +649,8 @@ export function LibraryPage({ data, toast, filters, onFiltersChange, selection,useBrowserLayoutEffect(()=>{if(!dialogGame||dialogGame.kind!=='settings'){runtimeChoice.current=undefined;return;}if(runtimeChoice.current?.gameId===dialogGame.id&&runtimeChoice.current.key!==installedChoiceKey){- setEditSeparatePrefix(false);setEditApproveRuntimeBuild(false);setEditExpectedRuntimeBuild(undefined);+ const game=data.games.find(item=>item.id===dialogGame.id);+ setEditSeparatePrefix(game?.runtime===editRuntime&&game.runtimeSeparatePrefix===true&&sameRuntimeBuild(game.runtimeBuild,game.runtimeBuild));setEditApproveRuntimeBuild(false);setEditExpectedRuntimeBuild(undefined);}runtimeChoice.current={gameId:dialogGame.id,key:installedChoiceKey};},[dialogGame?.id,dialogGame?.kind,installedChoiceKey]);@@ -731,13 +732,12 @@ export function LibraryPage({ data, toast, filters, onFiltersChange, selection,setEditTitle(game.title);setEditLocale(game.locale ?? '');setEditRuntime(game.runtime ?? 'default');- const installed=runtimeChoices.find(item=>item.id===game.runtime);- setEditSeparatePrefix(game.runtimeSeparatePrefix===true&&sameRuntimeBuild(game.runtimeBuild,installed));+ setEditSeparatePrefix(game.runtimeSeparatePrefix===true&&sameRuntimeBuild(game.runtimeBuild,game.runtimeBuild));setEditApproveRuntimeBuild(false);setEditExpectedRuntimeBuild(undefined);setEditTools({ ...defaultLaunchTools, ...game.launchTools });setLocaleOptions([]);const request = ++localeRequest.current;- if(kind==='settings')void window.launcher.getRuntimeFamilies().then(families=>{if(request===localeRequest.current){setRuntimeChoices(families);if(!sameRuntimeBuild(game.runtimeBuild,families.find(item=>item.id===game.runtime))){setEditSeparatePrefix(false);setEditApproveRuntimeBuild(false);setEditExpectedRuntimeBuild(undefined);}}}).catch(error=>{if(request===localeRequest.current){setRuntimeChoices([]);toast({kind:'error',message:errorMessage(error)});}});+ if(kind==='settings')void window.launcher.getRuntimeFamilies().then(families=>{if(request===localeRequest.current){setRuntimeChoices(families);}}).catch(error=>{if(request===localeRequest.current){setRuntimeChoices([]);toast({kind:'error',message:errorMessage(error)});}});if (kind === 'settings') void window.launcher.getGameLocales(game.id).then(locales => {if (request === localeRequest.current) setLocaleOptions(locales);}).catch((error) => { if (request === localeRequest.current) toast({ kind: 'error', message: errorMessage(error) }); });@@ -859,7 +859,7 @@ export function LibraryPage({ data, toast, filters, onFiltersChange, selection,<h2>{ui("ui.game_settings_fece860")}</h2><label>{ui("ui.display_name_2b7f6a8")}<input data-gamepad-initial required value={editTitle} onChange={(event) => setEditTitle(event.target.value)} /></label><GameLanguage value={editLocale} locales={localeOptions} onChange={setEditLocale} />- <GameRuntimeFields value={editRuntime} separate={editSeparatePrefix} approved={modalGame.runtimeBuild} installed={runtimeChoices} change={value=>{setEditRuntime(value);setEditSeparatePrefix(false);setEditApproveRuntimeBuild(false);setEditExpectedRuntimeBuild(undefined);}} changeSeparate={value=>{setEditSeparatePrefix(value);setEditApproveRuntimeBuild(value);const installed=runtimeChoices.find(item=>item.id===editRuntime);setEditExpectedRuntimeBuild(value&&installed?runtimeBuildApproval(installed):undefined);}}/>+ <GameRuntimeFields value={editRuntime} separate={editSeparatePrefix} approved={editRuntime===(modalGame.runtime??'default')?modalGame.runtimeBuild:undefined} installed={runtimeChoices} change={value=>{setEditRuntime(value);setEditSeparatePrefix(false);setEditApproveRuntimeBuild(false);setEditExpectedRuntimeBuild(undefined);}} changeSeparate={value=>{setEditSeparatePrefix(value);setEditApproveRuntimeBuild(value);const installed=runtimeChoices.find(item=>item.id===editRuntime);setEditExpectedRuntimeBuild(value&&installed?runtimeBuildApproval(installed):undefined);}}/><GameLaunchToolFields value={editTools} change={setEditTools} /><div className="dialog-actions"><button type="button" className="secondary" disabled={dialogBusy} data-gamepad-cancel onClick={() => setDialogGame(undefined)}>{ui("ui.cancel_19766ed")}</button><button className="primary" disabled={dialogBusy || !editTitle.trim()}><Check />{ui("ui.save_1509f56")}</button></div></form>}diff --git a/src/renderer/GameRuntimeFields.tsx b/src/renderer/GameRuntimeFields.tsxindex 82d4459..0092e43 100644--- a/src/renderer/GameRuntimeFields.tsx+++ b/src/renderer/GameRuntimeFields.tsx@@ -5,6 +5,7 @@ export function GameRuntimeFields({value,separate,installed,approved,change,chanconst current=installed.find(item=>item.id===value);const missing=value!=='default'&&!current;const changed=value!=='default'&&Boolean(current)&&!sameRuntimeBuild(approved,current);+ const retained=changed&&sameRuntimeBuild(approved,approved)&&separate;return <><label>{ui('runtime.game_runtime')}<select value={value} onChange={event=>change(event.target.value as GameRuntimeSelection)}><option value="default">{ui('runtime.use_default')}</option>@@ -12,7 +13,8 @@ export function GameRuntimeFields({value,separate,installed,approved,change,chan{missing?<option value={value} disabled>{ui('runtime.unavailable',{name:runtimeFamilyLabels[value as keyof typeof runtimeFamilyLabels]??String(value)})}</option>:null}</select></label>{value!=='default'?<>- {changed?<p role="alert">{ui('runtime.build_changed')}</p>:null}+ {changed?<p role="alert">{retained?ui('runtime.new_build_available'):ui('runtime.build_changed')}</p>:null}+ {retained?<button type="button" onClick={()=>changeSeparate(true)}>{ui('runtime.use_installed_build')}</button>:null}<CheckField required checked={separate} onChange={event=>changeSeparate(event.target.checked)} label={ui('runtime.separate_prefix')} description={ui('runtime.prefix_warning')}/></>:null}</>;diff --git a/src/renderer/game-runtime-settings.test.tsx b/src/renderer/game-runtime-settings.test.tsxindex 5473f5a..d9c3b0d 100644--- a/src/renderer/game-runtime-settings.test.tsx+++ b/src/renderer/game-runtime-settings.test.tsx@@ -29,40 +29,43 @@ beforeEach(async()=>{document.body.innerHTML='<div id="root"></div>';root=createRoot(document.getElementById('root')!);await render();});afterEach(async()=>{await act(async()=>root.unmount());vi.restoreAllMocks();vi.unstubAllGlobals();document.body.innerHTML='';});-it('permits same-family A-to-B recovery only after a fresh consent interaction',async()=>{- await openSettings();expect(consent().checked).toBe(false);- expect(document.querySelector('[role="alert"]')?.textContent).toContain('runtime build changed');- const select=[...document.querySelectorAll<HTMLSelectElement>('[role="dialog"] select')].find(select=>select.value===family)!;- expect(select).toBeTruthy(); // Same family remains selected, no default detour.- await click(consent());await save();+const chooseInstalled=()=>click([...document.querySelectorAll('[role="dialog"] button')].find(button=>button.textContent==='Use the newly installed build with a separate prefix')!);+it('preserves approved A while B is current and unrelated settings Save sends no new approval',async()=>{+ await openSettings();expect(consent().checked).toBe(true);+ expect(document.querySelector('[role="alert"]')?.textContent).toContain('approved build');+ await save();expect(window.launcher.updateGame).toHaveBeenCalledWith(data.games[0].id,expect.objectContaining({runtime:family,runtimeSeparatePrefix:true,runtimeApproveBuild:false,runtimeExpectedBuild:undefined}));+});+it('permits same-family A-to-B only after explicit choice of the installed build',async()=>{+ await openSettings();await chooseInstalled();await save();expect(window.launcher.updateGame).toHaveBeenCalledWith(data.games[0].id,expect.objectContaining({runtime:family,runtimeSeparatePrefix:true,runtimeApproveBuild:true,runtimeExpectedBuild:b}));});-it('ordinary Save of an already approved build sends no fresh build approval',async()=>{+it('ordinary Save of an already current approved build sends no fresh build approval',async()=>{data.runtime.variants=[installed(a)];await render();await openSettings();expect(consent().checked).toBe(true);await save();expect(window.launcher.updateGame).toHaveBeenCalledWith(data.games[0].id,expect.objectContaining({runtimeApproveBuild:false,runtimeExpectedBuild:undefined}));});-it('clears pending B consent when a C snapshot arrives, requiring a fresh C interaction',async()=>{- await openSettings();await click(consent());data.runtime.variants=[installed(c)];await render();- expect(consent().checked).toBe(false);await save();expect(window.launcher.updateGame).not.toHaveBeenCalled();- await click(consent());await save();- expect(window.launcher.updateGame).toHaveBeenCalledWith(data.games[0].id,expect.objectContaining({runtimeApproveBuild:true,runtimeExpectedBuild:c}));+it('invalidates pending B approval when C arrives, retaining A until explicit C choice',async()=>{+ await openSettings();await chooseInstalled();data.runtime.variants=[installed(c)];await render();+ expect(consent().checked).toBe(true);await save();expect(window.launcher.updateGame).toHaveBeenLastCalledWith(data.games[0].id,expect.objectContaining({runtimeApproveBuild:false,runtimeExpectedBuild:undefined}));+ await openSettings();await chooseInstalled();await save();+ expect(window.launcher.updateGame).toHaveBeenLastCalledWith(data.games[0].id,expect.objectContaining({runtimeApproveBuild:true,runtimeExpectedBuild:c}));});-it('clears prefilled A consent when the installed build changes while the form stays open',async()=>{+it('preserves A approval when current changes while the form stays open',async()=>{data.runtime.variants=[installed(a)];await render();await openSettings();expect(consent().checked).toBe(true);- data.runtime.variants=[installed(b)];await render();expect(consent().checked).toBe(false);- await save();expect(window.launcher.updateGame).not.toHaveBeenCalled();- await click(consent());await save();- expect(window.launcher.updateGame).toHaveBeenCalledWith(data.games[0].id,expect.objectContaining({runtimeApproveBuild:true,runtimeExpectedBuild:b}));+ data.runtime.variants=[installed(b)];await render();expect(consent().checked).toBe(true);+ await save();expect(window.launcher.updateGame).toHaveBeenCalledWith(data.games[0].id,expect.objectContaining({runtimeSeparatePrefix:true,runtimeApproveBuild:false}));});-it('resets fresh approval after closing and reopening the same-family settings form',async()=>{- await openSettings();await click(consent());await click(document.querySelector('[role="dialog"] [data-gamepad-cancel]')!);- await openSettings();expect(consent().checked).toBe(false);+it('resets fresh B approval after closing and reopening, preserving A',async()=>{+ await openSettings();await chooseInstalled();await click(document.querySelector('[role="dialog"] [data-gamepad-cancel]')!);+ await openSettings();expect(consent().checked).toBe(true);await save();+ expect(window.launcher.updateGame).toHaveBeenCalledWith(data.games[0].id,expect.objectContaining({runtimeApproveBuild:false}));});--it('refreshes verified families locally when opening settings, recovering B from a stale A snapshot',async()=>{+it('refreshes verified current B locally without clearing saved A approval',async()=>{data.runtime.variants=[installed(a)];await render();vi.mocked(window.launcher.getRuntimeFamilies).mockResolvedValue([installed(b)]);- await openSettings();expect(window.launcher.getRuntimeFamilies).toHaveBeenCalledOnce();expect(consent().checked).toBe(false);- expect(document.querySelector('[role="alert"]')?.textContent).toContain('runtime build changed');- await click(consent());await save();+ await openSettings();expect(window.launcher.getRuntimeFamilies).toHaveBeenCalledOnce();expect(consent().checked).toBe(true);+ await chooseInstalled();await save();expect(window.launcher.updateGame).toHaveBeenCalledWith(data.games[0].id,expect.objectContaining({runtime:family,runtimeApproveBuild:true,runtimeExpectedBuild:b}));});+it('does not fabricate valid approval for a legacy family-wide consent',async()=>{+ data.games=[{...data.games[0],runtimeBuild:undefined}];await render();await openSettings();expect(consent().checked).toBe(false);+ await click(consent());await save();expect(window.launcher.updateGame).toHaveBeenCalledWith(data.games[0].id,expect.objectContaining({runtimeApproveBuild:true,runtimeExpectedBuild:b}));+});