fix(ui): cache control ui markdown
parent
b697374ce5
commit
d57cb2e1a8
@ -1,34 +1,46 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { stripEnvelope } from "./message-extract";
|
||||
|
||||
describe("stripEnvelope", () => {
|
||||
it("strips UTC envelope", () => {
|
||||
const text = "[WebChat agent:main:main 2026-01-18T05:19Z] hello world";
|
||||
expect(stripEnvelope(text)).toBe("hello world");
|
||||
});
|
||||
|
||||
it("strips local-time envelope", () => {
|
||||
const text = "[Telegram Ada Lovelace (@ada) id:1234 2026-01-18 19:29 GMT+1] test";
|
||||
expect(stripEnvelope(text)).toBe("test");
|
||||
});
|
||||
import {
|
||||
extractText,
|
||||
extractTextCached,
|
||||
extractThinking,
|
||||
extractThinkingCached,
|
||||
} from "./message-extract";
|
||||
|
||||
it("strips envelopes without timestamps for known channels", () => {
|
||||
const text = "[WhatsApp +1234567890] hi there";
|
||||
expect(stripEnvelope(text)).toBe("hi there");
|
||||
describe("extractTextCached", () => {
|
||||
it("matches extractText output", () => {
|
||||
const message = {
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "Hello there" }],
|
||||
};
|
||||
expect(extractTextCached(message)).toBe(extractText(message));
|
||||
});
|
||||
|
||||
it("handles multi-line messages", () => {
|
||||
const text = "[Slack #general 2026-01-18T05:19Z] first line\nsecond line";
|
||||
expect(stripEnvelope(text)).toBe("first line\nsecond line");
|
||||
it("returns consistent output for repeated calls", () => {
|
||||
const message = {
|
||||
role: "user",
|
||||
content: "plain text",
|
||||
};
|
||||
expect(extractTextCached(message)).toBe("plain text");
|
||||
expect(extractTextCached(message)).toBe("plain text");
|
||||
});
|
||||
});
|
||||
|
||||
it("returns text as-is when no envelope present", () => {
|
||||
const text = "just a regular message";
|
||||
expect(stripEnvelope(text)).toBe("just a regular message");
|
||||
describe("extractThinkingCached", () => {
|
||||
it("matches extractThinking output", () => {
|
||||
const message = {
|
||||
role: "assistant",
|
||||
content: [{ type: "thinking", thinking: "Plan A" }],
|
||||
};
|
||||
expect(extractThinkingCached(message)).toBe(extractThinking(message));
|
||||
});
|
||||
|
||||
it("does not strip non-envelope brackets", () => {
|
||||
expect(stripEnvelope("[OK] hello")).toBe("[OK] hello");
|
||||
expect(stripEnvelope("[1/2] step one")).toBe("[1/2] step one");
|
||||
it("returns consistent output for repeated calls", () => {
|
||||
const message = {
|
||||
role: "assistant",
|
||||
content: [{ type: "thinking", thinking: "Plan A" }],
|
||||
};
|
||||
expect(extractThinkingCached(message)).toBe("Plan A");
|
||||
expect(extractThinkingCached(message)).toBe("Plan A");
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue