Browse Source

Add package fetching logic fix proposal

master
AI Bot 22 hours ago committed by Riyyi
parent
commit
536a8d5ccb
  1. 2
      openspec/changes/fix-package-fetch-logic/.openspec.yaml
  2. 44
      openspec/changes/fix-package-fetch-logic/design.md
  3. 26
      openspec/changes/fix-package-fetch-logic/proposal.md
  4. 7
      openspec/changes/fix-package-fetch-logic/tasks.md
  5. 45
      openspec/specs/package-resolve-logic/spec.md

2
openspec/changes/fix-package-fetch-logic/.openspec.yaml

@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-04-17

44
openspec/changes/fix-package-fetch-logic/design.md

@ -0,0 +1,44 @@
## Context
Current `Resolve` in `pkg/fetch/fetch.go`:
1. Initialize all packages with `Exists: true`
2. Check local DB, set `Installed: true` if found
3. Check sync DBs, set `Installed: false`
4. Check AUR, set `InAUR: true`
5. Error if not found anywhere
Bug: wrong default + wrong order + conflates two concerns.
## Goals / Non-Goals
**Goals:**
- Fix Resolve algorithm to correctly classify packages
- Separate "available" from "installed" concerns
**Non-Goals:**
- No new APIs or features
- No refactoring outside Resolve function
## Decisions
**Decision 1: Start with Exists: false**
- Default `Exists: false` (unknown) instead of `true`
- Only set true when confirmed in sync DBs
**Decision 2: Check sync DBs first**
- Order: sync → local → AUR
- First determine if package exists (anywhere)
- Then determine if installed (local only)
**Decision 3: Two-phase classification**
| Phase | Check | Sets |
|------|-------|-----|
| 1. Availability | sync DBs | Exists: true/false |
| 2. Installation | local DB | Installed: true/false |
| 3. Fallback | AUR | InAUR: true if not in sync |
## Risks / Trade-offs
- Minimal risk: localized fix only
- Trade-off: slight performance cost (check sync before local) - acceptable for correctness

26
openspec/changes/fix-package-fetch-logic/proposal.md

@ -0,0 +1,26 @@
## Why
The `Resolve` function in `pkg/fetch/fetch.go` has incorrect logic flow. It
initializes all packages with `Exists: true`, then checks local DB first, then
sync DBs, then AUR. This wrong order causes incorrect package state
classification - packages that exist only in AUR may be incorrectly marked as
found.
## What Changes
- Fix initialization: packages should start with `Exists: false` (unknown), not `true`
- Fix order: check sync DBs BEFORE local DB to determine availability
- Separate independent concerns: "available" (sync/AUR) from "installed" (local)
- All packages must validate: either `Exists: true` or `InAUR: true`
## Capabilities
### New Capabilities
- `package-resolve-logic`: Correct resolution algorithm for pacman packages
### Modified Capabilities
- None
## Impact
- `pkg/fetch/fetch.go`: `Resolve` function

7
openspec/changes/fix-package-fetch-logic/tasks.md

@ -0,0 +1,7 @@
## 1. Fix Resolve Function Logic
- [ ] 1.1 Change initialization: start packages with Exists: false instead of true
- [ ] 1.2 Reorder to check sync DBs BEFORE local DB
- [ ] 1.3 Separate availability check (sync DBs) from installation check (local DB)
- [ ] 1.4 Add AUR fallback for packages not in sync DBs
- [ ] 1.5 Validate all packages have either Exists or InAUR before returning

45
openspec/specs/package-resolve-logic/spec.md

@ -0,0 +1,45 @@
## ADDED Requirements
### Requirement: Package existence check via sync DBs
When resolving packages, the system SHALL first check sync databases (core, extra, multilib) to determine if a package exists in official repositories. If found in sync DBs, `Exists` SHALL be set to true.
#### Scenario: Package found in sync DB
- **WHEN** package name exists in any sync database
- **THEN** set `Exists: true`, `InAUR: false`
#### Scenario: Package not found in sync DB
- **WHEN** package name does not exist in any sync database
- **THEN** keep `Exists: false` for further lookup
### Requirement: Package installation check via local database
After checking sync DBs, the system SHALL check the local package database to determine if a package is installed. This is independent of existence check.
#### Scenario: Package installed locally
- **WHEN** package is installed on the system
- **THEN** set `Installed: true`
#### Scenario: Package not installed locally
- **WHEN** package is not installed on the system
- **THEN** set `Installed: false`
### Requirement: AUR fallback check
If package is not found in sync DBs, the system SHALL check the AUR as a fallback.
#### Scenario: Package found in AUR
- **WHEN** package exists in AUR but not in sync DBs
- **THEN** set `InAUR: true`
#### Scenario: Package not found anywhere
- **WHEN** package not in sync DBs, not in local DB, not in AUR
- **THEN** return error "package not found"
### Requirement: Validation at resolution end
After all checks complete, the system SHALL ensure every package has either `Exists: true` or `InAUR: true`. No package SHALL leave the resolver in an ambiguous state.
#### Scenario: All packages valid
- **WHEN** all packages resolved successfully
- **THEN** every package has Exists=true OR InAUR=true
Loading…
Cancel
Save