Skip to content

Stabilize paywall reconnect source tests on Windows#7779

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
tianmind-studio:codex/paywall-reconnect-source-utf8-windows
Jun 11, 2026
Merged

Stabilize paywall reconnect source tests on Windows#7779
kodjima33 merged 1 commit into
BasedHardware:mainfrom
tianmind-studio:codex/paywall-reconnect-source-utf8-windows

Conversation

@tianmind-studio

Copy link
Copy Markdown
Contributor

Summary

  • read source files as UTF-8 in test_paywall_reconnect_gate.py so 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 passed
  • python -m black --line-length 120 --skip-string-normalization tests\unit\test_paywall_reconnect_gate.py --check
  • python -m py_compile tests\unit\test_paywall_reconnect_gate.py
  • git diff --check --cached

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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_source fix: open(path, encoding='utf-8') prevents UnicodeDecodeError on Windows locales (e.g. GBK) that use a non-UTF-8 default codec.
  • TestPlatformFiltering updates: 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 current is_trial_paywalled implementation.
  • TestIsTrialPaywalledBehavioral updates: Three kill-switch/test-UID behavioural tests are replaced with equivalent tests for the always-on path; stale _TRIAL_PAYWALL_ENABLED/_TRIAL_PAYWALL_TEST_UIDS assignments 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]
Loading

Comments Outside Diff (1)

  1. backend/tests/unit/test_paywall_reconnect_gate.py, line 450-451 (link)

    P2 Stale attribute assignments not cleaned up

    _TRIAL_PAYWALL_ENABLED and _TRIAL_PAYWALL_TEST_UIDS no longer exist as module-level globals in utils/subscription.py (the always-on implementation removed them), yet this fixture in TestByokRequestEscapeHatch still assigns them to the freshly-imported module. The exact same stale lines were removed from TestIsTrialPaywalledBehavioral._setup_subscription in this PR but were missed here. They are harmless at runtime (Python allows adding arbitrary attributes to a module object, and is_trial_paywalled never 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

@tianmind-studio tianmind-studio force-pushed the codex/paywall-reconnect-source-utf8-windows branch from f6c8a20 to 608c124 Compare June 10, 2026 08:17

Copy link
Copy Markdown
Contributor Author

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).

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-only stabilization (backend/tests/unit), CI green

@kodjima33 kodjima33 merged commit f786756 into BasedHardware:main Jun 11, 2026
1 check passed
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.

2 participants