97 lines
4.2 KiB
TypeScript
97 lines
4.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { createAssistantTurnMeaningPolicy } from "../src/services/assistantTurnMeaningPolicy";
|
|
import { resolveAddressIntent } from "../src/services/addressIntentResolver";
|
|
|
|
function buildPolicy(overrides: Record<string, unknown> = {}) {
|
|
return createAssistantTurnMeaningPolicy({
|
|
compactWhitespace: (value: string) => String(value ?? "").replace(/\s+/g, " ").trim(),
|
|
repairAddressMojibake: (value: string) => value,
|
|
resolveAddressIntent,
|
|
toNonEmptyString: (value: unknown) => {
|
|
if (value === null || value === undefined) {
|
|
return null;
|
|
}
|
|
const text = String(value).trim();
|
|
return text.length > 0 ? text : null;
|
|
},
|
|
...overrides
|
|
});
|
|
}
|
|
|
|
describe("assistantTurnMeaningPolicy", () => {
|
|
it("recovers a supported receivables intent from light current-turn typo noise", () => {
|
|
const policy = buildPolicy();
|
|
|
|
const meaning = policy.resolveAssistantTurnMeaning({
|
|
rawUserMessage:
|
|
"\u043a\u0442\u043e \u043d\u0430\u043c\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0434\u0435\u043d\u0435\u0433 \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f"
|
|
});
|
|
|
|
expect(meaning.schema_version).toBe("assistant_turn_meaning_v1");
|
|
expect(meaning.explicit_intent_candidate).toBe("receivables_confirmed_as_of_date");
|
|
expect(meaning.asked_domain_family).toBe("receivables");
|
|
expect(meaning.carryover_budget).toBe("matching_family_only");
|
|
expect(meaning.stale_replay_forbidden).toBe(false);
|
|
});
|
|
|
|
it("promotes specific counterparty turnover to the supported revenue intent", () => {
|
|
const policy = buildPolicy();
|
|
|
|
const meaning = policy.resolveAssistantTurnMeaning({
|
|
rawUserMessage:
|
|
"\u043a\u0430\u043a\u043e\u0439 \u043e\u0431\u043e\u0440\u043e\u0442 \u0431\u044b\u043b \u0441\u0432\u043a"
|
|
});
|
|
|
|
expect(meaning.explicit_intent_candidate).toBe("customer_revenue_and_payments");
|
|
expect(meaning.asked_domain_family).toBe("counterparty");
|
|
expect(meaning.asked_action_family).toBe("counterparty_value_or_turnover");
|
|
expect(meaning.unsupported_but_understood_family).toBeNull();
|
|
expect(meaning.stale_replay_forbidden).toBe(false);
|
|
expect(meaning.carryover_budget).toBe("matching_family_only");
|
|
expect(meaning.explicit_entity_candidates).toEqual([
|
|
{
|
|
type: "counterparty",
|
|
value: "\u0441\u0432\u043a",
|
|
source: "current_turn_loose_entity_tail"
|
|
}
|
|
]);
|
|
});
|
|
|
|
it("ignores temporal tail words in all-time revenue ranking questions", () => {
|
|
const policy = buildPolicy({
|
|
resolveAddressIntent: (text: string) =>
|
|
text.includes("\u0434\u043e\u0445\u043e\u0434\u043d\u044b\u0439")
|
|
? { intent: "customer_revenue_and_payments", confidence: "high" }
|
|
: resolveAddressIntent(text)
|
|
});
|
|
|
|
const meaning = policy.resolveAssistantTurnMeaning({
|
|
rawUserMessage:
|
|
"\u043a\u0442\u043e \u0443 \u043d\u0430\u0441 \u0441\u0430\u043c\u044b\u0439 \u0434\u043e\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442 \u0437\u0430 \u0432\u0441\u0435 \u0432\u0440\u0435\u043c\u044f"
|
|
});
|
|
|
|
expect(meaning.explicit_intent_candidate).toBe("customer_revenue_and_payments");
|
|
expect(meaning.explicit_entity_candidates).toEqual([]);
|
|
expect(meaning.stale_replay_forbidden).toBe(false);
|
|
});
|
|
|
|
it("treats VAT period questions as supported current-turn intent", () => {
|
|
const policy = buildPolicy({
|
|
resolveAddressIntent: (text: string) =>
|
|
text.includes("\u043d\u0434\u0441")
|
|
? { intent: "vat_liability_confirmed_for_tax_period", confidence: "high" }
|
|
: resolveAddressIntent(text)
|
|
});
|
|
|
|
const meaning = policy.resolveAssistantTurnMeaning({
|
|
rawUserMessage:
|
|
"\u0430 \u043a\u0430\u043a\u043e\u0439 \u043d\u0434\u0441 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u0437\u0430 \u044d\u0442\u043e\u0442 \u043f\u0435\u0440\u0438\u043e\u0434"
|
|
});
|
|
|
|
expect(meaning.explicit_intent_candidate).toBe("vat_liability_confirmed_for_tax_period");
|
|
expect(meaning.asked_domain_family).toBe("vat");
|
|
expect(meaning.asked_action_family).toBe("confirmed_tax_period");
|
|
expect(meaning.stale_replay_forbidden).toBe(false);
|
|
});
|
|
});
|