Skip to content

Commit c5aedd2

Browse files
committed
test(people): pin the same-batch manager tie-break and document it
1 parent fde80b7 commit c5aedd2

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎apps/sim/lib/people/sync/stage.integration.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ it('resumes relationship pages from stored continuations, refuses incomplete Gra
104104
.update(peopleDirectorySync)
105105
.set({ source: 'entra' })
106106
.where(eq(peopleDirectorySync.organizationId, run.organizationId))
107-
await writeUsers(null, [person('lead'), person('worker'), person('other')])
107+
await writeUsers(null, [person('lead'), person('worker'), person('other'), person('peer')])
108108
await expect(db.transaction((tx) => publishStagedSnapshot(tx, run, 'entra'))).rejects.toThrow(
109109
/relationship|report/i
110110
)
@@ -124,12 +124,17 @@ it('resumes relationship pages from stored continuations, refuses incomplete Gra
124124
})
125125
await record('lead', 'continuation', ['worker'], null)
126126
await record('other', null, ['worker'], null)
127-
await record('worker', null, [], null)
127+
await db.transaction((tx) =>
128+
stageRelationships(tx, run, [
129+
{ managerId: 'worker', cursor: null, reportIds: ['other'], nextCursor: null },
130+
{ managerId: 'peer', cursor: null, reportIds: ['other'], nextCursor: null },
131+
])
132+
)
128133
expect(await pendingManagers(db, run)).toEqual([])
129134
await db.transaction((tx) => publishStagedSnapshot(tx, run, 'entra'))
130-
expect((await published()).find((r) => r.externalId === 'worker')?.managerExternalId).toBe(
131-
'other'
132-
)
135+
const managers = new Map((await published()).map((r) => [r.externalId, r.managerExternalId]))
136+
expect(managers.get('worker')).toBe('other')
137+
expect(managers.get('other')).toBe('peer')
133138
})
134139
it('refuses to publish a replaced generation', async () => {
135140
await writeUsers(null, [person('live')])

‎apps/sim/lib/people/sync/stage.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ export async function pendingManagers(executor: DbOrTx, run: StageRun) {
103103

104104
/**
105105
* Commits only completed subrequests and rejects a cursor replay. Graph gives a person one
106-
* manager, so a person claimed again was moved during a read that spans many slices: the
107-
* latest read wins, and publication's cycle check still guards the finished graph.
106+
* manager, so a person claimed again was moved during a read that spans many slices: a later
107+
* batch overwrites an earlier one, and publication's cycle check still guards the finished
108+
* graph. Reads inside one batch are concurrent, so a claim repeated there resolves to the
109+
* lowest manager ID, independent of response order.
108110
*/
109111
export async function stageRelationships(
110112
tx: DbTransaction,

0 commit comments

Comments
 (0)