49 lines
5.5 KiB
JavaScript
49 lines
5.5 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import net from 'node:net';
|
|
import {execFileSync} from 'node:child_process';
|
|
import {publicSnapshot,compareOriginalState,hash} from './desktop-f-state.mjs';
|
|
import {upgradeRunning} from '../scripts/upgrade-running.mjs';
|
|
import {inspectHostInstallation} from '../src/core/desktop/app-installation.mjs';
|
|
const root=path.resolve('.qa/live-retest-e-20261102-c'),origin='http://127.0.0.1:4318';
|
|
const dataRoot='C:/Users/wangy/AppData/Local/Packages/OpenAI.Codex_2p2nqsd0c76g0/LocalCache/Local/AgentWorkbench';
|
|
assert.equal(fs.existsSync(root),false,'Never overwrite an original batch.');
|
|
const d=JSON.parse(fs.readFileSync('docs/original-purge-production-evidence/manifest.json'));
|
|
assert.equal(hash(fs.readFileSync('docs/original-purge-production-evidence/manifest.json')),'ce3e7cec4136627cd3ad4bdea5f69bf46dbdf5c8db93876d33e72667598d32d1');
|
|
for(const input of [...d.sourceInputs,...d.buildInputs])assert.equal(hash(fs.readFileSync(input.path)),input.sha256,input.path);
|
|
const boot=await(await fetch(origin+'/api/bootstrap')).json();
|
|
const api=async route=>{const r=await fetch(origin+'/api'+route,{headers:{'X-Workbench-Token':boot.token,Connection:'close'}});assert.ok(r.ok,route);return r.json();};
|
|
const host=await api('/host/status');assert.equal(host.activity.active,false);assert.equal(host.desktopWindows.count,0);
|
|
assert.equal(boot.config.hasKey,true);assert.equal(host.identity.pid,36552);
|
|
const before=await publicSnapshot(origin,dataRoot),center=await api('/model-center');assert.deepEqual(before.active,[]);
|
|
const pinned=center.connections.find(c=>c.id==='09b0293b-faad-45c3-832d-7c8b615813aa');assert.ok(pinned?.enabled&&pinned.hasKey);
|
|
const inspectorClosed=()=>new Promise((resolve,reject)=>{const s=net.createConnection({host:'127.0.0.1',port:9229});s.setTimeout(1500);s.once('connect',()=>{s.destroy();reject(Error('Inspector already open'));});s.once('timeout',()=>{s.destroy();reject(Error('Inspector state unknown'));});s.once('error',e=>{s.destroy();e.code==='ECONNREFUSED'?resolve():reject(e);});});
|
|
await inspectorClosed();fs.mkdirSync(root);
|
|
const save=(name,value)=>fs.writeFileSync(path.join(root,name),JSON.stringify(value,null,2)+'\n',{flag:'wx'});
|
|
save('private-before-activation.json',before);
|
|
const runtime=path.join(root,'runtime');fs.mkdirSync(runtime);
|
|
for(const dir of ['dist-client','dist-server','dist-desktop','public'])fs.cpSync(dir,path.join(runtime,dir),{recursive:true});
|
|
fs.mkdirSync(path.join(runtime,'scripts'));fs.copyFileSync('scripts/python-check-runner.py',path.join(runtime,'scripts/python-check-runner.py'));
|
|
fs.copyFileSync('package.json',path.join(runtime,'package.json'));
|
|
const files=[];function walk(dir){for(const entry of fs.readdirSync(dir,{withFileTypes:true})){const file=path.join(dir,entry.name);assert.equal(entry.isSymbolicLink(),false);if(entry.isDirectory())walk(file);else{const bytes=fs.readFileSync(file);files.push({path:path.relative(runtime,file).replaceAll('\\','/'),bytes:bytes.length,sha256:hash(bytes)});}}}walk(runtime);
|
|
for(const input of d.buildInputs)assert.equal(hash(fs.readFileSync(path.join(runtime,input.path))),input.sha256,input.path);
|
|
fs.writeFileSync(path.join(runtime,'MANIFEST.json'),JSON.stringify({app:'agent-workbench',version:boot.version,kind:'qa-frozen-same-source',files},null,2)+'\n',{flag:'wx'});
|
|
const hostIdentity=inspectHostInstallation(runtime,{full:true});
|
|
const identity={sourceCommit:execFileSync('git',['rev-parse','HEAD'],{encoding:'utf8',windowsHide:true}).trim(),dSourceCommit:d.sourceCommit,
|
|
sourceManifestSha256:hash(fs.readFileSync('docs/original-purge-production-evidence/manifest.json')),runtime,files,hostIdentity,
|
|
scope:'Same compiled A-D bytes frozen in an owned runtime; temporary activation retaining original Provider, not an installed release or a new version claim.'};
|
|
save('runtime-identity.json',identity);
|
|
const info=JSON.parse(fs.readFileSync(path.join(dataRoot,'service-info.json')));
|
|
const upgraded=await upgradeRunning({url:origin,pid:before.pid,currentRoot:info.appRoot,handlerRoot:before.runtimeRoot,newRoot:runtime});
|
|
await inspectorClosed();const after=await publicSnapshot(origin,dataRoot);compareOriginalState(before,after);
|
|
assert.equal(after.runtimeRoot,runtime);assert.equal(upgraded.connectionPreserved,true);save('private-after-activation.json',after);
|
|
const engine=await api('/engines/deepseek/controlled-availability'),purge=await api('/engines/purge/source?kind=purge-original-restricted-v1');
|
|
assert.equal(engine.controlledStatus,'available',engine.message);assert.equal(purge.status,'available',purge.message);
|
|
save('setup.json',{root,origin,dataRoot,runtime,originalRuntime:before.runtimeRoot,originalSelection:center.selected,originalConfig:boot.config,originalModelCenter:center,
|
|
connection:pinned,engine,purge,identitySha256:hash(fs.readFileSync(path.join(root,'runtime-identity.json'))),upgraded,
|
|
limits:{samples:6,requestsPerSample:24,totalRequests:100,totalReportedTokens:700000,durationMsPerSample:600000,engineeringTokens:140000,purgeTokens:105000},
|
|
keyHandling:'Original Provider retains credentials; public views and presence bits only.',startedAt:new Date().toISOString()});
|
|
save('activation.json',{passed:true,pid:after.pid,version:after.version,runtime,connectionPreserved:true,originalState:'Every current session export, row and artifact byte unchanged',realModelRequests:0,inspectorClosed:true});
|
|
console.log(JSON.stringify({passed:true,root,runtime,pid:after.pid,version:after.version,hasKey:after.hasKey,model:pinned.model,originalSessions:before.database.sessionIds.length,realModelRequests:0}));
|