From ed47cf1562f7ffb9a662165cd87830e91ff10f0c Mon Sep 17 00:00:00 2001 From: bingqilinweimaotai <111987281+bingqilinweimaotai@users.noreply.github.com> Date: Mon, 13 Jul 2026 15:08:57 +0800 Subject: [PATCH] fix(dream): ignore line-ending-only memory diffs --- nanobot/utils/gitstore.py | 10 +++++++--- tests/agent/test_dream.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/nanobot/utils/gitstore.py b/nanobot/utils/gitstore.py index bb61bb6c..58daeeac 100644 --- a/nanobot/utils/gitstore.py +++ b/nanobot/utils/gitstore.py @@ -377,12 +377,16 @@ class GitStore: changed += 1 summary_lines.append(f"{path}: binary or non-UTF-8 file changed") continue - if head_text == wt_text: + # Git blobs preserve line endings while read_text() normalizes + # them. Compare the same logical lines used by the diff. + head_lines = head_text.splitlines() + wt_lines = wt_text.splitlines() + if head_lines == wt_lines: continue changed += 1 hunks = list(difflib.unified_diff( - head_text.splitlines(), - wt_text.splitlines(), + head_lines, + wt_lines, fromfile=path, tofile=path, lineterm="", diff --git a/tests/agent/test_dream.py b/tests/agent/test_dream.py index 7b3f41e5..b2791502 100644 --- a/tests/agent/test_dream.py +++ b/tests/agent/test_dream.py @@ -666,6 +666,37 @@ class TestDreamContentDiff: store.git.auto_commit("initial") assert store.dream_content_diff() == "" + def test_ignores_platform_line_ending_normalization(self, store, monkeypatch): + import subprocess + + system_config = store.workspace / "system.gitconfig" + global_config = store.workspace / "global.gitconfig" + system_config.touch() + global_config.touch() + subprocess.run( + [ + "git", "config", "--file", str(system_config), + "core.autocrlf", "false", + ], + check=True, + capture_output=True, + ) + monkeypatch.delenv("GIT_CONFIG_NOSYSTEM", raising=False) + monkeypatch.setenv("GIT_CONFIG_SYSTEM", str(system_config)) + monkeypatch.setenv("GIT_CONFIG_GLOBAL", str(global_config)) + + store.soul_file.write_bytes(b"# Soul\r\n- Helpful") + store.memory_file.write_bytes(b"# Memory\r\n- Project X active") + store.git.init() + + status = subprocess.check_output( + ["git", "status", "--porcelain", "--", "SOUL.md", "memory/MEMORY.md"], + cwd=store.workspace, + text=True, + ) + assert status == "" + assert store.dream_content_diff() == "" + def test_reflects_real_content_edits(self, store): store.git.init() store.git.auto_commit("initial")