Skip to content

fix(crosslink): correct pruning logic to ensure all replace statement…#1597

Open
Abhay349 wants to merge 2 commits intoopen-telemetry:mainfrom
Abhay349:fix/prune-logic-and-tests
Open

fix(crosslink): correct pruning logic to ensure all replace statement…#1597
Abhay349 wants to merge 2 commits intoopen-telemetry:mainfrom
Abhay349:fix/prune-logic-and-tests

Conversation

@Abhay349
Copy link
Contributor

Description:

In continuation with PR #1593, this PR fixes a bug in the prune command where some replace statements were not being removed correctly.

Changes:

Pointer usage for in-place modification: Changed modContents to use a pointer. Previously, it was creating a value copy of the module struct, so DropReplace calls were modifying a local copy that was discarded, leaving the original module unchanged.

Safe iteration: Implemented a two-pass approach for pruning. We now collect all replace statements to be pruned into a toPrune slice first, and then iterate over that slice to remove them. This prevents index-shifting bugs that occur when modifying a slice (removing elements) while iterating over it, which previously caused some statements to be skipped.

…s are removed

Signed-off-by: ABHAY PANDEY <pandeyabhay967@gmail.com>
@Abhay349 Abhay349 requested review from a team as code owners February 13, 2026 16:14
@Abhay349 Abhay349 requested a review from bogdandrutu February 13, 2026 16:14
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.16%. Comparing base (963233d) to head (23aaa19).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
crosslink/internal/prune.go 61.53% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1597      +/-   ##
==========================================
+ Coverage   64.08%   64.16%   +0.08%     
==========================================
  Files          66       66              
  Lines        3408     3427      +19     
==========================================
+ Hits         2184     2199      +15     
- Misses        988      990       +2     
- Partials      236      238       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Abhay349
Copy link
Contributor Author

Abhay349 commented Feb 13, 2026

Hi @dmathieu @mx-psi I attempted to add a specific unit test, however I encountered flaky behavior related to modfile.File internal state management. Since the existing test suite covers the general pruning functionality and passes with these changes, I have omitted the flaky test case for now to maintain CI stability.

Let me know if there are issues, happy to iterate on feedback.
Thanks :)

@mx-psi
Copy link
Member

mx-psi commented Feb 16, 2026

I am not supportive of adding this without a unit test

@Abhay349
Copy link
Contributor Author

@mx-psi Totally understand your concern. I’ll revisit this and make another attempt at adding a proper unit test. If I run into issues while stabilizing it, I’ll reach out for guidance.
Thanks for the feedback!

@Abhay349 Abhay349 force-pushed the fix/prune-logic-and-tests branch from 0fe9429 to 23aaa19 Compare February 21, 2026 10:45
@Abhay349
Copy link
Contributor Author

Hi @mx-psi @dmathieu,
I’ve added the missing test case. I was getting flaky behaviour in earlier attempts because I was comparing the whole modfile.File, and DropReplace tweaks thing internally in ways that made that unreliable.
Now I’m just adding a few dummy replace entries, running Cleanup(), and checking that the Replace slice ends up empty. If the bug were still there, some entries would remain.

@Abhay349
Copy link
Contributor Author

Let me know if this approach looks good, happy to iterate on further feedback.
Thanks :)

@mx-psi
Copy link
Member

mx-psi commented Feb 24, 2026

The test you added does not seem to fail if I revert your changes on crosslink/internal/prune.go. I would want a test that is able to reproduce the issue you are fixing before you change the code, and that it passes after your changes are applied

@Abhay349
Copy link
Contributor Author

@mx-psi @dmathieu I have tried a lot to add test but feeling stuck at this pont, could you pls help me with some hints and all to proceed further.

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.

2 participants