unit(D6): candidate ranking service (availability -> readiness -> score)
rankCandidates() implements ARCHITECTURE §5.8.4: availability-filtered first, then ranked by readiness. Reuses computeReadiness (C4), isUnavailable (D4), levelRank (C3). Pure — no DB, route, or migration. Pipeline precedence: inactive -> away -> already_serving -> unqualified -> eligible. Deterministic tie-break (score desc, name, id). Comfort lowers rank but never blocks (§7 rule 14); never-served is not stale. 18 tests (away excluded; unqualified + reason code; deterministic ordering; roster/instance gates; sort modes; picker signals). tsc/eslint/vitest (178) / next build all green.
This commit is contained in:
+20
-1
@@ -543,7 +543,26 @@ Build log for Media Team Hub. One unit per commit, top to bottom. Append after e
|
||||
- **Staleness takes a reference date.** The function is pure and deterministic, so `daysBetween(lastServedOn, today)` takes `today` as input rather than reading the clock — the test pins it to a fixed date.
|
||||
- **Shadow mentor reuses `isMentorReady`.** A shadow slot (§7 rule 16) needs a mentor who is mentor-ready for that exact skill; the C5 predicate is called directly, and an unpaired shadow (`pairedMentor` null) is a hard conflict.
|
||||
|
||||
**Next: D6 — candidate ranking service (availability filter → readiness → score).**
|
||||
## D6 — Candidate ranking service (availability → readiness → score) — DONE 2026-11-18
|
||||
|
||||
**Scope (from BUILD-PLAN.md):** candidate ranking service — availability filter → readiness → score. Done when: Test: away user excluded; unqualified blocked with reason code; ordering deterministic. ARCHITECTURE §5.8.4 / §5.8.3.
|
||||
|
||||
**Delivered:**
|
||||
- `src/domain/ranking.ts` — pure `rankCandidates({ position, candidates, sortBy })` returns `{ eligible, excluded }`. Pipeline is exactly §5.8.4: **availability-filtered first, then ranked by readiness**. Reuses `computeReadiness` (C4) for the score, `isUnavailable` (D4) for the blackout filter, `levelRank` (C3) for staleness. No DB, no route, no migration — the join-resolving data layer (D8/D9) passes facts in.
|
||||
- `src/domain/ranking.test.ts` — 18 tests: the three DONE-when assertions (away excluded; unqualified + `core_skill_below_required` reason code; deterministic ordering), roster/instance gates (inactive, unapproved, already-serving), sort modes (bestMatch score-desc + name/id tie-break, availableOnly alphabetical), and picker signals (mentor badge, stale vs never-served, comfort-lowers-rank-never-blocks).
|
||||
|
||||
**Verification (all exit 0):**
|
||||
- `tsc --noEmit` ✓ · `eslint .` ✓ (0 problems) · `vitest run` ✓ (**178** total; D6 = 18) · `next build` ✓
|
||||
|
||||
**Decisions:**
|
||||
- **Precedence mirrors §5.8.4.** inactive → away → already_serving → unqualified → eligible. Availability is checked before the one-assignment-per-instance rule, matching "availability-filtered first".
|
||||
- **`score` is always a number.** `computeReadiness` returns 0 for an empty skill set, so `RankedCandidate.score` is `number` (not `number | null`).
|
||||
- **Null required level never blocks.** A position skill with no solo threshold is passed through as `none` to `computeReadiness`, so it still ranks but never hard-gates.
|
||||
- **Comfort lowers rank, never blocks (§7 rule 14).** `comfort_below_50` is not a ranking exclusion — it only pulls the blended score down (70% level / 30% comfort).
|
||||
- **Never-served is not stale.** A core skill with no `last_served_on` is a readiness concern, not a "needs refresher" — flagging a beginner as stale would mislead (same call as D5).
|
||||
- **Deterministic tie-break.** bestMatch orders by score desc, then displayName, then userId; the excluded list is sorted by name then id, so a fixed input always yields the same picker order.
|
||||
|
||||
**Next: D7 — read-only grid UI (rows = instances, cols = positions, week nav).**
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user