Skip to content

Read pusher ghost test sources as UTF-8 on Windows#7797

Open
tianmind-studio wants to merge 1 commit into
BasedHardware:mainfrom
tianmind-studio:codex/windows-pusher-ghost-encoding-test
Open

Read pusher ghost test sources as UTF-8 on Windows#7797
tianmind-studio wants to merge 1 commit into
BasedHardware:mainfrom
tianmind-studio:codex/windows-pusher-ghost-encoding-test

Conversation

@tianmind-studio

Copy link
Copy Markdown
Contributor

Summary

  • Add a small _read_source() helper in test_pusher_ghost_connections.py that reads source files with encoding='utf-8'.
  • Route the pusher/transcribe source-inspection assertions through that helper.

Why

On this Windows backend venv, collecting test_pusher_ghost_connections.py failed before any assertions ran because Path.read_text() used the system default GBK codec. routers/pusher.py contains UTF-8 comments with non-ASCII punctuation, so the default decode raised UnicodeDecodeError.

The test is reading Python source for structural assertions, so using explicit UTF-8 matches Python source-file expectations and makes the test portable across Windows locales.

Testing

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

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a Windows-locale portability issue in test_pusher_ghost_connections.py where Path.read_text() calls used the system default codec (e.g., GBK on Chinese Windows), causing a UnicodeDecodeError at collection time because routers/pusher.py contains UTF-8 encoded non-ASCII characters in its comments.

  • Introduces a one-line _read_source(path: Path) -> str helper that calls path.read_text(encoding='utf-8'), matching Python's own source-file encoding expectation (PEP 3120).
  • Routes all 17 existing read_text() call-sites — including module-level ast.parse() calls and all inline string-search assertions — through the new helper.

Confidence Score: 5/5

Safe to merge — the change is a targeted one-liner helper with consistent call-site updates, carrying no risk of changing test logic or production behaviour.

The change is a single-file test utility addition where the new helper is an exact wrapper around the existing call with an explicit encoding parameter. Every call-site in the file has been updated, the fix matches the Python source-file encoding standard, and the PR author verified all 43 tests pass on both Windows and CI.

No files require special attention.

Important Files Changed

Filename Overview
backend/tests/unit/test_pusher_ghost_connections.py Adds a _read_source() helper with explicit encoding='utf-8' and routes all 17 read_text() call-sites through it to fix UnicodeDecodeError on Windows locales that default to GBK.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Test collection starts] --> B{OS locale}
    B -->|Linux UTF-8| C[read_text uses system default]
    B -->|Windows GBK before fix| D[read_text uses GBK codec]
    B -->|Windows after fix| E[_read_source uses utf-8]
    C --> F[Tests run normally]
    D --> G[UnicodeDecodeError - collection fails]
    E --> F
    F --> H[43 tests pass]
Loading

Reviews (1): Last reviewed commit: "test(backend): read pusher ghost sources..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant