Files
dxdesigner-part-replacement/tools/check_harness_shell.mjs

24 lines
1.5 KiB
JavaScript

/** Check actual shell file access separately from model behavior. */
import {mkdir,mkdtemp,writeFile} from 'node:fs/promises';
import path from 'node:path';
import os from 'node:os';
import {bootRuntime} from '../integration/dsh/start.mjs';
const base=process.argv.includes('--local-appdata')?path.join(process.env.LOCALAPPDATA,'DxProductivity/acceptance-shell'):os.tmpdir();
await mkdir(base,{recursive:true});
const root=await mkdtemp(path.join(base,'shell-check-'));
for(const key of ['DSH_API_KEY','DSH_API_BASE','DSH_MODEL','DX_DSH_MODELS'])delete process.env[key];
process.env.DX_DSH_HOME=path.join(root,'home');
process.env.DX_DSH_CONTEXT_FILE=path.join(root,'context.json');
await writeFile(process.env.DX_DSH_CONTEXT_FILE,'{"task_id":"","revision":"shell-check"}');
const {ctx,shutdown}=await bootRuntime({announce:false});
try{
const workspace=await ctx.workspaceRegistry.create(process.env.DX_DSH_WORKSPACE,'Shell check');
const {sessionId}=await ctx.sessionController.create({workspaceId:workspace.id});
const agent=ctx.agents.get(sessionId);
const filename=path.join(process.env.DX_DSH_WORKSPACE,'input.txt');
await writeFile(filename,'SHELL_FILE_READ_OK');
const result=await ctx.tools.execute({agent,callId:crypto.randomUUID(),name:'pwsh',
arguments:{description:'Read the owned shell verification file',command:`[System.IO.File]::ReadAllText('${filename.replaceAll("'","''")}')`},signal:AbortSignal.timeout(30000)});
console.log(JSON.stringify({root,result}));
}finally{await shutdown.shutdown(0);}