Stabilize product data export flow

This commit is contained in:
wuyang6
2026-05-11 11:46:09 +08:00
parent 1752c81913
commit 0e2a00990f
19 changed files with 659 additions and 31 deletions
+58
View File
@@ -769,6 +769,64 @@ class AgentRuntimeTests(unittest.TestCase):
self.assertGreaterEqual(mutation_totals.get('assistant_tool_call_delta', 0), 2)
self.assertEqual(mutation_totals.get('assistant_finalize', 0), 1)
def test_agent_reports_malformed_streaming_tool_arguments(self) -> None:
responses = [
[
{
'choices': [
{
'delta': {
'tool_calls': [
{
'index': 0,
'id': 'call_1',
'function': {
'name': 'data_agent_normalize_dataset_draft',
'arguments': '{"draft_text": "target: Agent(tag="地图导航")"}',
},
}
]
},
'finish_reason': None,
}
]
},
{
'choices': [{'delta': {}, 'finish_reason': 'tool_calls'}],
'usage': {'prompt_tokens': 9, 'completion_tokens': 4},
},
]
]
with tempfile.TemporaryDirectory() as tmp_dir:
workspace = Path(tmp_dir)
with patch(
'src.openai_compat.request.urlopen',
side_effect=make_streaming_urlopen_side_effect(responses),
):
agent = LocalCodingAgent(
model_config=ModelConfig(
model='Qwen/Qwen3-Coder-30B-A3B-Instruct',
base_url='http://127.0.0.1:8000/v1',
),
runtime_config=AgentRuntimeConfig(
cwd=workspace,
stream_model_responses=True,
),
)
result = agent.run('Generate records')
self.assertEqual(result.stop_reason, 'backend_error')
self.assertIn('模型返回的工具参数不是合法 JSON', result.final_output)
self.assertIn('data_agent_normalize_dataset_draft', result.final_output)
malformed = [
message
for message in result.transcript
if message.get('stop_reason') == 'malformed_tool_arguments'
]
self.assertEqual(len(malformed), 1)
self.assertNotIn('tool_calls', malformed[0])
self.assertEqual(result.transcript[-1]['content'], result.final_output)
def test_transcript_entries_include_structured_blocks(self) -> None:
responses = [
{