Skip to content

Restore deriveSegmentText() to fix missing matchedText - #155

Merged
shouze merged 1 commit into
fix/regex-local-filter-full-contentfrom
fix/derive-segment-text
Aug 23, 2026
Merged

Restore deriveSegmentText() to fix missing matchedText#155
shouze merged 1 commit into
fix/regex-local-filter-full-contentfrom
fix/derive-segment-text

Conversation

@shouze

@shouze shouze commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #151.

Pull request #133 introduced deriveSegmentText() to derive a text-match segment's matched text from fragment.slice(indices[0], indices[1]) when GitHub omits the text field, but the current code on this branch still defaulted to an empty string in that case. This reintroduces the helper in src/api.ts and wires it into fetchAllResults()'s mapping.

How did you verify your code works?

  • Added a unit test suite for deriveSegmentText() itself (provided text, omitted text, out-of-range indices, inverted indices).
  • Added an integration test through fetchAllResults() covering a text_matches segment with no text field, asserting the derived value is correct.
  • Ran the full suite, lint, format check and knip; all green.

@shouze shouze changed the title Restore deriveSegmentText() to fix missing matchedText (#151) Restore deriveSegmentText() to fix missing matchedText Aug 23, 2026
@shouze
shouze force-pushed the fix/derive-segment-text branch from ec46820 to 5f83337 Compare August 23, 2026 13:58
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/derive-segment-text into fix/regex-local-filter-full-content will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.72%100%100%94.04%335–339, 400, 417, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.37%100%100%99.32%320
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

1 similar comment
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/derive-segment-text into fix/regex-local-filter-full-content will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.72%100%100%94.04%335–339, 400, 417, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.37%100%100%99.32%320
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

@shouze
shouze marked this pull request as ready for review August 23, 2026 14:07
Copilot AI lite review requested due to automatic review settings August 23, 2026 14:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR restores deriveSegmentText() in src/api.ts so text-match segments missing the text field from GitHub’s API derive their matched text from fragment.slice(indices[0], indices[1]), preventing empty/missing matched text in downstream output.

Changes:

  • Reintroduced deriveSegmentText(fragment, seg) and applied it during fetchAllResults() text-match normalization.
  • Added unit tests for deriveSegmentText() covering provided text, omitted text, and invalid indices.
  • Added a fetchAllResults() regression test ensuring derived segment text is produced when segment.text is omitted.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/api.ts Restores deriveSegmentText() and uses it when mapping raw GitHub text-match segments into normalized matches.
src/api.test.ts Adds unit coverage for deriveSegmentText() and an integration-style regression test for fetchAllResults() deriving missing segment text.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/api.test.ts
Comment on lines +170 to +174
it("derives matchedText from fragment + indices when GitHub omits the segment's text field (issue #151)", async () => {
const fakeItem = {
path: "src/foo.ts",
html_url: "https://github.com/org/repo/blob/main/src/foo.ts",
repository: { full_name: "org/repo", archived: false },
@shouze
shouze force-pushed the fix/derive-segment-text branch from 5f83337 to 7879ae5 Compare August 23, 2026 14:26
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/derive-segment-text into fix/regex-local-filter-full-content will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.72%100%100%94.04%335–339, 400, 417, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.37%100%100%99.32%320
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

1 similar comment
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/derive-segment-text into fix/regex-local-filter-full-content will be

95.96%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.72%100%100%94.04%335–339, 400, 417, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.37%100%100%99.32%320
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

@shouze
shouze force-pushed the fix/derive-segment-text branch from 7879ae5 to 5d605b1 Compare August 23, 2026 14:36
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/derive-segment-text into fix/regex-local-filter-full-content will be

95.97%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.72%100%100%94.04%335–339, 400, 417, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.39%100%100%99.34%329
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

1 similar comment
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/derive-segment-text into fix/regex-local-filter-full-content will be

95.97%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.72%100%100%94.04%335–339, 400, 417, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.39%100%100%99.34%329
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

PR #133 introduced deriveSegmentText() to derive a text-match segment's
matched text from fragment.slice(indices[0], indices[1]) when GitHub omits
the text field, but the current code on this branch still defaulted to an
empty string in that case. Reintroduced the helper and wired it into
fetchAllResults()'s mapping, with unit tests for the helper itself and an
integration test through fetchAllResults() covering the omitted-text case.

Closes #151
@shouze
shouze force-pushed the fix/derive-segment-text branch from 5d605b1 to e4b7220 Compare August 23, 2026 14:51
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/derive-segment-text into fix/regex-local-filter-full-content will be

96.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.74%100%100%94.07%340–344, 405, 422, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.39%100%100%99.34%329
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

1 similar comment
@github-actions

Copy link
Copy Markdown

Coverage after merging fix/derive-segment-text into fix/regex-local-filter-full-content will be

96.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.74%100%100%94.07%340–344, 405, 422, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.42%100%100%99.37%270
   group.ts99.50%100%97.44%100%
   output.ts99.29%100%95.65%99.61%80
   regex.ts99.39%100%100%99.34%329
   render.ts89.87%100%89.47%89.89%167, 191–196, 198–200, 202–203, 254–255, 276, 463–464, 487–489, 555–559, 571–572, 577–584, 586–594, 596–597
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   rows.ts97.58%100%100%97.44%168, 54–55
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%

@shouze
shouze merged commit d6a11ec into main Aug 23, 2026
9 checks passed
@shouze
shouze deleted the fix/derive-segment-text branch August 23, 2026 15:00
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.

Restore the missing matched text derivation regression from PR 133

2 participants