fix(api): harden user self-service and resource linking

This commit is contained in:
2026-03-31 21:02:36 +02:00
parent e8c0d3c3eb
commit 99db52929f
24 changed files with 2882 additions and 38 deletions
@@ -0,0 +1,59 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { SystemRole } from "@capakraken/shared";
vi.mock("@capakraken/application", async (importOriginal) => {
const actual = await importOriginal<typeof import("@capakraken/application")>();
return {
...actual,
getDashboardBudgetForecast: vi.fn().mockResolvedValue([]),
getDashboardPeakTimes: vi.fn().mockResolvedValue([]),
listAssignmentBookings: vi.fn().mockResolvedValue([]),
};
});
import { executeTool, type ToolContext } from "../router/assistant-tools.js";
import { createToolContext } from "./assistant-tools-user-self-service-test-helpers.js";
describe("assistant user self-service auth guard tools", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("returns a stable assistant error when authenticated assistant context is missing for a self-service read tool", async () => {
const ctx = {
...createToolContext({}, SystemRole.ADMIN),
session: null,
dbUser: null,
} as unknown as ToolContext;
const result = await executeTool("get_current_user", "{}", ctx);
expect(JSON.parse(result.content)).toEqual({
error: "Authenticated assistant context is required for this tool.",
});
});
it("returns a stable assistant error when authenticated assistant context is missing for a self-service mutation tool", async () => {
const ctx = {
...createToolContext({}, SystemRole.ADMIN),
session: null,
dbUser: null,
} as unknown as ToolContext;
const result = await executeTool(
"save_dashboard_layout",
JSON.stringify({
layout: {
version: 2,
gridCols: 12,
widgets: [],
},
}),
ctx,
);
expect(JSON.parse(result.content)).toEqual({
error: "Authenticated assistant context is required for this tool.",
});
});
});