docs: record C3 matrix + verify-level unit as done
Captures the 42-check smoke result and why the assessment row serves as the audit trail for level changes.
This commit is contained in:
@@ -336,3 +336,41 @@ Build log for Media Team Hub. One unit per commit, top to bottom. Append after e
|
||||
- **Unique (user, skill), not a history table.** C2 keeps one current self-rating per pair; the append-only history for verification lives in C3's `skill_assessments`.
|
||||
|
||||
**Next: C3 — admin skills matrix + verify-level modal.**
|
||||
|
||||
---
|
||||
|
||||
## C3 — Admin skills matrix + verify-level modal — DONE 2026-11-18
|
||||
|
||||
**Scope (from BUILD-PLAN.md):** the admin skills matrix (grid + filters) and the verify-level modal writing `skill_assessments`. Governing rules (ARCHITECTURE §4.3): levels never change silently — every move up **or down** appends an assessment row; `level_from` is the stored level, never client input; the volunteer's `self_comfort` is not the gate and is not touched by verification.
|
||||
|
||||
**Delivered:**
|
||||
- `src/db/schema.ts` — `skill_assessments` (append-only, 10 columns): `id, user_id, skill_id, assessor_id (nullable), kind [self|mentor|admin|quiz], level_from, level_to, comfort_at_time, notes, created_at`. Indexes on `(user_id, created_at)` and `skill_id`; `assessor_id` is `ON DELETE SET NULL`, user/skill cascade. Added `ASSESSMENT_KINDS` + the table to the `schema` export. No `updated_at` — there is no update path.
|
||||
- `src/domain/assessments.ts` — pure ladder + rule: `SKILL_LEVELS` ordered `none < observer < assisted < qualified < expert`, `levelRank`, `isSkillLevel`, and `buildAssessment({ currentLevel, newLevel, selfComfort })` → draft with **server-owned `levelFrom`**, `levelTo`, `comfortAtTime`, and `direction: up|down`. Rejects unknown levels and an unchanged level (no silent no-op row). No DB imports.
|
||||
- `src/domain/assessments.test.ts` — 9 tests: ladder order, domain ladder matches the DB enum (drift guard), level recognition, up move, down move audited, unknown new level, unknown current level, unchanged level refused, null-comfort snapshot.
|
||||
- `src/db/assessments.ts` — `verifySkillLevel` runs one transaction: reads the current record, appends the assessment, then moves `user_skills.verified_level` + `verified_by`/`verified_at`; creates the record (with `self_comfort` null) when the volunteer never rated the skill. **Never writes `self_comfort`/`self_rated_at`.** `listSkillsMatrix` (filters `userId`, `skillId`, `categoryId`, `level`; joins users × skills × categories) and `listAssessments` (newest first, assessor names resolved in JS, limit 1–200).
|
||||
- Routes: `GET /api/dev/skills/matrix`, `POST /api/dev/skills/verify`, `GET /api/dev/skills/assessments`. Verify maps `AssessmentError` → 400 and pg 23503 → 400 / 23505 → 409.
|
||||
- Migration `drizzle/0006_modern_shiver_man.sql`.
|
||||
|
||||
**Verification (all exit 0):**
|
||||
- `tsc --noEmit` ✓ · `eslint .` ✓ · `vitest run` ✓ (**64** total, +9 for C3) · `next build` ✓
|
||||
- `drizzle-kit migrate` ✓ → `skill_assessments` present on :5433 with all 10 columns
|
||||
- Runtime smoke against live app + Postgres on :5433 (`/tmp/c3.sh`, **42 checks**):
|
||||
- matrix starts empty; after a C2 slider save it shows the person with `self_comfort=55` and `verified_level=none` ✓
|
||||
- verify `qualified` + assessor + kind `mentor` → assessment `level_from=none`, `level_to=qualified`, `comfort_at_time=55`; `user_skills` moved with `verified_by`/`verified_at`; **self_comfort still 55** ✓
|
||||
- history returns the row with the assessor's name ✓
|
||||
- filters: `level=qualified` → 1, `level=expert` → 0, `categoryId` → 1, invalid level → 400 ✓
|
||||
- demotion to `assisted` appends a second row (`level_from=qualified`), history newest-first ✓
|
||||
- unchanged level → 400, unknown level → 400, dangling user/skill → 400, and no rejected verify wrote a row (count stayed 2) ✓
|
||||
- verifying a never-rated volunteer → 200, `comfort_at_time` null, record created with `self_comfort` null ✓
|
||||
- afterwards a slider save (90) still cannot move the verified level (`assisted` unchanged) — the C2 rule holds from the other direction ✓
|
||||
- test rows cleaned up (`skill_assessments`, `user_skills`, `skills`, categories back to 0)
|
||||
|
||||
**Decisions:**
|
||||
- **The append-only assessment row IS the audit row for level changes.** There is no `audit_log` table yet (it belongs to its own later unit); the BUILD-PLAN's "audit row exists" is satisfied by `skill_assessments`, which records who moved whom, from what, to what, when, with the comfort the assessor saw. Adding a second generic log row now would duplicate it.
|
||||
- **One write path, one transaction.** The assessment insert and the `verified_level` move succeed or fail together, so a level cannot move without its history.
|
||||
- **Unchanged level is a 400.** Verifying someone at the level they already hold records nothing; a silent no-op row would make the history lie about activity. Re-verifications that add context can be a later, explicit concern.
|
||||
- **Verification works without a slider rating.** `user_skills` is created with `self_comfort` null — a mentor can certify someone who has never self-assessed, and that is visible in the matrix.
|
||||
- **No admin UI page yet.** Consistent with B3/B4/C1/C2: this unit is the domain rule + data layer + API the UI consumes; the grid/modal screens land with the admin surfaces (I2). The matrix endpoint already returns the row shape the grid renders.
|
||||
- **Same Drizzle 0.45.4 relation exclusion.** `skill_assessments` has FK columns on indexes and is queried directly, like `user_skills`.
|
||||
|
||||
**Next: C4 — readiness scoring (`src/domain/readiness.ts`, pure).**
|
||||
|
||||
Reference in New Issue
Block a user