fix(webui): keep completed subagent results with loaded prompts (#6630)
This commit is contained in:
1 parent
e6b0aec2a8
commit
c37af82e3f
19 files changed
+157
-148
No files matched your search
@@ -3,7 +3,7 @@ import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { SubagentTaskDock } from "@/components/thread/SubagentTaskDock";
|
||||
import { SubagentThreadMessages, useHasSubagentResults } from "@/components/thread/SubagentTaskResults";
|
||||
import { SubagentThreadMessages } from "@/components/thread/SubagentTaskResults";
|
||||
import { SubagentTasksProvider } from "@/components/thread/SubagentTasks";
|
||||
import { setAppLanguage } from "@/i18n";
|
||||
import { DEFAULT_LOCAL_PREFS, LOCAL_PREFS_STORAGE_KEY, writeLocalPreferences } from "@/lib/local-preferences";
|
||||
@@ -47,9 +47,6 @@ function emitTask(snapshot: SubagentTaskSnapshot) {
|
||||
chatHandlers.forEach((handler) => handler({ event: "subagent_task", chat_id: "a", task: snapshot }));
|
||||
});
|
||||
}
|
||||
function ResultsPresence() {
|
||||
return <output data-testid="has-results">{useHasSubagentResults() ? "yes" : "no"}</output>;
|
||||
}
|
||||
function layout({ threadMessages = messages, sessionKey = "websocket:a", liveEvents = true, historyEnabled = false, onActivityToggle }: {
|
||||
threadMessages?: UIMessage[];
|
||||
sessionKey?: string;
|
||||
@@ -58,13 +55,12 @@ function layout({ threadMessages = messages, sessionKey = "websocket:a", liveEve
|
||||
onActivityToggle?: () => void;
|
||||
} = {}) {
|
||||
return <SubagentTasksProvider client={client} sessionKey={sessionKey} token="tok" enabled liveEvents={liveEvents} historyEnabled={historyEnabled}>
|
||||
<ResultsPresence />
|
||||
<div data-testid="messages"><SubagentThreadMessages messages={threadMessages} onActivityToggle={onActivityToggle} /></div>
|
||||
<div data-testid="composer" className="thread-composer-stack"><SubagentTaskDock /><textarea aria-label="Message" /></div>
|
||||
</SubagentTasksProvider>;
|
||||
}
|
||||
function summary(region: HTMLElement) {
|
||||
return within(region).getByRole("button", { name: /^(Subtasks|Other tasks) (Completed|Finished):/ });
|
||||
return within(region).getByRole("button", { name: /^Subtasks (Completed|Finished):/ });
|
||||
}
|
||||
function expectBefore(first: Node, second: Node) {
|
||||
expect(first.compareDocumentPosition(second) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
@@ -99,14 +95,12 @@ describe("subagent result archives", () => {
|
||||
expect(await screen.findByTestId("subagent-task-dock-trigger")).toHaveTextContent("Running: 3");
|
||||
const transcript = screen.getByTestId("messages");
|
||||
expect(transcript.querySelector("[data-subagent-results]")).toBeNull();
|
||||
expect(screen.getByTestId("has-results")).toHaveTextContent("no");
|
||||
expect(transcript).not.toHaveTextContent("Config check");
|
||||
expect(transcript).not.toHaveTextContent("Waiting check");
|
||||
expect(transcript).not.toHaveTextContent("Stopping check");
|
||||
|
||||
emitTask(task({ revision: 2, result: "Full findings stay in details" }));
|
||||
const archive = screen.getByRole("region", { name: "Subtasks" });
|
||||
expect(screen.getByTestId("has-results")).toHaveTextContent("yes");
|
||||
expect(summary(archive)).toHaveTextContent("Completed: 1");
|
||||
expect(summary(archive).querySelector("img")).toHaveAttribute("src", "/brand/nanobot_mark.svg");
|
||||
expect(summary(archive).querySelector("img")).toHaveAttribute("alt", "");
|
||||
@@ -237,7 +231,7 @@ describe("subagent result archives", () => {
|
||||
expect(screen.getByTestId("messages").querySelectorAll("[data-subagent-id]")).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("keeps unmatched terminal work before the chat and preserves open details when its source is loaded", async () => {
|
||||
it("shows older results only with their loaded prompt and preserves details through history navigation", async () => {
|
||||
vi.mocked(fetch).mockImplementation(async () => response([
|
||||
task({ task_id: "older", label: "Earlier check", origin_turn_id: "older-turn", origin_message_id: "older-prompt",
|
||||
result: "## Earlier findings\n\nThe saved result remains available" }),
|
||||
@@ -246,27 +240,26 @@ describe("subagent result archives", () => {
|
||||
]));
|
||||
const user = userEvent.setup();
|
||||
const view = render(layout());
|
||||
const unlinked = await screen.findByRole("region", { name: "Other tasks" });
|
||||
expectBefore(unlinked, screen.getByText("Inspect config"));
|
||||
expect(summary(unlinked)).toHaveAttribute("aria-expanded", "false");
|
||||
await user.click(summary(unlinked));
|
||||
expect(within(unlinked).getByText("These tasks have no matching request in the displayed messages.")).toBeVisible();
|
||||
expect(unlinked).not.toHaveTextContent("Unlinked live check");
|
||||
await user.click(within(unlinked).getByRole("button", { name: "Earlier check Completed 4s" }));
|
||||
const detail = screen.getByRole("dialog", { name: "Earlier check" });
|
||||
expect(await within(detail).findByRole("heading", { name: "Earlier findings" })).toBeVisible();
|
||||
|
||||
view.rerender(layout({ threadMessages: [
|
||||
expect(await screen.findByTestId("subagent-task-dock-trigger")).toHaveTextContent("Running: 1");
|
||||
expect(screen.getByTestId("messages").querySelector("[data-subagent-results]")).toBeNull();
|
||||
const olderMessages: UIMessage[] = [
|
||||
{ id: "older-prompt", role: "user", content: "Inspect earlier work", turnId: "older-turn", createdAt: 99_000 },
|
||||
...messages,
|
||||
] }));
|
||||
expect(screen.getByRole("dialog", { name: "Earlier check" })).toBe(detail);
|
||||
];
|
||||
view.rerender(layout({ threadMessages: olderMessages }));
|
||||
let linked = screen.getByRole("region", { name: "Subtasks" });
|
||||
expect(summary(linked)).toHaveAttribute("aria-expanded", "false");
|
||||
await user.click(summary(linked));
|
||||
await user.click(within(linked).getByRole("button", { name: "Earlier check Completed 4s" }));
|
||||
const detail = screen.getByRole("dialog", { name: "Earlier check" });
|
||||
expect(await within(detail).findByRole("heading", { name: "Earlier findings" })).toBeVisible();
|
||||
view.rerender(layout());
|
||||
expect(screen.getByTestId("messages").querySelector("[data-subagent-results]")).toBeNull();
|
||||
expect(within(detail).getByText("The saved result remains available")).toBeVisible();
|
||||
view.rerender(layout({ threadMessages: olderMessages }));
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.queryByRole("region", { name: "Other tasks" })).not.toBeInTheDocument();
|
||||
const linked = screen.getByRole("region", { name: "Subtasks" });
|
||||
const header = summary(linked);
|
||||
expect(header).toHaveAttribute("aria-expanded", "true");
|
||||
linked = screen.getByRole("region", { name: "Subtasks" });
|
||||
expect(summary(linked)).toHaveAttribute("aria-expanded", "true");
|
||||
await waitFor(() => expect(within(linked).getByRole("button", { name: "Earlier check Completed 4s" })).toHaveFocus());
|
||||
expect(screen.getByTestId("messages").querySelectorAll('[data-subagent-id="older"]')).toHaveLength(1);
|
||||
expectBefore(screen.getByText("Inspect earlier work"), linked);
|
||||
@@ -291,7 +284,7 @@ describe("subagent result archives", () => {
|
||||
expect(within(replayed).getByRole("button", { name: "Config check Completed 4s" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("preserves each disclosure through other task outcomes, history prepends and Activity preference changes", async () => {
|
||||
it("preserves disclosure through off-page task outcomes, history prepends and Activity preference changes", async () => {
|
||||
act(() => { writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, activityMode: "expanded" }); });
|
||||
vi.mocked(fetch).mockImplementation(async () => response([
|
||||
task(),
|
||||
@@ -309,9 +302,7 @@ describe("subagent result archives", () => {
|
||||
emitTask(task({ task_id: "other", label: "Other check", revision: 2, state: "error", error: "Other work failed",
|
||||
origin_message_id: null, origin_turn_id: null, created_at: 102 }));
|
||||
expect(summary(archive)).toHaveAttribute("aria-expanded", "true");
|
||||
const unlinked = screen.getByRole("region", { name: "Other tasks" });
|
||||
expect(summary(unlinked)).toHaveAttribute("aria-expanded", "false");
|
||||
await user.click(summary(unlinked));
|
||||
expect(screen.getByTestId("messages").querySelector('[data-subagent-id="other"]')).toBeNull();
|
||||
view.rerender(layout({ threadMessages: [
|
||||
{ id: "prepended", role: "user", content: "Earlier request from this turn", turnId: "turn-a", createdAt: 99_000 },
|
||||
...messages,
|
||||
@@ -321,7 +312,6 @@ describe("subagent result archives", () => {
|
||||
expect(within(retained).getByRole("button", { name: "Config check Completed 4s" })).toBeVisible();
|
||||
expect([...retained.querySelectorAll("[data-subagent-id]")].map((row) => row.getAttribute("data-subagent-id")))
|
||||
.toEqual(["task-1", "second"]);
|
||||
expect(summary(screen.getByRole("region", { name: "Other tasks" }))).toHaveAttribute("aria-expanded", "true");
|
||||
await user.click(summary(retained));
|
||||
act(() => { writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, activityMode: "expanded" }); });
|
||||
expect(summary(retained)).toHaveAttribute("aria-expanded", "false");
|
||||
|
||||
@@ -138,9 +138,7 @@ describe("session-owned task UI", () => {
|
||||
const archive = await openArchive(user);
|
||||
expect(taskIds(archive)).toEqual(older.map(saved => saved.task_id));
|
||||
expect(within(archive).queryByRole("button", { name: /Config check Running/ })).not.toBeInTheDocument();
|
||||
const other = await openArchive(user, "Other tasks");
|
||||
await user.click(within(other).getByRole("button", { name: /Earlier check Completed/ }));
|
||||
expect(within(screen.getByRole("dialog", { name: "Earlier check" })).getByText("Saved result")).toBeVisible();
|
||||
expect(taskIds(screen.getByTestId("messages"))).toEqual(older.map(saved => saved.task_id));
|
||||
expect(requestMutation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -901,7 +899,7 @@ describe("session-owned task UI", () => {
|
||||
expect(screen.queryByTestId("subagent-task-dock")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps legacy work separate after refresh and preserves its disclosure through local history prepends", async () => {
|
||||
it("keeps unmatched legacy work out of the transcript through refresh and unrelated history prepends", async () => {
|
||||
vi.mocked(fetch).mockImplementation(async () => response([
|
||||
task({ task_id: "legacy", revision: 0, label: "Nanjing weather", state: "done", completed_at: 102,
|
||||
origin_turn_id: "websocket:a:1791046873588004336", result: "## Nanjing\n\n- **Rain**" }),
|
||||
@@ -910,63 +908,20 @@ describe("session-owned task UI", () => {
|
||||
const user = userEvent.setup();
|
||||
const view = render(layout());
|
||||
await screen.findByTestId("subagent-task-dock-trigger");
|
||||
const otherWork = screen.getByRole("region", { name: "Other tasks" });
|
||||
const header = within(otherWork).getByRole("button", { name: /Other tasks/ });
|
||||
expect(header).toHaveAttribute("aria-expanded", "false");
|
||||
expect(otherWork.compareDocumentPosition(screen.getByText("Inspect config")) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(screen.queryByRole("region", { name: "Subtasks" })).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId("messages")).not.toHaveTextContent("Config check");
|
||||
await user.click(header);
|
||||
expect(within(otherWork).getByText("These tasks have no matching request in the displayed messages.")).toBeVisible();
|
||||
await user.click(within(otherWork).getByRole("button", { name: /Nanjing weather Completed/ }));
|
||||
const detail = screen.getByRole("dialog", { name: "Nanjing weather" });
|
||||
expect(within(detail).getByRole("heading", { name: "Nanjing" })).toBeVisible();
|
||||
expect(within(detail).getByRole("list")).toHaveTextContent("Rain");
|
||||
await user.keyboard("{Escape}");
|
||||
expect(taskIds(await openTaskList(user))).toEqual(["task-1"]);
|
||||
expect(taskIds(screen.getByTestId("messages"))).toEqual([]);
|
||||
view.rerender(layout({ threadMessages: [
|
||||
{ id: "cached-prompt", role: "user", content: "Earlier cached prompt", createdAt: 99_000 },
|
||||
...messages,
|
||||
] }));
|
||||
const expanded = screen.getByRole("region", { name: "Other tasks" });
|
||||
expect(within(expanded).getByRole("button", { name: /Other tasks/ })).toHaveAttribute("aria-expanded", "true");
|
||||
expect(within(expanded).getByRole("button", { name: /Nanjing weather Completed/ })).toBeVisible();
|
||||
expect(taskIds(screen.getByTestId("messages"))).toEqual([]);
|
||||
view.unmount();
|
||||
render(layout());
|
||||
const restored = await screen.findByRole("region", { name: "Other tasks" });
|
||||
expect(within(restored).getByRole("button", { name: /Other tasks/ })).toHaveAttribute("aria-expanded", "false");
|
||||
expect(restored.compareDocumentPosition(screen.getByText("Inspect config")) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(taskIds(await openTaskList(user))).toEqual(["task-1"]);
|
||||
expect(taskIds(screen.getByTestId("messages"))).toEqual([]);
|
||||
expect(requestMutation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reattaches archived work when its prompt loads without duplicating it, closing details or losing focus", async () => {
|
||||
vi.mocked(fetch).mockImplementation(async () => response([
|
||||
task({ task_id: "older", label: "Earlier check", state: "done", completed_at: 102, result: "Earlier finding", origin_turn_id: "older-turn", origin_message_id: "older-prompt" }),
|
||||
task({ created_at: 200 }),
|
||||
]));
|
||||
const user = userEvent.setup();
|
||||
const view = render(layout());
|
||||
const otherWork = await openArchive(user, "Other tasks");
|
||||
await user.click(within(otherWork).getByRole("button", { name: /Earlier check Completed/ }));
|
||||
const detail = screen.getByRole("dialog", { name: "Earlier check" });
|
||||
view.rerender(layout({ threadMessages: [
|
||||
{ id: "older-prompt", role: "user", content: "Inspect earlier work", turnId: "older-turn", createdAt: 99_000 },
|
||||
...messages,
|
||||
] }));
|
||||
expect(detail).toBeVisible();
|
||||
expect(within(detail).getByText("Earlier finding")).toBeVisible();
|
||||
await user.keyboard("{Escape}");
|
||||
expect(screen.queryByRole("region", { name: "Other tasks" })).not.toBeInTheDocument();
|
||||
const archive = screen.getByRole("region", { name: "Subtasks" });
|
||||
const summary = within(archive).getByRole("button", { name: /Subtasks/ });
|
||||
expect(summary).toHaveAttribute("aria-expanded", "true");
|
||||
expect(taskIds(screen.getByTestId("messages"))).toEqual(["older"]);
|
||||
expect(screen.getByText("Inspect earlier work").compareDocumentPosition(archive) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(screen.getByText("Inspect config").compareDocumentPosition(archive) & Node.DOCUMENT_POSITION_PRECEDING).toBeTruthy();
|
||||
const row = within(archive).getByRole("button", { name: /Earlier check Completed/ });
|
||||
await waitFor(() => expect(row).toHaveFocus());
|
||||
expect(row).toBeVisible();
|
||||
});
|
||||
|
||||
it("merges live work before the initial read without polling or rolling back completed work", async () => {
|
||||
let resolveRead!: (value: Response) => void;
|
||||
vi.mocked(fetch).mockImplementationOnce(() => new Promise((resolve) => { resolveRead = resolve; }));
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
unitKeysForDisplay,
|
||||
} from "@/components/thread/ThreadMessages";
|
||||
import { preloadMarkdownText } from "@/components/MarkdownText";
|
||||
import { projectThreadEvents } from "@/lib/thread-event-projection";
|
||||
import type { UIMessage } from "@/lib/types";
|
||||
|
||||
// These DOM tests exercise disclosure/source contracts; the real shadow renderer runs in browser tests.
|
||||
@@ -1179,6 +1180,40 @@ describe("ThreadMessages", () => {
|
||||
expect(dividerIndex).toBe(branchPromptIndex - 1);
|
||||
});
|
||||
|
||||
it("hides redundant task creation while retaining failed creates and other tool activity", async () => {
|
||||
const messages = projectThreadEvents([
|
||||
{ event: "user_message", chat_id: "a", starts_turn: true, turn_id: "turn", text: "Inspect" },
|
||||
{ event: "message", chat_id: "a", turn_id: "turn", kind: "progress", text: "Tools", tool_events: [
|
||||
{ call_id: "create", name: "subagent", phase: "end", arguments: { action: "create" } },
|
||||
{ call_id: "failed", name: "subagent", phase: "error", arguments: { action: "create" }, error: "Creation failed" },
|
||||
{ call_id: "check", name: "subagent", phase: "end", arguments: { action: "check" } },
|
||||
{ call_id: "exec", name: "exec", phase: "end", arguments: { command: "pwd" } },
|
||||
] },
|
||||
{ event: "message", chat_id: "a", turn_id: "turn", text: "Done" },
|
||||
]);
|
||||
render(<ThreadMessages messages={messages} />);
|
||||
openAssistantBlockMenu();
|
||||
fireEvent.click(await screen.findByRole("button", { name: /worked/i }));
|
||||
expect(screen.getByText(/could not create subtask/i)).toBeVisible();
|
||||
expect(screen.getByText(/subtask status retrieved/i)).toBeVisible();
|
||||
expect(screen.getByText(/ran command/i)).toBeVisible();
|
||||
expect(screen.queryByText(/^subtask created/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the fork boundary after a hidden subagent create activity", () => {
|
||||
const messages: UIMessage[] = [
|
||||
{ id: "original", role: "user", content: "original", createdAt: 1 },
|
||||
{ id: "created", role: "tool", kind: "trace", content: 'subagent({"action":"create"})',
|
||||
traces: ['subagent({"action":"create"})'], createdAt: 2,
|
||||
toolEvents: [{ call_id: "call-1", name: "subagent", phase: "end", arguments: { action: "create" } }] },
|
||||
{ id: "branch", role: "user", content: "branch prompt", createdAt: 3 },
|
||||
];
|
||||
render(<ThreadMessages messages={messages} forkBoundaryMessageCount={2} />);
|
||||
const divider = screen.getByText("Forked from history");
|
||||
expect(divider.compareDocumentPosition(screen.getByText("branch prompt")) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(screen.queryByText(/subtask created/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps turn unit keys stable across replayed ids and mutable turn sequence", () => {
|
||||
const liveUnits = buildDisplayUnits([
|
||||
{ id: "optimistic-user", role: "user", content: "go", turnId: "turn-1", turnPhase: "user", turnSeq: 0, createdAt: 1 },
|
||||
|
||||
Reference in new issue
Block a user