v1.0
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
# tests/test_integration.py
|
||||
import os
|
||||
import tempfile
|
||||
from unittest.mock import patch, MagicMock
|
||||
from agent import generate
|
||||
|
||||
FIXTURE_DIR = os.path.join(os.path.dirname(__file__), 'test_data')
|
||||
|
||||
|
||||
@patch('agent.api_client.requests.post')
|
||||
def test_full_pipeline_mock_api(mock_post):
|
||||
"""完整流水线测试,API 调用使用 mock。"""
|
||||
mock_response = MagicMock()
|
||||
mock_response.json.return_value = {
|
||||
'choices': [{'message': {'content': '''{
|
||||
"groups": {
|
||||
"g1": {
|
||||
"program": "ZAN04MAT",
|
||||
"records": [
|
||||
{
|
||||
"input": {
|
||||
"R01INNFIL": {
|
||||
"R01-APPL-ID": "A0000001",
|
||||
"R01-EMP-ID": "00000101",
|
||||
"R01-APPL-DATE": "20260101",
|
||||
"R01-START-TIME": "0900",
|
||||
"R01-END-TIME": "1800",
|
||||
"R01-STATUS": "0",
|
||||
"R01-OVT-TYPE": "W",
|
||||
"R01-FILLER": "D000000000000000000000000000000000000000000001"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}'''}}]
|
||||
}
|
||||
mock_response.raise_for_status = MagicMock()
|
||||
mock_post.return_value = mock_response
|
||||
|
||||
cpy_dir = FIXTURE_DIR
|
||||
output_dir = tempfile.mkdtemp()
|
||||
rules_dir = os.path.join(os.path.dirname(__file__), '..', 'rules')
|
||||
|
||||
design_md = os.path.join(FIXTURE_DIR, '詳細設計書_ZAN04MAT.md')
|
||||
source_cbl = os.path.join(FIXTURE_DIR, '..', '..', '..',
|
||||
'cobol-tna-system', 'src', 'ZAN04MAT.cbl')
|
||||
|
||||
# Fallback if real source not found
|
||||
if not os.path.exists(source_cbl):
|
||||
source_cbl = os.path.join(output_dir, 'dummy.cbl')
|
||||
with open(source_cbl, 'w', encoding='utf-8') as f:
|
||||
f.write("COPY ZAN01REC REPLACING ==(A)== BY ==R01==.\n")
|
||||
|
||||
try:
|
||||
result = generate(
|
||||
design_md=design_md,
|
||||
source_cbl=source_cbl,
|
||||
file_db_md='dummy.md',
|
||||
cpy_dir=cpy_dir,
|
||||
db_md='dummy_db.md',
|
||||
output_dir=output_dir,
|
||||
api_key='test-key',
|
||||
rules_dir=rules_dir,
|
||||
)
|
||||
|
||||
assert result['program_id'] == 'ZAN04MAT'
|
||||
assert result['groups'] > 0
|
||||
assert len(result['output_files']) > 0
|
||||
|
||||
for path in result['output_files'].values():
|
||||
assert os.path.exists(path), f"输出文件不存在: {path}"
|
||||
|
||||
finally:
|
||||
if source_cbl.endswith('dummy.cbl') and os.path.exists(source_cbl):
|
||||
os.remove(source_cbl)
|
||||
Reference in New Issue
Block a user