Repository navigation
feat: drop shadow-diff body mismatches on records edited after capture (CM-1473) #4896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+355
−4
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0bb5e34
feat: drop shadow-diff body mismatches on records edited after captur…
mbani01 8b0351e
fix: scope edited-record check to parent-body events, log unchecked o…
mbani01 95e3b1c
fix: count null nodes as unchecked in the edited-record confirmation …
mbani01 d2abd8d
Merge branch 'main' into feat/shadow-diff-edited-body-check
mbani01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
175 changes: 175 additions & 0 deletions
175
services/apps/connectors_worker/src/editedRecords.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import type { ConnectorHttp } from '@crowd/connectors' | ||
| import type { Logger } from '@crowd/logging' | ||
|
|
||
| import { dropConfirmedEditedRecords, hasEditedRecordCandidates } from './editedRecords' | ||
| import { IShadowDiffMismatch } from './shadowDiff' | ||
|
|
||
| const log = { info: vi.fn(), warn: vi.fn(), error: vi.fn() } as unknown as Logger | ||
|
|
||
| function bodyMismatch(sourceId: string, type = 'issue-comment'): IShadowDiffMismatch { | ||
| return { | ||
| sourceId, | ||
| type, | ||
| kind: 'field_mismatch', | ||
| severity: 'high', | ||
| fields: [{ field: 'body', shadowValue: 'old', nangoValue: 'new' }], | ||
| } | ||
| } | ||
|
|
||
| function httpWithHandler(handler: (ids: string[]) => Promise<unknown>): ConnectorHttp { | ||
| return { | ||
| request: async (config: { data: { variables: { ids: string[] } } }) => | ||
| handler(config.data.variables.ids), | ||
| requestCount: () => 0, | ||
| } as unknown as ConnectorHttp | ||
| } | ||
|
|
||
| function editedResponse(editedIds: string[]) { | ||
| return async (ids: string[]) => ({ | ||
| data: { | ||
| nodes: ids.map((id) => ({ | ||
| id, | ||
| lastEditedAt: editedIds.includes(id) ? '2026-10-07T00:00:00Z' : null, | ||
| })), | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| describe('hasEditedRecordCandidates', () => { | ||
| it('is false for the pull-request-commits sync', () => { | ||
| expect( | ||
| hasEditedRecordCandidates('pull-request-commits', [ | ||
| bodyMismatch('abc123', 'authored-commit'), | ||
| ]), | ||
| ).toBe(false) | ||
| }) | ||
|
|
||
| it('is false when the mismatch involves fields other than body', () => { | ||
| const mismatch: IShadowDiffMismatch = { | ||
| ...bodyMismatch('IC_abc'), | ||
| fields: [ | ||
| { field: 'body', shadowValue: 'old', nangoValue: 'new' }, | ||
| { field: 'url', shadowValue: 'a', nangoValue: 'b' }, | ||
| ], | ||
| } | ||
| expect(hasEditedRecordCandidates('issue-comments', [mismatch])).toBe(false) | ||
| }) | ||
|
|
||
| it('is false for missing_in_shadow mismatches', () => { | ||
| expect( | ||
| hasEditedRecordCandidates('issue-comments', [ | ||
| { sourceId: 'IC_abc', type: 'issue-comment', kind: 'missing_in_shadow', severity: 'high' }, | ||
| ]), | ||
| ).toBe(false) | ||
| }) | ||
|
|
||
| it('is true for a body-only mismatch on a real node id', () => { | ||
| expect(hasEditedRecordCandidates('issue-comments', [bodyMismatch('IC_abc')])).toBe(true) | ||
| }) | ||
|
|
||
| it('is true for a body-only mismatch on a synthetic id carrying a parent node', () => { | ||
| expect( | ||
| hasEditedRecordCandidates('pull-requests', [ | ||
| bodyMismatch( | ||
| 'gen-RRE_PR_kwDOI7xefs8AAAABGaViEg_alice_bob_2026-10-06T15:07:23.000Z', | ||
| 'pull_request-review-requested', | ||
| ), | ||
| ]), | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it('is false for a reviewed event whose body belongs to the review, not the parent PR', () => { | ||
| expect( | ||
| hasEditedRecordCandidates('pull-requests', [ | ||
| bodyMismatch( | ||
| 'gen-PRR_PR_kwDOI7xefs8AAAABGaViEg_alice_2026-10-06T15:07:23.000Z', | ||
| 'pull_request-reviewed', | ||
| ), | ||
| ]), | ||
| ).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('dropConfirmedEditedRecords', () => { | ||
| it('drops body mismatches whose node was edited and keeps the never-edited ones', async () => { | ||
| const mismatches = [bodyMismatch('IC_edited'), bodyMismatch('IC_pristine')] | ||
| const http = httpWithHandler(editedResponse(['IC_edited'])) | ||
|
|
||
| const result = await dropConfirmedEditedRecords('issue-comments', mismatches, http, log) | ||
|
|
||
| expect(result.mismatches).toEqual([bodyMismatch('IC_pristine')]) | ||
| expect(result.confirmedEditedCount).toBe(1) | ||
| expect(result.unconfirmedCount).toBe(0) | ||
| }) | ||
|
|
||
| it('resolves synthetic timeline ids to their parent node and queries each parent once', async () => { | ||
| const prId = 'PR_kwDOI7xefs8AAAABGaViEg' | ||
| const mismatches = [ | ||
| bodyMismatch( | ||
| `gen-RRE_${prId}_alice_bob_2026-10-06T15:07:23.000Z`, | ||
| 'pull_request-review-requested', | ||
| ), | ||
| bodyMismatch( | ||
| `gen-RRE_${prId}_alice_carol_2026-10-06T15:07:23.000Z`, | ||
| 'pull_request-review-requested', | ||
| ), | ||
| bodyMismatch(prId, 'pull_request-opened'), | ||
| ] | ||
| const seen: string[][] = [] | ||
| const http = httpWithHandler(async (ids) => { | ||
| seen.push(ids) | ||
| return editedResponse([prId])(ids) | ||
| }) | ||
|
|
||
| const result = await dropConfirmedEditedRecords('pull-requests', mismatches, http, log) | ||
|
|
||
| expect(seen).toEqual([[prId]]) | ||
| expect(result.mismatches).toEqual([]) | ||
| expect(result.confirmedEditedCount).toBe(3) | ||
| }) | ||
|
|
||
| it('keeps mismatches and counts them unconfirmed when the request fails', async () => { | ||
| const mismatches = [bodyMismatch('IC_unknown')] | ||
| const http = httpWithHandler(async () => { | ||
| throw new Error('network exploded') | ||
| }) | ||
|
|
||
| const result = await dropConfirmedEditedRecords('issue-comments', mismatches, http, log) | ||
|
|
||
| expect(result.mismatches).toEqual(mismatches) | ||
| expect(result.confirmedEditedCount).toBe(0) | ||
| expect(result.unconfirmedCount).toBe(1) | ||
| }) | ||
|
|
||
| it('keeps mismatches whose node resolved to null and counts them unconfirmed', async () => { | ||
| const mismatches = [bodyMismatch('IC_gone')] | ||
| const http = httpWithHandler(async (ids) => ({ data: { nodes: ids.map(() => null) } })) | ||
|
|
||
| const result = await dropConfirmedEditedRecords('issue-comments', mismatches, http, log) | ||
|
|
||
| expect(result.mismatches).toEqual(mismatches) | ||
| expect(result.confirmedEditedCount).toBe(0) | ||
| expect(result.unconfirmedCount).toBe(1) | ||
| }) | ||
|
|
||
| it('leaves non-candidate mismatches untouched', async () => { | ||
| const other: IShadowDiffMismatch = { | ||
| sourceId: 'IC_other', | ||
| type: 'issue-comment', | ||
| kind: 'missing_in_nango', | ||
| severity: 'high', | ||
| } | ||
| const http = httpWithHandler(editedResponse(['IC_edited'])) | ||
|
|
||
| const result = await dropConfirmedEditedRecords( | ||
| 'issue-comments', | ||
| [other, bodyMismatch('IC_edited')], | ||
| http, | ||
| log, | ||
| ) | ||
|
|
||
| expect(result.mismatches).toEqual([other]) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.