C1 — Skills composer (name composition + dedupe_key preview)

Skills composer: category (required) + optional technology + optional
function -> composed name prefill + dedupe_key. Governing rule: a null
technology yields a generic (technology-agnostic) skill; a duplicate
(category, tech, function) is rejected.
Delivered:
- src/domain/skills.ts — pure composeSkillName (no DB, no src/db imports).
  Rule: function+technology -> '<fn> on <tech>'; function only -> '<fn>';
  technology only -> '<tech>'; neither -> category. Null technology ->
  generic skill (name never names a specific piece of gear).
- src/domain/skills.test.ts — 6 tests named after the composition
  behaviors.
- src/app/api/dev/skills/compose/route.ts — POST /api/dev/skills/compose
  returns { name, dedupeKey } for prefilling the form; writes no row.
  The admin edits the name, then submits to POST /api/dev/skills, which
  generates slug + dedupe_key and enforces the unique constraint (409 on
  duplicate).
No schema change, no migration: the skills table, data-layer CRUD, and
dedupeKey were delivered in B4; C1 adds only the composition rule +
composer endpoint (matching the isPublishable/validateRequirements
domain pattern).
Verification: typecheck lint test (50, +6) build all green; runtime
smoke /tmp/c1.sh (13 checks): compose fn+tech -> '<fn> on <tech>',
compose function-only -> generic, create composed skill (slug frozen,
dedupe_key persisted), duplicate -> 409, null-tech generic skill,
dangling FK -> 400.
This commit is contained in:
Tiel Coder
2026-11-18 03:08:25 +00:00
parent 5c789f63cc
commit e9168def6c
4 changed files with 183 additions and 1 deletions
+31 -1
View File
@@ -267,4 +267,34 @@ Build log for Media Team Hub. One unit per commit, top to bottom. Append after e
- **`join` resolved in JS.** Drizzle 0.45.4 exports no `join` from `drizzle-orm` or `drizzle-orm/pg-core`. `getPositionSkills` fetches `position_skills` then the referenced `skills` and merges in JS.
- **No skill/position seed yet.** Per ARCHITECTURE the only seeded artifact is `seed/catalog.json` (later unit). Tables start empty; this unit is the data layer + API other units consume.
**Next: B5 — user_skills + verified levels (who has what, and at what level).****
**Next: B5 — user_skills + verified levels (who has what, and at what level).**
---
## C1 — Skills composer — DONE 2026-11-18
**Scope (from BUILD-PLAN.md):** Skills composer — category (required) + optional technology + optional function → `dedupe_key`, name prefill. ARCHITECTURE §4.3: a skill is "function applied to a technology (either may be generic)"; the name is auto-composed on create ("Switch cameras on ATEM Mini Pro") then freely editable. Done when: a duplicate (category, tech, function) is rejected; a null-tech skill is generic.
**Delivered:**
- `src/domain/skills.ts` — pure `composeSkillName({ categoryName, technologyName, functionName })` (no DB, no `src/db` imports). Rule: function + technology → "<fn> on <tech>"; function only → "<fn>"; technology only → "<tech>"; neither → category. A null technology yields a generic (technology-agnostic) skill — the name never names a specific piece of gear.
- `src/domain/skills.test.ts` — 6 tests named after the composition behaviors (compose fn+tech, generic on null tech, tech-only, category fallback, null-tech never names gear, trims whitespace).
- `src/app/api/dev/skills/compose/route.ts` — `POST /api/dev/skills/compose` returns `{ name, dedupeKey }` for prefilling the form; writes no row. The admin edits the name, then submits to `POST /api/dev/skills` (which generates slug + dedupe_key and enforces the unique constraint → 409 on duplicate).
**No schema change, no migration.** The `skills` table, data-layer CRUD, and `dedupeKey` were delivered in B4; C1 adds only the composition rule + composer endpoint.
**Verification (all exit 0):**
- `pnpm typecheck` ✓ · `pnpm lint` ✓ · `pnpm test` ✓ (**50** total, +6 for compose) · `pnpm build` ✓
- Runtime smoke against live app + Postgres on :5433 (`/tmp/c1.sh`, **13 checks**):
- compose function + technology → "Switch cameras on ATEM C1 Pro", dedupe_key = `category|tech|func` ✓
- compose function only (null tech) → "Run FOH audio", dedupe_key = `category||func` (empty tech segment) ✓
- create composed skill → 201, slug frozen from composed name, dedupe_key persisted ✓
- duplicate (category, tech, function) → **409** (the C1 rule) ✓
- create null-tech (generic) skill → 201, `technology_id` null ✓
- dangling category FK → 400 ✓
**Decisions:**
- **C1 is the composition rule, not new tables.** The `skills` table + data-layer CRUD + dedupe_key already exist from B4. C1's distinguishing logic is the name-composition (prefill) rule, so it lives as a pure function in `src/domain/skills.ts` and is exercised by a composer endpoint — matching the `isPublishable`/`validateRequirements` domain pattern from B4.
- **Composer endpoint returns a preview, writes nothing.** `POST /api/dev/skills/compose` returns `{ name, dedupeKey }` so the UI prefills the form; the edit-then-submit flow keeps slug + dedupe_key generation server-authoritative in `POST /api/dev/skills`.
- **No skill/position seed yet.** Per ARCHITECTURE the only seeded artifact is `seed/catalog.json` (later unit). Tables start empty; this unit is the composition layer other units (C2 sliders, C3 matrix) consume.
**Next: C2 — volunteer `/profile/skills` sliders (self_comfort) with verified chip.****