fix(dsh): restore native file tools and official loading UI
Core regression / Python core and release configuration (push) Successful in 20s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 15s
Core regression / JavaScript syntax (pull_request) Successful in 3s
Core regression / Python core and release configuration (push) Successful in 20s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 15s
Core regression / JavaScript syntax (pull_request) Successful in 3s
This commit is contained in:
1 parent
1340f6c233
commit
705c15eb93
19 files changed
+398
-42
No files matched your search
@@ -0,0 +1,77 @@
|
||||
/** Exercise actual Harness file tools against owned folders and ZIP archives. */
|
||||
import assert from 'node:assert/strict';
|
||||
import {mkdir,mkdtemp,writeFile,readFile,readdir} from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {createRequire} from 'node:module';
|
||||
import {bootRuntime} from '../integration/dsh/start.mjs';
|
||||
const require=createRequire(new URL('../integration/dsh/start.mjs',import.meta.url));
|
||||
const {zipSync,strToU8}=require('fflate');
|
||||
const output=path.resolve('build/dsh-files-verification');await mkdir(output,{recursive:true});
|
||||
const root=await mkdtemp(path.join(output,'run-'));
|
||||
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":"files-fixture","revision":"files","status":"observe"}');
|
||||
const source=path.join(root,'输入 文件夹');await mkdir(source);
|
||||
await writeFile(path.join(source,'说明.txt'),'DSH_FILE_CONTENT_中文\n');
|
||||
const archive=path.join(source,'资料.zip');
|
||||
await writeFile(archive,zipSync({'子目录/说明.txt':strToU8('DSH_ZIP_CONTENT_中文'),'binary.bin':new Uint8Array([0,1,2,255])}));
|
||||
const {ctx,shutdown}=await bootRuntime({announce:false});
|
||||
try{
|
||||
const names=ctx.tools.schemas().map(x=>x.name);
|
||||
for(const name of ['read','read_image','glob','grep','working_directory','extract_zip'])
|
||||
assert.ok(names.includes(name),'Missing file capability: '+name);
|
||||
const workspace=await ctx.workspaceRegistry.create(process.env.DX_DSH_WORKSPACE,'File fixture');
|
||||
const {sessionId}=await ctx.sessionController.create({workspaceId:workspace.id,agentPreset:'dx-task'});
|
||||
const agent=ctx.agents.get(sessionId);
|
||||
const call=async(name,args)=>ctx.tools.execute({name,arguments:args,callId:crypto.randomUUID(),agent,signal:AbortSignal.timeout(20000)});
|
||||
const ok=async(name,args)=>{
|
||||
const result=await call(name,args);assert.equal(result.isError,false,name+': '+JSON.stringify(result));return result;
|
||||
};
|
||||
assert.match(JSON.stringify(await ok('read',{file_path:path.join(source,'说明.txt')})),/DSH_FILE_CONTENT_中文/);
|
||||
assert.match(JSON.stringify(await ok('glob',{pattern:'*',path:source})),/说明.txt/);
|
||||
assert.match(JSON.stringify(await ok('grep',{pattern:'DSH_FILE_CONTENT',path:source})),/DSH_FILE_CONTENT/);
|
||||
await ok('working_directory',{cd:source});
|
||||
assert.match(JSON.stringify(await ok('read',{file_path:'说明.txt'})),/DSH_FILE_CONTENT/);
|
||||
const extracted=await ok('extract_zip',{file_path:'资料.zip'});
|
||||
const destination=extracted.value.directory;
|
||||
assert.equal(await readFile(path.join(destination,'子目录/说明.txt'),'utf8'),'DSH_ZIP_CONTENT_中文');
|
||||
assert.deepEqual(new Uint8Array(await readFile(path.join(destination,'binary.bin'))),new Uint8Array([0,1,2,255]));
|
||||
assert.match(JSON.stringify(await ok('read',{file_path:path.join(destination,'子目录/说明.txt')})),/DSH_ZIP_CONTENT/);
|
||||
assert.notEqual((await ok('extract_zip',{file_path:archive})).value.directory,destination,'repeated extraction must not overwrite');
|
||||
await writeFile(path.join(source,'unsafe.zip'),zipSync({'../escaped.txt':strToU8('must not escape')}));
|
||||
const before=await readdir(source);
|
||||
assert.equal((await call('extract_zip',{file_path:'unsafe.zip'})).isError,true);
|
||||
assert.deepEqual(await readdir(source),before,'unsafe archive must not publish a partial directory');
|
||||
await writeFile(path.join(source,'broken.zip'),'not a zip');
|
||||
assert.equal((await call('extract_zip',{file_path:'broken.zip'})).isError,true);
|
||||
const corrupt=Buffer.from(zipSync({'evidence.txt':strToU8('ORIGINAL_CONTENT')},{level:0}));
|
||||
const payload=corrupt.indexOf(Buffer.from('ORIGINAL_CONTENT'));assert.ok(payload>0);corrupt[payload]=88;
|
||||
await writeFile(path.join(source,'corrupt.zip'),corrupt);
|
||||
assert.equal((await call('extract_zip',{file_path:'corrupt.zip'})).isError,true,'CRC mismatch must not report successful extraction');
|
||||
assert.equal(await readFile(path.join(source,'说明.txt'),'utf8'),'DSH_FILE_CONTENT_中文\n');
|
||||
ctx.emit('dx/diagnose-request',{request_id:'files-incident-probe',incident_id:'a'.repeat(24),phase:'diagnose',
|
||||
snapshot:{task_id:'files-fixture'},evidence:'Owned fixture; no model is configured.'});
|
||||
let incident;
|
||||
const deadline=Date.now()+20000;
|
||||
while(Date.now()<deadline){
|
||||
incident=ctx.agents.list().find(value=>value.id!==agent.id);
|
||||
if(incident)break;
|
||||
await new Promise(resolve=>setTimeout(resolve,50));
|
||||
}
|
||||
assert.ok(incident,'automatic incident session must be created');
|
||||
let marked=false;
|
||||
while(Date.now()<deadline){
|
||||
const snapshot=await ctx.tools.execute({name:'dx_task_snapshot',arguments:{},callId:crypto.randomUUID(),agent:incident,signal:AbortSignal.timeout(2000)});
|
||||
if(snapshot.value?.revision==='a'.repeat(24)){marked=true;break;}
|
||||
await new Promise(resolve=>setTimeout(resolve,50));
|
||||
}
|
||||
assert.ok(marked,'incident snapshot must be bound before checking admission');
|
||||
for(const [name,args] of [['read',{file_path:path.join(source,'说明.txt')}],['extract_zip',{file_path:archive}]]){
|
||||
const denied=await ctx.tools.execute({name,arguments:args,callId:crypto.randomUUID(),agent:incident,signal:AbortSignal.timeout(2000)});
|
||||
assert.equal(denied.isError,true,'automatic incident must not inherit interactive file access');
|
||||
}
|
||||
const report={status:'passed',realHarness:true,read:true,folderSearch:true,workingDirectory:true,
|
||||
zipTextAndBinary:true,repeatedExtractionNoOverwrite:true,zipTraversalRejected:true,invalidZipRejected:true,corruptZipRejected:true,
|
||||
automaticSessionIsolation:true};
|
||||
await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2));console.log(JSON.stringify(report));
|
||||
}finally{await shutdown.shutdown(0);}
|
||||
Reference in new issue
Block a user