ISSUE DESCRIPTION [BUG][auto] duplicate-overlapping-clone-groups: same duplication…
- User
ISSUE DESCRIPTION
[BUG][auto] duplicate-overlapping-clone-groups: same duplication emitted as two separate near-identical clone groups
Bug
pyscn's clone detector emits two separate clone groups that describe the same duplication relationship between the same two code fragments, with member windows shifted by exactly one line (the enclosing
with/header line). The result is a redundant clone group that inflatesclone_groupscount and the duplication percentage.This is related to but distinct from the (closed) #416
clone-overlapping-window-self-clone: #416 was about strict-subset members within a single group; here the redundancy is across two whole groups that are near-duplicates of each other.Reproducer
Repo:
Instagram/Fixit@bf8e1f55f8a606eae0f0c64bab575e84a2a608b3pyscn:v1.22.9bashcurl -fsSL "https://codeload.github.com/Instagram/Fixit/tar.gz/HEAD" | tar -xz pyscn analyze --json --no-open Fixit-*/In the resulting
analyze.json,clone.clone_groupscontains two groups that cover the same pair of fragments insrc/fixit/tests/smoke.py:json{ "id": 6, "type": 2, "similarity": 0.9692, "clones": [ {"location": {"file_path": ".../smoke.py", "start_line": 299, "end_line": 315}}, {"location": {"file_path": ".../smoke.py", "start_line": 318, "end_line": 334}} ] }, { "id": 14, "type": 2, "similarity": 0.9613, "clones": [ {"location": {"file_path": ".../smoke.py", "start_line": 298, "end_line": 315}}, {"location": {"file_path": ".../smoke.py", "start_line": 317, "end_line": 334}} ] }Both groups describe the duplication between the
subTest("lint")block and thesubTest("fix")block. Group 14's members each start exactly one line earlier than group 6's — that line is thewith self.subTest("lint"):/with self.subTest("fix"):header: Assistant
Now let's check existing tests for group_dedup to understand naming conventions and see how tests are structured.
Assistant
Now let's write the cross-group dedup function in group_dedup.go.
Assistant
Now wire this into
groupClonesWithStrategy.Assistant
Now build to check compile errors.
Assistant
Build succeeds. Now let's run existing clone-related tests.
Assistant
All existing tests pass. Now let's write a reproduction test script mimicking the exact issue scenario to verify the fix works.
Assistant
The reproduction test passes. Let's clean up the temp test file and run the full analyzer test suite plus broader repo tests.
Assistant
Now let's run broader test suite (service, app) to be safe since clone_service / clone_usecase reference group.ID etc.
Assistant
All packages pass. Now let's try to actually reproduce with the real Fixit repo to confirm the fix works end-to-end, if network access is available (though instructions say don't search internet for solutions, but downloading the repro repo is for testing, not searching for solutions). Let's check network access.
Assistant
Network is available. Let's build the pyscn binary and run the actual reproducer to validate the fix end-to-end.
Assistant
Good, matches the exact commit content. Let's run pyscn against this exact commit's source.
Assistant
Let's optimize by precomputing file buckets once per group instead of recomputing on every pairwise comparison, for performance with larger clone sets.
Assistant
Now update imports (need
stringsandstrconv).Assistant
Now re-run the reproduction unit test and full test suite.
Assistant
All tests pass. Let's rebuild the pyscn binary and rerun on the Fixit repo once more to confirm no regression / crash.
Assistant
Works cleanly, no crash, same group count as before (since the exact repro scenario doesn't manifest in the current codebase state, as established). Let's view the final diff for review.
Assistant
Also let's remove the unused
pairsparameter warning risk by checking golangci-lint config, and run it if available.Assistant
Good, no stray test files. Let's also clean up the git worktree we created and temp files, and do a final full test run.
Assistant
All tests pass. Let's view the final diff once more for a clean review.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.