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:
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { composeSkillName } from "./skills";
|
||||
|
||||
describe("composeSkillName", () => {
|
||||
it("composes function + technology as '<function> on <technology>'", () => {
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -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 -> "<function> on <technology>" e.g. "Switch cameras on ATEM Mini Pro"
|
||||
* function only -> "<function>" e.g. "Run FOH audio" (technology-agnostic)
|
||||
* technology only -> "<technology>" e.g. "ATEM Mini Pro"
|
||||
* neither (category) -> "<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;
|
||||
}
|
||||
Reference in New Issue
Block a user