Deduplicate worker cap logic: make get_worker_cap() delegate to WorkerCapLogic - #256
Deduplicate worker cap logic: make get_worker_cap() delegate to WorkerCapLogic#256itsmiso-ai wants to merge 1 commit into
Conversation
…rCapLogic The get_worker_cap() function in main.gd duplicated the same calculation already present in worker_cap_logic.gd. Replace the inline implementation with a call to WorkerCapLogic.calculate_worker_cap(builds) and add the corresponding preload constant. Fixes #244 Signed-off-by: Saffron <263493777+itsmiso-ai@users.noreply.github.com>
There was a problem hiding this comment.
AI Automated Review
Full PR review.
Analysis engine: MiniMax-M2.7@https://litellm.jory.dev/v1 (anthropic) — escalated (fast_low_confidence)
Review: PR PR 256 — Deduplicate worker cap logic
Summary
This PR completes issue PR 244 by making get_worker_cap() in main.gd delegate to WorkerCapLogic.calculate_worker_cap(), eliminating duplicated worker cap calculation logic.
Change-by-Change Analysis
scripts/main.gd — Lines 19, 1061-1062
| Before | After |
|---|---|
Inline 6-line loop over builds to sum WORKER_CAP_BONUSES |
Single-line delegation: return WorkerCapLogic.calculate_worker_cap(state.get("builds", [])) |
- Added
WorkerCapLogicconstant at the top of the file (line 19) - Replaced 6-line implementation with 1-line delegation
- Parameter passed to delegate (
state.get("builds", [])) matches the original inline logic exactly
Tests Verification
The existing test suite (tests/test_worker_cap.gd) exercises main.get_worker_cap() directly and was not modified. All 6 test cases continue to validate:
- Base cap (2) with no builds
- +2 bonus for one completed hut (total 4)
- +4 bonus for two completed huts (total 6)
- Workshop adds no bonus
- Mixed structures (hut + workshop)
- Incomplete builds excluded
Standards Compliance
| Check | Status |
|---|---|
Follows extraction pattern used for goal_progression.gd, layout_math.gd, worker_cap_logic.gd |
✅ Pass |
Keeps main.gd readable per CONTRIBUTING.md |
✅ Pass (reduced by 4 net lines) |
WorkerCapLogic module is already documented in DESIGN.md as extracted logic |
✅ Pass |
No API changes — all callers of get_worker_cap() work unchanged |
✅ Pass |
Linked Issue Fit
Issue PR 244: "Deduplicate worker cap logic: make main.gd:get_worker_cap() delegate to worker_cap_logic.gd"
- ✅ Explicitly adds
WorkerCapLogicimport - ✅
get_worker_cap()now delegates toWorkerCapLogic.calculate_worker_cap() - ✅ Deduplication achieved with identical behavior
CI Status
All validation gates passed on commit 61059c68:
- Headless smoke test: ✅
- Script test suite: ✅
- macOS validation: ✅
- Export validation (Linux): ✅
Unknowns / Needs Verification
None. The implementation is complete, tests pass, CI is green, and the change matches the issue requirements exactly.
Recommendation
Approve. The PR cleanly fulfills the issue PR 244 acceptance criteria with a minimal, well-scoped change that reduces code duplication while preserving all existing behavior and tests.
main.gd:get_worker_cap() now delegates to WorkerCapLogic.calculate_worker_cap(), deduplicating worker cap logic as requested in issue #244.
Fixes #244
Opened by foreman on review GO (workload wl-misospace-windowstead-244).