63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { parseControlTokens } from "./control-token-parser.js";
|
|
|
|
describe("parseControlTokens", () => {
|
|
it("extracts handoff control tokens and strips them from text", () => {
|
|
const parsed = parseControlTokens(
|
|
"잠시 확인할게요. [HANDOFF:moderation:policy-risk]",
|
|
);
|
|
|
|
expect(parsed.stripped).toBe("잠시 확인할게요.");
|
|
expect(parsed.tokens).toEqual([
|
|
{
|
|
kind: "handoff",
|
|
raw: "[HANDOFF:moderation:policy-risk]",
|
|
reason: "policy-risk",
|
|
targetAgent: "moderation",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("extracts no-response tokens", () => {
|
|
const parsed = parseControlTokens("[NO_RESPONSE]");
|
|
|
|
expect(parsed.stripped).toBe("");
|
|
expect(parsed.tokens).toEqual([
|
|
{
|
|
kind: "no-response",
|
|
raw: "[NO_RESPONSE]",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("keeps invalid handoff reasons visible", () => {
|
|
const parsed = parseControlTokens("[HANDOFF:moderation:not-a-reason]");
|
|
|
|
expect(parsed.stripped).toBe("[HANDOFF:moderation:not-a-reason]");
|
|
expect(parsed.tokens).toEqual([]);
|
|
});
|
|
|
|
it("accepts all handoff reason codes", () => {
|
|
const reasons = [
|
|
"out-of-scope",
|
|
"missing-tool",
|
|
"low-confidence",
|
|
"validation-failed",
|
|
"same-agent-revisit",
|
|
"max-hop",
|
|
"high-risk-action",
|
|
"policy-risk",
|
|
];
|
|
|
|
for (const reason of reasons) {
|
|
const parsed = parseControlTokens(`[HANDOFF:supervisor:${reason}]`);
|
|
expect(parsed.tokens[0]).toMatchObject({
|
|
kind: "handoff",
|
|
reason,
|
|
targetAgent: "supervisor",
|
|
});
|
|
}
|
|
});
|
|
});
|