mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-09-07 04:10:42 +00:00
142 lines
4.5 KiB
Python
142 lines
4.5 KiB
Python
from __future__ import annotations
|
|
|
|
import runpy
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
SMOKE = runpy.run_path(ROOT / "scripts" / "smoke-python-runtime.py")
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("prompt_name", "expected"),
|
|
[
|
|
("SNAPSHOT_DIRECT_CHILD_PROMPT", "DIRECT_CHILD_OK"),
|
|
("SNAPSHOT_WORKFLOW_CHILD_PROMPT", "WORKFLOW_CHILD_OK"),
|
|
],
|
|
)
|
|
def test_child_prompt_precedes_runtime_context(prompt_name: str, expected: str) -> None:
|
|
chunks = SMOKE["completion_chunks"]({
|
|
"messages": [
|
|
{"role": "user", "content": SMOKE[prompt_name]},
|
|
{"role": "user", "content": "Current runtime context"},
|
|
],
|
|
})
|
|
|
|
assert any(
|
|
choice.get("delta", {}).get("content") == expected
|
|
for chunk in chunks
|
|
for choice in chunk.get("choices", [])
|
|
)
|
|
|
|
|
|
def test_mcp_smoke_requests_the_discovered_tool() -> None:
|
|
chunks = SMOKE["completion_chunks"]({
|
|
"messages": [{"role": "user", "content": SMOKE["MCP_PROMPT"]}],
|
|
"tools": [{"type": "function", "function": {"name": "mcp__fixture__add"}}],
|
|
})
|
|
|
|
calls = [
|
|
call
|
|
for chunk in chunks
|
|
for choice in chunk.get("choices", [])
|
|
for call in choice.get("delta", {}).get("tool_calls", [])
|
|
]
|
|
assert calls[0]["function"] == {
|
|
"name": "mcp__fixture__add",
|
|
"arguments": '{"a": 19, "b": 23}',
|
|
}
|
|
|
|
|
|
def test_mcp_smoke_accepts_the_external_server_result() -> None:
|
|
chunks = SMOKE["completion_chunks"]({
|
|
"messages": [
|
|
{"role": "user", "content": SMOKE["MCP_PROMPT"]},
|
|
{
|
|
"role": "assistant",
|
|
"tool_calls": [{
|
|
"id": "mcp-add",
|
|
"type": "function",
|
|
"function": {"name": "mcp__fixture__add", "arguments": '{}'},
|
|
}],
|
|
},
|
|
{"role": "tool", "tool_call_id": "mcp-add", "content": "42"},
|
|
],
|
|
})
|
|
|
|
assert any(
|
|
choice.get("delta", {}).get("content") == SMOKE["MCP_TEXT"]
|
|
for chunk in chunks
|
|
for choice in chunk.get("choices", [])
|
|
)
|
|
|
|
|
|
def test_snapshot_comparison_normalizes_only_session_generation_provenance() -> None:
|
|
normalize = SMOKE["normalize_session_format_comparison"]
|
|
expected = {
|
|
"header": {"type": "session", "version": 0, "otherVersion": 7},
|
|
"accepted": {
|
|
"type": "session-log-deepseek/delivery-accepted",
|
|
"data": {"sessionId": "s", "throughSeq": 4},
|
|
},
|
|
"source": {
|
|
"kind": "session-reference",
|
|
"references": [{"sessionId": "other", "capturedThroughSeq": 8}],
|
|
},
|
|
}
|
|
actual = {
|
|
"header": {"type": "session", "version": 1, "otherVersion": 7},
|
|
"accepted": {
|
|
"type": "session-log-deepseek/delivery-accepted",
|
|
"data": {"sessionId": "s", "sessionFormatVersion": 1, "throughSeq": 4},
|
|
},
|
|
"source": {
|
|
"kind": "session-reference",
|
|
"references": [{
|
|
"sessionId": "other",
|
|
"capturedFormatVersion": 1,
|
|
"capturedThroughSeq": 8,
|
|
}],
|
|
},
|
|
}
|
|
|
|
assert normalize(expected) == normalize(actual)
|
|
assert normalize(expected)["header"]["otherVersion"] == 7
|
|
|
|
|
|
def test_snapshot_generation_names_select_highest_role_without_double_counting(
|
|
tmp_path: Path,
|
|
) -> None:
|
|
render = SMOKE["snapshot_session_filename"]
|
|
select = SMOKE["selected_snapshot_session_files"]
|
|
assert render(0, 0) == "session.jsonl"
|
|
assert render(0, 2) == "session.v2.jsonl"
|
|
assert render(3, 0) == "session.3.jsonl"
|
|
assert render(3, 2) == "session.3.v2.jsonl"
|
|
|
|
(tmp_path / "session.jsonl").write_text(
|
|
'{"type":"session","version":0}\n', encoding="utf-8",
|
|
)
|
|
(tmp_path / "session.v1.jsonl").write_text(
|
|
'{"type":"session","version":1}\n', encoding="utf-8",
|
|
)
|
|
(tmp_path / "session.1.jsonl").write_text(
|
|
'{"type":"session","version":0}\n', encoding="utf-8",
|
|
)
|
|
|
|
assert {index: path.name for index, path in select(tmp_path).items()} == {
|
|
0: "session.v1.jsonl",
|
|
1: "session.1.jsonl",
|
|
}
|
|
|
|
|
|
def test_snapshot_generation_filename_must_match_header(tmp_path: Path) -> None:
|
|
(tmp_path / "session.v1.jsonl").write_text(
|
|
'{"type":"session","version":0}\n', encoding="utf-8",
|
|
)
|
|
|
|
with pytest.raises(AssertionError, match="filename declares Session format v1"):
|
|
SMOKE["selected_snapshot_session_files"](tmp_path)
|