100 lines
5.8 KiB
JavaScript
100 lines
5.8 KiB
JavaScript
/** 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,TASK_TOOLS} 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.ok(TASK_TOOLS.every(name=>report.tools.includes(name)));
|
|
const presets=await ctx.agentPresets.list();
|
|
report.presets=presets.map(x=>x.id);
|
|
for(const preset of ['standard','minimal','cordis','ptc','dx-task'])assert.ok(report.presets.includes(preset));
|
|
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;
|
|
for(const [name,args] of [
|
|
['dx_task_catalog',{}],['dx_task_preflight',{task_ids:['fixture']}],
|
|
['dx_task_manage',{operation:'archive',task_id:'fixture'}],
|
|
['dx_task_execute',{operation:'start',task_ids:['fixture']}],
|
|
['dx_task_operations',{operation:'history'}],
|
|
]){
|
|
const result=await ctx.tools.execute({callId:'desktop-only-'+name,name,arguments:args,signal:AbortSignal.timeout(2000)});
|
|
assert.equal(result.isError,true,name+' requires parent desktop');
|
|
}
|
|
report.lifecycleRequiresDesktop=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 extension=await ctx.tools.execute({callId:'verify-extension',name:'forbidden_probe',arguments:{},signal:new AbortController().signal});
|
|
release();
|
|
assert.equal(extension.isError,false);
|
|
assert.equal(bodyRan,true);
|
|
report.nativeExtensionsAllowed=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;
|
|
for(const endpoint of ['/dx/runtime','/dx/workspace']){
|
|
assert.equal((await fetch(base+endpoint)).status,401);
|
|
}
|
|
assert.equal((await fetch(base+'/dx/operations',{method:'POST',headers:{'Content-Type':'application/json'},body:'{}'})).status,401);
|
|
report.operationsAndUsageAuthenticationEnforced=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;
|
|
assert.ok((await fetch(base+'/dx/workspace',{headers:auth}).then(r=>r.json())).workspace_id);
|
|
const usage=await fetch(base+'/dx/runtime',{headers:auth}).then(r=>r.json());
|
|
assert.equal(usage.settings.response_timeout_seconds,0);
|
|
assert.equal((await fetch(base+'/dx/operations',{method:'POST',headers:{...auth,'Content-Type':'application/json'},
|
|
body:JSON.stringify({revision:'stale',spec:{operation:'history'}})})).status,409);
|
|
report.operationsStaleAdmissionDenied=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;
|
|
await writeFile(process.env.DX_DSH_CONTEXT_FILE,JSON.stringify({task_id:'',revision:'taskless-revision',
|
|
status:'observe',automation:{task_id:'',incident_id:'a'.repeat(24)}}));
|
|
for(const [action,expected] of [['retry_issue',200],['open_evidence',200],['retry_failed',409],['pause_task',409]]){
|
|
const response=await fetch(base+'/dx/action',{method:'POST',headers:{...auth,'Content-Type':'application/json'},
|
|
body:JSON.stringify({action,task_id:'',revision:'taskless-revision'})});
|
|
assert.equal(response.status,expected,action);
|
|
}
|
|
report.tasklessEvidenceAndOutboxAllowed=true;
|
|
report.tasklessEngineeringActionsDenied=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);}
|