generated from coulomb/repo-seed
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
from llm_connect.replay import parse_audit_record
|
|
|
|
|
|
STRUCTURED_SCHEMA = {
|
|
"type": "object",
|
|
"properties": {
|
|
"summary": {"type": "string"},
|
|
"recommendations": {"type": "array", "items": {"type": "string"}},
|
|
},
|
|
"required": ["summary", "recommendations"],
|
|
}
|
|
|
|
|
|
def test_replay_parses_openai_style_provider_response():
|
|
record = {
|
|
"provider": "openrouter",
|
|
"config": {"model_params": {"json_schema": STRUCTURED_SCHEMA}},
|
|
"provider_response": {
|
|
"status": 200,
|
|
"body": {
|
|
"choices": [
|
|
{
|
|
"message": {
|
|
"content": '{"summary":"ok","recommendations":[]}'
|
|
}
|
|
}
|
|
]
|
|
},
|
|
},
|
|
"parsed_content": '{"summary":"ok","recommendations":[]}',
|
|
}
|
|
|
|
report = parse_audit_record(record)
|
|
|
|
assert report["parsed_content"] == '{"summary":"ok","recommendations":[]}'
|
|
assert report["matches_recorded_content"] is True
|
|
assert report["structured_output"] == {"checked": True, "valid": True}
|
|
|
|
|
|
def test_replay_reuses_claude_code_envelope_unwrapper():
|
|
record = {
|
|
"provider": "claude-code",
|
|
"config": {"model_params": {"json_schema": STRUCTURED_SCHEMA}},
|
|
"provider_response": {
|
|
"status": 0,
|
|
"body": {
|
|
"stdout": (
|
|
'{"type":"result","result":"prose",'
|
|
'"structured_result":"{\\"summary\\":\\"ok\\",'
|
|
'\\"recommendations\\":[]}"}'
|
|
),
|
|
"stderr": "",
|
|
},
|
|
},
|
|
"parsed_content": '{"summary":"ok","recommendations":[]}',
|
|
}
|
|
|
|
report = parse_audit_record(record)
|
|
|
|
assert report["parsed_content"] == '{"summary":"ok","recommendations":[]}'
|
|
assert report["matches_recorded_content"] is True
|
|
assert report["structured_output"] == {"checked": True, "valid": True}
|