From e9168def6cd9b97e58dfcd411c87a3cf9b552724 Mon Sep 17 00:00:00 2001 From: Tiel Coder Date: Wed, 18 Nov 2026 03:08:25 +0000 Subject: [PATCH] =?UTF-8?q?C1=20=E2=80=94=20Skills=20composer=20(name=20co?= =?UTF-8?q?mposition=20+=20dedupe=5Fkey=20preview)=20Skills=20composer:=20?= =?UTF-8?q?category=20(required)=20+=20optional=20technology=20+=20optiona?= =?UTF-8?q?l=20function=20->=20composed=20name=20prefill=20+=20dedupe=5Fke?= =?UTF-8?q?y.=20Governing=20rule:=20a=20null=20technology=20yields=20a=20g?= =?UTF-8?q?eneric=20(technology-agnostic)=20skill;=20a=20duplicate=20(cate?= =?UTF-8?q?gory,=20tech,=20function)=20is=20rejected.=20Delivered:=20-=20s?= =?UTF-8?q?rc/domain/skills.ts=20=E2=80=94=20pure=20composeSkillName=20(no?= =?UTF-8?q?=20DB,=20no=20src/db=20imports).=20=20=20Rule:=20function+techn?= =?UTF-8?q?ology=20->=20'=20on=20';=20function=20only=20->=20'';=20=20=20technology=20only=20->=20'';=20neither=20->?= =?UTF-8?q?=20category.=20Null=20technology=20->=20=20=20generic=20skill?= =?UTF-8?q?=20(name=20never=20names=20a=20specific=20piece=20of=20gear).?= =?UTF-8?q?=20-=20src/domain/skills.test.ts=20=E2=80=94=206=20tests=20name?= =?UTF-8?q?d=20after=20the=20composition=20=20=20behaviors.=20-=20src/app/?= =?UTF-8?q?api/dev/skills/compose/route.ts=20=E2=80=94=20POST=20/api/dev/s?= =?UTF-8?q?kills/compose=20=20=20returns=20{=20name,=20dedupeKey=20}=20for?= =?UTF-8?q?=20prefilling=20the=20form;=20writes=20no=20row.=20=20=20The=20?= =?UTF-8?q?admin=20edits=20the=20name,=20then=20submits=20to=20POST=20/api?= =?UTF-8?q?/dev/skills,=20which=20=20=20generates=20slug=20+=20dedupe=5Fke?= =?UTF-8?q?y=20and=20enforces=20the=20unique=20constraint=20(409=20on=20?= =?UTF-8?q?=20=20duplicate).=20No=20schema=20change,=20no=20migration:=20t?= =?UTF-8?q?he=20skills=20table,=20data-layer=20CRUD,=20and=20dedupeKey=20w?= =?UTF-8?q?ere=20delivered=20in=20B4;=20C1=20adds=20only=20the=20compositi?= =?UTF-8?q?on=20rule=20+=20composer=20endpoint=20(matching=20the=20isPubli?= =?UTF-8?q?shable/validateRequirements=20domain=20pattern).=20Verification?= =?UTF-8?q?:=20typecheck=20lint=20test=20(50,=20+6)=20build=20all=20green;?= =?UTF-8?q?=20runtime=20smoke=20/tmp/c1.sh=20(13=20checks):=20compose=20fn?= =?UTF-8?q?+tech=20->=20'=20on=20',=20compose=20function-only=20?= =?UTF-8?q?->=20generic,=20create=20composed=20skill=20(slug=20frozen,=20d?= =?UTF-8?q?edupe=5Fkey=20persisted),=20duplicate=20->=20409,=20null-tech?= =?UTF-8?q?=20generic=20skill,=20dangling=20FK=20->=20400.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .agent/PROGRESS.md | 32 ++++++++++++- src/app/api/dev/skills/compose/route.ts | 58 ++++++++++++++++++++++ src/domain/skills.test.ts | 64 +++++++++++++++++++++++++ src/domain/skills.ts | 30 ++++++++++++ 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 src/app/api/dev/skills/compose/route.ts create mode 100644 src/domain/skills.test.ts create mode 100644 src/domain/skills.ts diff --git a/.agent/PROGRESS.md b/.agent/PROGRESS.md index daeaf5a..4d4a904 100644 --- a/.agent/PROGRESS.md +++ b/.agent/PROGRESS.md @@ -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 → " on "; function only → ""; technology only → ""; 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.**** diff --git a/src/app/api/dev/skills/compose/route.ts b/src/app/api/dev/skills/compose/route.ts new file mode 100644 index 0000000..c6dcbcd --- /dev/null +++ b/src/app/api/dev/skills/compose/route.ts @@ -0,0 +1,58 @@ +import { NextRequest } from "next/server"; +import { z } from "zod"; +import { composeSkillName } from "@/domain/skills"; +import { dedupeKey } from "@/db/positions"; + +const JSON_HEADERS = { "content-type": "application/json" }; + +/** + * The composer: pick a category (required) + optional technology + optional + * function, and get back the prefilled display name and the dedupe_key the + * create path will persist. The UI fills the form with `name` (editable) and + * submits to POST /api/dev/skills. This endpoint never writes a row. + */ +const composeSchema = z.object({ + categoryId: z.string().min(1), + categoryName: z.string().min(1), + technologyId: z.string().nullable().optional(), + technologyName: z.string().nullable().optional(), + functionId: z.string().nullable().optional(), + functionName: z.string().nullable().optional(), +}); + +async function readBody(req: NextRequest) { + try { + return await req.json(); + } catch { + return null; + } +} + +const bad = (message: string) => + new Response(JSON.stringify({ error: message }), { + status: 400, + headers: JSON_HEADERS, + }); + +/** + * POST /api/dev/skills/compose { categoryId, categoryName, technologyId?, + * technologyName?, functionId?, functionName? } -> { name, dedupeKey }. + */ +export const POST = async (req: NextRequest) => { + const body = await readBody(req); + if (!body || typeof body !== "object") return bad("invalid body"); + const parsed = composeSchema.safeParse(body); + if (!parsed.success) return bad(parsed.error.message); + const d = parsed.data; + return new Response( + JSON.stringify({ + name: composeSkillName({ + categoryName: d.categoryName, + technologyName: d.technologyName, + functionName: d.functionName, + }), + dedupeKey: dedupeKey(d.categoryId, d.technologyId, d.functionId), + }), + { status: 200, headers: JSON_HEADERS }, + ); +}; diff --git a/src/domain/skills.test.ts b/src/domain/skills.test.ts new file mode 100644 index 0000000..0577d94 --- /dev/null +++ b/src/domain/skills.test.ts @@ -0,0 +1,64 @@ +import { describe, expect, it } from "vitest"; +import { composeSkillName } from "./skills"; + +describe("composeSkillName", () => { + it("composes function + technology as ' on '", () => { + expect( + composeSkillName({ + categoryName: "Audio", + functionName: "Switch cameras", + technologyName: "ATEM Mini Pro", + }), + ).toBe("Switch cameras on ATEM Mini Pro"); + }); + + it("uses just the function when technology is null (generic skill)", () => { + expect( + composeSkillName({ + categoryName: "Audio", + functionName: "Run FOH audio", + technologyName: null, + }), + ).toBe("Run FOH audio"); + }); + + it("uses just the technology when no function is selected", () => { + expect( + composeSkillName({ + categoryName: "Livestream", + functionName: null, + technologyName: "ATEM Mini Pro", + }), + ).toBe("ATEM Mini Pro"); + }); + + it("falls back to the category when neither function nor technology (generic skill)", () => { + expect( + composeSkillName({ + categoryName: "Audio", + functionName: null, + technologyName: null, + }), + ).toBe("Audio"); + }); + + it("never names a specific gear when technology is null", () => { + const name = composeSkillName({ + categoryName: "Audio", + functionName: "Gain staging", + technologyName: null, + }); + expect(name).not.toMatch(/console|mixer|gate/i); + expect(name).toBe("Gain staging"); + }); + + it("trims surrounding whitespace from each selection", () => { + expect( + composeSkillName({ + categoryName: " Audio ", + functionName: " Switch cameras ", + technologyName: " ATEM Mini Pro ", + }), + ).toBe("Switch cameras on ATEM Mini Pro"); + }); +}); diff --git a/src/domain/skills.ts b/src/domain/skills.ts new file mode 100644 index 0000000..fbd22ad --- /dev/null +++ b/src/domain/skills.ts @@ -0,0 +1,30 @@ +/** + * Skill name composition (ARCHITECTURE §4.3, unit C1 — Skills composer). + * + * A skill is composed from a category (required) + optional technology + + * optional function. The composer prefills the display name from these + * selections; the admin may then edit it before saving. The rule: + * + * function + technology -> " on " e.g. "Switch cameras on ATEM Mini Pro" + * function only -> "" e.g. "Run FOH audio" (technology-agnostic) + * technology only -> "" e.g. "ATEM Mini Pro" + * neither (category) -> "" e.g. "Audio" (generic) + * + * A null technology yields a generic (technology-agnostic) skill: the composed + * name never names a specific piece of gear. Pure — no DB, no imports from + * `src/db`. + */ +export function composeSkillName(params: { + categoryName: string; + technologyName?: string | null; + functionName?: string | null; +}): string { + const categoryName = params.categoryName.trim(); + const technologyName = params.technologyName?.trim() ?? ""; + const functionName = params.functionName?.trim() ?? ""; + + if (functionName && technologyName) return `${functionName} on ${technologyName}`; + if (functionName) return functionName; + if (technologyName) return technologyName; + return categoryName; +}