2026-05-02: Fix AssetTypeGroup enum cast in Prisma repository
Status: Complete
Section titled “Status: Complete”Context
Section titled “Context”After merging all branches into main (see 2026-05-02 merge plan), running npm run docker:reset still failed — this time during the backend Docker build step (npx nest build):
src/infrastructure/repositories/prisma-asset-type.repository.ts:30:51 - error TS2322:Type 'string' is not assignable to type 'AssetTypeGroup'.The bug was introduced when the group field was added to AssetType (plan D1). The repository adapter was wired to pass data.group directly from the domain port type (string) to Prisma’s typed input ($Enums.AssetTypeGroup).
Root Cause
Section titled “Root Cause”Hexagonal architecture correctly keeps Prisma types OUT of the domain layer:
AssetTypeentity:group: string✅CreateAssetTypeData/UpdateAssetTypeDataports:group: string✅
But the infrastructure adapter (PrismaAssetTypeRepository) did not perform the necessary cast at the boundary:
// Before (broken)data: { code: data.code, label: data.label, group: data.group }// ^^^ string ≠ $Enums.AssetTypeGroup
// After (fixed)data: { code: data.code, label: data.label, group: data.group as $Enums.AssetTypeGroup }File: backend/src/infrastructure/repositories/prisma-asset-type.repository.ts
- Added
$Enumsto the@prisma/clientimport - Cast
data.group as $Enums.AssetTypeGroupincreate() - Cast
data.group as $Enums.AssetTypeGroupinupdate()
The cast is safe because the domain validation layer (class-validator on DTOs + domain entity) ensures only valid enum string values reach the repository.
Test Added (AGENTS.md Convention #5 — Bug-to-Test)
Section titled “Test Added (AGENTS.md Convention #5 — Bug-to-Test)”New file: backend/test/asset-type.e2e-spec.ts
Covers:
- POST
/api/v1/asset-typeswith agroupenum value → 201 - PUT
/api/v1/asset-types/:idto update group → 200 - DELETE
/api/v1/asset-types/:id→ 200
Uses real NestJS app + in-memory SQLite. Would have caught the compile error at e2e time.
AGENTS.md Enforcement Improvement
Section titled “AGENTS.md Enforcement Improvement”Created .github/instructions/agents-plan-checklist.instructions.md with applyTo: '**/*'.
The .github/instructions/ mechanism is the strongest enforcement tool for AI agents in this repo: these files are explicitly shown with a forced-read reminder before any code change. By adding the 8 AGENTS.md conventions as a mandatory checklist here, they cannot be missed.
Trade-offs
Section titled “Trade-offs”- Cast vs. validation: using
ascast is appropriate here because the infrastructure layer is the boundary where Prisma types belong. The domain stays clean. - Instruction file vs. AGENTS.md: AGENTS.md remains the prose source of truth; the instruction file is a compact checklist derivative that triggers the enforcement mechanism.