Skip to content

Live sync over Firebase (Cloud Firestore) - #12

Open
LeventeBotos wants to merge 6 commits into
reviewjs:mainfrom
LeventeBotos:feat/firebase-live-sync
Open

LeventeBotos wants to merge 6 commits into
reviewjs:mainfrom
LeventeBotos:feat/firebase-live-sync

Conversation

@LeventeBotos

Copy link
Copy Markdown

Summary

Lets a site owner sync reviews through their own Firebase project, with comments reaching the author live (no reload, no server to run). Local-only mode, the HTTP backend, exports and the dependency-free annotate.js are unchanged.

  • Core: a transport option. annotate.js already has a persisted queue, conflict handling and merge logic behind one function (apiFetch). A transport answers the same wire-protocol routes in-process and may push the page's visible comments. The existing sync engine is reused rather than duplicated. Polling drops to a 60 s safety net when a transport can push. Snapshots that race an in-flight or just-acknowledged write cannot drop it.
  • @reviewjs/annotate/firebase. firebase.mjs implements wire protocol v1 on Firestore (transactions give the stale check, tombstones and reply idempotency; onSnapshot gives live push). firebase is an optional peer dependency.
  • examples/firebase/firestore.rules. The trust boundary: reviewers see and change only their own comments, only authors assign, clients cannot hard-delete or promote themselves.
  • Docs per the repo's conventions: design spec and plan under docs/superpowers/, a new additive Transports section in wire-protocol.md (no /v2), a README setup guide, site FAQ.

Design and known limits: docs/superpowers/specs/2026-11-19-firebase-live-sync-design.md. No version bump; releasing is left to the maintainer.

Things worth a reviewer's attention

  • A reviewer can write any field of their own comment (for example forge an author reply inside it); only they and the authors ever see that document. Stricter integrity would need a Cloud Function. Called out in the spec.
  • updatedAt comes from the browser clock; the adapter keeps it strictly increasing per document.
  • There is no invite-link flow for Firebase: reviews are open or restricted to members an author adds.
  • The firebase peer range (>=12) is a judgement call; only 13.4 was tested.

Test plan

  • npm run test:server: 21 pass (reference server unchanged)
  • npx playwright test --project=chromium: 165 pass, then the new suites separately
  • tests/transport.spec.js (7, in-memory transport) and tests/remote.spec.js on Firefox and WebKit: 44 pass
  • npm run test:firebase: 25 pass on the emulators (rules attacked directly, protocol conformance, live subscription)
  • npm run test:firebase:e2e: 2 pass (two real browsers: reviewer to author live, author decision back, a second reviewer sees nothing)
  • CI: new firebase job (emulators, no secrets); needs to run on this PR
  • Not exercised: a real Firebase project (emulators only)

🤖 Generated with Claude Code

LeventeBotos and others added 6 commits November 19, 2026 13:46
A transport answers the wire-protocol routes in-process and may push the
page's visible comments live. The existing queue, conflict handling and
merge code is reused unchanged; apiFetch just calls transport.request
instead of fetch. With subscribe(), polling drops to a 60 s safety net,
snapshots that race an in-flight or just-acknowledged write cannot drop
it, and a refused subscription falls back to local mode like a refused
session. HTTP behaviour is untouched.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
firebase.mjs implements wire protocol v1 in the browser on top of
Firestore (transactions give the stale check, tombstones and reply
idempotency) and pushes each page's visible comments with onSnapshot.
It ships as @reviewjs/annotate/firebase with firebase as an optional
peer dependency; annotate.js stays dependency-free.

examples/firebase/firestore.rules is the trust boundary: reviewers see
and change only their own comments, only authors assign, clients cannot
hard-delete or promote themselves. Tested on the emulators with the real
rules: 25 tests covering the protocol cases, the rules attacked directly,
and live subscriptions. Pen strokes are flattened because Firestore
rejects nested arrays.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A reviewer's comment reaches the author without a reload, the author's
decision reaches the reviewer, and a second reviewer never sees it. The
browser bundle is built with esbuild; a new CI job runs the rules,
conformance and e2e suites on the emulators (demo- project, no secrets).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Design spec and plan, a README setup guide, the wire protocol's new
Transports section (additive, no /v2), and the site FAQ. Raises the
optional firebase peer range to 12.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Behaviour change: reviewers previously saw only their own comments;
every member now reads every comment and its activity and may reply to
any comment. Writes are unchanged: a reviewer creates comments and
edits, resolves or deletes only their own, and only authors assign.

Rules: get/list/activity read are isMember(). A non-owner's update may
change only replies and updatedAt and may append exactly one reply of
their own (a non-owner may also log a 'replied' activity event). The
empty-thread case needed a guard because slicing an empty prefix is a
rules evaluation error, which would have refused every first reply.

Adapter: drop the authorId list filter and the reply/activity ownership
gates; reply removal stays a write (403 not_owner for non-authors); the
ifDenied mapping is gone since a denial no longer means 'not yours'.

Tests rewritten for the new model, plus rules tests for reply append,
forging, stacking, tampering and the first reply. README, design spec
and the wire protocol's Transports section record the change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Follow-up to letting every member read all comments.

- Rules: a non-author may only append or remove one reply of their own, and
  a comment's owner can no longer forge replies in another member's name.
  Non-owners may log "replied" and "reply_deleted" activity.
- Adapter: a reply's author can remove it from any comment.
- Core: Resolve/Reopen is shown only on comments a reviewer owns, and
  toasts no longer blame "the review owner" for other reviewers' changes.
- Add examples/firebase/index.html, a no-bundler demo that runs against the
  emulators in two windows.
- Tests for each of the above; docs updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant