Stabilize trial metadata source tests on Windows
Summary
- read
users.pyandsubscription.pysource snapshots with explicit UTF-8 encoding intest_trial_metadata.py - include a
plan_grants_desktopstub in the extractedget_trial_metadatanamespace so the source-level function test matches the current production helper dependencies - mirror the Neo grandfather desktop entitlement path in the stub and cover it with a regression test that avoids falling through to Firebase trial lookup
Testing
python -m pytest tests\unit\test_trial_metadata.py -q-> 38 passed, 1 warningpython -m black --line-length 120 --skip-string-normalization tests\unit\test_trial_metadata.py --checkpython -m py_compile tests\unit\test_trial_metadata.pygit diff --check origin/main...HEAD
Greptile Summary
This PR stabilizes test_trial_metadata.py on Windows by adding explicit encoding='utf-8' to all file-read operations and adding a plan_grants_desktop stub to the exec-compiled namespace so the behavioral tests no longer raise a NameError at runtime.
- All four
open()/.read_text()calls that previously relied on the platform default encoding now specifyencoding='utf-8'. - A
plan_grants_desktopstub is injected into theexecnamespace used by_get_trial_metadata_fn, matching the dependency added when the production helper was updated.
Confidence Score: 4/5
Safe to merge; the changes are test-only and fix a real cross-platform incompatibility.
The UTF-8 fixes are straightforward and correct. The plan_grants_desktop stub makes all 37 tests pass but silently omits the Neo grandfather branch (PlanType.unlimited with a pre-cutoff current_period_start). A future test for that case would get the wrong result from the stub without any obvious failure signal, making it a latent documentation/maintenance hazard rather than a current breakage.
backend/tests/unit/test_trial_metadata.py — the plan_grants_desktop stub at line 131 warrants a second look before Neo grandfather tests are added.
Important Files Changed
| Filename | Overview |
|---|---|
| backend/tests/unit/test_trial_metadata.py | Four UTF-8 encoding fixes (correct) and one new plan_grants_desktop stub; the stub omits the Neo grandfather path, leaving that edge case untested. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["_get_trial_metadata_fn()"] --> B["read_text(encoding='utf-8')\nsubscription.py source"]
B --> C["Extract func_source\n(get_trial_metadata body)"]
C --> D["Build namespace dict\n+ plan_grants_desktop stub"]
D --> E["exec() func_source\nin namespace"]
E --> F["return fn, namespace"]
F --> G["Test calls fn('uid_test')"]
G --> H{plan_grants_desktop\nstub returns?}
H -- "operator/architect → True" --> I["Return TrialMetadata\ntrial_expired=False\n(trial moot)"]
H -- "basic/unlimited → False" --> J["Check is_byok_active"]
J -- True --> I
J -- False --> K["Firebase auth lookup\n(mocked)"]
K --> L{creation_timestamp?}
L -- None --> I
L -- present --> M["Compute remaining\n= trial_ends_at - now"]
M --> N["Return TrialMetadata\nwith timing fields"]
style H fill:#ffe0b2
style D fill:#e3f2fd
Reviews (1): Last reviewed commit: "Stabilize trial metadata source tests on..." | Re-trigger Greptile
Superseded by #7781, which carries this same trial metadata Windows test fix rebased onto the current main and is mergeable.
Correction after rechecking mergeability: this PR is now mergeable and already has the existing review context, so I am keeping #7756 as the canonical PR and closing #7781 as the duplicate.