Skip to content

fix(reader-access): atomic code consume, Mailgun auth, retention and chapter route - #652

Merged
mergify[bot] merged 5 commits into
mainfrom
fix/reader-access-restore-code-store
Nov 21, 2026
Merged

mergify[bot] merged 5 commits into
mainfrom
fix/reader-access-restore-code-store

Conversation

@ashleyshaw

@ashleyshaw ashleyshaw commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR originally restored spec 005's code storage after PR #635 broke the reader functions. Since then, lightspeedwp/ThisOneTimeOnAcidCom#653 (spec 006 US1) landed on main with its own fix. It restored codes in store.ts, put sessions behind a token index, hashed the emailed code and fixed sign-out.

06621b6 merges main and adopts that design. The six conflicting files take main's version, and my separate code-store.ts and its test are removed. What's left is only what main still lacks:

Gap on main Effect Fix here
Codes are consumed delete-first (session-service.ts says it is "not a true atomic consume") Two simultaneous submissions of one code can both create a session (breaks spec 005 RA-002) store.consumeCode() writes a code-consumed:<sha256> marker with onlyIfNew, and session creation uses it; the losing request gets 401 verification_failed
Mailgun client has no username: 'api' Every send fails authentication Added
reader-retention.ts imports list/get/delete, which @netlify/blobs doesn't export, and has no schedule Doesn't build, and would never run Uses the store API; config.schedule = '@daily'; its skipped test is enabled (9 tests)
/api/reader/chapters/:chapterId missing from public/_redirects (applied before netlify.toml) Chapter requests return index.html Added, passing the id through as netlify.toml does
Nothing bundles the handlers A missing export passes every unit test tests/reader-access/functions-build.test.ts bundles every function and checks every redirect target exists

Changes

  • netlify/lib/blobs.ts: BlobStore.set accepts { onlyIfNew } and returns the write result.
  • netlify/lib/reader-access/store.ts: consumeCode(email, codeHash).
  • netlify/lib/reader-access/session-service.ts: createSessionFromVerification uses consumeCode in place of deleteCode.
  • @netlify/blobs ^6.2.0 → ^11.1.6 (conditional writes; needs Node ≥ 22.12, deploys use 24). esbuild 0.28.2 added as an exact devDependency for the guard test.
  • tests/reader-access/us1-test-helpers.ts: the in-memory store honours onlyIfNew, so every US1 test runs the real consume path.
  • New tests: consume-code.test.ts (3) and a concurrency case in session-create.test.ts.

Testing

  • Full npx vitest run: 1092 passed, 0 failed (main: 1060 passed, 0 failed).
  • The new race test fails against main's delete-first logic (both requests get a 201), and passes with consumeCode.
  • The guard test fails against the old broken functions and passes now.
  • npm run build passes; dist/_redirects contains the chapter route.
  • Not yet run against live Netlify Blobs or Mailgun; that needs a deploy preview with credentials.

Follow-ups (not in this PR)

  • Chapter content is still placeholder text until the protected manuscript is in place (RA-T054).
  • rate-limiter.ts is in-memory, so limits reset across function instances.
  • createSession's device-limit check is serialised only within one function instance (noted in session-service.ts). An onlyIfMatch counter could close that using the same Blobs 11 upgrade.
  • Spec 005 document reconciliation follows on docs/reader-access-spec-005-reconcile.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CADHZdpaiuKYHLz2mX9por

PR #635 (spec 006) rewrote netlify/lib/reader-access/store.ts for
email + device sessions and removed the verification-code exports.
reader-code-request, reader-verify and reader-chapter stopped
bundling, reader-session called the new two-argument API with one
argument (sign-out left the server session alive), and no test failed
because handlers were never bundled.

- Add netlify/lib/reader-access/code-store.ts for codes, sessionId
  access sessions and recovery attempts, under key prefixes distinct
  from spec 006.
- Consume codes once with a Blobs onlyIfNew marker (RA-002); upgrade
  @netlify/blobs 6.5 -> 11.1.6 for conditional writes.
- Store the hash of the code that is emailed; previously a second,
  unrelated code was hashed so no emailed code could verify.
- Use timing-safe hash comparison; hash readerId with SHA-256.
- Mailgun client: add username 'api' so sends authenticate.
- Return contract states: 502 provider-failure, 429 limited,
  401 request-pending; stop echoing internal error text.
- reader-retention: use the store API and run @daily.
- Route /api/reader/chapters/:chapterId to reader-chapter in
  public/_redirects (it fell through to index.html) and netlify.toml.
- Add a test that bundles every function and checks redirect targets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CADHZdpaiuKYHLz2mX9por
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

Deployment failed for project thisonetimeonacidcom with the following error:

Resource is limited - try again in 1 day (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/lightspeedwp?upgradeToPro=build-rate-limit

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7650a5a and 3b7759c.

Files ignored due to path filters: 1

  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing: 13

  • CHANGELOG.md
  • netlify/__tests__/reader-retention.test.ts
  • netlify/functions/reader-retention.ts
  • netlify/lib/blobs.ts
  • netlify/lib/reader-access/mailer.ts
  • netlify/lib/reader-access/session-service.ts
  • netlify/lib/reader-access/store.ts
  • package.json
  • public/_redirects
  • tests/reader-access/consume-code.test.ts
  • tests/reader-access/functions-build.test.ts
  • tests/reader-access/session-create.test.ts
  • tests/reader-access/us1-test-helpers.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown

Drift Detection ✅

✅ No drift detected. Configuration is canonical.

Canonical governance files are correctly centralized in lightspeedwp/.github.

@github-actions

Copy link
Copy Markdown

✅ PR Template Routing

Branch prefix: fix
Template selected: pr_bug.md
Type: Bug Fix PR


This PR's template has been automatically routed based on the canonical branching strategy defined in lightspeedwp/.github.

📋 Template routing rules:

✨ Automatic routing ensures all PRs follow the organization-wide governance structure.

@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

Deployment failed for project thisonetimeonacidcom with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/lightspeedwp?upgradeToPro=build-rate-limit

@github-actions

Copy link
Copy Markdown

Drift Detection ✅

✅ No drift detected. Configuration is canonical.

Canonical governance files are correctly centralized in lightspeedwp/.github.

Copy link
Copy Markdown
Member Author

CI notes on this PR:

  • Require changelog or skip label: failed on 5ba97d9 because the PR had no CHANGELOG.md entry. 6d6a9d8 adds one under [Unreleased] → Fixed.
  • Vercel deployment: failed with api-deployments-free-per-day. That's the Vercel account's daily limit of 100 free deployments, not something in this diff. Netlify is the production host (.github/specs/005-reader-access/deployment-validation.md), so a Netlify deploy preview is the one to use for checking the functions against Blobs and Mailgun.

Generated by Claude Code

@github-actions

Copy link
Copy Markdown

📋 Changelog Quality Validation

Metric Count
✅ Passing 1
❌ Failing 0
🆕 New failures in this PR 0
📦 Pre-existing failures 0

Status

✅ Validation PASSED - No new failures introduced by this PR.

No action required.

Copy link
Copy Markdown
Member Author

No new test failures: the 66 "new" failures already exist on main. The check compares two different test runners:

  • Base runs npx jest --config jest.config.js, whose testMatch only covers **/tests/**/*.test.js, so the TypeScript suites in tests/session/ and tests/performance/ never run on base (base reported 8 failures in 8 files).
  • Head runs npx vitest run, which does run them.

Running Vitest on a clean checkout of main (3907f71) gives 67 failures in the same nine files: tests/performance/session-latency.test.ts (14), tests/session/session.test.ts (19), device-limit-tests (12), security (6–7), session-persistence (6), session-renewal (4), session-expiry (2–3), session-create (1), session-logout (1). This PR touches none of those files; its own new tests (tests/reader-access/functions-build.test.ts, code-store.test.ts, the unskipped netlify/__tests__/reader-retention.test.ts) all pass.

The proposed fix is to run Vitest on base as well in .github/workflows/tests.yml. The comment there says base still uses jest.mock(), but main now passes 929 tests under Vitest. That would affect every PR, so I've left it for a maintainer to decide rather than changing CI here. Separately, the 006 session suites need fixing.


Generated by Claude Code

@ashleyshaw
ashleyshaw marked this pull request as ready for review November 20, 2026 11:42
@github-actions

Copy link
Copy Markdown

Drift Detection ✅

✅ No drift detected. Configuration is canonical.

Canonical governance files are correctly centralized in lightspeedwp/.github.

@mergify

mergify Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

PR #653 (spec 006 US1) restored code storage in store.ts, unified
sessions behind a token index, hashed the emailed code and fixed
sign-out. Take main's version of the six conflicting files and drop
code-store.ts and its test, which that design supersedes.

Keep only what main still lacks:
- Atomic consume-once (RA-002): store.consumeCode writes a
  code-consumed:<sha256> marker with onlyIfNew; session creation uses it
  instead of delete-first. The in-memory test store honours onlyIfNew,
  and a race test shows exactly one of two concurrent submissions wins
  (it fails against delete-first).
- Mailgun username 'api'.
- reader-retention store API and @daily schedule.
- /api/reader/chapters/:chapterId in public/_redirects, passing the id
  through as netlify.toml does.
- The function bundle and redirect-target guard test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CADHZdpaiuKYHLz2mX9por
@vercel

vercel Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
thisonetimeonacidcom Ready Ready Preview Nov 21, 2026 11:22am UTC

@github-actions

Copy link
Copy Markdown

Drift Detection ✅

✅ No drift detected. Configuration is canonical.

Canonical governance files are correctly centralized in lightspeedwp/.github.

@ashleyshaw ashleyshaw changed the title fix(reader-access): restore code storage so spec 005 functions build fix(reader-access): atomic code consume, Mailgun auth, retention and chapter route Nov 21, 2026
ashleyshaw pushed a commit that referenced this pull request Nov 21, 2026
The comparison job ran Jest on the PR base and Vitest on the head.
Jest's testMatch only covers *.test.js, so TypeScript suites never ran
on base and every failure in them was reported as new on each PR
(e.g. 66 "new" failures on #652 that already existed on main).

main now passes the full Vitest suite (1060 passed, 0 failed locally),
so the Jest baseline the cutover comment relied on is no longer needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CADHZdpaiuKYHLz2mX9por
Signed-off-by: Ash Shaw <ashley@lightspeedwp.agency>
@github-actions

Copy link
Copy Markdown

Drift Detection ✅

✅ No drift detected. Configuration is canonical.

Canonical governance files are correctly centralized in lightspeedwp/.github.

@ashleyshaw

Copy link
Copy Markdown
Member Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 0e37c86 at 11:22 UTC

Less than a minute in the queue, with no time running CI.

So far

  • ✅ Entered the queue Sat 21 Nov, 11:22 · rule default · triggered by @ashleyshaw with the @mergifyio queue command
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged 11:22 · 0e37c86

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 21, 2026
@mergify
mergify Bot merged commit 0e37c86 into main Nov 21, 2026
25 of 26 checks passed
@mergify
mergify Bot deleted the fix/reader-access-restore-code-store branch November 21, 2026 11:22
@mergify mergify Bot removed the queued label Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants