|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import json |
3 | 4 | from pathlib import Path |
4 | 5 |
|
5 | 6 | from minicode.tooling import ToolRegistry |
@@ -121,3 +122,52 @@ def test_run_headless_provider_failure_uses_runtime_channel_details( |
121 | 122 | assert "Active channel: anthropic-compatible via baseUrl/authToken." in response |
122 | 123 | assert "Next step: Primary runtime is using a single anthropic-compatible channel from baseUrl/authToken." in response |
123 | 124 |
|
| 125 | + |
| 126 | +def test_run_headless_writes_messages_trace_when_requested(monkeypatch, tmp_path: Path) -> None: |
| 127 | + import minicode.headless |
| 128 | + |
| 129 | + runtime = { |
| 130 | + "model": "deepseek-v4-pro[1m]", |
| 131 | + "baseUrl": "https://openai-proxy.example/v1", |
| 132 | + "authToken": "test-token", |
| 133 | + } |
| 134 | + trace_path = tmp_path / "artifacts" / "messages.json" |
| 135 | + |
| 136 | + monkeypatch.chdir(tmp_path) |
| 137 | + monkeypatch.setenv("MINI_CODE_HEADLESS_MESSAGES_OUT", str(trace_path)) |
| 138 | + monkeypatch.setattr( |
| 139 | + "minicode.config.load_runtime_config", |
| 140 | + lambda cwd: runtime, |
| 141 | + ) |
| 142 | + monkeypatch.setattr( |
| 143 | + "minicode.tools.create_default_tool_registry", |
| 144 | + lambda cwd, runtime=None: ToolRegistry([]), |
| 145 | + ) |
| 146 | + monkeypatch.setattr("minicode.permissions.PermissionManager", _DummyPermissions) |
| 147 | + monkeypatch.setattr("minicode.memory.MemoryManager", _DummyMemoryManager) |
| 148 | + monkeypatch.setattr( |
| 149 | + "minicode.prompt.build_system_prompt", |
| 150 | + lambda cwd, permissions, context: "sys", |
| 151 | + ) |
| 152 | + monkeypatch.setattr( |
| 153 | + "minicode.model_registry.create_model_adapter", |
| 154 | + lambda model, tools, runtime=None: object(), |
| 155 | + ) |
| 156 | + monkeypatch.setattr( |
| 157 | + "minicode.agent_loop.run_agent_turn", |
| 158 | + lambda **kwargs: [ |
| 159 | + {"role": "assistant", "content": "traceable"}, |
| 160 | + {"role": "tool", "content": "python -m unittest"}, |
| 161 | + ], |
| 162 | + ) |
| 163 | + |
| 164 | + response = minicode.headless.run_headless("Run the visible tests.") |
| 165 | + |
| 166 | + assert response == "traceable" |
| 167 | + payload = json.loads(trace_path.read_text(encoding="utf-8")) |
| 168 | + assert payload["cwd"] == str(tmp_path) |
| 169 | + assert payload["prompt"] == "Run the visible tests." |
| 170 | + assert payload["model"] == "deepseek-v4-pro[1m]" |
| 171 | + assert payload["assistant_response"] == "traceable" |
| 172 | + assert payload["error"] is None |
| 173 | + assert payload["messages"][0]["role"] == "assistant" |
0 commit comments