fix: reconcile ai-11-2 with local knowledge and permission changes

This commit is contained in:
gr
2026-11-03 12:13:47 +08:00
parent 276338381b
commit 3cb30a7574
18 changed files with 3094 additions and 337 deletions
+17 -8
View File
@@ -97,8 +97,10 @@ class ModelOutputWorkerTest(TestCase):
job = self.seed()
first_reply = json.dumps(fields(answer=None))
second_reply = json.dumps(fields(title='正常第二条', question='测试门店周末几点营业?'))
with mock.patch('model_gateway.call_outlet', new_callable=mock.AsyncMock) as call:
call.side_effect = [{'text': first_reply, 'error': ''}, {'text': second_reply, 'error': ''}]
async def reply(client, outlet, messages, **kwargs):
# 两段问答并发整理,调用顺序不固定:按问题内容决定回什么
return {'text': first_reply if '提前多久预约' in messages[0]['content'] else second_reply, 'error': ''}
with mock.patch('model_gateway.call_outlet', side_effect=reply):
KnowledgeWorker(self.store).step()
result = self.store.job('default', job['id'])
self.assertEqual((result['status'], result['created_items'], result['pending_items'], result['model_calls']), ('completed', 2, 0, 2))
@@ -116,13 +118,20 @@ class ModelOutputWorkerTest(TestCase):
def test_fallback_commit_survives_later_transport_failure_and_resume(self):
job = self.seed()
with mock.patch('model_gateway.call_outlet', new_callable=mock.AsyncMock) as call:
call.side_effect = [{'text': 'incomplete JSON', 'error': ''}, {'text': '', 'error': '上游返回 429: private-provider-body'}]
async def reply(client, outlet, messages, **kwargs):
if '提前多久预约' in messages[0]['content']:
return {'text': 'incomplete JSON', 'error': ''}
return {'text': '', 'error': '上游返回 429: private-provider-body'}
with mock.patch('model_gateway.call_outlet', side_effect=reply):
KnowledgeWorker(self.store).step()
failed = self.store.job('default', job['id'])
self.assertEqual((failed['status'], failed['created_items'], failed['pending_items']), ('failed', 1, 1))
self.assertEqual(failed['options']['model_format_fallbacks'], 1)
self.assertIn('429', failed['error']); self.assertNotIn('private-provider-body', failed['error'])
# 限流是临时错误:保存好的结果留着,任务放回队列、退避后自动重试,而不是停下来等人
waiting = self.store.job('default', job['id'])
self.assertEqual((waiting['status'], waiting['created_items'], waiting['pending_items']), ('queued', 1, 1))
self.assertEqual(waiting['options']['model_format_fallbacks'], 1)
self.assertIn('429', waiting['error']); self.assertIn('自动重试', waiting['error'])
self.assertNotIn('private-provider-body', waiting['error'])
self.assertFalse(KnowledgeWorker(self.store).step(), 'A backing-off job must not be claimed early')
self.store.job_action('default', job['id'], 'pause', self.actor, '')
self.store.job_action('default', job['id'], 'resume', self.actor, '')
with mock.patch('model_gateway.call_outlet', new_callable=mock.AsyncMock) as call:
call.return_value = {'text': json.dumps(fields()), 'error': ''}