Skip to content

Commit 79c3ebc

Browse files
committed
feat: implement official repository queries and index fetching (Task 3.3)
- feat: add search_official() function with substring and optional fuzzy matching - feat: add all_official() function to return all packages from index - feat: add fetch_official_index() sync function using pacman -Sl - feat: add fetch_official_index_async() with pacman-first, API-fallback strategy - feat: add fetch_via_pacman() internal function for local package fetching - feat: add fetch_via_api() internal function for Arch Packages API fetching - feat: add fuzzy-search feature flag with fuzzy-matcher optional dependency - change: update index module exports to include query and fetch functions - change: update index module documentation with usage examples - test: add unit tests for search_official() with various matching modes - test: add unit tests for all_official() function - test: add unit tests for fetch functions with graceful degradation - docs: update INDEX_MODULE_PHASE.md to mark Task 3.3 as complete - docs: update AUR_TOOLKIT_CRATE_PREPARATION.md with progress notes
1 parent a886c1c commit 79c3ebc

7 files changed

Lines changed: 910 additions & 79 deletions

File tree

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ default = ["aur"]
1313
aur = ["dep:reqwest", "dep:tokio", "dep:scraper", "dep:chrono", "dep:rand", "dep:lru", "dep:async-trait"]
1414
deps = [] # No additional dependencies for types only
1515
index = ["dep:tokio"] # For async operations with spawn_blocking
16+
fuzzy-search = ["dep:fuzzy-matcher"] # Optional fuzzy matching for search
1617
cache-disk = ["dep:dirs"]
1718

1819
[dependencies]
@@ -44,6 +45,9 @@ async-trait = { version = "0.1", optional = true }
4445
# Directory utilities (for cache-disk feature)
4546
dirs = { version = "5.0", optional = true }
4647

48+
# Fuzzy matching (for fuzzy-search feature)
49+
fuzzy-matcher = { version = "0.3", optional = true }
50+
4751
[dev-dependencies]
4852
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
4953
wiremock = "0.6"

dev/AUR_TOOLKIT_CRATE_PREPARATION.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ This document analyzes framework-agnostic modules in Pacsea (`src/sources/`, `sr
4848
- ⏳ AUR dependency queries (async .SRCINFO fetching limitation noted - future enhancement)
4949
- **Detailed Plan**: [DEPENDENCIES_MODULE_PHASE.md](./DEPENDENCIES_MODULE_PHASE.md)
5050

51-
**Phase 3 - Index Module: ⏳ PLANNED**
51+
**Phase 3 - Index Module: 🚧 IN PROGRESS**
5252

5353
- Index module (package database queries)
54-
- Installed package queries
55-
- Official repository queries
56-
- Mirror management
57-
- Index persistence
54+
- ✅ Installed package queries (Task 3.2.1 - complete)
55+
- ✅ Explicit package tracking (Task 3.2.2 - complete)
56+
- ✅ Index types (Task 3.1.1 - complete)
57+
- ✅ Official repository queries (Task 3.3 - complete)
58+
- ⏳ Mirror management (Task 3.5 - optional, pending)
59+
- ⏳ Index persistence (Task 3.4 - pending)
5860

5961
**Phase 4+ - Remaining Modules: ⏳ PLANNED**
6062

@@ -682,11 +684,13 @@ arch-toolkit/
682684
- [ ] **Port AUR dependency queries** - From `src/logic/deps/aur.rs`
683685

684686
#### Index Module (`feature = "index"`)
685-
- [ ] **Port installed package queries** - From `src/index/installed.rs`
686-
- [ ] **Port official repo queries** - From `src/index/query.rs`
687-
- [ ] **Port mirror management** - From `src/index/mirrors.rs` (optional, Windows-specific)
688-
- [ ] **Port index persistence** - From `src/index/persist.rs`
689-
- [ ] **Remove Pacsea-specific caching** - Let callers handle persistence
687+
- [x] **Create index types** - `OfficialPackage`, `OfficialIndex`, `IndexQueryResult`, `InstalledPackagesMode` (Task 3.1.1)
688+
- [x] **Port installed package queries** - From `src/index/installed.rs` (Task 3.2.1 - complete)
689+
- [x] **Port explicit package tracking** - From `src/index/explicit.rs` (Task 3.2.2 - complete)
690+
- [x] **Port official repo queries** - From `src/index/query.rs` (Task 3.3 - complete)
691+
- [ ] **Port index persistence** - From `src/index/persist.rs` (Task 3.4 - pending)
692+
- [ ] **Port mirror management** - From `src/index/mirrors.rs` (Task 3.5 - optional, Windows-specific, pending)
693+
- [x] **Remove Pacsea-specific caching** - Let callers handle persistence (for completed tasks)
690694
- **Detailed Plan**: [INDEX_MODULE_PHASE.md](./INDEX_MODULE_PHASE.md)
691695

692696
#### Install Module (`feature = "install"`)
@@ -985,15 +989,18 @@ The Dependencies Module is complete in v0.1.2:
985989
- ✅ Module entry point
986990
- **Plan Document**: [DEPENDENCIES_MODULE_PHASE.md](./DEPENDENCIES_MODULE_PHASE.md)
987991

988-
### Phase 3 Status: ⏳ PLANNED
992+
### Phase 3 Status: 🚧 IN PROGRESS
989993

990-
The Index Module is planned but not yet started:
994+
The Index Module is partially complete:
991995

992-
1. **Index Module** - ⏳ Planned
993-
- ⏳ Installed package queries
994-
- ⏳ Official repo queries
995-
- ⏳ Mirror management (optional)
996-
- ⏳ Index persistence
996+
1. **Index Module** - 🚧 In Progress
997+
- ✅ Index types (`OfficialPackage`, `OfficialIndex`, `IndexQueryResult`, `InstalledPackagesMode`) - Task 3.1.1 complete
998+
- ✅ Installed package queries (`refresh_installed_cache`, `is_installed`, `get_installed_packages`) - Task 3.2.1 complete
999+
- ✅ Explicit package tracking (`refresh_explicit_cache`, `is_explicit`) - Task 3.2.2 complete
1000+
- ✅ Official repo queries (`search_official`, `all_official`, `fetch_official_index`, `fetch_official_index_async`) - Task 3.3 complete
1001+
- ✅ Module entry point updated with query/fetch modules - Task 3.7 partial
1002+
- ⏳ Index persistence (Task 3.4 - pending)
1003+
- ⏳ Mirror management (Task 3.5 - optional, pending)
9971004
- **Plan Document**: [INDEX_MODULE_PHASE.md](./INDEX_MODULE_PHASE.md)
9981005

9991006
### Phase 4+ Status: ⏳ PLANNED
@@ -1024,11 +1031,14 @@ These modules may still have blockers similar to what the AUR module had:
10241031
- **Remaining**: AUR dependency queries (async .SRCINFO fetching limitation noted - future enhancement)
10251032
- **Plan Document**: [DEPENDENCIES_MODULE_PHASE.md](./DEPENDENCIES_MODULE_PHASE.md)
10261033

1027-
3. **Phase 3**: Add index module (~20-30 hours) ⏳ **PLANNED**
1028-
- Package database queries (installed, official repos)
1029-
- Mirror management
1030-
- Index persistence
1031-
- **Status**: Not yet started
1034+
3. **Phase 3**: Add index module (~20-30 hours) 🚧 **IN PROGRESS**
1035+
- ✅ Index types (Task 3.1.1 - complete)
1036+
- ✅ Installed package queries (Task 3.2.1 - complete)
1037+
- ✅ Explicit package tracking (Task 3.2.2 - complete)
1038+
- ✅ Official repository queries (Task 3.3 - complete)
1039+
- ⏳ Index persistence (Task 3.4 - pending)
1040+
- ⏳ Mirror management (Task 3.5 - optional, pending)
1041+
- **Status**: Tasks 3.1, 3.2, and 3.3 complete, remaining tasks pending
10321042
- **Plan Document**: [INDEX_MODULE_PHASE.md](./INDEX_MODULE_PHASE.md)
10331043

10341044
4. **Phase 4+**: Add remaining modules incrementally ⏳ **PLANNED**

dev/INDEX_MODULE_PHASE.md

Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This document provides a detailed structured plan for implementing the Index Mod
1313
| **Estimated Effort** | 20-30 hours |
1414
| **Complexity** | Medium (system command execution, data persistence, async operations) |
1515
| **Dependencies** | `types` module, optional `aur` module for enrichment |
16-
| **Status** | ⏳ Planned - Not yet started |
16+
| **Status** | 🚧 In Progress - Tasks 3.1, 3.2, and 3.3 complete |
1717

1818
## Overview
1919

@@ -78,7 +78,7 @@ This module is foundational and used by other modules (deps, install) for packag
7878
- `OfficialIndex` - Collection of official packages with name lookup
7979
```rust
8080
pub struct OfficialIndex {
81-
pub packages: Vec<OfficialPackage>,
81+
pub pkgs: Vec<OfficialPackage>,
8282
// Internal: name_to_idx for O(1) lookups
8383
}
8484
```
@@ -89,15 +89,23 @@ This module is foundational and used by other modules (deps, install) for packag
8989
pub fuzzy_score: Option<i64>,
9090
}
9191
```
92+
- `InstalledPackagesMode` - Filter mode for explicit package queries (added in Task 3.2)
93+
```rust
94+
pub enum InstalledPackagesMode {
95+
LeafOnly, // pacman -Qetq
96+
AllExplicit, // pacman -Qeq
97+
}
98+
```
9299

93100
**Estimated Effort**: 2-3 hours
94101

95102
**Acceptance Criteria**:
96-
- [ ] All types have rustdoc comments (What/Inputs/Output/Details)
97-
- [ ] Types are serializable with serde
98-
- [ ] `OfficialIndex` has `rebuild_name_index()` method
99-
- [ ] Unit tests for type operations
100-
- [ ] Code passes `cargo fmt`, `cargo clippy`, `cargo check`
103+
- [x] All types have rustdoc comments (What/Inputs/Output/Details)
104+
- [x] Types are serializable with serde
105+
- [x] `OfficialIndex` has `rebuild_name_index()` method
106+
- [x] `OfficialIndex` has `find_package_by_name()` method
107+
- [x] Unit tests for type operations
108+
- [x] Code passes `cargo fmt`, `cargo clippy`, `cargo check`
101109

102110
---
103111

@@ -123,12 +131,12 @@ This module is foundational and used by other modules (deps, install) for packag
123131
**Estimated Effort**: 3-4 hours
124132

125133
**Acceptance Criteria**:
126-
- [ ] Functions work without global state
127-
- [ ] Graceful degradation when pacman unavailable
128-
- [ ] Async operations use `spawn_blocking` correctly
129-
- [ ] Unit tests for installed package queries
130-
- [ ] Integration tests with mock pacman
131-
- [ ] Code passes quality checks
134+
- [x] Functions work without global state
135+
- [x] Graceful degradation when pacman unavailable
136+
- [x] Async operations use `spawn_blocking` correctly
137+
- [x] Unit tests for installed package queries
138+
- [x] Integration tests with mock pacman
139+
- [x] Code passes quality checks
132140

133141
#### Task 3.2.2: Port Explicit Package Tracking
134142

@@ -141,10 +149,10 @@ This module is foundational and used by other modules (deps, install) for packag
141149
**Estimated Effort**: 1-2 hours
142150

143151
**Acceptance Criteria**:
144-
- [ ] Functions work without global state
145-
- [ ] Graceful degradation when pacman unavailable
146-
- [ ] Unit tests
147-
- [ ] Code passes quality checks
152+
- [x] Functions work without global state
153+
- [x] Graceful degradation when pacman unavailable
154+
- [x] Unit tests
155+
- [x] Code passes quality checks
148156

149157
---
150158

@@ -171,11 +179,11 @@ This module is foundational and used by other modules (deps, install) for packag
171179
**Estimated Effort**: 4-5 hours
172180

173181
**Acceptance Criteria**:
174-
- [ ] Functions accept `&OfficialIndex` parameter (no global state)
175-
- [ ] Fuzzy matching works correctly
176-
- [ ] Case-insensitive substring matching works
177-
- [ ] Unit tests for search functionality
178-
- [ ] Code passes quality checks
182+
- [x] Functions accept `&OfficialIndex` parameter (no global state)
183+
- [x] Fuzzy matching works correctly
184+
- [x] Case-insensitive substring matching works
185+
- [x] Unit tests for search functionality
186+
- [x] Code passes quality checks
179187

180188
#### Task 3.3.2: Port Official Index Fetching
181189

@@ -194,12 +202,12 @@ This module is foundational and used by other modules (deps, install) for packag
194202
**Estimated Effort**: 3-4 hours
195203

196204
**Acceptance Criteria**:
197-
- [ ] Uses `reqwest` via arch-toolkit client
198-
- [ ] Respects rate limiting
199-
- [ ] Handles errors gracefully
200-
- [ ] Unit tests with mock HTTP responses
201-
- [ ] Integration tests (optional, requires network)
202-
- [ ] Code passes quality checks
205+
- [x] Uses `reqwest` via arch-toolkit client
206+
- [x] Respects rate limiting
207+
- [x] Handles errors gracefully
208+
- [x] Unit tests with mock HTTP responses
209+
- [x] Integration tests (optional, requires network)
210+
- [x] Code passes quality checks
203211

204212
---
205213

@@ -306,11 +314,12 @@ This module is foundational and used by other modules (deps, install) for packag
306314
**Estimated Effort**: 1-2 hours
307315

308316
**Acceptance Criteria**:
309-
- [ ] All public APIs exported
310-
- [ ] Comprehensive module documentation
311-
- [ ] Usage examples in rustdoc
312-
- [ ] Feature flags documented
313-
- [ ] Code passes quality checks
317+
- [x] All public APIs exported (for installed/explicit/query/fetch modules)
318+
- [x] Comprehensive module documentation
319+
- [x] Usage examples in rustdoc
320+
- [x] Feature flags documented
321+
- [x] Code passes quality checks
322+
- [ ] Additional exports for persist module (pending)
314323

315324
---
316325

@@ -329,10 +338,11 @@ This module is foundational and used by other modules (deps, install) for packag
329338
**Estimated Effort**: 3-4 hours
330339

331340
**Acceptance Criteria**:
332-
- [ ] All functions have unit tests
333-
- [ ] Error cases covered
334-
- [ ] Edge cases covered
335-
- [ ] Tests pass with `cargo test -- --test-threads=1`
341+
- [x] All functions have unit tests (for installed/explicit/query/fetch modules)
342+
- [x] Error cases covered (for installed/explicit/query/fetch modules)
343+
- [x] Edge cases covered (for installed/explicit/query/fetch modules)
344+
- [x] Tests pass with `cargo test -- --test-threads=1` (for completed modules)
345+
- [ ] Additional tests for persist module (pending)
336346

337347
#### Task 3.8.2: Integration Tests
338348

@@ -347,9 +357,10 @@ This module is foundational and used by other modules (deps, install) for packag
347357
**Estimated Effort**: 2-3 hours
348358

349359
**Acceptance Criteria**:
350-
- [ ] Integration tests cover main workflows
351-
- [ ] Tests use mock commands where possible
352-
- [ ] Tests pass with `cargo test -- --test-threads=1`
360+
- [x] Integration tests cover main workflows (for installed/explicit modules)
361+
- [x] Tests use mock commands where possible (mock pacman scripts)
362+
- [x] Tests pass with `cargo test -- --test-threads=1` (for completed modules)
363+
- [ ] Additional integration tests for persist module (pending)
353364

354365
#### Task 3.8.3: Documentation and Examples
355366

@@ -376,7 +387,7 @@ This module is foundational and used by other modules (deps, install) for packag
376387
```toml
377388
[features]
378389
default = ["aur"]
379-
index = [] # No additional dependencies, uses std and serde
390+
index = ["dep:tokio"] # For async operations with spawn_blocking
380391

381392
[dependencies]
382393
# Index module dependencies (always included)
@@ -388,7 +399,7 @@ fuzzy-matcher = { version = "0.3", optional = true } # For fuzzy search
388399
tokio = { version = "1", features = ["rt", "time"], optional = true } # For async operations
389400
```
390401

391-
**Note**: The index module should work without async by default, but async operations are available when `tokio` feature is enabled.
402+
**Note**: The index module includes tokio as a dependency for async operations. Async functions are available when the `index` feature is enabled.
392403

393404
---
394405

@@ -466,30 +477,33 @@ Once the index module is complete, Pacsea can:
466477

467478
The Index Module is complete when:
468479

469-
- [ ] All core functionality ported (installed queries, official queries, persistence)
470-
- [ ] No dependencies on Pacsea internals
471-
- [ ] All functions have rustdoc documentation
472-
- [ ] Unit tests pass
473-
- [ ] Integration tests pass
480+
- [x] Installed package queries ported (Task 3.2)
481+
- [x] Explicit package tracking ported (Task 3.2)
482+
- [x] Official repository queries ported (Task 3.3)
483+
- [ ] Index persistence ported (Task 3.4)
484+
- [x] No dependencies on Pacsea internals (for completed tasks)
485+
- [x] All functions have rustdoc documentation (for completed tasks)
486+
- [x] Unit tests pass (for completed tasks)
487+
- [x] Integration tests pass (for completed tasks)
474488
- [ ] Example program works
475-
- [ ] Code passes `cargo fmt`, `cargo clippy`, `cargo check`
489+
- [x] Code passes `cargo fmt`, `cargo clippy`, `cargo check` (for completed tasks)
476490
- [ ] README updated with index module documentation
477-
- [ ] Module entry point complete
491+
- [x] Module entry point created (Task 3.7 - partial, installed/explicit modules complete)
478492

479493
---
480494

481495
## Timeline
482496

483-
| Task | Estimated Hours | Priority |
484-
|------|----------------|----------|
485-
| 3.1: Define Types | 2-3 | High |
486-
| 3.2: Installed Queries | 4-6 | High |
487-
| 3.3: Official Queries | 7-9 | High |
497+
| Task | Estimated Hours | Priority | Status |
498+
|------|----------------|----------|--------|
499+
| 3.1: Define Types | 2-3 | High | ✅ Complete |
500+
| 3.2: Installed Queries | 4-6 | High | ✅ Complete |
501+
| 3.3: Official Queries | 7-9 | High | ✅ Complete |
488502
| 3.4: Persistence | 2-3 | High |
489503
| 3.5: Mirror Management | 2-3 | Medium (Optional) |
490504
| 3.6: Background Updates | 2-3 | Low (Optional) |
491-
| 3.7: Module Entry Point | 1-2 | High |
492-
| 3.8: Testing & Docs | 7-10 | High |
505+
| 3.7: Module Entry Point | 1-2 | High | ✅ Partial (installed/explicit/query/fetch complete) |
506+
| 3.8: Testing & Docs | 7-10 | High | ✅ Partial (installed/explicit/query/fetch complete) |
493507
| **Total** | **27-39 hours** | |
494508

495509
**Recommended Approach**: Start with high-priority tasks (3.1-3.4, 3.7-3.8), then add optional features (3.5-3.6) as needed.

0 commit comments

Comments
 (0)