Skip to content

Commit 7421cfc

Browse files
committed
fix(core): align checksums with persisted bytes
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 5069b46 commit 7421cfc

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/basic_memory/services/file_service.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,13 @@ async def read_file(self, path: FilePath) -> Tuple[str, str]:
350350
async with aiofiles.open(full_path, mode="r", encoding="utf-8") as f:
351351
content = await f.read()
352352

353-
checksum = await file_utils.compute_checksum(content)
353+
# Trigger: text-mode reads normalize line endings on Windows, so the
354+
# decoded string can differ from the bytes we just wrote.
355+
# Why: write_file/update_frontmatter now return the checksum of the
356+
# persisted file, and read_file should report the same authority.
357+
# Outcome: callers get human-readable content plus the checksum for the
358+
# exact bytes stored on disk.
359+
checksum = await self.compute_checksum(full_path)
354360

355361
logger.debug(
356362
"File read completed",

tests/indexing/test_batch_indexer.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,15 @@ async def test_batch_indexer_returns_original_markdown_content_when_no_frontmatt
265265
parse_max_concurrent=1,
266266
)
267267

268+
# Trigger: Windows persists CRLF for text writes even when the test literal uses LF.
269+
# Why: this assertion cares about "no rewrite happened", not about forcing one newline
270+
# convention across platforms.
271+
# Outcome: compare against the exact markdown text stored on disk for this file.
272+
persisted_content = (project_config.home / path).read_text()
273+
268274
assert result.errors == []
269275
assert len(result.indexed) == 1
270-
assert result.indexed[0].markdown_content == original_content
276+
assert result.indexed[0].markdown_content == persisted_content
271277

272278

273279
@pytest.mark.asyncio
@@ -514,9 +520,15 @@ async def test_batch_indexer_uses_parsed_markdown_body_for_malformed_frontmatter
514520
parse_max_concurrent=1,
515521
)
516522

523+
# Trigger: malformed frontmatter should pass through without normalization.
524+
# Why: Windows can still surface that unchanged file with CRLF line endings.
525+
# Outcome: compare the indexed markdown to the persisted file content, not the LF
526+
# test literal used to create it.
527+
persisted_content = (project_config.home / path).read_text()
528+
517529
assert result.errors == []
518530
assert len(result.indexed) == 1
519-
assert result.indexed[0].markdown_content == malformed_content
531+
assert result.indexed[0].markdown_content == persisted_content
520532

521533
entity = await entity_repository.get_by_file_path(path)
522534
assert entity is not None

0 commit comments

Comments
 (0)