fix(sanity): resolve 15 gaps from sanity check audit (G-01 through G-15)

- G-01: ProjectWizard renders blueprint fieldDefs with DynamicFieldInput component
- G-02: Blueprint rolePresets validated via RolePresetsSchema in wizard; API keeps loose schema
- G-03: ProjectWizard step 2/3 validation (role, hoursPerDay, headcount required)
- G-04: EstimateWizard validates baseCurrency and demand line cost rates
- G-05: Project lifecycle transition guards with ALLOWED_TRANSITIONS map
- G-06: Blueprint validator extended for minLength/maxLength/pattern and DATE range checks
- G-07: assertBlueprintDynamicFields merges global blueprint fieldDefs into validation
- G-08: (tracked — chapter managed dropdown; deferred to backend ticket)
- G-09: JSDoc added to lcrCents/ucrCents clarifying LCR/UCR terminology
- G-10: Dispo route redirect already in place — closed as done
- G-11: packages/ui empty by design — closed as documented
- G-12: @deprecated JSDoc added to CreateAllocationSchema and UpdateAllocationSchema
- G-13: ProjectWizard review step enhanced with blueprint name, field values, skills, assignments
- G-14: ProjectWizard handleSubmit collects per-item warnings instead of silent swallowing
- G-15: Vacation cancel reverses usedDays entitlement for APPROVED ANNUAL/OTHER vacations

Tests: all 1575 passing (1 pre-existing failure in insights-summary unrelated to these changes)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-06 00:11:12 +02:00
parent fba65387fe
commit 4a49ec4f05
17 changed files with 903 additions and 46 deletions
@@ -2,6 +2,15 @@ import { PermissionKey, SystemRole } from "@capakraken/shared";
import type { ToolContext } from "../router/assistant-tools.js";
import { vi } from "vitest";
const defaultDbDefaults = {
blueprint: {
findUnique: vi.fn().mockResolvedValue(null),
findMany: vi.fn().mockResolvedValue([]),
},
};
export function createToolContext(
db: Record<string, unknown>,
options?: {
@@ -10,8 +19,16 @@ export function createToolContext(
},
): ToolContext {
const userRole = options?.userRole ?? SystemRole.ADMIN;
const mergedDb = {
...defaultDbDefaults,
...db,
blueprint: {
...defaultDbDefaults.blueprint,
...(db.blueprint as Record<string, unknown> | undefined),
},
};
return {
db: db as ToolContext["db"],
db: mergedDb as ToolContext["db"],
userId: "user_1",
userRole,
permissions: new Set(options?.permissions ?? []),
@@ -38,6 +38,7 @@ describe("assistant project admin create tools - success", () => {
fieldDefs: [],
}),
findFirst: vi.fn().mockResolvedValue(null),
findMany: vi.fn().mockResolvedValue([]),
},
client: {
findUnique: vi.fn().mockResolvedValue({
@@ -159,6 +159,12 @@ export function createHappyPathDb() {
findMany: vi.fn().mockResolvedValue([]),
},
};
(db as Record<string, unknown>).$transaction = vi.fn(
async (callback: (tx: typeof db) => Promise<unknown>) => callback(db),
);
return db;
}
export const executeTool = executeAssistantTool;
@@ -7,6 +7,7 @@ function createDbMock(result: { fieldDefs: unknown; target: BlueprintTarget } |
return {
blueprint: {
findUnique: vi.fn().mockResolvedValue(result),
findMany: vi.fn().mockResolvedValue([]),
},
};
}
@@ -499,6 +499,7 @@ describe("project router", () => {
const updated = { ...sampleProject, status: ProjectStatus.COMPLETED };
const db = {
project: {
findUnique: vi.fn().mockResolvedValue(sampleProject),
update: vi.fn().mockResolvedValue(updated),
},
webhook: { findMany: vi.fn().mockResolvedValue([]) },
@@ -526,6 +527,7 @@ describe("project router", () => {
const updated = { ...sampleProject, status: ProjectStatus.COMPLETED };
const db = {
project: {
findUnique: vi.fn().mockResolvedValue(sampleProject),
update: vi.fn().mockResolvedValue(updated),
},
webhook: { findMany: vi.fn().mockResolvedValue([]) },
@@ -163,9 +163,12 @@ function createVacationDb(overrides: Record<string, unknown> = {}) {
auditLog: {
create: vi.fn().mockResolvedValue({}),
},
vacationEntitlement: {
updateMany: vi.fn().mockResolvedValue({ count: 0 }),
},
};
return {
const merged = {
...db,
...overrides,
user: { ...db.user, ...(overrides.user as Record<string, unknown> | undefined) },
@@ -176,6 +179,15 @@ function createVacationDb(overrides: Record<string, unknown> = {}) {
...(overrides.notification as Record<string, unknown> | undefined),
},
auditLog: { ...db.auditLog, ...(overrides.auditLog as Record<string, unknown> | undefined) },
vacationEntitlement: {
...db.vacationEntitlement,
...(overrides.vacationEntitlement as Record<string, unknown> | undefined),
},
};
return {
...merged,
$transaction: vi.fn(async (callback: (tx: typeof merged) => Promise<unknown>) => callback(merged)),
};
}