diff --git a/orchestrator.py b/orchestrator.py index 4437ddc..f638cb3 100644 --- a/orchestrator.py +++ b/orchestrator.py @@ -264,9 +264,20 @@ def append_file(filepath, content): try: os.makedirs(os.path.dirname(abs_path), exist_ok=True) + + # Check if the file currently exists and ensure it ends with a newline + prefix = "" + if os.path.exists(abs_path): + with open(abs_path, encoding="utf-8") as f: + current_content = f.read() + if current_content and not current_content.endswith("\n"): + prefix = "\n" + + # Append the prefix, the content, and a trailing newline with open(abs_path, "a", encoding="utf-8") as f: - f.write(content) - return f"[SUCCESS: File appended to {filepath}]" + f.write(prefix + content + "\n") + + return f"[SUCCESS: Data appended to {filepath}]" except Exception as e: return f"[ERROR: Failed to append to {filepath} - {e}]" diff --git a/tests/evals/test_orchestrator.py b/tests/evals/test_orchestrator.py index 0fef97f..ad80ee9 100644 --- a/tests/evals/test_orchestrator.py +++ b/tests/evals/test_orchestrator.py @@ -170,7 +170,7 @@ def test_actual_file_io(tmp_path, monkeypatch) -> None: # Test read_directory_contents dir_res = read_directory_contents(str(docs_dir)) # SHIFT-LEFT: Updated test to check for the new XML caching tags - assert "--- FILE: test.md ---" in dir_res + assert '' in dir_res def test_get_active_artifacts(tmp_path, monkeypatch) -> None: