50 lines
2.0 KiB
TypeScript
50 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { PermissionKey, SystemRole, type PermissionKey as PermissionKeyValue } from "@capakraken/shared";
|
|
import { getAvailableAssistantTools } from "../router/assistant-tool-policy.js";
|
|
import { selectAssistantToolsForRequest } from "../router/assistant-tool-selection.js";
|
|
|
|
function getSelectedToolNames(
|
|
permissions: PermissionKeyValue[],
|
|
messages: Array<{ role: "user" | "assistant"; content: string }>,
|
|
userRole: SystemRole = SystemRole.ADMIN,
|
|
pageContext?: string,
|
|
) {
|
|
return selectAssistantToolsForRequest(
|
|
getAvailableAssistantTools(new Set(permissions), userRole),
|
|
messages,
|
|
pageContext,
|
|
).map((tool) => tool.function.name);
|
|
}
|
|
|
|
describe("assistant tool selection", () => {
|
|
it("caps the OpenAI tool payload to 128 definitions even for fully privileged admins", () => {
|
|
const allPermissions = Object.values(PermissionKey);
|
|
const selectedNames = getSelectedToolNames(
|
|
allPermissions,
|
|
[{ role: "user", content: "Bitte gib mir einen Überblick über das System." }],
|
|
SystemRole.ADMIN,
|
|
);
|
|
|
|
expect(selectedNames.length).toBeLessThanOrEqual(128);
|
|
expect(selectedNames).toContain("get_current_user");
|
|
expect(selectedNames).toContain("search_resources");
|
|
expect(selectedNames).toContain("search_projects");
|
|
});
|
|
|
|
it("prioritizes holiday and resource tools for German holiday questions", () => {
|
|
const allPermissions = Object.values(PermissionKey);
|
|
const selectedNames = getSelectedToolNames(
|
|
allPermissions,
|
|
[{ role: "user", content: "Kannst du mir alle Feiertage nennen, die Peter Parker in 2026 zustehen?" }],
|
|
SystemRole.ADMIN,
|
|
);
|
|
|
|
expect(selectedNames.length).toBeLessThanOrEqual(128);
|
|
expect(selectedNames).toContain("search_resources");
|
|
expect(selectedNames).toContain("get_resource");
|
|
expect(selectedNames).toContain("get_resource_holidays");
|
|
expect(selectedNames).toContain("list_holidays_by_region");
|
|
expect(selectedNames).toContain("list_holiday_calendars");
|
|
});
|
|
});
|