Add parallel download worker-count configuration through all three config layers: Config dataclass (workers=3 default), YAML parsing with InvalidWorkersError validation, and -w/--workers CLI flag with three-layer resolution (CLI > config > hardcoded 3). 6 new tests. Closes #12
4.6 KiB
Issue #12: Slice 1 — Config workers field + CLI --workers flag
Date: 2026-06-03 Type: issue Status: Complete
Summary
Added parallel download worker-count configuration through all three config layers (YAML → Config dataclass → CLI → resolution). Follows the existing pattern established by format/InvalidFormatError and --limit.
What Was Done
config.py changes
- Added
workers: int = 3field to frozenConfigdataclass (default 3, backward-compatible) - Added
InvalidWorkersError(ConfigError)subclass for validation failures - Added
_validate_workers()function — rejects non-int and values < 1 - Wired validation into
load_config()— only validates whenworkerskey is explicitly present in YAML - Parses
librofm.workersfrom merged YAML dict with fallback to3
cli.py changes
- Added
-w/--workersargument to argparse (type=int,metavar="N",default=0) - Added
workers: int = 0parameter torun()function - Implemented 3-layer resolution in
run(): CLI flag (>0?) →config.workers→ hardcoded3 - Stored as
resolved_workersvariable (for slice 6 to wire to orchestrator) - Updated docstring with new parameter
Test changes (6 new tests, 179 total)
- test_config.py — 3 new tests:
TestWorkersDefault::test_default_workers_is_3— absent from YAML → defaults to 3TestWorkersFromYaml::test_workers_5_from_yaml—workers: 5in YAML parsed correctlyTestWorkersValidation::test_workers_zero_raises_error—workers: 0raisesInvalidWorkersErrorTestWorkersValidation::test_workers_negative_raises_error—workers: -1raisesInvalidWorkersError
- test_cli.py — 3 new tests:
TestCLIWorkersFlag::test_cli_workers_overrides_config—--workers 8overrides config.workers=3TestCLIWorkersFlag::test_no_flag_uses_config_value— no flag uses config value (5)TestCLIWorkersFlag::test_workers_1_accepted—--workers 1accepted (sequential)
Fixture files added
tests/fixtures/config_workers_zero.yaml— workers: 0 (invalid)tests/fixtures/config_workers_negative.yaml— workers: -1 (invalid)- Updated
config_with_overrides.yaml— addedworkers: 5
Existing test fixes
- Updated ~15 existing tests across
test_cli.py,test_progress.pythat mockload_configto includemock_config.return_value.workers = 3 - No logic changes needed —
Config.workers = 3default made all directConfig(...)constructions backward-compatible
Decisions & Rationale
-
Default on dataclass, not just in loader: Gave
workersa default of3in theConfigdataclass itself so existing tests that constructConfig(...)directly don't break. This is more defensive than requiring every caller to pass it. -
Validate only when explicit: Only call
_validate_workers()when theworkerskey is present in YAML. This means omitting it silently gets the default (3), which is the desired behavior per the AC. -
CLI default=0 as sentinel: Used
0as the "not specified" sentinel for the CLI flag (matching the--limitpattern). The resolution logic checks> 0before using the CLI value. -
Store resolved value now: Even though slice 6 wires it to the orchestrator, storing
resolved_workersinrun()makes it visible for debugging and avoids another refactor pass.
Gotchas & Fixes
- MagicMock comparison error: Adding a new field to
Configbroke ~15 existing tests that mockload_config()becauseMagicMockcan't be compared with<operator. Fixed by addingworkers=3to all mock configs. - Duplicate docstring: The initial edit to add
workersto the docstring created a duplicate. Fixed by removing the old docstring fragment. - Edit anchor format: Multi-line anchors don't work with
set_line. Had to use single-line anchors.
Next Steps
- Slice 6 will wire
resolved_workersto the parallel download orchestrator - Consider adding
workersto verbose output display
Acceptance Criteria
| # | Criterion | Status |
|---|---|---|
| 1 | Config.workers defaults to 3 |
✅ |
| 2 | workers: 5 in config.yaml produces Config(workers=5) |
✅ |
| 3 | workers: 0 or workers: -1 in YAML raises InvalidWorkersError |
✅ |
| 4 | --workers 8 on CLI resolves to 8 regardless of config.yaml value |
✅ |
| 5 | No --workers flag uses config.yaml value; missing from both yields default 3 |
✅ |
| 6 | --workers 1 is accepted (sequential fallback) |
✅ |
| 7 | 3–4 new tests in test_config.py covering default, YAML parse, validation rejection, CLI resolution |
✅ (6 new) |
All 7/7 AC met • 179 tests pass