Files
dxdesigner-part-replacement/tools/accept_native_runtime.mjs
T
阿白叔 488bf027cc
Core regression / Python core, intervention UI and release configuration (push) Successful in 16m20s
Core regression / JavaScript syntax (push) Successful in 11s
Core regression / Python core, intervention UI and release configuration (pull_request) Failing after 11m11s
Core regression / JavaScript syntax (pull_request) Successful in 7s
feat: update DeepSeek Harness and support runtime upgrades
2026-11-20 15:43:58 +08:00

50 lines
4.0 KiB
JavaScript

/** Local-only official-runtime comparator. No task plugin or host prompt injection. */
import {createRequire} from 'node:module';
import {mkdir, readFile, writeFile} from 'node:fs/promises';
import path from 'node:path';
import {pathToFileURL} from 'node:url';
import {observeRuntime} from './acceptance_runtime_state.mjs';
const require=createRequire(new URL('../integration/dsh/start.mjs',import.meta.url));
const load=name=>import(pathToFileURL(require.resolve(name)).href);
const [source,home,workspace,port='9241',mode='inspect']=process.argv.slice(2);
if(!source||!home||!workspace)throw Error('Usage: node tools/accept_native_runtime.mjs SOURCE_PROFILE ISOLATED_HOME WORKSPACE [PORT] [inspect|run]');
const {loadProfileDirectory,composeEntries}=await load('@deepseek-ai/dsh-app-boot');
const {runProfile,INSTALL_ANCHOR}=await load('@deepseek-ai/dsh/profile-boot');
const {createLaunchEnvironmentSnapshot}=await load('@deepseek-ai/dsh-launch-environment');
const installed=require('@deepseek-ai/dsh/package.json');
const expected=require('../package.json').dependencies['@deepseek-ai/dsh'];
if(installed.version!==expected)throw Error('Runtime version mismatch');
const original=loadProfileDirectory('paired-source',path.resolve(source),INSTALL_ANCHOR);
const effective=composeEntries([...original.layers.map(layer=>layer.patches),original.patches]);
// Copy effective routing/model/shell budgets, never credential values to reports.
const matched=new Set(['llm-pi-ai','llm-deepseek','agent-default-model','pwsh-sandbox','sandbox-policy','agent-loop','workspace-controller']);
const patches=effective.filter(row=>matched.has(row.id)).map(row=>structuredClone(row));
const upsert=(id,config)=>{const row=patches.find(r=>r.id===id);if(row)row.config={...row.config,...config};else patches.push({id,config});};
upsert('sandbox-policy',{workspaceRoot:path.resolve(workspace)});
upsert('agent-preset-registry',{default:'standard'});
upsert('web-runtime',{openBrowser:false,printUrl:false,surfaceContext:false});
upsert('ui-settings-general',{welcomeNoticeVersion:'2026-09-28.1'});
upsert('ui-settings-models',{credentialOnboarding:false});
patches.push(...['desktop-product-telemetry','product-analytics','session-telemetry-otel'].map(id=>({id,disabled:true})));
const directory=path.resolve(home,'profiles','accept-native');
await mkdir(directory,{recursive:true});await mkdir(path.resolve(workspace),{recursive:true});
await writeFile(path.join(directory,'package.json'),JSON.stringify({private:true,type:'module',dsh:{profile:{bundles:['@deepseek-ai/dsh-base','@deepseek-ai/dsh-web-app']}}}));
await writeFile(path.join(directory,'cordis.patch.yml'),JSON.stringify(patches));
process.env.DSH_HOME=path.resolve(home);process.env.DSH_TELEMETRY_DISABLED='1';
const profile=loadProfileDirectory('accept-native',directory,INSTALL_ANCHOR);
const rows=composeEntries([...profile.layers.map(layer=>layer.patches),profile.patches]);
if(rows.some(row=>row.disabled!==true&&(row.name==='@dx/dsh-task'||row.id==='dx-task')))throw Error('Native baseline contains host plugin');
console.log(JSON.stringify({runtime:installed.version,mode,hostPlugin:false,matched:patches.filter(row=>matched.has(row.id)).map(row=>row.id),
credentialPrerequisite:'Copy source Harness .credentials.yaml into isolated home when using saved refs; never print it',
goalCoverage:'Official standard preset only; compare artifacts separately from host goal lifecycle'}));
if(mode==='run'){
const {ctx,shutdown}=await runProfile({profile:'accept-native',resolvedProfile:{profile,installAnchor:INSTALL_ANCHOR},patchFiles:[],
args:['--no-open','--host','127.0.0.1','--port',port],environment:createLaunchEnvironmentSnapshot([{source:'process',values:process.env}])});
await ctx.loader.await();
await ctx.workspaceRegistry.create(path.resolve(workspace),'Paired acceptance');
observeRuntime(ctx);
console.log('NATIVE_READY '+JSON.stringify({url:ctx.connection.authenticatedUrl(`http://127.0.0.1:${ctx.webServer.port}/`)}));
process.on('SIGINT',()=>void shutdown.shutdown(0));
}