|
| 1 | +# ADR-0006: Multi-Location Detection for Package Managers |
| 2 | + |
| 3 | +## Status |
| 4 | + |
| 5 | +Accepted |
| 6 | + |
| 7 | +## Context |
| 8 | + |
| 9 | +Package managers can have dependencies installed in multiple locations simultaneously. For example, pip can have packages installed in both a virtual environment and the system Python installation. The original detector architecture assumed each detector would return dependencies from a single location, missing packages in other locations. |
| 10 | + |
| 11 | +**Problem**: The pip detector prioritized virtual environments over system installations, so when both existed, only virtual environment packages were detected. This prevented comprehensive dependency analysis in mixed environments. |
| 12 | + |
| 13 | +**Alternatives Considered**: |
| 14 | + |
| 15 | +1. **Split into separate detectors**: Create `pip-venv` and `pip-system` detectors |
| 16 | + - ❌ Breaks existing API expectations |
| 17 | + - ❌ Requires orchestrator changes |
| 18 | + - ❌ Confusing output with multiple pip entries |
| 19 | + |
| 20 | +2. **Always merge dependencies**: Combine all packages into single result |
| 21 | + - ❌ Loses location information for each package |
| 22 | + - ❌ Cannot track location-specific hashes |
| 23 | + - ❌ Reduces traceability |
| 24 | + |
| 25 | +3. **Universal nested structure**: Change all detectors to use locations format |
| 26 | + - ❌ Major breaking change |
| 27 | + - ❌ Unnecessary complexity for single-location detectors |
| 28 | + - ❌ Verbose output when most detectors have only one location |
| 29 | + - ❌ Inconsistent with the principle of simple structures for simple cases |
| 30 | + |
| 31 | +4. **Conditional output structure**: Single location uses existing format, multiple locations use nested format |
| 32 | + - ✅ Preserves backward compatibility |
| 33 | + - ✅ Simple structure for simple cases |
| 34 | + - ✅ Maintains location-specific metadata |
| 35 | + - ✅ Clear semantic distinction |
| 36 | + - ✅ Efficient output format |
| 37 | + |
| 38 | +## Decision |
| 39 | + |
| 40 | +We will implement **conditional output structure** for multi-location detection: |
| 41 | + |
| 42 | +### Single Location (Existing Format) |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "pip": { |
| 47 | + "scope": "project", |
| 48 | + "location": "/path/to/venv", |
| 49 | + "hash": "abc123...", |
| 50 | + "dependencies": {...} |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +### Multiple Locations (New Format) |
| 56 | + |
| 57 | +```json |
| 58 | +{ |
| 59 | + "pip": { |
| 60 | + "scope": "mixed", |
| 61 | + "locations": { |
| 62 | + "/path/to/venv": { |
| 63 | + "scope": "project", |
| 64 | + "hash": "abc123...", |
| 65 | + "dependencies": {...} |
| 66 | + }, |
| 67 | + "/usr/lib/python3/dist-packages": { |
| 68 | + "scope": "system", |
| 69 | + "hash": "def456...", |
| 70 | + "dependencies": {...} |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +### Implementation Approach |
| 78 | + |
| 79 | +1. **Detector Interface**: No changes to `PackageManagerDetector` interface |
| 80 | +2. **Conditional Logic**: Detectors return nested structure only when multiple locations exist |
| 81 | +3. **Orchestrator Support**: Enhanced to recognize `scope: "mixed"` pattern |
| 82 | +4. **Generalized Pattern**: Any detector can implement multi-location detection |
| 83 | + |
| 84 | +## Consequences |
| 85 | + |
| 86 | +### Positive |
| 87 | + |
| 88 | +- ✅ **Backward Compatible**: Existing code continues to work unchanged |
| 89 | +- ✅ **Location Transparency**: Each package's source location is preserved |
| 90 | +- ✅ **Hash Preservation**: Location-specific hashes maintained |
| 91 | +- ✅ **Extensible**: Pattern available for future detectors (npm, maven, etc.) |
| 92 | +- ✅ **Self-Documenting**: Output structure indicates single vs. multi-location |
| 93 | +- ✅ **Efficient**: Simple structure for simple cases, complex structure only when needed |
| 94 | + |
| 95 | +### Negative |
| 96 | + |
| 97 | +- ❌ **Complexity**: Consumers must handle two different output formats |
| 98 | +- ❌ **Testing Overhead**: Additional test scenarios for mixed-scope handling |
| 99 | + |
| 100 | +### Neutral |
| 101 | + |
| 102 | +- **New Scope Value**: Introduces `"mixed"` as third scope option alongside `"system"` and `"project"` |
| 103 | + |
| 104 | +## Implementation Notes |
| 105 | + |
| 106 | +- **pip detector**: First implementation targeting venv + system detection |
| 107 | +- **Test Infrastructure**: Updated to handle both output formats generically |
| 108 | +- **Documentation**: Updated to explain conditional structure behavior |
| 109 | +- **Future Detectors**: npm could implement similar pattern for global vs. local node_modules |
| 110 | + |
| 111 | +This approach solves the multi-location problem while minimizing breaking changes and maintaining clear traceability of package origins. |
0 commit comments