Skip to content

fix(pull): Handle SegmentsResult union in ImpactedFileSchema - #4107

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/gazebo-16h7-segments-schema
Open

sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/gazebo-16h7-segments-schema

Conversation

@sentry

@sentry sentry Bot commented Sep 3, 2026

Copy link
Copy Markdown

Description

This PR resolves GAZEBO-16H7, a ZodError occurring when parsing the segments field in ImpactedFileSchema.

Problem:
The GraphQL SegmentsResult is a union type (SegmentComparisons | UnknownPath | ProviderError), but the ImpactedFileSchema in src/services/pull/fragments.ts and the corresponding GraphQL fragment only accounted for SegmentComparisons. When UnknownPath or ProviderError were returned, Zod failed to parse the response, leading to errors in usePrefetchSingleFileComp.

Code Example

N/A

Notable Changes

  1. GraphQL Fragment Update: Modified src/services/pull/fragments.ts to include inline fragments for UnknownPath and ProviderError within the segments field.
  2. Zod Schema Refinement: Updated ImpactedFileSchema.segments to use z.discriminatedUnion('__typename', [...]), correctly handling all three possible SegmentsResult types.
  3. Type Extraction: Extracted SegmentSchema and Segment type for better reusability and type safety.
  4. Downstream Consumer Update: Modified transformImpactedPullFileToDiff in src/services/pull/utils/transformImpactedPullFileToDiff.ts to safely access segments.results only when __typename is SegmentComparisons.
  5. TypeScript Fixes: Updated type annotations in src/pages/PullRequestPage/PullCoverage/routes/*/PullFileDiff/PullFileDiff.tsx to use the new Segment[] type, resolving previous TypeScript errors caused by the schema change.

Screenshots

N/A

Link to Sample Entry

N/A

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes GAZEBO-16H7

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

❌ 7 Tests Failed:

Tests completed Failed Passed Skipped
3079 7 3072 1
View the top 3 failed test(s) by shortest run time
src/services/pull/usePrefetchSingleFileComp.test.tsx > usePrefetchSingleFileComp > successful request > when called with a unchanged file label > queries the api
Stack Traces | 0.00736s run time
AssertionError: expected undefined to strictly equal { fileLabel: null, …(3) }

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

+ 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.0082s run time
AssertionError: expected undefined to strictly equal { fileLabel: 'Deleted', …(3) }

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

+ Received: 
undefined

 ❯ .../services/pull/usePrefetchSingleFileComp.test.tsx:318:22
src/services/pull/utils/transformImpactedPullFileToDiff.test.ts > transformImpactedPullFileToDiff > returns file information
Stack Traces | 0.00923s run time
AssertionError: expected { fileLabel: null, …(3) } to strictly equal { fileLabel: null, …(3) }

- Expected
+ Received

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

 ❯ .../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.0123s run time
AssertionError: expected undefined to strictly equal { fileLabel: 'Renamed', …(3) }

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

+ Received: 
undefined

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

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

+ Received: 
undefined

 ❯ .../services/pull/usePrefetchSingleFileComp.test.tsx:248:22
src/pages/PullRequestPage/PullCoverage/routes/FilesChangedTab/FilesChanged/NameColumn/NameColumn.test.jsx > NameColumn > when component is not expanded > prefetches query data
Stack Traces | 1.13s run time
AssertionError: expected undefined to strictly equal { fileLabel: 'New', …(3) }

Ignored nodes: comments, script, style
<html>
  <head />
  <body>
    <div>
      <div
        class="flex cursor-pointer items-center gap-2"
        data-testid="name-expand"
      >
        <span
          class="text-current"
        >
          <svg
            class="w-6 h-6"
            data-icon=""
            data-testid=""
            fill="currentColor"
            viewBox="0 0 20 20"
            xmlns="http://www.w3.org/2000/svg"
          >
            <path
              clip-rule="evenodd"
              d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
              fill-rule="evenodd"
            />
          </svg>
        </span>
        file.ts
      </div>
    </div>
  </body>
</html>

- Expected: 
{
  "fileLabel": "New",
  "hashedPath": "hashed-path",
  "headName": "file A",
  "segments": [
    {
      "hasUnintendedChanges": false,
      "header": "@@ -0,0 1,45 @@",
      "lines": [
        {
          "baseCoverage": null,
          "baseNumber": null,
          "content": "export default class Calculator {",
          "headCoverage": "H",
          "headNumber": "1",
        },
      ],
    },
  ],
}

+ Received: 
undefined

 ❯ .../FilesChanged/NameColumn/NameColumn.test.jsx:140:44
 ❯ runWithExpensiveErrorDiagnosticsDisabled node_modules/@.../dom/dist/config.js:47:12
 ❯ checkCallback node_modules/@.../dom/dist/wait-for.js:124:77
 ❯ Timeout.checkRealTimersCallback node_modules/@.../dom/dist/wait-for.js:118:16
src/pages/PullRequestPage/PullCoverage/routes/IndirectChangesTab/IndirectChangedFiles/NameColumn/NameColumn.test.jsx > NameColumn > when component is not expanded > prefetches query data
Stack Traces | 1.14s run time
AssertionError: expected undefined to strictly equal { fileLabel: 'New', …(3) }

Ignored nodes: comments, script, style
<html>
  <head />
  <body>
    <div>
      <div
        class="flex cursor-pointer items-center gap-2"
        data-testid="name-expand"
      >
        <span
          class="text-current"
        >
          <svg
            class="w-6 h-6"
            data-icon=""
            data-testid=""
            fill="currentColor"
            viewBox="0 0 20 20"
            xmlns="http://www.w3.org/2000/svg"
          >
            <path
              clip-rule="evenodd"
              d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
              fill-rule="evenodd"
            />
          </svg>
        </span>
        file.ts
      </div>
    </div>
  </body>
</html>

- Expected: 
{
  "fileLabel": "New",
  "hashedPath": "hashed-path",
  "headName": "file A",
  "segments": [
    {
      "hasUnintendedChanges": false,
      "header": "@@ -0,0 1,45 @@",
      "lines": [
        {
          "baseCoverage": null,
          "baseNumber": null,
          "content": "export default class Calculator {",
          "headCoverage": "H",
          "headNumber": "1",
        },
      ],
    },
  ],
}

+ Received: 
undefined

 ❯ .../IndirectChangedFiles/NameColumn/NameColumn.test.jsx:139:44
 ❯ runWithExpensiveErrorDiagnosticsDisabled node_modules/@.../dom/dist/config.js:47:12
 ❯ checkCallback node_modules/@.../dom/dist/wait-for.js:124:77
 ❯ Timeout.checkRealTimersCallback node_modules/@.../dom/dist/wait-for.js:118:16

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

@codecov-public-qa

codecov-public-qa Bot commented Sep 3, 2026

Copy link
Copy Markdown

❌ 5 Tests Failed:

Tests completed Failed Passed Skipped
2262 5 2257 0
View the top 3 failed test(s) by shortest run time
src/services/pull/usePrefetchSingleFileComp.test.tsx > usePrefetchSingleFileComp > successful request > when called with a unchanged file label > queries the api
Stack Traces | 0.00736s run time
AssertionError: expected undefined to strictly equal { fileLabel: null, …(3) }

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

+ 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.0082s run time
AssertionError: expected undefined to strictly equal { fileLabel: 'Deleted', …(3) }

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

+ Received: 
undefined

 ❯ .../services/pull/usePrefetchSingleFileComp.test.tsx:318:22
src/services/pull/utils/transformImpactedPullFileToDiff.test.ts > transformImpactedPullFileToDiff > returns file information
Stack Traces | 0.00923s run time
AssertionError: expected { fileLabel: null, …(3) } to strictly equal { fileLabel: null, …(3) }

- Expected
+ Received

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

 ❯ .../pull/utils/transformImpactedPullFileToDiff.test.ts:40:18

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

@sentry

sentry Bot commented Sep 3, 2026

Copy link
Copy Markdown
Author

⚠️ Seer needs additional GitHub permissions

Seer wants to keep iterating on this pull request to get CI passing, but the Sentry GitHub App installation is missing permissions it needs to read the failing checks and push a fix.

Review and accept the updated permissions to let Seer continue: https://github.com/organizations/codecov/settings/installations/86101127/permissions/update

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.

0 participants