INSTAGRAM-002B: source-only social-post persistence-plan builder and Rules boundary - #681
Open
rusty-sj wants to merge 1 commit into
Open
INSTAGRAM-002B: source-only social-post persistence-plan builder and Rules boundary#681rusty-sj wants to merge 1 commit into
rusty-sj wants to merge 1 commit into
Conversation
…Rules boundary
Compose the merged INSTAGRAM-002A classifySocialPostTransition reducer into a
pure, non-throwing buildSocialPostPersistencePlan(input): given a store envelope
plus the reducer's own record and command, return the deterministic Firestore
write set (socialPosts/{postId} update + one append-only auditEvents row under
the social_post aggregate) and the optimistic-concurrency precondition a
caller's transaction must assert. Rejected and idempotent-no-op verdicts yield
zero writes. No I/O, no clock (auditInstant is a caller token), node:util +
./socialPostState only, unregistered in index.js.
Add the server-only socialPosts/{postId} Rules boundary (allow read, write: if
false, nested records included) with allow/deny coverage across the anonymous /
would-be author / member / browser-admin actor matrix in
tests/firestore-rules/social-post.test.js. The audit trail reuses the existing
server-only auditEvents collection.
Document both slices in SYSTEM_DESIGN.md 8.7. Officer docs unaffected: a
source-only contract with no officer-visible behavior, task, page, permission,
or data movement.
Verification:
- npm --prefix functions run lint: clean
- npm --prefix functions run test:run: 70 suites / 7629 pass (2 emulator suites skipped)
- npm run test:rules: 6 suites / 433 pass (includes new social-post.test.js)
- node --test tests/ci-workflow.test.js tests/test-artifact-safety.test.js tests/root-dependency-security.test.js: 72 pass
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GPs7CQHK2h8KqhgKKsXevv
✅ Deploy Preview for luminous-fox-7c393f ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Outcome
Add the source-only persistence-plan builder that turns an approved-before-published social post transition into an exact Firestore write set, and add the server-only Rules boundary for the post collection. Nothing new runs yet.
Scope
socialPostState.js, §8.7).functions/socialPostStore.js(new) —buildSocialPostPersistencePlan(input). A pure, non-throwing builder that composesclassifySocialPostTransitioninto a deterministic plan: asocialPosts/{postId}update carrying the reducer projection plusrevision := expectedRevision + 1, and one append-onlyauditEventsrow under asocial_postaggregate discriminator, its document id a deterministicsocial_post_{postId}_{nextRevision}join so a retried transaction collides on the same id instead of appending twice. Returnsprecondition{ collection, docId, expectedRevision }for the caller's transaction to assert. Rejected verdicts (reducer_rejected) and the reducer's idempotent no-op (no_write_needed) yield zero writes; a malformed envelope yieldsinvalid_store_input. Clock-free (auditInstantis a caller-supplied opaque token); requires onlynode:utiland./socialPostState.functions/socialPostStore.test.js(new) — plan shape, all 13 command types → audit event types, approve/edit verdict passthrough, six reducer-rejection passthrough cases, idempotent no-op, 23 malformed-envelope cases, Proxy/accessor rejection without trap invocation, determinism and input-immutability, deep-freeze, hostile-canary non-echo, and a source-boundary battery (no clock/randomness/network/provider surface, no PII or credential vocabulary, no concrete provider name, not imported byindex.js).firestore.rules— server-onlysocialPosts/{postId}boundary (allow read, write: if false, nested records included), matching the existingmemberDirectoryEntriespattern.tests/firestore-rules/social-post.test.js(new) — allow/deny coverage forsocialPosts/{postId}, its nested records, and theauditEventstrail across anonymous / would-be author / verified member / unverified browser admin / verified browser admin.SYSTEM_DESIGN.md§8.7 — addendum documenting this slice.index.jswiring, no transaction is opened, no Instagram/provider adapter, no scheduling clock, no officer UI, no migration. The audit trail reuses the existing server-onlyauditEventscollection. TheselfApprovalAllowedpolicy default is unchanged and remains an owner decision (open question on INSTAGRAM-002 — Add an approval-gated social-post state and audit model #92).Officer handoff
NOT AVAILABLE YET.Proof by surface
npm --prefix functions run lint— clean.npm --prefix functions run test:run -- --runInBand— 70 suites / 7629 pass (2 unrelated emulator suites skipped).npm run test:rules— 6 suites / 433 pass, including the newsocial-post.test.js.node --test tests/ci-workflow.test.js tests/test-artifact-safety.test.js tests/root-dependency-security.test.js— 72 pass.runmprc.comverified: not relevant.socialPostsRules boundary ships to Firebase only through the protected release path.Safety review
NOT AVAILABLE YET.Open question for @daliu
The
selfApprovalAllowedflag on a command still needs the owner policy: may the same officer author and approve a post, or must the approver differ? It does not block this slice — the builder only threads the flag through and the reducer already enforces both directions — but the callable command entry point in the next slice needs the default.