fix(webui): link automation history to the recorded chat

This commit is contained in:
Xubin Ren committed 2026-10-07 01:12:23 +08:00
1 parent c932720b20
commit 5719ed6e16
6 files changed
+42 -11

No files matched your search

@@ -41,6 +41,8 @@ is pending, so the PR remains a draft.
- Each run retains its session identity. Before the first supported move, older
run records are stamped with the known unchanged original binding. Audit result
checks still verify job, run, session, status, and file path.
History links use that run's WebUI chat key, not the task's current chat.
External runs expose no recipient key and have no WebUI chat link.
No new execution path, agent-loop policy, dependencies, or separate CSS system
are added. The dialog uses the existing Select, Dialog, Button, Textarea, channel
@@ -56,8 +56,9 @@ export function AutomationRunDialog({ token = "", job, run, locale, open, onOpen
: run.status === "skipped" ? t("settings.automations.skipped")
: t("settings.automations.calendar.recorded");
const duration = run.duration_ms;
const chatHref = job.origin?.channel === "websocket" && job.origin.session_key
? `#/chat/${encodeURIComponent(job.origin.session_key)}` : null;
const chatKey = run.webui_session_key !== undefined ? run.webui_session_key
: job.origin?.channel === "websocket" ? job.origin.session_key : null;
const chatHref = chatKey ? `#/chat/${encodeURIComponent(chatKey)}` : null;
return (
<Dialog open={open} onOpenChange={onOpenChange}>
+1
View File
@@ -252,6 +252,7 @@ export interface SessionAutomationJob {
status: "ok" | "error" | "skipped" | string;
duration_ms?: number;
error?: string | null;
webui_session_key?: string | null; // null: external chat; absent: older host.
}>;
};
origin?: {
@@ -323,6 +323,22 @@ describe("Automation task list and detail sheet", () => {
expect(within(screen.getByRole("dialog", { name: "PR watch" })).getByRole("button", { name: "Edit" })).toBeVisible();
});
it.each(["websocket:original-chat", null])("uses the recorded chat for a historical run (%s), not the task's current chat", async (webuiSessionKey) => {
const user = userEvent.setup();
render(<Harness payload={{ jobs: [{ ...task, state: { run_history: [{
run_at_ms: now - 60_000, status: "ok", webui_session_key: webuiSessionKey,
}] } }] }} />);
await user.click(screen.getByRole("button", { name: /PR watch.*Completed/ }));
const dialog = within(screen.getByRole("dialog", { name: "PR watch" }));
if (webuiSessionKey) {
expect(dialog.getByRole("link", { name: "Open a chat" })).toHaveAttribute(
"href", "#/chat/websocket%3Aoriginal-chat",
);
} else {
expect(dialog.queryByRole("link", { name: "Open a chat" })).not.toBeInTheDocument();
}
});
it("keeps the selected historical result across refreshes and restores focus when its day button disappears", async () => {
const user = userEvent.setup();
const start = new Date(new Date(now).setHours(8, 0, 0, 0)).getTime();