Repository navigation
chore(audit): write entitlements to Upstash only in production - #2563
Conversation
saveEntitlement wrote entitlements.json before redis.set, so a read-only filesystem throw skipped Upstash, and an empty catch hid Redis errors. When Upstash is configured, write Redis only and let set failures propagate. Co-authored-by: KK <kk-agent@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Please add a See governance: #898 |
✅ E2E Test Results: ALL TESTS PASSED
Test Output |
✅ E2E Test Results: ALL TESTS PASSED
Test Output |
Outcome
Production entitlement saves reach Upstash. When Upstash credentials are set,
saveEntitlementwritesredis.setand does not touch.data/entitlements.json, so a read-only deploy filesystem cannot skip the Upstash write. A Redis write error now propagates.Findings
saveEntitlementupdated the in-memory map, awaitedwriteEntitlementToFile(mkdir+writeFileinentitlement-file-store.ts, not caught), and only then calledredis.set.rg writeEntitlementToFileon current main hitsentitlement-file-store.ts,entitlement-store.ts, andentitlement-file-store.test.ts. The file store stays for the local no-Redis path.catcharoundredis.set.billing/paywall-bypass.tsand Stripe/checkout code.Scope
apps/web/src/lib/billing/entitlement-store.tsandapps/web/src/lib/billing/__tests__/entitlement-store.test.ts.Risk
Verification
Reproduced before the code change.
npm --workspace=apps/web exec vitest run src/lib/billing/__tests__/entitlement-store.test.tsfailed both cases:mkdirthrow (EEXIST: file already exists) fromwriteEntitlementToFileabortedsaveEntitlementbeforeredis.set.redis.setrejecting, the save resolved the record. The mock recorded onesetcall and the empty catch swallowedupstash unavailable.After the change, that file passed (2 tests). The Redis client in the test is a
vi.mockof@upstash/redisso the assertion can seesetwithout a live Upstash account. The file-write failure in the reproduction was a real filesystem error.Local commands:
npm cicompletednpm --workspace=apps/web run lintpassednpm run build:webpassed, including TypeScriptnpm --workspace=apps/web test: 1562 passed, 2 failed, 1 skipped. Both failures aresrc/lib/__tests__/home-sell-surface.test.tsCI on head
d1371ccb9(https://github.com/groupthinking/EventRelay/actions/runs/41670537706):buildpassed (type-check, ESLint, web build, Studio preflight, production image)lint-frontend,guards, Python 3.11 and 3.12 tests passedtest-frontendfailed. The log showsentitlement-store.test.tspassed (2 tests). The only failures are the twohome-sell-surface.test.tscases, the same failure already on main run 41659258955. Left unchanged.Production evidence
Not applicable. No deploy was performed. The change is the entitlement write path, covered by the unit test above. CI did not call a live Upstash account.
Issue link check
The Closing keyword to open issue check failed, as expected: https://github.com/groupthinking/EventRelay/actions/runs/41670537564/job/126037389310
Related: #2328
Closes #2581