test_smoke_model.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from __future__ import annotations
  2. import runpy
  3. from pathlib import Path
  4. import pytest
  5. ROOT = Path(__file__).resolve().parents[3]
  6. SMOKE = runpy.run_path(ROOT / "scripts" / "smoke-python-runtime.py")
  7. @pytest.mark.parametrize(
  8. ("prompt_name", "expected"),
  9. [
  10. ("SNAPSHOT_DIRECT_CHILD_PROMPT", "DIRECT_CHILD_OK"),
  11. ("SNAPSHOT_WORKFLOW_CHILD_PROMPT", "WORKFLOW_CHILD_OK"),
  12. ],
  13. )
  14. def test_child_prompt_precedes_runtime_context(prompt_name: str, expected: str) -> None:
  15. chunks = SMOKE["completion_chunks"]({
  16. "messages": [
  17. {"role": "user", "content": SMOKE[prompt_name]},
  18. {"role": "user", "content": "Current runtime context"},
  19. ],
  20. })
  21. assert any(
  22. choice.get("delta", {}).get("content") == expected
  23. for chunk in chunks
  24. for choice in chunk.get("choices", [])
  25. )
  26. def test_mcp_smoke_requests_the_discovered_tool() -> None:
  27. chunks = SMOKE["completion_chunks"]({
  28. "messages": [{"role": "user", "content": SMOKE["MCP_PROMPT"]}],
  29. "tools": [{"type": "function", "function": {"name": "mcp__fixture__add"}}],
  30. })
  31. calls = [
  32. call
  33. for chunk in chunks
  34. for choice in chunk.get("choices", [])
  35. for call in choice.get("delta", {}).get("tool_calls", [])
  36. ]
  37. assert calls[0]["function"] == {
  38. "name": "mcp__fixture__add",
  39. "arguments": '{"a": 19, "b": 23}',
  40. }
  41. def test_mcp_smoke_accepts_the_external_server_result() -> None:
  42. chunks = SMOKE["completion_chunks"]({
  43. "messages": [
  44. {"role": "user", "content": SMOKE["MCP_PROMPT"]},
  45. {
  46. "role": "assistant",
  47. "tool_calls": [{
  48. "id": "mcp-add",
  49. "type": "function",
  50. "function": {"name": "mcp__fixture__add", "arguments": '{}'},
  51. }],
  52. },
  53. {"role": "tool", "tool_call_id": "mcp-add", "content": "42"},
  54. ],
  55. })
  56. assert any(
  57. choice.get("delta", {}).get("content") == SMOKE["MCP_TEXT"]
  58. for chunk in chunks
  59. for choice in chunk.get("choices", [])
  60. )