feat: make context compaction visible in channels (#5656)

* feat: surface context compaction lifecycle

* fix: complete and simplify context compaction notifications
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-05 20:21:54 +08:00
1 parent 455533169d
commit 5229989f28
52 files changed
+1849 -140

No files matched your search

+41
View File
@@ -2,6 +2,7 @@ import { act, fireEvent, render, screen, waitFor } from "@testing-library/react"
import { describe, expect, it, vi } from "vitest";
import { MessageBubble } from "@/components/MessageBubble";
import { setAppLanguage } from "@/i18n";
import { fmtDateTime, formatMessageEndTime } from "@/lib/format";
import type {
CliAppInfo,
@@ -95,6 +96,46 @@ const SLASH_COMMANDS: SlashCommand[] = [
];
describe("MessageBubble", () => {
it("copies the localized compact reply instead of the stored English text", async () => {
await setAppLanguage("zh-CN");
const writeText = vi.fn().mockResolvedValue(undefined);
Object.defineProperty(navigator, "clipboard", {
configurable: true,
value: { writeText },
});
render(<MessageBubble message={{
id: "compact-empty", role: "assistant", content: "Nothing to compact.",
compactReply: "empty", createdAt: 1,
}} />);
expect(screen.getByText("无需压缩上下文")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "复制" }));
await waitFor(() => expect(writeText).toHaveBeenCalledWith("无需压缩上下文"));
});
it("renders a compacted context notice", () => {
const message: UIMessage = {
id: "compaction-1",
role: "assistant",
content: "",
kind: "compaction",
createdAt: Date.now(),
compaction: {
id: "compact-1",
phase: "succeeded",
announce: true,
},
};
const { container } = render(<MessageBubble message={message} />);
const notice = container.querySelector("[data-context-compaction='succeeded']");
expect(notice).toHaveAttribute("role", "status");
expect(notice).toHaveAttribute("aria-live", "polite");
expect(screen.getByText("Context compacted")).toBeInTheDocument();
expect(notice).toHaveTextContent(/^Context compacted$/);
expect(notice?.querySelector(".lucide-archive")).toBeInTheDocument();
});
it("renders user messages as right-aligned pills", () => {
const message: UIMessage = {
id: "u1",