deer-flow/frontend/tests/unit/core/messages/model-control.test.ts
Totoro 0baa99ca90
feat(models): add scoped model controls to Web chats (#7249)
* test: stabilize reporter evidence and guard missing chat nodes

* feat(models): scope Web model choices to tasks, turns and conversations

* test(e2e): mock model-control preview for ordinary chat submissions

* fix(models): harden scoped choices and stale Agent submissions

---------

Co-authored-by: Totoro-qaq <279883115+Totoro-qaq@users.noreply.github.com>
2026-10-22 08:08:23 +08:00

58 lines
1.7 KiB
TypeScript

import type { Message } from "@langchain/langgraph-sdk";
import { expect, it } from "@rstest/core";
import { modelControlDisplayText } from "@/core/messages/model-control";
import { modelTaskInput } from "@/core/models/control";
it("separates an already applied control from the business task without losing its visible text", () => {
const original = "Use B for this turn: calculate 17 * 23";
const input = modelTaskInput(original, {
status: "resolved",
scope: "turn",
query: "B",
model_name: "B",
candidates: [],
task_offset: original.indexOf("calculate"),
});
expect(input.text).toBe("calculate 17 * 23");
const message = {
type: "human",
content: input.text,
additional_kwargs: input.additionalKwargs,
} as Message;
expect(modelControlDisplayText(message)).toBe(original);
expect(
modelControlDisplayText({ ...message, content: "an edited task" }),
).toBeNull();
expect(
modelControlDisplayText({ ...message, type: "ai" } as Message),
).toBeNull();
});
it("preserves long Unicode task bodies beyond the preview window", () => {
const original = "Use B for this turn: " + "🦌".repeat(5000);
const input = modelTaskInput(original, {
status: "resolved",
scope: "turn",
query: "B",
model_name: "B",
candidates: [],
task_offset: 21,
});
expect(input.text).toBe("🦌".repeat(5000));
});
it("leaves the delegation request for the parent agent to dispatch", () => {
const text = "Ask B to calculate 17 * 23";
expect(
modelTaskInput(text, {
status: "resolved",
scope: "task",
query: "B",
model_name: "B",
candidates: [],
task_offset: 9,
}).text,
).toBe(text);
});