Stabilize firestore cache source tests on Windows
Summary
- read inspected
payment.pyandtranscribe.pysource files as UTF-8 intest_firestore_read_ops_cache.py - update webhook invalidation source assertions to accept direct calls or
run_blocking(...)calls containing bothset_credits_invalidation_signalanduid - replace fixed-length schedule slices with source blocks bounded by webhook branch markers
Windows reproduction
Before this change on Windows with the default GBK locale:
python -m pytest tests\unit\test_firestore_read_ops_cache.py -q-> 8 failed, 40 passed, 3 skipped- failures were
UnicodeDecodeError: 'gbk' codec can't decode byte ...while reading UTF-8 source files
After fixing the read encoding, the source-level tests exposed stale direct-call assertions: the current async webhook handler calls set_credits_invalidation_signal through run_blocking(...).
Testing
python -m pytest tests\unit\test_firestore_read_ops_cache.py -q-> 48 passed, 3 skippedpython -m black --line-length 120 --skip-string-normalization tests\unit\test_firestore_read_ops_cache.py --checkpython -m py_compile tests\unit\test_firestore_read_ops_cache.pygit diff --check
Greptile Summary
This PR stabilizes TestWebhookInvalidationCoverage tests on Windows by fixing a UnicodeDecodeError (adding encoding='utf-8' to source file reads) and updating assertions to match the current async webhook implementation where set_credits_invalidation_signal is called through run_blocking(...) rather than directly.
- Adds
encoding='utf-8'to_read_sourceso tests no longer fail on non-UTF-8 locales (e.g. GBK on Windows). - Introduces
_find_invalidation_callstatic method with two regex patterns — one for direct calls, one forrun_blocking(...)wrappers — so assertions survive future call-style changes. - Replaces fragile fixed-offset slices (e.g.
source[idx - 200 : idx]) with marker-bounded blocks anchored to actual event-type branch strings inpayment.py.
Confidence Score: 4/5
Safe to merge — changes are test-only and fix a real cross-platform failure; no production code is modified.
The UTF-8 encoding fix and the marker-bounded block approach are straightforward improvements. The only concern is the [^)]* in the run_blocking_call regex, which would silently return no match if any executor argument becomes a call expression, but this does not affect current code and does not break anything today.
backend/tests/unit/test_firestore_read_ops_cache.py — specifically the _find_invalidation_call regex.
Important Files Changed
| Filename | Overview |
|---|---|
| backend/tests/unit/test_firestore_read_ops_cache.py | Adds UTF-8 encoding to source reads (fixing Windows UnicodeDecodeError), introduces _find_invalidation_call regex helper, and replaces fixed-offset slices with marker-bounded blocks; one minor regex fragility with [^)]* and nested parens. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["_read_source(path, encoding='utf-8')"] --> B[source text]
B --> C{test case}
C --> D["test_checkout_completed\nslice: checkout marker → subscription.updated marker"]
C --> E["test_subscription_webhook\nslice: subscription.updated → schedule.completed marker"]
C --> F["test_schedule_completed\nslice: schedule.completed → elif canceled branch"]
C --> G["test_schedule_canceled\nslice: rfind elif canceled → log message"]
D & E & F & G --> H["_find_invalidation_call(block)"]
H --> I["direct_call regex\nset_credits_invalidation_signal(uid)"]
H --> J["run_blocking_call regex\nrun_blocking(...set_credits...uid...)"]
I --> K{match found after update call?}
J --> K
K -->|yes| L[PASS]
K -->|no| M[FAIL]
Reviews (1): Last reviewed commit: "Stabilize firestore cache source tests o..." | Re-trigger Greptile