Skip to content

refactor: eliminate duplicate code patterns in internal/difc package#1916

Merged
lpcox merged 1 commit intomainfrom
copilot/duplicate-code-analysis-report
Mar 14, 2026
Merged

refactor: eliminate duplicate code patterns in internal/difc package#1916
lpcox merged 1 commit intomainfrom
copilot/duplicate-code-analysis-report

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 14, 2026

Summary

Resolves all three duplicate code patterns identified in the DIFC package analysis.

Changes

1. Agent Tag Add/Drop Operations (agent.go) — Closes #1720

Extracted modifyTag private helper to consolidate the lock/log/mutate pattern shared by AddSecrecyTag, AddIntegrityTag, and DropIntegrityTag. The three methods now delegate to this single helper, eliminating ~15 lines of duplication and ensuring the locking and logging patterns stay in sync.

2. DIFC Label CheckFlow Implementations (labels.go) — Closes #1721

Extracted checkFlowHelper private helper to consolidate the nil-guard, double RLock, wildcard handling, and tag-subset-check pattern shared by SecrecyLabel.CheckFlow and IntegrityLabel.CheckFlow. The only meaningful difference between the two — direction of the subset check — is parameterised via a checkSubset bool argument.

3. EvaluationResult Default Initialization (evaluator.go) — Closes #1722

Extracted newEmptyEvaluationResult factory to centralise default EvaluationResult construction (AccessAllow + empty tag slices) used in Evaluate, evaluateRead, and evaluateWrite. Any future change to EvaluationResult defaults now has a single authoritative location.

Closes #1719
Closes #1720
Closes #1721
Closes #1722

Copilot AI requested a review from lpcox March 14, 2026 23:30
@lpcox lpcox marked this pull request as ready for review March 14, 2026 23:32
Copilot AI review requested due to automatic review settings March 14, 2026 23:32
@lpcox lpcox merged commit 430b2c6 into main Mar 14, 2026
4 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-analysis-report branch March 14, 2026 23:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


💡 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants