omi icon indicating copy to clipboard operation
omi copied to clipboard

Stabilize memories create source tests on Windows

Open tianmind-studio opened this issue 5 months ago • 1 comments

Summary

  • read routers/memories.py as UTF-8 in test_memories_create.py
  • fix Windows non-UTF-8 locale failures in source-level memories create/router tests
  • keep the existing rate-limit and error-handling assertions unchanged

Windows reproduction

Before this change on Windows with the default GBK locale:

  • python -m pytest tests\unit\test_memories_create.py -q -> 13 failed, 9 passed
  • failures were UnicodeDecodeError: 'gbk' codec can't decode byte ... while reading routers/memories.py

Testing

  • python -m pytest tests\unit\test_memories_create.py -q -> 22 passed
  • python -m black --line-length 120 --skip-string-normalization tests\unit\test_memories_create.py --check
  • python -m py_compile tests\unit\test_memories_create.py
  • git diff --check

tianmind-studio avatar Jun 10 '26 07:06 tianmind-studio

Greptile Summary

Fixes a Windows-only test failure caused by Python's open() defaulting to the system locale encoding (e.g. GBK) instead of UTF-8 when reading routers/memories.py. Both file-reading helpers now pass encoding='utf-8' explicitly.

  • _read_router() and _grep_router() each gain encoding='utf-8' in their open() calls — the only two places the router source is read.
  • All existing rate-limit and error-handling assertions are preserved without modification.

Confidence Score: 5/5

Safe to merge — two-line change adds explicit UTF-8 encoding to file reads in tests with no production code touched.

The change is isolated to a test helper file: two open() calls gain encoding='utf-8', which is the standard cross-platform fix for reading UTF-8 source files. No logic is altered, no assertions are changed, and the fix directly addresses the documented Windows failure mode.

No files require special attention.

Important Files Changed

Filename Overview
backend/tests/unit/test_memories_create.py Adds explicit encoding='utf-8' to both open() calls in _read_router() and _grep_router() to prevent UnicodeDecodeError on Windows non-UTF-8 locales; no logic changes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[pytest collects test] --> B{Test class}
    B --> C[TestMemoriesRateLimitWiring]
    B --> D[TestCreateMemoryErrorHandling]
    C --> E["_grep_router(pattern)\nopen(ROUTER_PATH, encoding='utf-8')"]
    D --> F["_read_router()\nopen(ROUTER_PATH, encoding='utf-8')"]
    E --> G[Iterate lines, re.search match]
    F --> H[Return full source string]
    G --> I[Assert count / content]
    H --> I

Reviews (1): Last reviewed commit: "Stabilize memories create source tests o..." | Re-trigger Greptile

greptile-apps avatar Jun 10 '26 07:06 greptile-apps