69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { createAssistantDataScopePolicy } from "../src/services/assistantDataScopePolicy";
|
|
|
|
function createPolicy() {
|
|
return createAssistantDataScopePolicy({
|
|
activeMcpChannel: "default",
|
|
mcpProxyUrl: "http://localhost",
|
|
executeAddressMcpQuery: vi.fn(async () => ({ rows: [] })),
|
|
repairAddressMojibake: (value: unknown) => String(value ?? "")
|
|
});
|
|
}
|
|
|
|
describe("assistantDataScopePolicy", () => {
|
|
it("extracts known organizations from shared assistant organization authority and assistant text fallback", () => {
|
|
const policy = createPolicy();
|
|
|
|
const organizations = policy.extractKnownOrganizationsFromHistory([
|
|
{
|
|
role: "assistant",
|
|
text: "Доступны организации: Org Text, Org Extra.",
|
|
debug: {
|
|
execution_lane: "living_chat",
|
|
living_chat_selected_organization: "Org Selected",
|
|
assistant_active_organization: "Org Selected",
|
|
assistant_known_organizations: ["Org Selected", "Org Backup"],
|
|
organization_candidates: ["Org Candidate"]
|
|
}
|
|
},
|
|
{
|
|
role: "assistant",
|
|
debug: {
|
|
execution_lane: "address_query",
|
|
answer_grounding_check: { status: "grounded" },
|
|
extracted_filters: {
|
|
organization: "Org Grounded"
|
|
}
|
|
}
|
|
}
|
|
]);
|
|
|
|
expect(organizations).toEqual([
|
|
"Org Grounded",
|
|
"Org Selected",
|
|
"Org Backup",
|
|
"Org Candidate",
|
|
"Org Text",
|
|
"Org Extra"
|
|
]);
|
|
});
|
|
|
|
it("recovers active organization from assistant-side living chat authority when grounded answer is absent", () => {
|
|
const policy = createPolicy();
|
|
|
|
const activeOrganization = policy.findLastAssistantActiveOrganization([
|
|
{
|
|
role: "assistant",
|
|
debug: {
|
|
execution_lane: "living_chat",
|
|
living_chat_selected_organization: "Org Selected",
|
|
assistant_active_organization: "Org Selected",
|
|
assistant_known_organizations: ["Org Selected", "Org Backup"]
|
|
}
|
|
}
|
|
]);
|
|
|
|
expect(activeOrganization).toBe("Org Selected");
|
|
});
|
|
});
|