refactor: freeze DEFAULT_CONFIG to prevent shared-state mutation - #584
Conversation
VS Code's WorkspaceConfiguration.get(key, defaultValue) returns the exact same defaultValue reference when a setting isn't overridden by the user. This means every call to getConfiguration() for a workspace without a custom excludePatterns setting returns the same array object as DEFAULT_CONFIG.excludePatterns. Any accidental mutation of that array by current or future code would silently corrupt the shared defaults for the rest of the session. Freeze DEFAULT_CONFIG and its excludePatterns array to make such mutations throw (strict mode) or no-op instead of corrupting shared state. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #584 +/- ##
=======================================
Coverage 98.11% 98.11%
=======================================
Files 12 12
Lines 3931 3931
Branches 451 451
=======================================
Hits 3857 3857
Misses 74 74 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
The mutable type contract conflicts with frozen runtime values, and the new behavior lacks targeted tests.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Freezes shared default configuration values to prevent accidental mutation across workspace scopes.
Changes:
- Freezes
DEFAULT_CONFIGand its nested exclusion patterns. - Documents the shared-reference rationale.
File summaries
| File | Description |
|---|---|
src/configuration.ts |
Adds defensive freezing for defaults. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |
Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
…freeze behavior Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
Addressed both review points in commits
|
🤖 This pull request was created by Repo Assist, an automated AI assistant.
Summary
Freezes
DEFAULT_CONFIG(and itsexcludePatternsarray) insrc/configuration.tsto guard against a latent shared-mutable-state bug.Why
VS Code's
WorkspaceConfiguration.get(key, defaultValue)returns the exact same reference todefaultValuewhenever the user hasn't overridden that setting — it does not clone. That means every call toConfigurationManager.getConfiguration()for a workspace without a customexcludePatternssetting returns the same array object asDEFAULT_CONFIG.excludePatterns.If any current or future code accidentally mutated that returned array (e.g.
.push(),.sort()), it would silently corrupt the shared default for the rest of the extension's session across all workspace folders — a subtle bug that would be very hard to trace back to its cause.Fix
Wrap
DEFAULT_CONFIGand itsexcludePatternsarray inObject.freeze(). This is a zero-behavior-change, defensive hardening: no current code path mutates the array, but freezing costs nothing and converts a future accidental mutation into a loud failure (in strict mode) or a silent no-op, instead of quiet corruption.Trade-offs
None — purely additive safety, no API or behavior change.
Test Status
npm run compile✅npm run lint✅npm run test:unit✅ 241 passing, coverage 98.77/95.16/99.1/98.77 (thresholds 95/88/97/95, unchanged)npm test(full, requires VS Code download) not run — blocked by sandbox network restrictions (expected/known limitation, unrelated to this change)Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run