Skip to content

ISSUE-372: Warn when global sync duplicates project-installed packs - #381

Merged
bguidolim merged 2 commits into
mainfrom
bruno/ISSUE-372-warn-global-duplicates
Sep 2, 2026
Merged

ISSUE-372: Warn when global sync duplicates project-installed packs#381
bguidolim merged 2 commits into
mainfrom
bruno/ISSUE-372-warn-global-duplicates

Conversation

@bguidolim

@bguidolim bguidolim commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Installing a pack globally when projects already have it locally duplicates its hooks and skills — the global and project copies register as distinct settings entries, so both fire. #370 blocks the reverse direction, and the doctor check from #371 only runs inside an affected project, so today this duplication is created silently and surfaces only when you next happen to work in each affected project. mcs sync --global now names those projects at the moment it creates the duplication, and points at the existing mcs doctor --fix remediation. Informational only — it never blocks or prompts.

Closes #372

Changes

  • Keys on packs newly entering the global scope rather than on pack identity, so a second mcs sync --global and every mcs update stay silent.
  • Read-only: it never filters the pack set, and never writes to the project index — stale entries included.
  • An unreadable ~/.mcs/projects.yaml degrades to a notice rather than failing the sync.

Test plan

  • swift test passes locally
  • swiftformat --lint . and swiftlint pass without violations
  • Affected commands verified with a real pack (e.g. mcs sync, mcs doctor)

Left unchecked deliberately: the CLI resolves its home directory in a way that ignores a HOME override, so a manual run cannot be sandboxed away from real ~/.mcs state. Covered by integration tests instead — global sync, dry run, a second sync, the no-overlap case, and an unreadable index.

Checklist for engine changes
  • Integration tests updated for new features (LifecycleIntegrationTests or DoctorRunnerIntegrationTests)

https://claude.ai/code/session_01MkBJdGBUoZ2aRtchjaKXMN

- Fires only for packs newly entering the global scope, so re-syncs and `mcs update` stay silent
- Warning text lives in a pure function, since `CLIOutput` has no capture seam for tests
- `dryRunSummary` returns its additions set so the dry-run path reuses one diff

Claude-Session: https://claude.ai/code/session_01MkBJdGBUoZ2aRtchjaKXMN

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The warning is currently emitted before the removal confirmation gate, so it can print (and read the index) even when the sync is cancelled and no duplication is actually created.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an informational warning to mcs sync --global (and its dry-run flow) when a pack newly entering the global scope is already installed in tracked projects, so users are alerted that hooks/skills will run twice until the project-scoped copy is removed.

Changes:

  • Introduces ConfiguratorSupport.projectDuplicationWarning and warnProjectDuplication to compute and emit a stable, testable warning message from the project index.
  • Wires the warning into global-scope configure and dryRun flows, keyed on scope additions (transition-based) to keep repeated global syncs and mcs update quiet.
  • Adds unit + integration coverage for overlap detection, stale paths, dry-run behavior, second-sync silence, and unreadable index handling.
File summaries
File Description
Tests/MCSTests/SyncCommandTests.swift Unit tests for the warning line generation (sorting, filtering global sentinel, stale paths, multi-pack header).
Tests/MCSTests/LifecycleIntegrationTests.swift Integration scenarios validating warning emission, non-mutation of project index entries, dry-run behavior, and unreadable index degradation.
Sources/mcs/Sync/ConfiguratorSupport.swift Implements warning computation + scoped emission helper; updates dryRunSummary to return additions for reuse.
Sources/mcs/Sync/Configurator.swift Hooks warning emission into dry-run plan output and global configure flow.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Sources/mcs/Sync/Configurator.swift Outdated
- Cancelling at "Proceed with removal?" returned before installing, so the warning could describe duplicates that were never created
- Also avoids reading the project index on the cancelled path

Claude-Session: https://claude.ai/code/session_01MkBJdGBUoZ2aRtchjaKXMN
@bguidolim
bguidolim merged commit 11198a8 into main Sep 2, 2026
4 checks passed
@bguidolim
bguidolim deleted the bruno/ISSUE-372-warn-global-duplicates branch September 2, 2026 15:15
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.

Warn when 'mcs sync --global' duplicates a pack that projects already have

2 participants