fix(memory): preserve Dream input integrity (#5114)

This commit is contained in:
chengyongru
2026-07-27 21:37:13 +08:00
committed by GitHub
parent e819b7eea4
commit f78ad59ed0
2 changed files with 24 additions and 7 deletions
+22 -6
View File
@@ -127,15 +127,15 @@ class TestBuildDreamPrompt:
prompt, _ = result
assert "memory consolidation engine" in prompt
def test_truncates_long_entries(self, store):
def test_truncates_long_entries_at_1000_chars(self, store):
long_content = "x" * 2000
store.append_history(long_content)
result = store.build_dream_prompt()
assert result is not None
prompt, _ = result
# The full 2000 chars should not appear — truncated to 500
assert long_content not in prompt
assert "x" * 500 in prompt
assert "x" * 1000 in prompt
assert "x" * 1001 not in prompt
def test_batches_oldest_unprocessed_entries_first(self, store):
for i in range(25):
@@ -222,11 +222,20 @@ class TestDreamTools:
"new_text": "Precise",
},
)
user_result = await tools.execute(
"write_file",
{
"path": "USER.md",
"content": "# User Profile\n\n- **Name**: Ada\n",
},
)
assert "Patch applied" in memory_result
assert "Successfully edited" in soul_result
assert "Successfully wrote" in user_result
assert "Project Y active" in store.memory_file.read_text(encoding="utf-8")
assert "Precise" in store.soul_file.read_text(encoding="utf-8")
assert "**Name**: Ada" in store.user_file.read_text(encoding="utf-8")
@pytest.mark.asyncio
async def test_dream_can_write_workspace_skills(self, store):
@@ -306,9 +315,17 @@ class TestDreamTools:
"new_text": "2",
},
)
history_write_result = await tools.execute(
"write_file",
{
"path": "memory/history.jsonl",
"content": "after\n",
},
)
assert "outside allowed directory" in history_result
assert "outside allowed directory" in cursor_result
assert "outside allowed directory" in history_write_result
assert store.history_file.read_text(encoding="utf-8") == "before\n"
assert store._dream_cursor_file.read_text(encoding="utf-8") == "1"
@@ -331,11 +348,10 @@ class TestDreamTools:
},
)
user_result = await tools.execute(
"edit_file",
"write_file",
{
"path": "USER.md/evil.txt",
"old_text": "",
"new_text": "owned",
"content": "owned",
},
)