fix(assistant): authorize selected archives independently of recent snapshots
This commit is contained in:
1 parent
f136e1e503
commit
83606af1c4
5 files changed
+29
-8
No files matched your search
@@ -25,6 +25,13 @@ test('diagnosis and recovery cannot use another connection owner\'s export or ar
|
||||
const data=await(await f.call('/api/assistant/context',undefined,cookie)).json();assert.deepEqual(data.jobs.map(x=>x.jobId),['own-pdf']);assert.deepEqual(data.archives.map(x=>x.id),['mine']);
|
||||
assert.throws(()=>require('../../src/modules/assistant/policy.cjs').checkAction({kind:'retry_archive',targetId:'secret'},f.assistant.deps,{username:'member',role:'operator'}),e=>e.status===403);
|
||||
});
|
||||
test('archive authorization is independent of diagnostic recent-list truncation',async t=>{
|
||||
const f=await fixture(t),user={username:'member',role:'operator'},target={id:'older',jobId:'old-job',serverId:'shared',status:'error'};f.assistant.deps.dashboard={recentJobs:()=>[],job:id=>id==='old-job'?{jobId:id,connectionId:'own'}:null};
|
||||
f.assistant.deps.storage.store.archives=()=>[...Array.from({length:16},(_,i)=>({id:'new-'+i,connectionId:'own',serverId:'shared',status:'error'})),target];
|
||||
assert.doesNotThrow(()=>require('../../src/modules/assistant/policy.cjs').checkAction({kind:'retry_archive',targetId:'older'},f.assistant.deps,user));
|
||||
assert.deepEqual(require('../../src/modules/assistant/diagnostic-context.cjs').validateDiagnostic({command:'archive',targetId:'older'},f.assistant.deps,user),{command:'archive',targetId:'older'});
|
||||
const cookie=await f.login('member'),c=await(await f.call('/api/assistant/conversations',{},cookie)).json();let actual;f.assistant.runtime.chat=async input=>{actual=input.context;return JSON.stringify({reply:'diagnosed',actions:[]});};f.store.saveSettings({...f.store.settings(),enabled:true,runtimePath:process.execPath,apiBase:'https://fixture.example/anthropic',model:'fixture',apiKey:'TEST_ONLY_KEY',allowActions:false});const sent=await f.call('/api/assistant/conversations/'+c.id+'/messages',{text:'分析旧归档',diagnostic:{command:'archive',targetId:'older'}},cookie);assert.equal(sent.status,202);const turn=await sent.json();await f.assistant.running.get(turn.id)?.task;assert.equal(actual.selectedTarget.id,'older');
|
||||
});
|
||||
test('diagnostic command targets are validated at the API rather than trusted from display names',async t=>{
|
||||
const f=await fixture(t),cookie=await f.login('member'),created=await(await f.call('/api/assistant/conversations',{},cookie)).json();
|
||||
f.store.saveSettings({...f.store.settings(),enabled:true,runtimePath:process.execPath,apiBase:'https://fixture.example/anthropic',model:'test',apiKey:'TEST_ONLY_KEY',allowActions:false});
|
||||
|
||||
Reference in new issue
Block a user