| 1 | from types import SimpleNamespace |
| 2 | |
| 3 | from agent import AgentContextType |
| 4 | from extensions.python.hist_add_tool_result._90_save_tool_call_file import SaveToolCallFile |
| 5 | |
| 6 | |
| 7 | def test_tool_result_file_persistence_skips_background_context(tmp_path, monkeypatch) -> None: |
| 8 | target = tmp_path / "messages" |
| 9 | agent = SimpleNamespace( |
| 10 | context=SimpleNamespace(id="background-worker", type=AgentContextType.BACKGROUND) |
| 11 | ) |
| 12 | data = {"tool_result": "x" * 501} |
| 13 | |
| 14 | monkeypatch.setattr( |
| 15 | "extensions.python.hist_add_tool_result._90_save_tool_call_file.persist_chat.get_chat_msg_files_folder", |
| 16 | lambda _ctxid: str(target), |
| 17 | ) |
| 18 | |
| 19 | SaveToolCallFile(agent=agent).execute(data=data) |
| 20 | |
| 21 | assert "file" not in data |
| 22 | assert not target.exists() |