The platform for continuously improving AI agents.
// covers: console-logic
import { describe, expect, it } from "vitest";
import { editMentionRanges, type MentionRange, serializeMentions } from "./entity-mentions";
const range: MentionRange = {
end: 9,
entity: { group: "Datasets", href: "/datasets/one?projectId=project", id: "one", label: "data" },
start: 4,
};
describe("entity mention identities", () => {
it("preserves identity when surrounding text changes and drops edited tokens", () => {
expect(editMentionRanges("Use @data now", "Please use @data now", [range])[0]).toMatchObject({
end: 16,
entity: range.entity,
start: 11,
});
expect(editMentionRanges("Use @data now", "Use @date now", [range])).toEqual([]);
expect(editMentionRanges("Use @data now", "Use @data later", [range])).toEqual([range]);
});
it("serializes selected identities, including duplicate names, without guessing typed mentions", () => {
const other = {
...range,
end: 15,
entity: { ...range.entity, href: "/datasets/two?projectId=project", id: "two" },
start: 10,
};
expect(serializeMentions("Use @data @data @data", [range, other])).toBe(
"Use [@data](/datasets/one?projectId=project) [@data](/datasets/two?projectId=project) @data"
);
});
});