/** Exercise the real official runtime and policy pipeline without CAD or a model. */ import assert from 'node:assert/strict'; import {mkdir,writeFile} from 'node:fs/promises'; import path from 'node:path'; import {fileURLToPath,pathToFileURL} from 'node:url'; import {createRequire} from 'node:module'; import {bootRuntime} from '../integration/dsh/start.mjs'; const repo=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'); const output=path.join(repo,'build/dsh-native-cli-verification'); await mkdir(output,{recursive:true}); process.env.DX_DSH_HOME=path.join(output,'home'); process.env.DX_DSH_CONTEXT_FILE=path.join(output,'context.json'); await writeFile(process.env.DX_DSH_CONTEXT_FILE,JSON.stringify({task_id:'cli-verification',status:'paused', revision:'cli-revision',rules_count:2,progress:{},issue:'',issue_code:'',events:[]})); const {ctx,shutdown}=await bootRuntime({announce:false}); const report={}; try { const schemas=ctx.tools.schemas(); report.tools=schemas.map(x=>x.name); assert.deepEqual(report.tools,['dx_task_snapshot','dx_task_create']); const presets=await ctx.agentPresets.list(); report.presets=presets.map(x=>x.id); assert.deepEqual(report.presets,['dx-task']); if(process.env.DSH_MODEL) { report.configuredModels=(await ctx.llm.listModels('dx')).map(model=>model.id); assert.ok(report.configuredModels.includes(process.env.DSH_MODEL)); } const snapshot=await ctx.tools.execute({callId:'verify-read',name:'dx_task_snapshot',arguments:{},signal:new AbortController().signal}); assert.equal(snapshot.isError,false,JSON.stringify(snapshot)); report.snapshotRead=true; const desktopOnly=await ctx.tools.execute({callId:'verify-desktop-only',name:'dx_task_create',arguments:{name:'CLI must not mutate'},signal:new AbortController().signal}); assert.equal(desktopOnly.isError,true); report.creationRequiresDesktopConfirmation=true; const require=createRequire(path.join(repo,'integration/dsh/package.json')); const {defineTool}=await import(pathToFileURL(require.resolve('@deepseek-ai/dsh-tools')).href); let bodyRan=false; const release=ctx.tools.register(defineTool({name:'forbidden_probe',description:'Never executes',parameters:{}, output:{schema:{type:'boolean'},render:()=>[{type:'text',text:'probe'}]},execute:async()=>{bodyRan=true;return true;}})); const denial=await ctx.tools.execute({callId:'verify-denial',name:'forbidden_probe',arguments:{},signal:new AbortController().signal}); release(); assert.equal(denial.isError,true); assert.equal(bodyRan,false); report.forbiddenToolDenied=true; const base=`http://127.0.0.1:${ctx.webServer.port}`; const unauth=await fetch(base+'/dx/context'); assert.equal(unauth.status,401); report.unauthenticatedContextDenied=true; const login=await fetch(ctx.connection.authenticatedUrl(base+'/'),{redirect:'manual'}); const cookie=login.headers.getSetCookie().map(x=>x.split(';')[0]).join('; '); assert.ok(cookie); const auth={Cookie:cookie}; const visible=await fetch(base+'/dx/context',{headers:auth}); assert.equal(visible.status,200); assert.equal((await visible.json()).task_id,'cli-verification'); report.authenticatedContextRead=true; for (const payload of [ {action:'shell',task_id:'cli-verification',revision:'cli-revision'}, {action:'retry_failed',task_id:'another-task',revision:'cli-revision'}, {action:'refresh_snapshot',task_id:'cli-verification',revision:'stale-revision'}, ]) { const response=await fetch(base+'/dx/action',{method:'POST',headers:{...auth,'Content-Type':'application/json'},body:JSON.stringify(payload)}); assert.equal(response.status,409); } report.invalidActionsDenied=true; report.status='passed'; await writeFile(path.join(output,'report.json'),JSON.stringify(report,null,2)); console.log(JSON.stringify(report)); } finally {await shutdown.shutdown(0);}