fix(webui): keep automation review stable and share complete task details

This commit is contained in:
Xubin Ren committed 2026-10-07 01:12:23 +08:00
1 parent 845afe9215
commit c932720b20
8 files changed
+107 -23

No files matched your search

+11 -3
View File
@@ -1775,9 +1775,13 @@ describe("App layout", () => {
expect(within(screen.getByRole("dialog", { name: "Daily repo check" })).getByText("Check the repo status")).toBeVisible();
const detail = within(screen.getByRole("dialog", { name: "Daily repo check" }));
expect(detail.queryByText("Release prep")).not.toBeInTheDocument();
expect(detail.getByRole("link", { name: "Open a chat" })).toHaveAttribute(
const user = userEvent.setup();
await user.click(detail.getByRole("button", { name: "More actions" }));
expect(screen.getByRole("menuitem", { name: "Open a chat" })).toHaveAttribute(
"href", "#/chat/websocket%3Achat-a",
);
await user.keyboard("{Escape}");
expect(detail.getByRole("button", { name: "More actions" })).toHaveFocus();
fireEvent.click(screen.getByRole("button", { name: "Close", exact: true }));
expect(screen.getByText("WeChat quiz")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: /WeChat quiz/ }));
@@ -1829,7 +1833,9 @@ describe("App layout", () => {
const dialog = screen.getByRole("dialog", { name: "Drink water" });
expect(within(dialog).queryByText("推特大战场")).not.toBeInTheDocument();
expect(within(dialog).queryByText("Stored title")).not.toBeInTheDocument();
expect(within(dialog).getByRole("link", { name: "Open a chat" })).toHaveAttribute(
const user = userEvent.setup();
await user.click(within(dialog).getByRole("button", { name: "More actions" }));
expect(screen.getByRole("menuitem", { name: "Open a chat" })).toHaveAttribute(
"href", "#/chat/websocket%3Alinked-chat",
);
for (const title of ["新会话名称", ""]) {
@@ -1841,10 +1847,12 @@ describe("App layout", () => {
const expected = title || "Stored title";
expect(within(sidebar).getByText(expected)).toBeInTheDocument();
expect(within(dialog).queryByText(expected)).not.toBeInTheDocument();
expect(within(dialog).getByRole("link", { name: "Open a chat" })).toHaveAttribute(
expect(screen.getByRole("menuitem", { name: "Open a chat" })).toHaveAttribute(
"href", "#/chat/websocket%3Alinked-chat",
);
}
await user.keyboard("{Escape}");
expect(within(dialog).getByRole("button", { name: "More actions" })).toHaveFocus();
expect(requestMutationSpy).not.toHaveBeenCalled();
});
@@ -31,7 +31,7 @@ it("keeps the original route until acknowledgement and saves the reviewed prompt
let finish!: () => void;
const save = vi.fn(() => new Promise<void>(resolve => { finish = resolve; }));
const user = userEvent.setup();
render(<AutomationDetailDialog {...props} job={job} onChangeChat={save} />);
const { rerender } = render(<AutomationDetailDialog {...props} job={job} onChangeChat={save} />);
await choose();
expect(save).not.toHaveBeenCalled();
expect(screen.getByText(/Previous chat:/)).toHaveTextContent("My planning");
@@ -41,8 +41,17 @@ it("keeps the original route until acknowledgement and saves the reviewed prompt
expect(save).toHaveBeenCalledWith(job, { target_id: "target", revision: "rev-1", message: "New instructions" });
expect(screen.getByRole("button", { name: "Changing…" })).toBeDisabled();
expect(screen.queryByRole("status")).not.toBeInTheDocument();
await act(async () => finish());
let refresh!: (value: AutomationChatsPayload) => void;
vi.mocked(fetchAutomationChats).mockImplementation(() => new Promise(resolve => { refresh = resolve; }));
await act(async () => {
rerender(<AutomationDetailDialog {...props} job={{ ...job, chat_binding_revision: "rev-2" }} onChangeChat={save} />);
finish();
});
expect(await screen.findByRole("status")).toHaveTextContent("Applies to future runs");
expect(screen.getByRole("combobox", { name: "Task chat" })).toHaveTextContent("Product team");
expect(screen.getByRole("combobox", { name: "Task chat" })).toBeDisabled();
await act(async () => refresh({ ...choices, current: target, revision: "rev-2" }));
expect(screen.getByRole("combobox", { name: "Task chat" })).toHaveFocus();
expect(props.onAction).not.toHaveBeenCalled();
});
@@ -71,6 +80,26 @@ it("does not send the new request to an old host and locks a pending task", asyn
expect(save).not.toHaveBeenCalled();
});
it("keeps the reviewed chat identity when refreshed choices no longer contain it", async () => {
const user = userEvent.setup();
const save = vi.fn();
const { rerender } = render(<AutomationDetailDialog {...props} job={job} onChangeChat={save} />);
await choose();
await user.type(screen.getByRole("textbox", { name: "Task instructions" }), " Reviewed");
vi.mocked(fetchAutomationChats).mockResolvedValue({
revision: "rev-2", current: { ...source, title: "Renamed planning" }, chats: [source],
});
rerender(<AutomationDetailDialog {...props} job={{ ...job, chat_binding_revision: "rev-2" }} onChangeChat={save} />);
expect(await screen.findByRole("alert")).toHaveTextContent("no longer available");
expect(screen.getByRole("combobox", { name: "New chat" })).toHaveTextContent("Product team");
expect(screen.getByText(/Previous chat:/)).toHaveTextContent("My planning");
expect(screen.getByRole("textbox", { name: "Task instructions" })).toHaveValue("Summarize the work. Reviewed");
expect(screen.getByRole("button", { name: "Confirm change" })).toBeDisabled();
expect(save).not.toHaveBeenCalled();
await user.click(screen.getByRole("button", { name: "Cancel" }));
expect(screen.getByRole("combobox", { name: "Task chat" })).toHaveTextContent("Renamed planning");
});
it("keeps the current chat visible when discovery fails and permits a retry", async () => {
const user = userEvent.setup();
vi.mocked(fetchAutomationChats).mockRejectedValueOnce(new Error("offline"));
+19 -3
View File
@@ -87,7 +87,11 @@ describe("SessionInfoPopover", () => {
});
it("manages a session task through the shared detail dialog", async () => {
const pausedJob = { ...automationJob(), enabled: false };
const boundJob = { ...automationJob(), origin: {
session_key: "websocket:chat-1", channel: "websocket", chat_id: "chat-1",
} };
vi.mocked(fetch).mockResolvedValue(automationsResponse([boundJob]));
const pausedJob = { ...boundJob, enabled: false };
requestMutation.mockResolvedValue({ jobs: [pausedJob] });
const user = userEvent.setup();
@@ -103,14 +107,26 @@ describe("SessionInfoPopover", () => {
await user.click(screen.getByRole("button", { name: "Session details" }));
await user.click(await screen.findByRole("button", { name: /Morning check/ }));
const detail = screen.getByRole("dialog", { name: "Morning check" });
await user.click(within(detail).getByRole("button", { name: "Disable" }));
await user.click(within(detail).getByRole("button", { name: "More actions" }));
await user.click(screen.getByRole("menuitem", { name: "Disable" }));
expect(requestMutation).toHaveBeenCalledWith(
"automation.disable",
{ id: "job-1" },
20_000,
);
await waitFor(() => expect(within(detail).getByRole("button", { name: "Enable" })).toBeVisible());
await waitFor(() => expect(within(detail).getByRole("button", { name: "More actions" })).toBeEnabled());
await user.click(within(detail).getByRole("button", { name: "More actions" }));
expect(screen.getByRole("menuitem", { name: "Enable" })).toBeVisible();
requestMutation.mockResolvedValue({ jobs: [boundJob] });
await user.click(screen.getByRole("menuitem", { name: "Enable" }));
expect(requestMutation).toHaveBeenLastCalledWith(
"automation.enable", { id: "job-1" }, 20_000,
);
await user.click(within(detail).getByRole("button", { name: "More actions" }));
expect(screen.getByRole("menuitem", { name: "Disable" })).toBeVisible();
await user.keyboard("{Escape}");
expect(within(detail).getByRole("button", { name: "More actions" })).toHaveFocus();
});
it("returns from the shared editor to the same task detail", async () => {