Skip to content

Validate duplicate copyPackFile destinations within a single pack #287

@bguidolim

Description

@bguidolim

Problem

ExternalPackManifest.validate() checks for duplicate component IDs (duplicateComponentID) but does not check for duplicate (destination, fileType) pairs within the same pack.

A pack author could write:

components:
  - id: lint-hook
    description: Lint hook
    hookEvent: PreToolUse
    hook:
      source: hooks/lint.sh
      destination: lint.sh

  - id: format-hook
    description: Format hook
    hookEvent: PreToolUse
    hook:
      source: hooks/format.sh
      destination: lint.sh   # ← same destination, different ID

This passes validation but the second component silently overwrites the first during mcs sync. Both get tracked in PackArtifactRecord, but only one file exists on disk.

Proposed Solution

Add a duplicateDestination validation in ExternalPackManifest.validate():

  1. Scan all components with copyPackFile install actions
  2. Build a set of (destination, fileType) pairs
  3. If a duplicate is found, throw a new ManifestError.duplicateDestination(destination:fileType:componentIDs:) error

This catches the mistake at pack load time with a clear error message, consistent with the existing duplicateComponentID check.

Context

The cross-pack collision resolver (DestinationCollisionResolver) deliberately skips intra-pack duplicates (distinctPackIndices.count >= 2) — namespacing a pack against itself doesn't make sense. This validation would catch the problem earlier, at manifest load time.

References

  • Sources/mcs/ExternalPack/ExternalPackManifest.swiftvalidate() method
  • Sources/mcs/Install/DestinationCollisionResolver.swift — cross-pack collision detection

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions