From 8b2d715741fca47e1f232556eb27aff82ceeec48 Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 9 Oct 2025 00:18:08 +0200 Subject: [PATCH 1/3] add test #7371 documents moving outside replication scope --- test/replication-firestore.test.ts | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/replication-firestore.test.ts b/test/replication-firestore.test.ts index fe4ec223b36..4581748077e 100644 --- a/test/replication-firestore.test.ts +++ b/test/replication-firestore.test.ts @@ -485,6 +485,47 @@ describe('replication-firestore.test.ts', function () { const docsOnServer = await getAllDocsOfFirestore(firestoreState, where('owner', '==', ownerUid)); assert.strictEqual(docsOnServer.length, 2); }); + it('#7371 documents moving outside replication scope', async () => { + const firestoreState = await getFirestoreState(); + const collection = await humansCollection.create(0); + const firstDocRef = + await addDoc(firestoreState.collection, makeFirestoreHumanDocument(schemaObjects.humanData('abc', 35, 'replicated'))); + await addDoc(firestoreState.collection, makeFirestoreHumanDocument(schemaObjects.humanData('def', 22, 'replicated'))); + await addDoc(firestoreState.collection, makeFirestoreHumanDocument(schemaObjects.humanData('fgh', 34, 'replicated'))); + + const replicationState = replicateFirestore({ + replicationIdentifier: firestoreState.projectId, + firestore: firestoreState as any, + collection: collection, + pull: { + filter: where('firstName', '==', 'replicated') + }, + push: {}, + live: true, + autoStart: true + }); + ensureReplicationHasNoErrors(replicationState); + await replicationState.awaitInitialReplication(); + + let allLocalDocs = await collection.find().exec(); + + assert.strictEqual(allLocalDocs.length, 3); + + /** update document to fall out of replication scope **/ + await updateDoc(doc(firestoreState.collection, firstDocRef.id), { + firstName: 'not-replicated' + }); + + await replicationState.awaitInSync(); + + allLocalDocs = await collection.find().exec(); + const docsOnServer = await getAllDocsOfFirestore(firestoreState, where('firstName', '==', 'replicated')); + + assert.strictEqual(allLocalDocs.length, docsOnServer.length); + + collection.close(); + collection.database.close(); + }); }); }); From 2ac701d50e95f7bce06dfa9b0bcea3cc80569659 Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 9 Oct 2025 00:30:25 +0200 Subject: [PATCH 2/3] missing imports --- test/replication-firestore.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/replication-firestore.test.ts b/test/replication-firestore.test.ts index 4581748077e..f15e89fc9b2 100644 --- a/test/replication-firestore.test.ts +++ b/test/replication-firestore.test.ts @@ -42,7 +42,10 @@ import { orderBy, limit, getDoc, - QueryConstraint + QueryConstraint, + addDoc, + updateDoc, + doc } from 'firebase/firestore'; import { FirestoreOptions, From 95a2621530b0849eec424308a542a1dfbfce013f Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 9 Oct 2025 00:38:12 +0200 Subject: [PATCH 3/3] fixed doc import --- test/replication-firestore.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/replication-firestore.test.ts b/test/replication-firestore.test.ts index f15e89fc9b2..ea7b68a28f2 100644 --- a/test/replication-firestore.test.ts +++ b/test/replication-firestore.test.ts @@ -44,8 +44,7 @@ import { getDoc, QueryConstraint, addDoc, - updateDoc, - doc + updateDoc } from 'firebase/firestore'; import { FirestoreOptions, @@ -516,7 +515,7 @@ describe('replication-firestore.test.ts', function () { assert.strictEqual(allLocalDocs.length, 3); /** update document to fall out of replication scope **/ - await updateDoc(doc(firestoreState.collection, firstDocRef.id), { + await updateDoc(DocRef(firestoreState.collection, firstDocRef.id), { firstName: 'not-replicated' });