fix(webui): keep restored waiting messages manual (NAN-275) (#6393)
This commit is contained in:
1 parent
abfe510ce1
commit
7dfeff9ddf
6 files changed
+179
-6
No files matched your search
@@ -32,6 +32,7 @@ import { SidebarActivityFixture } from "./sidebar-activity-fixture";
|
||||
import { HistoryHydrationFixture } from "./history-hydration-fixture";
|
||||
import { IdleCompactionFixture, installIdleCompactionApi } from "./idle-compaction-fixture";
|
||||
import { FileEditPathFixture } from "./file-edit-path-fixture";
|
||||
import { QueuedGuidanceFixture } from "./queued-guidance-fixture";
|
||||
|
||||
const history: UIMessage[] = [
|
||||
{ id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 },
|
||||
@@ -173,7 +174,9 @@ if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi()
|
||||
if (parameters.get("case") === "idle-compaction") installIdleCompactionApi();
|
||||
await initializeI18n();
|
||||
createRoot(document.getElementById("root")!).render(<TooltipProvider>
|
||||
{parameters.get("case") === "file-edit-path"
|
||||
{parameters.get("case") === "queued-guidance"
|
||||
? <QueuedGuidanceFixture />
|
||||
: parameters.get("case") === "file-edit-path"
|
||||
? <FileEditPathFixture />
|
||||
: parameters.get("case") === "answer-order"
|
||||
? <AnswerOrderFixture />
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
import type { SendAttachment, SendOptions } from "@/hooks/useNanobotStream";
|
||||
|
||||
export function QueuedGuidanceFixture() {
|
||||
const [away, setAway] = useState(false);
|
||||
const [completed, setCompleted] = useState(new URLSearchParams(location.search).has("complete"));
|
||||
const [sent, setSent] = useState<Array<{ text: string; images?: SendAttachment[]; options?: SendOptions }>>([]);
|
||||
return <main className="mx-auto max-w-3xl p-4">
|
||||
<div className="mb-4 flex flex-wrap gap-4">
|
||||
<button onClick={() => setAway(!away)}>Switch topic</button>
|
||||
<button onClick={() => setCompleted(true)}>Complete original reply</button>
|
||||
</div>
|
||||
{away ? <p>Another topic</p> : <ThreadComposer
|
||||
pendingQueueKey="queued-fixture"
|
||||
isStreaming={!completed}
|
||||
activeTurnId={completed ? null : "turn-a"}
|
||||
completedTurnIds={completed ? ["turn-a"] : []}
|
||||
onStop={() => setCompleted(true)}
|
||||
onSend={(text, images, options) => {
|
||||
setSent((current) => [...current, { text, images, options }]);
|
||||
return true;
|
||||
}}
|
||||
/>}
|
||||
<output aria-label="Submitted messages">{JSON.stringify(sent)}</output>
|
||||
</main>;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
|
||||
const fixture = "/browser/fixture.html?case=queued-guidance";
|
||||
const storageKey = "nanobot.webui.composerQueuedGuidance.v1:queued-fixture";
|
||||
|
||||
async function queue(page: Page, text = "Confirm this instruction") {
|
||||
const input = page.getByRole("textbox", { name: "Message input", exact: true });
|
||||
await input.fill(text);
|
||||
await input.press("Enter");
|
||||
await expect(page.getByRole("group", { name: "Waiting to send" })).toContainText(text);
|
||||
}
|
||||
|
||||
for (const width of [1440, 390]) {
|
||||
test(`a new page retains waiting content without executing it (${width}px)`, async ({ page }) => {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await page.goto(fixture);
|
||||
await queue(page);
|
||||
await page.goto(`${fixture}&complete`);
|
||||
await expect(page.getByRole("group", { name: "Waiting to send" })).toContainText("Confirm this instruction");
|
||||
await expect(page.getByLabel("Submitted messages")).toHaveText("[]");
|
||||
await page.getByRole("button", { name: "Send now", exact: true }).click();
|
||||
await expect(page.getByLabel("Submitted messages")).toHaveText('[{"text":"Confirm this instruction"}]');
|
||||
await expect(page.getByRole("group", { name: "Waiting to send" })).toHaveCount(0);
|
||||
});
|
||||
}
|
||||
|
||||
test("switching topics in the live page retains one automatic send", async ({ page }) => {
|
||||
await page.goto(fixture);
|
||||
await queue(page);
|
||||
await page.getByRole("button", { name: "Switch topic" }).click();
|
||||
await page.getByRole("button", { name: "Complete original reply" }).click();
|
||||
await page.getByRole("button", { name: "Switch topic" }).click();
|
||||
await expect(page.getByLabel("Submitted messages")).toHaveText('[{"text":"Confirm this instruction"}]');
|
||||
await expect(page.getByRole("group", { name: "Waiting to send" })).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("leaving and returning through browser history requires manual delivery", async ({ page }) => {
|
||||
await page.goto(fixture);
|
||||
await queue(page);
|
||||
await page.goto("about:blank");
|
||||
await page.goBack();
|
||||
await page.getByRole("button", { name: "Complete original reply" }).click();
|
||||
await expect(page.getByRole("group", { name: "Waiting to send" })).toContainText("Confirm this instruction");
|
||||
await expect(page.getByLabel("Submitted messages")).toHaveText("[]");
|
||||
await page.getByRole("button", { name: "Send now", exact: true }).click();
|
||||
await expect(page.getByLabel("Submitted messages")).toHaveText('[{"text":"Confirm this instruction"}]');
|
||||
});
|
||||
|
||||
test("legacy completed-turn drafts preserve every field until an explicit send", async ({ page }) => {
|
||||
await page.goto(fixture);
|
||||
const draft = {
|
||||
id: "queued-prompt-1792147773397-1", text: "Remember @alpha", autoAfterTurnId: "turn-a",
|
||||
quotedContext: "Original quote", sessionMentions: [{ name: "alpha", title: "Alpha", session_key: "websocket:alpha" }],
|
||||
images: [{ dataUrl: "data:text/plain;base64,aGVsbG8=", kind: "file", name: "notes.txt" }],
|
||||
};
|
||||
await page.evaluate(({ key, value }) => localStorage.setItem(key, JSON.stringify([value])), { key: storageKey, value: draft });
|
||||
await page.goto(`${fixture}&complete`);
|
||||
await expect(page.getByRole("group", { name: "Waiting to send" })).toContainText("Remember @alpha");
|
||||
await expect(page.getByLabel("Submitted messages")).toHaveText("[]");
|
||||
await page.getByRole("button", { name: "Send now", exact: true }).click();
|
||||
const sent = JSON.parse(await page.getByLabel("Submitted messages").textContent() ?? "null");
|
||||
expect(sent).toEqual([{
|
||||
text: draft.text,
|
||||
images: [{ media: { data_url: draft.images[0].dataUrl, name: "notes.txt" }, preview: { kind: "file", url: draft.images[0].dataUrl, name: "notes.txt" } }],
|
||||
options: { quotedContext: draft.quotedContext, sessionMentions: draft.sessionMentions },
|
||||
}]);
|
||||
});
|
||||
Reference in new issue
Block a user