import fs from 'node:fs'; import path from 'node:path'; import assert from 'node:assert/strict'; import { fixture, launchWorkbench } from '../tests/helpers.mjs'; import { publicSnapshot, compareOriginalState } from './embedded-browser-d-state.mjs'; import { upgradeRunning } from '../scripts/upgrade-running.mjs'; const read=file=>JSON.parse(fs.readFileSync(file)),prefix='.qa/embedded-browser-d-owned-upgrade-continuation'; assert.equal(read('.qa/embedded-browser-d-upgrade-schema-diagnostic-result.json').success,true); assert.equal(read('.qa/embedded-browser-d-state-checks.json').success,true); const oldPointer=read('C:/Users/wangy/AppData/Local/Programs/AgentWorkbench/current.json'); const oldRoot=path.join('C:/Users/wangy/AppData/Local/Programs/AgentWorkbench/versions',oldPointer.active.directory),release=read('releases/latest.json'); const disposers=[],t={after:fn=>disposers.push(fn)},f=fixture(t);f.store.close(); let result,before,after; try{ const host=await launchWorkbench(t,f.data,{}, {appRoot:oldRoot,nodePath:path.join(oldRoot,'runtime/node.exe')}); const member=await host.api('/model-center/connections',{name:'Owned retained credential',model:'owned-model',baseUrl:'http://127.0.0.1:1/v1',apiKey:'owned-upgrade-key',requiresKey:true}); const pool=await host.api('/model-center/pools',{name:'Owned retained pool',members:[{connectionId:member.id}]});await host.api('/model-center/select',{type:'pool',id:pool.id}); before=await publicSnapshot(host.url,f.data);assert.equal(before.version,'1.21.0'); const upgraded=await upgradeRunning({url:host.url,pid:before.pid,currentRoot:oldRoot,handlerRoot:oldRoot,newRoot:release.portableRoot});assert.equal(upgraded.connectionPreserved,true);assert.equal(upgraded.verified,true); after=await publicSnapshot(host.url,f.data);const retained=compareOriginalState(before,after); assert.equal(after.version,'1.22.0');assert.equal(after.runtimeRoot,release.portableRoot);assert.equal(after.modelCenter.selected.id,pool.id);assert.equal(after.modelCenter.connections.find(row=>row.id===member.id).hasKey,true); result={success:true,from:'1.21.0',version:'1.22.0',retained,upgraded,before,after,realModelRequests:0,originalRejectedAttempt:'.qa/embedded-browser-d-owned-upgrade.json',scope:'New owned upgrade. Every original field/row/config/artifact is exact; only four proven empty additions to the execution view are allowed. Complete view hashes retained; original D failure unchanged. Production untouched.'}; }catch(error){result={success:false,error:error.stack,before,after,realModelRequests:0};process.exitCode=1;} finally{for(const dispose of disposers.reverse())await dispose();fs.writeFileSync(prefix+'.json',JSON.stringify(result,null,2)+'\n',{flag:'wx'});console.log(JSON.stringify({success:result.success,retained:result.retained,error:result.error}));}