b41c1d2501
CI / Architecture Guardrails (push) Successful in 2m38s
CI / Assistant Split Regression (push) Successful in 3m33s
CI / Typecheck (push) Successful in 3m51s
CI / Lint (push) Successful in 5m2s
CI / E2E Tests (push) Has been cancelled
CI / Fresh-Linux Docker Deploy (push) Has been cancelled
CI / Release Images (push) Has been cancelled
CI / Build (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
rename(phase 1): CapaKraken → Nexus across code, UI, docs, CI (#61) Co-authored-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com> Co-committed-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com>
81 lines
3.0 KiB
TypeScript
81 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { PermissionKey, SystemRole, type PermissionKey as PermissionKeyValue } from "@nexus/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");
|
|
expect(selectedNames).toContain("get_vacation_balance");
|
|
expect(selectedNames).toContain("get_entitlement_summary");
|
|
expect(selectedNames).toContain("list_vacations_upcoming");
|
|
});
|
|
|
|
it("prioritizes report and dashboard tools for reporting requests", () => {
|
|
const allPermissions = Object.values(PermissionKey);
|
|
const selectedNames = getSelectedToolNames(
|
|
allPermissions,
|
|
[
|
|
{
|
|
role: "user",
|
|
content:
|
|
"Build me a dashboard report for monthly SAH, budget forecast and project health.",
|
|
},
|
|
],
|
|
SystemRole.ADMIN,
|
|
"/dashboard",
|
|
);
|
|
|
|
expect(selectedNames.length).toBeLessThanOrEqual(128);
|
|
expect(selectedNames).toContain("get_dashboard_detail");
|
|
expect(selectedNames).toContain("get_budget_forecast");
|
|
expect(selectedNames).toContain("get_project_health");
|
|
expect(selectedNames).toContain("run_report");
|
|
expect(selectedNames).toContain("get_statistics");
|
|
});
|
|
});
|