Stabilize paywall reconnect source tests on Windows
Summary
- read source files as UTF-8 in
test_paywall_reconnect_gate.pyso the source-level checks pass on Windows non-UTF-8 locales - update stale source and behavioral assertions to match the current always-on desktop trial paywall semantics
- keep the coverage focused on platform filtering and cached expiry delegation without changing production code
Windows reproduction
Before this change on Windows with the default GBK locale:
python -m pytest tests\unit\test_paywall_reconnect_gate.py -q-> 25 failed, 15 passed- 23 failures were
UnicodeDecodeError: 'gbk' codec can't decode byte ...while reading UTF-8 source files - after the source read issue, the remaining stale expectations were for trial-paywall kill-switch/test-UID globals that are no longer present in the current always-on implementation
Testing
python -m pytest tests\unit\test_paywall_reconnect_gate.py -q-> 40 passedpython -m black --line-length 120 --skip-string-normalization tests\unit\test_paywall_reconnect_gate.py --checkpython -m py_compile tests\unit\test_paywall_reconnect_gate.pygit diff --check --cached
Greptile Summary
This PR fixes a Windows-only UnicodeDecodeError in the paywall reconnect gate test suite by adding encoding='utf-8' to all open() calls in _read_source, and updates stale source-level and behavioral assertions to match the current always-on desktop trial paywall (which dropped the _TRIAL_PAYWALL_ENABLED kill-switch and _TRIAL_PAYWALL_TEST_UIDS gating in favour of a direct _is_trial_expired_cached delegation). No production code is changed.
_read_sourcefix:open(path, encoding='utf-8')preventsUnicodeDecodeErroron Windows locales (e.g. GBK) that use a non-UTF-8 default codec.TestPlatformFilteringupdates: Two tests that asserted the presence of now-deleted globals are replaced with assertions that verify the ordering of the platform-filter check and the cached-expiry delegation, matching the currentis_trial_paywalledimplementation.TestIsTrialPaywalledBehavioralupdates: Three kill-switch/test-UID behavioural tests are replaced with equivalent tests for the always-on path; stale_TRIAL_PAYWALL_ENABLED/_TRIAL_PAYWALL_TEST_UIDSassignments are removed from the fixture setup.
Confidence Score: 4/5
Safe to merge — only test code changes, no production logic is touched.
The UTF-8 encoding fix and assertion updates are correct and well-matched to the current production implementation. The only rough edge is that TestByokRequestEscapeHatch._setup_subscription still sets sub._TRIAL_PAYWALL_ENABLED and sub._TRIAL_PAYWALL_TEST_UIDS, which are now orphaned attributes with no effect — the same cleanup done for TestIsTrialPaywalledBehavioral was not applied to this class. Tests continue to pass regardless, but the leftover assignments are misleading about which code paths the BYOK tests actually exercise.
The TestByokRequestEscapeHatch._setup_subscription fixture (lines 450–451) still carries stale attribute assignments that no longer correspond to any production globals.
Important Files Changed
| Filename | Overview |
|---|---|
| backend/tests/unit/test_paywall_reconnect_gate.py | Added encoding='utf-8' to fix Windows UnicodeDecodeError; replaced stale kill-switch/test-UID assertions with current always-on semantics; stale _TRIAL_PAYWALL_ENABLED/_TRIAL_PAYWALL_TEST_UIDS assignments remain in TestByokRequestEscapeHatch fixture |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Test: _read_source] -->|encoding='utf-8' fix| B[UTF-8 source file read]
B --> C{Source-level assertions}
C --> D[TestPlatformFiltering\nfilters_before_expiry_lookup]
C --> E[TestPlatformFiltering\ndelegates_to_cached_expiry]
D -->|checks ordering| F["platform.lower() not in _TRIAL_PAYWALL_DESKTOP_TOKENS\nbefore _is_trial_expired_cached(uid)"]
E -->|checks delegation| G["return _is_trial_expired_cached(uid)\npresent in fn body"]
H[TestIsTrialPaywalledBehavioral\nfixture setup] -->|removed stale globals| I[sub._is_trial_expired_cached = mock]
I --> J[Behavioral tests\ndesktop_cache_false / uid_delegates / different_uid]
K[TestByokRequestEscapeHatch\nfixture setup] -->|stale still present| L["sub._TRIAL_PAYWALL_ENABLED = True\nsub._TRIAL_PAYWALL_TEST_UIDS = set()"]
L -->|no-op, globals removed from production| M[BYOK escape-hatch tests]
F --> N[Production: is_trial_paywalled]
G --> N
N -->|platform not desktop| O[return False]
N -->|platform is desktop| P[_is_trial_expired_cached uid]
Comments Outside Diff (1)
-
backend/tests/unit/test_paywall_reconnect_gate.py, line 450-451 (link)Stale attribute assignments not cleaned up
_TRIAL_PAYWALL_ENABLEDand_TRIAL_PAYWALL_TEST_UIDSno longer exist as module-level globals inutils/subscription.py(the always-on implementation removed them), yet this fixture inTestByokRequestEscapeHatchstill assigns them to the freshly-imported module. The exact same stale lines were removed fromTestIsTrialPaywalledBehavioral._setup_subscriptionin this PR but were missed here. They are harmless at runtime (Python allows adding arbitrary attributes to a module object, andis_trial_paywallednever reads them), but they mislead readers into thinking the kill-switch is relevant to BYOK escape-hatch tests.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Reviews (1): Last reviewed commit: "Stabilize paywall reconnect source tests..." | Re-trigger Greptile
Addressed in 608c12447: removed the remaining stale _TRIAL_PAYWALL_ENABLED and _TRIAL_PAYWALL_TEST_UIDS assignments from the BYOK escape-hatch fixture and reran the paywall reconnect tests (40 passed).