|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
5 | | -from test.support.openai_replay_server import validate_request |
| 5 | +from test.support.openai_replay_server import attachment_contexts, validate_request |
6 | 6 |
|
7 | 7 |
|
8 | 8 | @pytest.mark.parametrize("mutation", ["none", "drop_input", "reorder", "move_image"]) |
@@ -64,6 +64,42 @@ def test_replay_checks_each_input_attachment_anchor(marker, context, error): |
64 | 64 | assert validate_request("Bearer ci-replay-key", body) == error |
65 | 65 |
|
66 | 66 |
|
| 67 | +@pytest.mark.timeout(3) |
| 68 | +@pytest.mark.parametrize("kind", ["anchor", "absent"]) |
| 69 | +def test_replay_handles_many_unterminated_attachment_tags_with_bounded_work(kind): |
| 70 | + """大量未闭合标签不能让两个附件检查入口重复扫描整段文本。""" |
| 71 | + marker = "DETERMINISTIC_ATTACHMENT_ANCHOR:batch-0.txt" if kind == "anchor" else "DETERMINISTIC_ATTACHMENT_ABSENT:batch-1.txt" |
| 72 | + body = { |
| 73 | + "model": "deterministic-chat", |
| 74 | + "stream": True, |
| 75 | + "messages": [ |
| 76 | + {"role": "system", "content": "# 图片生成技能"}, |
| 77 | + {"role": "user", "content": f"DETERMINISTIC_AGENT_E2E_OK {marker} " + "<attachment_context>" * 25_000}, |
| 78 | + ], |
| 79 | + "tools": [{"type": "function", "function": {"name": "present_artifacts"}}], |
| 80 | + } |
| 81 | + expected = "attachment_anchor_missing" if kind == "anchor" else "future_attachment_in_current_input" |
| 82 | + assert validate_request("Bearer ci-replay-key", body) == expected |
| 83 | + |
| 84 | + |
| 85 | +@pytest.mark.parametrize( |
| 86 | + ("content", "expected"), |
| 87 | + [ |
| 88 | + ("plain", []), |
| 89 | + ("<attachment_context></attachment_context>", [""]), |
| 90 | + ("before<attachment_context>one\ntwo</attachment_context>after", ["one\ntwo"]), |
| 91 | + ( |
| 92 | + "<attachment_context>outer<attachment_context>inner</attachment_context></attachment_context>", |
| 93 | + ["outer<attachment_context>inner"], |
| 94 | + ), |
| 95 | + ("<attachment_context>a</attachment_context><attachment_context>b</attachment_context><attachment_context>c", ["a", "b"]), |
| 96 | + ], |
| 97 | +) |
| 98 | +def test_replay_attachment_tag_extraction_preserves_protocol_cases(content, expected): |
| 99 | + """固定空、跨行、嵌套、多段和末段未闭合样本,保持 oracle 内容语义。""" |
| 100 | + assert attachment_contexts(content) == expected |
| 101 | + |
| 102 | + |
67 | 103 | @pytest.mark.parametrize( |
68 | 104 | ("authorization", "change", "expected_error"), |
69 | 105 | [ |
|
0 commit comments