feat(#233): extract scheduler engine into pure lib (Phase 2 of Resource Optimiser)#235
Merged
NickMonrad merged 2 commits intomainfrom Apr 29, 2026
Merged
Conversation
…ce Optimiser) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… coverage Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2 of 4 for Resource Optimiser (#233). Extracts the timeline scheduling engine from the Express route handler into a pure, testable library (
server/src/lib/scheduler.ts) so the Phase 3 optimiser can call it in a tight loop with different resource configurations — no DB round-trips per iteration.Behaviour-preserving refactor. All existing tests pass without modification. The HTTP API response shape is unchanged.
Changes
server/src/lib/scheduler.ts(NEW, 799 lines)runScheduler(input: SchedulerInput): SchedulerOutput— no Prisma, no I/O, no module-level stateSchedulerInput,SchedulerOutput,SchedulerEpic,SchedulerFeature,SchedulerStory,SchedulerTask,SchedulerResourceType,SchedulerNamedResource,ParallelWarningeffectiveAllocationPct,getWeeklyCapacity,computeParallelWarningsserver/src/routes/timeline.ts(−730 lines net)/schedulenow: load Prisma data → map toSchedulerInput→ callrunScheduler→ write results to DB → respondgetWeeklyCapacityre-exported for backwards compat with existingtimeline.test.tsserver/src/test/scheduler.test.ts(NEW, 22 tests)Covers happy path, multi-feature parallelism, epic dependencies, feature dependencies, resource constraints, named-resource start/end weeks, manual story overrides, empty input, zero-hour features, cross-epic dependency anti-cycle (
hasCrossEpicDepguard), epictimelineStartWeekanchor.Review fixes applied (sub-agent review cycle)
epics.find()in epic-dep loop replaced withMap<id, epic>lookup (O(n×d) → O(d))adjListchanged fromMap<string, string[]>with.includes()dedup toMap<string, Set<string>>with.has()(O(e²) → O(e))timelineStartWeekanchor)computeParallelWarningsasync→sync conversion is safe (had no awaits), manual upsert guards preserved, MinHeap actually used, zero non-determinism in pure pathTests
npx tsc --noEmit(server) — ✅ cleannpx tsc --noEmit(client) — ✅ cleannpm test(server) — ✅ 164/164 passing (142 existing + 22 new scheduler tests)Phases
POST /projects/:id/optimiseendpoint with modes (Speed / Utilisation / Balanced)Refs #233