refactor: organize source web and tests by business module

This commit is contained in:
abaishu0730 committed 2026-10-19 08:45:51 +08:00
1 parent 9854d2d5c2
commit 2aed328774
113 files changed
+189 -183

No files matched your search

@@ -0,0 +1,29 @@
const {test}=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs/promises'),os=require('node:os'),path=require('node:path');
async function fixture(t){
const {Store}=require('../../src/modules/dashboard/store.cjs'),{AssistantStore}=require('../../src/modules/assistant/store.cjs'),{AssistantService}=require('../../src/modules/assistant/service.cjs'),{createDashboard}=require('../../src/app/dashboard.cjs');
const dir=await fs.mkdtemp(path.join(os.tmpdir(),'assistant-http-')),users=new Store(path.join(dir,'users'));users.bootstrap('admin','Test-password-123');users.addUser({username:'viewer',role:'viewer',password:'Test-password-123'},'admin');const store=new AssistantStore(path.join(dir,'assistant'));let checks=0;
const storage={store:{servers:()=>[{id:'server',name:'测试存储',enabled:true,state:{readable:true,writable:true,message:'正常'}}],archives:()=>[]},check:async()=>{checks++;return {state:{readable:true,writable:true}};}};
const runtime={probe:async()=>({available:true,version:'3.14.3',message:'运行包已就绪'}),chat:async({text,signal,config})=>{if(text.includes('挂起'))return new Promise((resolve,reject)=>signal.addEventListener('abort',()=>reject(signal.reason),{once:true}));return JSON.stringify({reply:'已读取运行状态。<img src=x onerror=alert(1)>',actions:config.allowActions?[{kind:'check_storage',targetId:'server'}]:[]});}};
const assistant=new AssistantService({store,runtime,storage,dashboard:users}),server=createDashboard({store:users,assistant,outputDir:dir});await new Promise(r=>server.listen(0,'127.0.0.1',r));
t.after(async()=>{await assistant.stop();server.closeAllConnections();await new Promise(r=>server.close(r));store.close();await fs.rm(dir,{recursive:true,force:true});});const base='http://127.0.0.1:'+server.address().port;
const call=(route,body,cookie,origin=base)=>fetch(base+route,{method:body===undefined?'GET':'POST',headers:{...(body===undefined?{}:{'Content-Type':'application/json',Origin:origin}),...(cookie?{Cookie:cookie}:{})},body:body===undefined?undefined:JSON.stringify(body)}),login=async name=>(await call('/api/login',{username:name,password:'Test-password-123'})).headers.get('set-cookie').split(';')[0];return {base,call,login,store,assistant,checks:()=>checks};
}
test('assistant HTTP enforces authentication, ownership, body validation and role constraints',async t=>{
const {call,login,store,assistant}=await fixture(t);assert.equal((await call('/api/assistant')).status,401);const admin=await login('admin'),viewer=await login('viewer');
const settings={...store.settings(),enabled:true,runtimePath:process.execPath,apiBase:'https://models.example/v1',model:'fixture',apiKey:'PRIVATE_HTTP_KEY',allowActions:true};
assert.equal((await call('/api/assistant/settings',settings,viewer)).status,403);assert.equal((await call('/api/assistant/settings',settings,admin,'https://evil.example')).status,403);assert.equal((await call('/api/assistant/settings',settings,admin)).status,200);
assert.doesNotMatch(await(await call('/api/assistant',undefined,admin)).text(),/PRIVATE_HTTP_KEY/);
const created=await call('/api/assistant/conversations',{},admin);assert.equal(created.status,201);const c=await created.json();assert.equal((await call('/api/assistant/conversations/'+c.id,undefined,viewer)).status,404);
assert.equal((await call('/api/assistant/conversations/'+c.id+'/messages',{text:'hello',command:'shell'},admin)).status,400);
const sent=await call('/api/assistant/conversations/'+c.id+'/messages',{text:'分析状态'},admin);assert.equal(sent.status,202);const turn=await sent.json();await assistant.running.get(turn.id)?.task;
const saved=await(await call('/api/assistant/conversations/'+c.id,undefined,admin)).json();assert.equal(saved.turns[0].status,'success');assert.equal((await call('/api/assistant/conversations/'+c.id+'/actions/'+saved.turns[0].actions[0].id+'/execute',{},viewer)).status,403);
});
test('chat UI persists conversations, shows escaped messages and explicit fixed action results, and cancels a running reply',{timeout:120000},async t=>{
const {base,store,checks}=await fixture(t);store.saveSettings({...store.settings(),enabled:true,runtimePath:process.execPath,apiBase:'https://models.example/v1',model:'fixture',apiKey:'PRIVATE_UI_KEY',allowActions:true});
const {loadPlaywright,browserOptions}=require('../../src/platform/browser.cjs'),browser=await loadPlaywright().chromium.launch(browserOptions());t.after(()=>browser.close());const page=await browser.newPage({viewport:{width:1440,height:1000}}),errors=[];page.on('pageerror',e=>errors.push(e.message));page.setDefaultTimeout(15000);
await page.goto(base+'/#assistant');await page.getByLabel('账号',{exact:true}).fill('admin');await page.getByLabel('密码',{exact:true}).fill('Test-password-123');await page.getByRole('button',{name:'登录',exact:true}).click();await page.getByRole('button',{name:'新建对话',exact:true}).click();
await page.getByLabel('发送给 ZCode',{exact:true}).fill('分析订单运行状态');await page.getByRole('button',{name:'发送',exact:true}).click();await page.locator('.assistant-reply').getByText('已读取运行状态。<img src=x onerror=alert(1)>',{exact:true}).waitFor();assert.equal(await page.locator('.assistant-reply img').count(),0);assert.equal(checks(),0);
await page.getByRole('button',{name:'执行:检查存储连接',exact:true}).click();await page.getByText('操作已完成',{exact:true}).waitFor();assert.equal(checks(),1);await page.reload();await page.locator('.assistant-reply').getByText('已读取运行状态。<img src=x onerror=alert(1)>',{exact:true}).waitFor();
await page.getByLabel('发送给 ZCode',{exact:true}).fill('挂起诊断');await page.getByRole('button',{name:'发送',exact:true}).click();await page.getByRole('button',{name:'停止回复',exact:true}).click();await page.getByText('已停止本轮回复。',{exact:true}).waitFor();
await fs.mkdir('output/verification',{recursive:true});await page.screenshot({path:'output/verification/zcode-chat-desktop.png',fullPage:true});await page.setViewportSize({width:390,height:844});assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);assert.deepEqual(errors,[]);
});
+61
View File
@@ -0,0 +1,61 @@
const {test}=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs/promises'),os=require('node:os'),path=require('node:path');
const admin={user:{id:'admin',username:'admin',role:'admin'},sessionId:'admin-session'},operator={user:{id:'operator',username:'operator',role:'operator'},sessionId:'operator-session'},viewer={user:{id:'viewer',username:'viewer',role:'viewer'},sessionId:'viewer-session'};
async function fixture(t,runtime){
const {AssistantStore}=require('../../src/modules/assistant/store.cjs'),{AssistantService}=require('../../src/modules/assistant/service.cjs');
const dir=await fs.mkdtemp(path.join(os.tmpdir(),'order-assistant-')),store=new AssistantStore(dir);let checks=0,scans=0,archives=0;
const connections=[{id:'own',owner:'operator',name:'Own BPM',status:'connected',identity:'PRIVATE_IDENTITY'},{id:'other',owner:'other',name:'Other BPM',status:'connected'}];
const workspace={snapshot:()=>({connections,exceptions:[{id:'e1',owner:'operator',title:'扫描失败',status:'open',description:'password=PRIVATE_PASSWORD Cookie=PRIVATE_COOKIE'}]}),getConnection:id=>connections.find(c=>c.id===id),record(){}};
const storage={store:{servers:()=>[{id:'server',name:'Archive',enabled:true,username:'SECRET_USER',password:'PRIVATE_PASSWORD',state:{readable:true,writable:true,message:'open C:/PRIVATE_FOLDER/file.txt'}}],archives:()=>[{id:'archive',status:'error',serverId:'server',jobId:'pdf',baseDirectory:'产业A',error:'共享不可用'}]},check:async()=>{checks++;return {state:{readable:true,writable:true}};},archive:async()=>{archives++;return {status:'success',relativePath:'产业A/123456/file.pdf'};}};
const scanner={store:{status:()=>({config:{enabled:true},runs:[{connectionId:'own',status:'success'},{connectionId:'other',status:'error',message:'Cookie=PRIVATE_COOKIE'}]})},scan:async()=>{scans++;return {seen:2,added:0};}};
const dashboard={jobs:()=>[{jobId:'pdf',status:'success',path:'C:/PRIVATE_PATH/file.pdf',metadata:{order:'123456'}}]};
const service=new AssistantService({store,workspace,storage,scanner,dashboard,runtime:runtime||{probe:async()=>({available:true,version:'3.14.3'}),chat:async()=>JSON.stringify({reply:'已查询状态',actions:[]})}});
t.after(async()=>{await service.stop();store.close();await fs.rm(dir,{recursive:true,force:true});});
store.saveSettings({...store.settings(),enabled:true,runtimePath:process.execPath,apiBase:'https://models.example/v1',model:'test-model',apiKey:'PRIVATE_API_KEY',allowActions:true});
return {dir,store,service,workspace,counters:()=>({checks,scans,archives})};
}
test('assistant conversations are private, encrypted and survive restart without exposing the API key',async t=>{
const {AssistantStore}=require('../../src/modules/assistant/store.cjs'),{dir,store,service}=await fixture(t),c=store.create(admin.user.id);const turn=service.send(c.id,admin,'PRIVATE_CHAT_MESSAGE');await service.running.get(turn.id).task;
assert.throws(()=>store.conversation(c.id,operator.user.id),e=>e.status===404);assert.deepEqual(store.conversations(operator.user.id),[]);assert.equal(store.settings().hasApiKey,true);assert.equal(store.settings().apiKey,undefined);
const restart=new AssistantStore(dir);try{assert.equal(restart.conversation(c.id,admin.user.id).turns[0].text,'PRIVATE_CHAT_MESSAGE');assert.equal(restart.secretSettings().apiKey,'PRIVATE_API_KEY');}finally{restart.close();}
for(const name of await fs.readdir(dir))if(name.includes('.sqlite')){const bytes=await fs.readFile(path.join(dir,name));assert.equal(bytes.includes(Buffer.from('PRIVATE_CHAT_MESSAGE')),false);assert.equal(bytes.includes(Buffer.from('PRIVATE_API_KEY')),false);}
});
test('model gets only permitted diagnostic fields and unsupported actions never execute',async t=>{
let request;const runtime={chat:async input=>{request=input;return JSON.stringify({reply:'状态已读取',actions:[{kind:'shell',targetId:'server'}]});}};const {store,service,counters}=await fixture(t,runtime),c=store.create(operator.user.id),turn=service.send(c.id,operator,'分析失败');await service.running.get(turn.id).task;
const context=JSON.stringify(request.context);assert.doesNotMatch(context,/PRIVATE_|SECRET_USER|C:\/|Other BPM|other"/);assert.equal(store.conversation(c.id,operator.user.id).turns[0].status,'error');assert.deepEqual(counters(),{checks:0,scans:0,archives:0});
});
test('fixed action cards require opt-in and current role, check ownership and are single use',async t=>{
const runtime={chat:async()=>JSON.stringify({reply:'建议检查共享',actions:[{kind:'check_storage',targetId:'server'},{kind:'scan_bpm',targetId:'own'},{kind:'retry_archive',targetId:'archive'}]})};const {store,service,counters}=await fixture(t,runtime),c=store.create(admin.user.id),turn=service.send(c.id,admin,'检查情况');await service.running.get(turn.id).task;
let saved=store.conversation(c.id,admin.user.id).turns[0];assert.deepEqual(counters(),{checks:0,scans:0,archives:0});assert.equal(saved.actions.length,3);
await assert.rejects(service.executeAction(c.id,saved.actions[0].id,{...viewer,user:{...viewer.user,id:admin.user.id}}),e=>e.status===403);
for(const action of saved.actions)await service.executeAction(c.id,action.id,admin);
assert.deepEqual(counters(),{checks:1,scans:1,archives:1});await assert.rejects(service.executeAction(c.id,saved.actions[0].id,admin),e=>e.status===409);
store.saveSettings({...store.settings(),apiKey:'',allowActions:false});saved=store.conversation(c.id,admin.user.id).turns[0];assert.ok(saved.actions.every(a=>a.status==='success'));
});
test('unauthorized BPM targets are rejected, and disabling actions also blocks previously proposed cards',async t=>{
let other=true;const {store,service,counters}=await fixture(t,{chat:async()=>JSON.stringify({reply:'建议扫描',actions:[{kind:'scan_bpm',targetId:other?'other':'own'}]})}),c=store.create(operator.user.id);let turn=service.send(c.id,operator,'扫描');await service.running.get(turn.id).task;assert.equal(store.conversation(c.id,operator.user.id).turns[0].status,'error');other=false;
turn=service.send(c.id,operator,'扫描我的连接');await service.running.get(turn.id).task;const action=store.conversation(c.id,operator.user.id).turns.at(-1).actions[0];store.saveSettings({...store.settings(),apiKey:'',allowActions:false});await assert.rejects(service.executeAction(c.id,action.id,operator),e=>e.status===403);assert.equal(counters().scans,0);
});
test('cancellation, per-conversation serialization and daily limits retain truthful task states',async t=>{
const {store,service}=await fixture(t,{chat:({signal})=>new Promise((resolve,reject)=>{if(signal.aborted)reject(signal.reason);else signal.addEventListener('abort',()=>reject(signal.reason),{once:true});})}),c=store.create(admin.user.id);store.saveSettings({...store.settings(),apiKey:'',dailyLimit:1});const turn=service.send(c.id,admin,'分析');assert.throws(()=>service.send(c.id,admin,'重复'),e=>e.status===409);service.cancel(c.id,admin);await service.running.get(turn.id).task;assert.equal(store.conversation(c.id,admin.user.id).turns[0].status,'cancelled');assert.throws(()=>service.send(c.id,admin,'第二次'),e=>e.status===429);
});
test('a failing diagnostic source does not leave an un-cancellable running turn',async t=>{
const {store,service}=await fixture(t),c=store.create(admin.user.id),status=service.deps.scanner.store.status;service.deps.scanner.store.status=()=>{throw new Error('damaged source');};
assert.throws(()=>service.send(c.id,admin,'分析'));assert.equal(store.conversation(c.id,admin.user.id).turns.length,0);
service.deps.scanner.store.status=status;const turn=service.send(c.id,admin,'再次分析');await service.running.get(turn.id).task;assert.equal(store.conversation(c.id,admin.user.id).turns[0].status,'success');
});
test('a known API key pasted into an earlier message never reappears in follow-up model history',async t=>{
const calls=[],{store,service}=await fixture(t,{chat:async input=>{calls.push(input);return JSON.stringify({reply:'已读取状态',actions:[]});}}),c=store.create(admin.user.id);
let turn=service.send(c.id,admin,'PRIVATE_API_KEY');await service.running.get(turn.id).task;store.saveSettings({...store.settings(),apiKey:'NEW_API_KEY',apiBase:'https://new-models.example/v1'});turn=service.send(c.id,admin,'继续'+'字'.repeat(2998));await service.running.get(turn.id).task;
assert.doesNotMatch(JSON.stringify(calls.map(({config,...rest})=>rest)),/PRIVATE_API_KEY/);assert.match(calls[1].history[0].user,/已隐藏/);assert.equal(calls[1].text.length,3000);assert.equal(store.conversation(c.id,admin.user.id).turns.at(-1).text.length,3000);
});
test('a cancellation signal alone cannot label an unconfirmed runtime failure as stopped',async t=>{
const {store,service}=await fixture(t,{chat:({signal})=>new Promise((resolve,reject)=>signal.addEventListener('abort',()=>reject(new Error('cleanup failed')),{once:true}))}),c=store.create(admin.user.id),turn=service.send(c.id,admin,'分析');
await new Promise(resolve=>setImmediate(resolve));service.cancel(c.id,admin);await service.running.get(turn.id).task;
assert.equal(store.conversation(c.id,admin.user.id).turns[0].status,'error');
});
test('only a matching installed runtime is discovered, without enabling the model',async t=>{
const {AssistantStore}=require('../../src/modules/assistant/store.cjs'),crypto=require('node:crypto'),root=await fs.mkdtemp(path.join(os.tmpdir(),'order-zcode-discovery-')),dir=path.join(root,'assistant'),install=path.join(root,'zcode-runtime'),runtimePath=path.join(install,'3.14.3/package/resources/glm/zcode.cjs');t.after(()=>fs.rm(root,{recursive:true,force:true}));
await fs.mkdir(path.dirname(runtimePath),{recursive:true});await fs.writeFile(runtimePath,'fixture');await fs.writeFile(path.join(install,'manifest.json'),JSON.stringify({releaseVersion:'3.14.3',cliVersion:'0.16.9',runtimePath,runtimeSha256:'sha256:'+crypto.createHash('sha256').update('fixture').digest('hex')}));
const store=new AssistantStore(dir);assert.equal(store.settings().runtimePath,runtimePath);assert.equal(store.settings().enabled,false);assert.equal(store.settings().hasApiKey,false);store.close();
await fs.writeFile(runtimePath,'modified');const changed=new AssistantStore(dir);try{assert.equal(changed.settings().runtimePath,'');}finally{changed.close();}
});
+25
View File
@@ -0,0 +1,25 @@
'use strict';
const {test}=require('node:test'),assert=require('node:assert/strict'),http=require('node:http'),fs=require('node:fs/promises'),os=require('node:os'),path=require('node:path');
const {ZcodeRuntime}=require('../../src/modules/assistant/zcode-runtime.cjs');
test('pinned official ZCode calls a local model with no native tools and cannot execute unsolicited tool calls',{skip:!process.env.ORDER_TEST_ZCODE_CLI,timeout:180000},async t=>{
const dir=await fs.mkdtemp(path.join(os.tmpdir(),'order-official-zcode-')),runtime=new ZcodeRuntime({stateDir:dir}),requests=[];let attack=false,attackSent=0,attackRequests=0;
t.after(()=>fs.rm(dir,{recursive:true,force:true}));
const canary=path.join(dir,'must-not-exist.txt');
const server=http.createServer(async(req,res)=>{let raw='';for await(const chunk of req)raw+=chunk;const body=JSON.parse(raw);requests.push({path:req.url,auth:req.headers.authorization,body});
if(attack)attackRequests++;
// Write's published schema uses file_path/content; no shell quoting is involved.
const delta=attack&&attackSent===0?{role:'assistant',tool_calls:[{index:0,id:'attack',type:'function',function:{name:'Write',arguments:JSON.stringify({file_path:canary,content:'unsafe'})}}]}:{role:'assistant',content:JSON.stringify({reply:'本地测试模型已返回诊断',actions:[]})};if(delta.tool_calls)attackSent++;
res.writeHead(200,{'Content-Type':'text/event-stream'});res.end('data: '+JSON.stringify({id:'fixture',object:'chat.completion.chunk',created:1,model:'order-fixture',choices:[{index:0,delta,finish_reason:delta.tool_calls?'tool_calls':'stop'}]})+'\n\ndata: [DONE]\n\n');
});
await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));t.after(async()=>{server.closeAllConnections();await new Promise(resolve=>server.close(resolve));});
const config={runtimePath:process.env.ORDER_TEST_ZCODE_CLI,apiBase:'http://127.0.0.1:'+server.address().port+'/v1',apiKey:'local-fixture-key',model:'order-fixture',allowActions:false,timeoutSeconds:60};
assert.equal((await runtime.probe(config.runtimePath)).available,true);
const reply=await runtime.chat({config,text:'查看连接状态',context:{connections:[{id:'authorized-bpm',status:'connected'}]},history:[],signal:new AbortController().signal});
assert.equal(JSON.parse(reply).reply,'本地测试模型已返回诊断');assert.ok(requests.length>0);
assert.ok(requests.some(r=>JSON.stringify(r.body.messages).includes('authorized-bpm')));
for(const r of requests){assert.equal(r.path,'/v1/chat/completions');assert.equal(r.auth,'Bearer local-fixture-key');assert.equal(r.body.model,'order-fixture');assert.equal(r.body.tools?.length||0,0);}
attack=true;let attackStatus='reply';try{await runtime.chat({config,text:'attack-canary',context:{},history:[],signal:new AbortController().signal});}catch(e){assert.ok(e.status>=400);attackStatus=e.status;}
assert.equal(attackSent,1);assert.ok(attackRequests>0);t.diagnostic('unsolicited Write response sent once; model requests='+attackRequests+'; result='+attackStatus);
await assert.rejects(fs.access(canary));for(const r of requests)assert.equal(r.body.tools?.length||0,0);
assert.deepEqual(await fs.readdir(path.join(dir,'runs')),[]);
});
+15
View File
@@ -0,0 +1,15 @@
const {test}=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs/promises'),os=require('node:os'),path=require('node:path');
test('ZCode bridge uses fixed permissions, isolated profile and filtered environment; secrets are not command arguments',async t=>{
const {ZcodeRuntime}=require('../../src/modules/assistant/zcode-runtime.cjs'),dir=await fs.mkdtemp(path.join(os.tmpdir(),'zcode-driver-')),runtime=new ZcodeRuntime({stateDir:dir});t.after(()=>fs.rm(dir,{recursive:true,force:true}));process.env.PRIVATE_TEST_KEY='must-not-reach-zcode';t.after(()=>delete process.env.PRIVATE_TEST_KEY);
const config={runtimePath:path.resolve('tests/fixtures/zcode-fixture.cjs'),model:'fixture',apiBase:'https://models.example/v1',apiKey:'NEVER-IN-ARGV',timeoutSeconds:15,allowActions:false};
assert.equal((await runtime.probe(config.runtimePath)).available,true);
const result=JSON.parse(await runtime.chat({config,text:'hello $() `shell`',history:[],context:{servers:[]},signal:new AbortController().signal}));assert.equal(result.observed.privateEnv,undefined);assert.equal(result.observed.args[result.observed.args.indexOf('--mode')+1],'plan');assert.ok(result.observed.args.includes('--disallowed-tools'));assert.doesNotMatch(JSON.stringify(result.observed.args),/NEVER-IN-ARGV/);assert.equal(result.observed.config.plugins.enabled,false);assert.equal(result.observed.config.features.mcp,false);assert.equal(result.observed.config.features.subagent,false);assert.match(result.observed.cwd,/zcode-driver/);assert.deepEqual(await fs.readdir(path.join(dir,'runs')),[]);
});
test('ZCode cancellation and excessive output terminate the invocation and clean private profiles',async t=>{
const {ZcodeRuntime}=require('../../src/modules/assistant/zcode-runtime.cjs'),dir=await fs.mkdtemp(path.join(os.tmpdir(),'zcode-abort-')),runtime=new ZcodeRuntime({stateDir:dir});t.after(()=>fs.rm(dir,{recursive:true,force:true}));const config={runtimePath:path.resolve('tests/fixtures/zcode-fixture.cjs'),model:'fixture',apiBase:'https://models.example/v1',apiKey:'secret',timeoutSeconds:15};
const controller=new AbortController(),pending=runtime.chat({config,text:'FIXTURE_HANG',history:[],context:{},signal:controller.signal});setTimeout(()=>controller.abort(Object.assign(new Error('cancelled'),{status:499})),350);await assert.rejects(pending,e=>e.status===499);assert.deepEqual(await fs.readdir(path.join(dir,'runs')),[]);
await assert.rejects(runtime.chat({config,text:'FIXTURE_OVERFLOW',history:[],context:{},signal:new AbortController().signal}),e=>e.status===502);assert.deepEqual(await fs.readdir(path.join(dir,'runs')),[]);
});
test('cancelling during runtime discovery interrupts the probe and cleans its profile',async t=>{
const {ZcodeRuntime}=require('../../src/modules/assistant/zcode-runtime.cjs'),dir=await fs.mkdtemp(path.join(os.tmpdir(),'zcode-probe-abort-')),entry=path.join(dir,'slow-probe.cjs'),runtime=new ZcodeRuntime({stateDir:dir});t.after(()=>fs.rm(dir,{recursive:true,force:true}));await fs.writeFile(entry,"setInterval(()=>{},1000);");const controller=new AbortController();const pending=runtime.chat({config:{runtimePath:entry,timeoutSeconds:15},text:'hello',history:[],context:{},signal:controller.signal});setTimeout(()=>controller.abort(Object.assign(new Error('cancelled'),{status:499})),500);await assert.rejects(pending,e=>e.status===499);assert.deepEqual(await fs.readdir(path.join(dir,'runs')),[]);
});