fix(goal): make cancellation a user-only control (#6667)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-14 23:48:13 +08:00
1 parent c927808aff
commit 12a86eaa86
33 files changed
+641 -63

No files matched your search

+8 -3
View File
@@ -52,7 +52,7 @@ import { AttachmentLayoutFixture } from "./attachment-layout-fixture";
import { LoadedSessionSearchFixture } from "./loaded-session-search-fixture";
import { AppearanceFixture } from "./appearance-fixture";
import { ContinuityFixture } from "./continuity-fixture";
import { SessionTransitionFixture } from "./session-transition-fixture";
import { installSessionTransitionPreviewApi, SessionTransitionFixture } from "./session-transition-fixture";
import { installSubagentDockApi, SubagentDockFixture } from "./subagent-dock-fixture";
const history: UIMessage[] = [
@@ -236,13 +236,18 @@ if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi()
if (parameters.get("case") === "tools-catalog") installToolsCatalogPreviewApi();
if (parameters.get("case") === "idle-compaction") installIdleCompactionApi();
if (parameters.get("case") === "subagent-dock") installSubagentDockApi();
if (parameters.get("case") === "session-transition" && parameters.has("preview")) installSessionTransitionPreviewApi();
await initializeI18n();
if (parameters.get("case") === "activity-wheel") await setAppLanguage("zh-CN");
if ((parameters.get("case") === "appearance" || historyPreview) && parameters.has("lang")) {
if ((["appearance", "session-transition"].includes(parameters.get("case") ?? "") || historyPreview) && parameters.has("lang")) {
await setAppLanguage(normalizeLocale(parameters.get("lang")));
}
const widePreview = new URL(location.href);
widePreview.searchParams.delete("narrow");
createRoot(document.getElementById("root")!).render(<TooltipProvider>
{parameters.get("case") === "session-transition"
{parameters.get("case") === "session-transition" && parameters.has("narrow")
? <iframe title="Narrow goal preview" src={widePreview.href} style={{ display: "block", margin: "0 auto", height: "100dvh", width: "100%", maxWidth: 390, border: 0 }} />
: parameters.get("case") === "session-transition"
? <SessionTransitionFixture />
: parameters.get("case") === "continuity"
? <ContinuityFixture />
+61 -9
View File
@@ -9,22 +9,65 @@ import { ThreadMessageCache } from "@/lib/thread-message-cache";
import { ClientProvider } from "@/providers/ClientProvider";
import { createStreamClient } from "@/tests/stream-client";
const { client, receive } = createStreamClient();
const goalSummary = new URLSearchParams(location.search).has("long-goal")
? "完成会话切换和目标状态界面的优化,统一明暗主题下的布局、文字、图标与交互,验证桌面和窄屏体验后提交代码并更新发布说明"
: "Keep the composer stable";
for (const topic of ["goal", "together", "blocked"]) {
receive({ event: "goal_state", chat_id: topic, goal_state: {
active: topic !== "blocked", status: topic === "blocked" ? "blocked" : "active",
ui_summary: goalSummary,
objective: "Verify session navigation with real components.\n\n" + "- Preserve drafts, reading position and usable header controls.\n".repeat(6),
...(topic === "blocked" ? { recap: "Waiting for a workspace permission decision." } : {}),
} });
export function installSessionTransitionPreviewApi() {
const original = window.fetch.bind(window);
window.fetch = async (input, init) => {
const url = new URL(input instanceof Request ? input.url : String(input), location.href);
if (url.origin !== location.origin || !url.pathname.startsWith("/api/")) return original(input, init);
if (url.pathname === "/api/commands") return Response.json({ commands: [
{ command: "/cancel_goal", title: "Cancel goal", description: "Cancel the goal", icon: "square", lifecycle: "side_channel", accepts_args: false },
] });
if (url.pathname.endsWith("/subagents")) return Response.json({ tasks: [] });
if (url.pathname.endsWith("/webui-thread")) {
const topic = decodeURIComponent(url.pathname.split("/")[3]).split(":")[1];
return Response.json({ schemaVersion: 3, projection: "events", events: [
{ event: "user_message", chat_id: topic, projection_id: `${topic}-prompt`, turn_id: "fixture-turn", starts_turn: true, text: `Question for ${topic}` },
{ event: "message", chat_id: topic, projection_id: `${topic}-answer`, turn_id: "fixture-turn", text: `Answer for ${topic}\n\n` + "A long conversation stays at its reading position.\n\n".repeat(25) },
] });
}
return Response.json({}, { status: 404 });
};
}
export function SessionTransitionFixture() {
const [pendingCancel, setPendingCancel] = useState<{ chat_id: string; turn_id: string } | null>(null);
const [{ client, receive, socket }] = useState(() => {
const preview = createStreamClient((data) => {
const frame = JSON.parse(data);
if (frame.content === "/cancel_goal") setPendingCancel({ chat_id: frame.chat_id, turn_id: frame.turn_id });
});
for (const topic of ["goal", "together", "blocked"]) {
preview.receive({ event: "goal_state", chat_id: topic, goal_state: {
active: topic !== "blocked", status: topic === "blocked" ? "blocked" : "active",
ui_summary: goalSummary,
objective: "Verify session navigation with real components.\n\n" + "- Preserve drafts, reading position and usable header controls.\n".repeat(6),
...(topic === "blocked" ? { recap: "Waiting for a workspace permission decision." } : {}),
} });
}
if (new URLSearchParams(location.search).has("preview")) {
const send = preview.client.sendSystemCommand.bind(preview.client);
preview.client.sendSystemCommand = (chatId, command) => send(chatId, command, 600_000);
}
return preview;
});
const [online, setOnline] = useState(true);
const cancelPreview = new URLSearchParams(location.search).has("cancel-goal");
const finishCancel = (success: boolean) => {
if (!pendingCancel) return;
if (success) {
if (client.getGoalState(pendingCancel.chat_id)?.active) {
receive({ event: "turn_end", chat_id: pendingCancel.chat_id, turn_id: "live-turn" });
}
receive({ event: "goal_state", chat_id: pendingCancel.chat_id, goal_state: { active: false } });
}
receive({ event: "message", ...pendingCancel, text: success ? "Goal cancelled." : "Could not save goal cancellation." });
setPendingCancel(null);
};
const workbench = new URLSearchParams(location.search).has("workbench");
const [topic, setTopic] = useState(workbench ? "goal" : "plain");
const [topic, setTopic] = useState(new URLSearchParams(location.search).get("topic") ?? (workbench ? "goal" : "plain"));
const [cache] = useState(() => new ThreadMessageCache(() => false));
const [drafts] = useState(() => new ComposerDraftStore());
const dark = new URLSearchParams(location.search).has("dark");
@@ -41,6 +84,15 @@ export function SessionTransitionFixture() {
receive({ event: "goal_status", chat_id: topic, turn_id: "live-turn", status: "running", started_at: Date.now() / 1000 });
receive({ event: "delta", chat_id: topic, turn_id: "live-turn", stream_id: "live", text: "Live reply continues" });
}}>Stream reply</button>
{cancelPreview ? <>
<button disabled={!pendingCancel} onClick={() => finishCancel(true)}>Confirm cancellation</button>
<button disabled={!pendingCancel} onClick={() => finishCancel(false)}>Fail cancellation</button>
<button onClick={() => {
if (online) client.close();
else { client.connect(); socket.onopen?.(); }
setOnline(!online);
}}>{online ? "Disconnect" : "Reconnect"}</button>
</> : null}
</nav>
{workbench ? <PaneWorkbench
panes={["goal", "blocked"].map(key => ({ key, title: key }))} activePaneKey={topic} layout="columns"
+26
View File
@@ -67,6 +67,32 @@ test("blocked goal remains visible until cleared and survives session switching"
await expect(page.locator(".goal-island")).toHaveCount(0);
});
for (const { width, topic } of [{ width: 1440, topic: "goal" }, { width: 390, topic: "blocked" }]) {
test(`goal cancellation is reachable at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 844 });
await installPreview(page);
await page.goto("/browser/fixture.html?case=session-transition&cancel-goal");
await select(page, topic);
await page.getByRole("textbox").fill("Keep this draft");
await page.getByRole("button", { name: "Show full goal" }).click();
const dialog = page.getByRole("dialog", { name: "Goal", exact: true });
await dialog.evaluate(async el => { await Promise.all(el.getAnimations({ subtree: true }).map(animation => animation.finished)); });
const cancel = dialog.getByRole("button", { name: "Cancel goal", exact: true });
const panelBounds = await dialog.boundingBox();
const buttonBounds = await cancel.boundingBox();
expect(buttonBounds!.y).toBeGreaterThanOrEqual(panelBounds!.y);
expect(buttonBounds!.y + buttonBounds!.height).toBeLessThanOrEqual(panelBounds!.y + panelBounds!.height);
await cancel.focus();
await page.keyboard.press("Enter");
const confirm = page.getByRole("button", { name: "Confirm cancellation", exact: true });
await expect(confirm).toBeEnabled();
await confirm.click();
await expect(page.locator(".goal-island")).toHaveCount(0);
await expect(page.getByRole("textbox")).toHaveValue("Keep this draft");
expect(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth)).toBe(false);
});
}
for (const viewport of [{ width: 390, height: 844 }, { width: 844, height: 390 }]) {
test(`long goal summaries leave the objective readable at ${viewport.width}x${viewport.height}`, async ({ page }) => {
await page.setViewportSize(viewport);