diff --git a/src/mapeo-manager.js b/src/mapeo-manager.js index a4bc8d42..4d02c247 100644 --- a/src/mapeo-manager.js +++ b/src/mapeo-manager.js @@ -792,6 +792,9 @@ export class MapeoManager extends TypedEmitter { // in the config store - defining the name of the project. // TODO: Enforce adding a project name in the invite method const isConfigSynced = configState.want === 0 && configState.have > 0 + if (isRoleSynced && ownRole.sync.config === 'blocked' && isAuthSynced) { + return true + } if ( isRoleSynced && isProjectSettingsSynced && @@ -803,6 +806,7 @@ export class MapeoManager extends TypedEmitter { this.#l.log( 'Pending initial sync: role %s, projectSettings %o, auth %o, config %o', isRoleSynced, + isProjectSettingsSynced, isAuthSynced, isConfigSynced ) @@ -811,12 +815,15 @@ export class MapeoManager extends TypedEmitter { /** @param {import('./sync/sync-state.js').State} syncState */ const onSyncState = (syncState) => { clearTimeout(timeoutId) - if (syncState.auth.dataToSync || syncState.config.dataToSync) { + if ( + syncState.auth.dataToSync || + (syncState.config.dataToSync && ownRole.sync.config === 'allowed') + ) { timeoutId = setTimeout(onTimeout, timeoutMs) return } project.$sync[kSyncState].off('state', onSyncState) - resolve(this.#waitForInitialSync(project, { timeoutMs })) + this.#waitForInitialSync(project, { timeoutMs }).then(resolve, reject) } const onTimeout = () => { project.$sync[kSyncState].off('state', onSyncState) diff --git a/test-e2e/sync.js b/test-e2e/sync.js index f696792b..0aa95872 100644 --- a/test-e2e/sync.js +++ b/test-e2e/sync.js @@ -900,6 +900,8 @@ test('no sync capabilities === no namespaces sync apart from auth', async (t) => const [invitor, invitee, blocked] = managers const disconnect1 = connectPeers(managers) + t.after(() => disconnect1()) + const projectId = await invitor.createProject({ name: 'Mapeo' }) await invite({ @@ -919,6 +921,8 @@ test('no sync capabilities === no namespaces sync apart from auth', async (t) => managers.map((m) => m.getProject(projectId)) ) + t.after(() => Promise.all(projects.map((p) => p.close()))) + const [invitorProject, inviteeProject] = projects assert.equal( @@ -955,18 +959,15 @@ test('no sync capabilities === no namespaces sync apart from auth', async (t) => assert.equal(blockedState.data.localState.have, 0) // no data docs synced for (const ns of NAMESPACES) { - assert.equal(invitorState[ns].coreCount, 3, ns) - assert.equal(inviteeState[ns].coreCount, 3, ns) - assert.equal(blockedState[ns].coreCount, 3, ns) + assert.equal(invitorState[ns].coreCount, 3, `invitor got cores for ${ns}`) + assert.equal(inviteeState[ns].coreCount, 3, `invitee got cores for ${ns}`) + assert.equal(blockedState[ns].coreCount, 3, `blocked got cores for ${ns}`) assert.deepEqual( invitorState[ns].localState, inviteeState[ns].localState, - ns + `invitor/invitee have same local state for ${ns}` ) } - - await disconnect1() - await Promise.all(projects.map((p) => p.close())) }) test('Sync state emitted when starting and stopping sync', async function (t) {