Skip to content

fix: Handle missing segments from ImpactedFileComparison response#3961

Open
calvin-codecov wants to merge 2 commits intomainfrom
cy/file_diff_400
Open

fix: Handle missing segments from ImpactedFileComparison response#3961
calvin-codecov wants to merge 2 commits intomainfrom
cy/file_diff_400

Conversation

@calvin-codecov
Copy link
Contributor

@calvin-codecov calvin-codecov commented Jan 13, 2026

Related to problem happening in: https://sentry.zendesk.com/agent/tickets/171579 where the customer's pull request has coverage data showing but displays a 400 error on the page with no useful information.

Our query ImpactedFileComparison is getting a 404 when trying to request the source code from the git provider for a specific file when expanding in the UI. This PR is adding better handling of the response from the query when it does not return segments of type SegmentComparisons (what we need to display the snippets with coverage) but instead UnknownPath or ProviderError. We are getting UnknownPath in this customer's case. These changes add UI components that mirror what we show for CommitDiff that get UnknownPath/ProviderError responses. Other files change include newly checking the segments part of the GQL response data to dictate behavior as opposed to moving straight segments?.results and dealing with undefineds.


Note

Improves robustness of impacted-file diff rendering when GraphQL segments isn’t SegmentComparisons.

  • Updates schemas to a discriminated union for segments (SegmentComparisons | UnknownPath | ProviderError) in services/pull/fragments and preserves full segments in transform utils
  • Guards all segment-to-line-data mappers to check segments.__typename === 'SegmentComparisons' before using .results
  • Pull request views (PullFileDiff for FilesChanged/IndirectChanges) now handle UnknownPath with a user-facing message and ProviderError with a generic error; similar handling added/confirmed for commit views
  • useSingularImpactedFileComparison returns raw impactedFile (no early transform); consumers call transformImpactedPullFileToDiff
  • Tests added/updated to cover UnknownPath and new data shape expectations

Written by Cursor Bugbot for commit 3eb024f. This will update automatically on new commits. Configure here.

@sentry
Copy link

sentry bot commented Jan 13, 2026

❌ 5 Tests Failed:

Tests completed Failed Passed Skipped
1783 5 1778 0
View the top 3 failed test(s) by shortest run time
src/services/pull/utils/transformImpactedPullFileToDiff.test.ts > transformImpactedPullFileToDiff > returns file information
Stack Traces | 0.00953s run time
AssertionError: expected { fileLabel: null, …(3) } to strictly equal { fileLabel: null, …(3) }

- Expected
+ Received

  Object {
    "fileLabel": null,
    "hashedPath": "hashedPath",
    "headName": "headName",
-   "segments": Array [
+   "segments": Object {
+     "results": Array [
        Object {
          "hasUnintendedChanges": false,
          "header": "header",
          "lines": Array [
            Object {
              "baseCoverage": "M",
              "baseNumber": "1",
              "content": "content",
              "headCoverage": "H",
              "headNumber": "1",
            },
          ],
        },
      ],
+   },
  }

 ❯ .../pull/utils/transformImpactedPullFileToDiff.test.ts:40:18
src/services/pull/usePrefetchSingleFileComp.test.tsx > usePrefetchSingleFileComp > successful request > when called with a renamed file > queries the api
Stack Traces | 0.0172s run time
AssertionError: expected undefined to strictly equal { fileLabel: 'Renamed', …(3) }

- Expected: 
Object {
  "fileLabel": "Renamed",
  "hashedPath": "hashed-path",
  "headName": "file A",
  "segments": Array [],
}

+ Received: 
undefined

 ❯ .../services/pull/usePrefetchSingleFileComp.test.tsx:283:22
src/services/pull/usePrefetchSingleFileComp.test.tsx > usePrefetchSingleFileComp > successful request > when called with a unchanged file label > queries the api
Stack Traces | 0.019s run time
AssertionError: expected undefined to strictly equal { fileLabel: null, …(3) }

- Expected: 
Object {
  "fileLabel": null,
  "hashedPath": "hashed-path",
  "headName": "file A",
  "segments": Array [],
}

+ Received: 
undefined

 ❯ .../services/pull/usePrefetchSingleFileComp.test.tsx:353:22
src/services/pull/usePrefetchSingleFileComp.test.tsx > usePrefetchSingleFileComp > successful request > when called with a deleted file > queries the api
Stack Traces | 0.0267s run time
AssertionError: expected undefined to strictly equal { fileLabel: 'Deleted', …(3) }

- Expected: 
Object {
  "fileLabel": "Deleted",
  "hashedPath": "hashed-path",
  "headName": "file A",
  "segments": Array [],
}

+ Received: 
undefined

 ❯ .../services/pull/usePrefetchSingleFileComp.test.tsx:318:22
src/services/pull/usePrefetchSingleFileComp.test.tsx > usePrefetchSingleFileComp > successful request > when called with a normal pull diff > queries the api
Stack Traces | 0.0976s run time
AssertionError: expected undefined to strictly equal { fileLabel: 'New', …(3) }

- Expected: 
Object {
  "fileLabel": "New",
  "hashedPath": "hashed-path",
  "headName": "file A",
  "segments": Array [],
}

+ Received: 
undefined

 ❯ .../services/pull/usePrefetchSingleFileComp.test.tsx:248:22

To view more test analytics, go to the Prevent Tests Dashboard

@codecov-public-qa
Copy link

codecov-public-qa bot commented Jan 13, 2026

❌ 5 Tests Failed:

Tests completed Failed Passed Skipped
1783 5 1778 0
View the top 3 failed test(s) by shortest run time
src/services/pull/utils/transformImpactedPullFileToDiff.test.ts > transformImpactedPullFileToDiff > returns file information
Stack Traces | 0.00953s run time
AssertionError: expected { fileLabel: null, …(3) } to strictly equal { fileLabel: null, …(3) }

- Expected
+ Received

  Object {
    "fileLabel": null,
    "hashedPath": "hashedPath",
    "headName": "headName",
-   "segments": Array [
+   "segments": Object {
+     "results": Array [
        Object {
          "hasUnintendedChanges": false,
          "header": "header",
          "lines": Array [
            Object {
              "baseCoverage": "M",
              "baseNumber": "1",
              "content": "content",
              "headCoverage": "H",
              "headNumber": "1",
            },
          ],
        },
      ],
+   },
  }

 ❯ .../pull/utils/transformImpactedPullFileToDiff.test.ts:40:18
src/services/pull/usePrefetchSingleFileComp.test.tsx > usePrefetchSingleFileComp > successful request > when called with a renamed file > queries the api
Stack Traces | 0.0172s run time
AssertionError: expected undefined to strictly equal { fileLabel: 'Renamed', …(3) }

- Expected: 
Object {
  "fileLabel": "Renamed",
  "hashedPath": "hashed-path",
  "headName": "file A",
  "segments": Array [],
}

+ Received: 
undefined

 ❯ .../services/pull/usePrefetchSingleFileComp.test.tsx:283:22
src/services/pull/usePrefetchSingleFileComp.test.tsx > usePrefetchSingleFileComp > successful request > when called with a unchanged file label > queries the api
Stack Traces | 0.019s run time
AssertionError: expected undefined to strictly equal { fileLabel: null, …(3) }

- Expected: 
Object {
  "fileLabel": null,
  "hashedPath": "hashed-path",
  "headName": "file A",
  "segments": Array [],
}

+ Received: 
undefined

 ❯ .../services/pull/usePrefetchSingleFileComp.test.tsx:353:22

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

</span>
</p>
)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical component duplicated across multiple files

Low Severity

The UnknownPathErrorDisplayMessage component is defined identically in two separate PullFileDiff.tsx files in this PR. The same component also already exists in the CommitFileDiff files, resulting in four total copies of identical code. This increases maintenance burden and risks inconsistent bug fixes if the error message or styling needs to change. While this follows an existing pattern in the codebase (similar to ErrorDisplayMessage), extracting it to a shared location would reduce duplication.

Additional Locations (1)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant