mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-04 22:49:23 +00:00
fix: use LF line endings in generate_tool_specs save_to_json
Pass newline='\n' to open() so that tool.specs.json is always written with LF line endings regardless of the platform. Without this, running the script on Windows produces CRLF, causing every line to show as modified in git diff. Adds a regression test that reads the output in binary mode and asserts no \r\n bytes are present. Closes #4737 Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -180,7 +180,7 @@ class ToolSpecExtractor:
|
||||
return json_schema
|
||||
|
||||
def save_to_json(self, output_path: str) -> None:
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
with open(output_path, "w", encoding="utf-8", newline="\n") as f:
|
||||
json.dump({"tools": self.tools_spec}, f, indent=2, sort_keys=True)
|
||||
|
||||
|
||||
|
||||
@@ -192,3 +192,28 @@ def test_save_to_json(extractor, tmp_path):
|
||||
assert len(data["tools"]) == 1
|
||||
assert data["tools"][0]["humanized_name"] == "Test Tool"
|
||||
assert data["tools"][0]["run_params_schema"][0]["name"] == "param1"
|
||||
|
||||
|
||||
def test_save_to_json_uses_lf_line_endings(extractor, tmp_path):
|
||||
"""Verify save_to_json writes LF (\\n) line endings, not CRLF (\\r\\n).
|
||||
|
||||
Regression test for https://github.com/crewAIInc/crewAI/issues/4737.
|
||||
On Windows, open() in text mode defaults to CRLF, which causes every
|
||||
line to appear modified in git diff when the committed file uses LF.
|
||||
"""
|
||||
extractor.tools_spec = [
|
||||
{
|
||||
"name": "TestTool",
|
||||
"humanized_name": "Test Tool",
|
||||
"description": "A test tool",
|
||||
"run_params_schema": [],
|
||||
}
|
||||
]
|
||||
|
||||
file_path = tmp_path / "output.json"
|
||||
extractor.save_to_json(str(file_path))
|
||||
|
||||
# Read in binary mode to inspect raw line endings
|
||||
raw_bytes = file_path.read_bytes()
|
||||
assert b"\r\n" not in raw_bytes, "File contains CRLF line endings; expected LF only"
|
||||
assert b"\n" in raw_bytes, "File should contain at least one newline"
|
||||
|
||||
Reference in New Issue
Block a user