Conversation
7 tasks
…icated dedup logic Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [duplicate-code] Refactor duplicate string deduplication pattern
refactor: extract DeduplicateStrings helper to eliminate duplicated dedup logic
Mar 18, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes a common “trim → skip-empty → deduplicate → optional sort” normalization pattern into a single canonical helper to eliminate duplicated implementations and reduce behavioral drift across packages.
Changes:
- Added
strutil.DeduplicateStringshelper implementing trim/skip-empty/dedup with optional sorting. - Added table-driven tests covering trimming, empty handling, dedup behavior, order preservation, and sorting.
- Refactored DIFC sink server ID normalization and CLI flag parsing to use the shared helper.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/strutil/deduplicate.go | Introduces the shared dedup/normalize helper with optional sorting. |
| internal/strutil/deduplicate_test.go | Adds unit tests validating helper behavior across key edge cases. |
| internal/difc/sink_server_ids.go | Replaces inline normalization/sort with the shared helper and logs when items are dropped. |
| internal/cmd/flags_difc.go | Keeps embedded-whitespace validation, delegates dedup to the shared helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
This was referenced Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The trim→skip-empty→deduplicate→optional-sort pattern was reimplemented inline in three separate packages, with behavioral drift already present (silent skip vs. error on duplicate, whitespace rejection in one but not others).
Changes
internal/strutil/deduplicate.go— newDeduplicateStrings(input []string, sorted bool) []stringcanonical helperinternal/strutil/deduplicate_test.go— table-driven tests covering nil input, trim, dedup, sort, and order preservationinternal/difc/sink_server_ids.go— replace 14-line inline loop withstrutil.DeduplicateStrings(serverIDs, true); log when entries are droppedinternal/cmd/flags_difc.go—parseDIFCSinkServerIDs: keep the embedded-whitespace error check (not handled by the helper), delegate dedup tostrutil.DeduplicateStringsinternal/config/guard_policy.go— unchanged;normalizeAndValidateScopeArrayreturns an error on duplicates rather than silently dropping them, so it doesn't share the same contractBefore / After
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build1731765213/b332/launcher.test /tmp/go-build1731765213/b332/launcher.test -test.testlogfile=/tmp/go-build1731765213/b332/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� 1.4.0/auth/auth.go 1.4.0/auth/client.go x_amd64/compile(dns block)/tmp/go-build908205860/b328/launcher.test /tmp/go-build908205860/b328/launcher.test -test.testlogfile=/tmp/go-build908205860/b328/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --version y 06bc07c272bb18e2 ntime.v2.task/mosystemd-run containerd.sock x_amd64/vet ctl insp�� .go {{.Config.OpenSt--property=CPUQuota=5% /usr/libexec/doc--property=MemoryHigh=170M 64/src/net ache/go/1.25.8/xinfo x_amd64/vet 45045761271a86c7-collect-logs(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build1731765213/b317/config.test /tmp/go-build1731765213/b317/config.test -test.testlogfile=/tmp/go-build1731765213/b317/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� .go(dns block)/tmp/go-build908205860/b313/config.test /tmp/go-build908205860/b313/config.test -test.testlogfile=/tmp/go-build908205860/b313/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 9c9123b84b4d4e8c -tests ash b8a4de3a75e76448grep fe9 x_amd64/compile fe9/init.pid --ve�� c48959766ef0f63f b8a4de3a75e764483c627dce6b038343b5b6efe353b9d178502 "CURL_CA_BUNDLE=/--systemd-cgroup b8a4de3a75e76448git(dns block)nonexistent.local/tmp/go-build1731765213/b332/launcher.test /tmp/go-build1731765213/b332/launcher.test -test.testlogfile=/tmp/go-build1731765213/b332/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� 1.4.0/auth/auth.go 1.4.0/auth/client.go x_amd64/compile(dns block)/tmp/go-build908205860/b328/launcher.test /tmp/go-build908205860/b328/launcher.test -test.testlogfile=/tmp/go-build908205860/b328/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --version y 06bc07c272bb18e2 ntime.v2.task/mosystemd-run containerd.sock x_amd64/vet ctl insp�� .go {{.Config.OpenSt--property=CPUQuota=5% /usr/libexec/doc--property=MemoryHigh=170M 64/src/net ache/go/1.25.8/xinfo x_amd64/vet 45045761271a86c7-collect-logs(dns block)slow.example.com/tmp/go-build1731765213/b332/launcher.test /tmp/go-build1731765213/b332/launcher.test -test.testlogfile=/tmp/go-build1731765213/b332/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� 1.4.0/auth/auth.go 1.4.0/auth/client.go x_amd64/compile(dns block)/tmp/go-build908205860/b328/launcher.test /tmp/go-build908205860/b328/launcher.test -test.testlogfile=/tmp/go-build908205860/b328/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --version y 06bc07c272bb18e2 ntime.v2.task/mosystemd-run containerd.sock x_amd64/vet ctl insp�� .go {{.Config.OpenSt--property=CPUQuota=5% /usr/libexec/doc--property=MemoryHigh=170M 64/src/net ache/go/1.25.8/xinfo x_amd64/vet 45045761271a86c7-collect-logs(dns block)this-host-does-not-exist-12345.com/tmp/go-build1731765213/b341/mcp.test /tmp/go-build1731765213/b341/mcp.test -test.testlogfile=/tmp/go-build1731765213/b341/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build1731765213/b271/vet.cfg flib/difflib.go main x_amd64/cgo(dns block)/tmp/go-build908205860/b337/mcp.test /tmp/go-build908205860/b337/mcp.test -test.testlogfile=/tmp/go-build908205860/b337/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true y x_amd64/vet by/027a141771b2cb8a4de3a75e764483c627dce6b038343b5b6efe353b9d178502/log.json azero@v1.11.0/bugrep azero@v1.11.0/ca-qE x_amd64/vet 709/log.json 92b4�� by/027a141771b2cb8a4de3a75e764483c627dce6b038343b5b6efe353b9d178502 --bundle by/027a141771b2cb8a4de3a75e764483c627dce6b038343b5b6efe353b9d178502/init.pid 6efe353b9d178502bash 77a1358e1f687d17/usr/bin/runc x_amd64/vet table.d/chrony-onoffline(dns block)If you need me to access, download, or install something from one of these locations, you can either:
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.