Skip to content

Automate browser based workflows with AI

Revert defineProperty export helper to plain assignment in injected-script wrapper (SKY-12875) (#7831)

Aaron Perez311e045a6366
diff --git a/skyvern-frontend/src/components/StatusBadge.test.tsx b/skyvern-frontend/src/components/StatusBadge.test.tsx
index 5889b4b50..fa21476df 100644
--- a/skyvern-frontend/src/components/StatusBadge.test.tsx
+++ b/skyvern-frontend/src/components/StatusBadge.test.tsx
@@ -66,13 +66,21 @@ describe("StatusBadge collapsible", () => {
expect(label.classList.contains("md:not-sr-only")).toBe(false);
});
- test("sizes to the icon until the container is wide", () => {
+ test("hugs its label when expanded instead of the table column width", () => {
const { container } = renderCollapsible(Status.Completed);
const badge = container.querySelector('[aria-label="completed"]');
expect(
badge?.classList.contains("[@container_status_(min-width:384px)]:w-28"),
+ ).toBe(false);
+ expect(
+ badge?.classList.contains("[@container_status_(min-width:384px)]:px-2.5"),
).toBe(true);
+ expect(
+ badge?.classList.contains(
+ "[@container_status_(min-width:384px)]:justify-start",
+ ),
+ ).toBe(false);
expect(badge?.classList.contains("md:w-28")).toBe(false);
});
diff --git a/skyvern-frontend/src/components/StatusBadge.tsx b/skyvern-frontend/src/components/StatusBadge.tsx
index b348e0745..6343cecef 100644
--- a/skyvern-frontend/src/components/StatusBadge.tsx
+++ b/skyvern-frontend/src/components/StatusBadge.tsx
@@ -138,8 +138,11 @@ function StatusBadge({
"justify-center gap-1.5 px-1.5 capitalize",
// Container query (no plugin — Tailwind core arbitrary at-rule variant)
// so the label returns once the `status` container is wide enough.
+ // The collapsible variant lives in flowing chip rows, so the expanded
+ // pill hugs its label; the fixed w-28 column width is a table concern
+ // and stays on the viewport-breakpoint variant only.
collapsible
- ? "[@container_status_(min-width:384px)]:w-28 [@container_status_(min-width:384px)]:justify-start [@container_status_(min-width:384px)]:px-2.5"
+ ? "[@container_status_(min-width:384px)]:px-2.5"
: "md:w-28 md:justify-start md:px-2.5",
className,
)}
diff --git a/skyvern-frontend/src/routes/workflows/studio/RunTab.test.tsx b/skyvern-frontend/src/routes/workflows/studio/RunTab.test.tsx
index e70ec4a0f..9492b8678 100644
--- a/skyvern-frontend/src/routes/workflows/studio/RunTab.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/RunTab.test.tsx
@@ -29,7 +29,7 @@ vi.mock("./runview/RunView", () => ({
>
{props.onRetry ? (
<button type="button" onClick={props.onRetry}>
- Retry as-is
+ Retry
</button>
) : null}
</div>
@@ -119,7 +119,7 @@ describe("RunTab retry navigation", () => {
mockWorkflowRun();
renderAt("/workflows/wpid_abc/studio?wr=run_1");
- fireEvent.click(screen.getByRole("button", { name: "Retry as-is" }));
+ fireEvent.click(screen.getByRole("button", { name: "Retry" }));
expect(screen.getByTestId("location").textContent).toBe(
"/agents/wpid_abc/run",
@@ -142,7 +142,7 @@ describe("RunTab retry navigation", () => {
mockWorkflowRun({ workflow_run_id: "run_latest" });
renderAt("/workflows/wpid_abc/studio");
- fireEvent.click(screen.getByRole("button", { name: "Retry as-is" }));
+ fireEvent.click(screen.getByRole("button", { name: "Retry" }));
expect(workflowRunQueryMock).toHaveBeenCalledWith({
workflowRunId: "run_latest",
@@ -161,7 +161,7 @@ describe("RunTab retry navigation", () => {
mockWorkflowRun({ task_v2: { task_id: "task_synthetic" } });
renderAt("/workflows/wpid_abc/studio?wr=run_1");
- fireEvent.click(screen.getByRole("button", { name: "Retry as-is" }));
+ fireEvent.click(screen.getByRole("button", { name: "Retry" }));
expect(screen.getByTestId("location").textContent).toBe(
"/agents/wpid_abc/run",
diff --git a/skyvern-frontend/src/routes/workflows/studio/RunTab.tsx b/skyvern-frontend/src/routes/workflows/studio/RunTab.tsx
index 2e8160bd7..5bb8ab919 100644
--- a/skyvern-frontend/src/routes/workflows/studio/RunTab.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/RunTab.tsx
@@ -26,7 +26,7 @@ export function RunTab() {
// Fix (Copilot) and Retry both mutate/rerun the workflow — gone with the
// source agent, so the CTAs go too (the run stays viewable).
const workflowDeleted = useStudioWorkflowDeletedAt() !== null;
- // ?bl= marks a block-scoped run; "Retry as-is" would rerun the whole workflow,
+ // ?bl= marks a block-scoped run; "Retry" would rerun the whole workflow,
// so suppress that CTA for block runs (the block is rerun from the editor).
const isBlockRun = searchParams.has("bl");
const retryRun = () => {
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx
index 1ab5876e7..842007920 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.test.tsx
@@ -12,17 +12,22 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import { Status } from "@/api/types";
import { TooltipProvider } from "@/components/ui/tooltip";
+import { WorkflowPermanentIdContext } from "@/routes/workflows/WorkflowPermanentIdContext";
import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";
import { StudioPaneToggles } from "./StudioPaneToggles";
-const { runsQueryMock, runWithWorkflowMock, infiniteRunsMock } = vi.hoisted(
- () => ({
+const { runsQueryMock, runWithWorkflowMock, infiniteRunsMock, copyTextMock } =
+ vi.hoisted(() => ({
runsQueryMock: vi.fn(),
runWithWorkflowMock: vi.fn(),
infiniteRunsMock: vi.fn(),
- }),
-);
+ copyTextMock: vi.fn(),
+ }));
+
+vi.mock("@/util/copyText", () => ({
+ copyText: (text: string) => copyTextMock(text),
+}));
vi.mock("../hooks/useWorkflowRunsQuery", () => ({
useWorkflowRunsQuery: () => runsQueryMock(),
@@ -65,10 +70,13 @@ function LocationProbe() {
function renderAt(path = "/workflows/wpid_abc/studio") {
return render(
<MemoryRouter initialEntries={[path]}>
- {/* The shell provides this in production (StudioShell root). */}
- <TooltipProvider delayDuration={0}>
- <StudioPaneToggles />
- </TooltipProvider>
+ {/* The shell provides these in production (StudioShell root / the
+ workflow route resolver). */}
+ <WorkflowPermanentIdContext.Provider value="wpid_abc">
+ <TooltipProvider delayDuration={0}>
+ <StudioPaneToggles />
+ </TooltipProvider>
+ </WorkflowPermanentIdContext.Provider>
<LocationProbe />
</MemoryRouter>,
);
@@ -78,6 +86,12 @@ function tab(name: RegExp | string): HTMLButtonElement {
return screen.getByRole("button", { name }) as HTMLButtonElement;
}
+// The run selector tab reads "View Run: <id>" once a run is inspected and
+// "Past Runs" otherwise; match either so tests survive both states.
+function runsTab(): HTMLButtonElement {
+ return tab(/^(Past Runs|View Run)/);
+}
+
function currentPanes(): string | null {
const search = screen.getByTestId("search").textContent ?? "";
return new URLSearchParams(search).get("panes");
@@ -119,14 +133,14 @@ describe("StudioPaneToggles structure", () => {
expect(tab(/^Copilot/).getAttribute("aria-expanded")).toBe("true");
// The Past Runs tab is a popover trigger; its active state (run pane open)
// is aria-pressed, not aria-expanded.
- expect(tab(/^Past Runs/).getAttribute("aria-pressed")).toBe("false");
+ expect(runsTab().getAttribute("aria-pressed")).toBe("false");
});
test("a block-run deep link opens Editor, Browser and the run pane", () => {
renderAt("/workflows/wpid_abc/studio?wr=run_1&bl=block_1");
expect(tab(/^Editor/).getAttribute("aria-expanded")).toBe("true");
expect(tab(/^Browser/).getAttribute("aria-expanded")).toBe("true");
- expect(tab(/^Past Runs/).getAttribute("aria-pressed")).toBe("true");
+ expect(runsTab().getAttribute("aria-pressed")).toBe("true");
expect(tab(/^Copilot/).getAttribute("aria-expanded")).toBe("false");
});
});
@@ -163,15 +177,55 @@ describe("StudioPaneToggles pane toggling", () => {
});
});
+describe("StudioPaneToggles run tab label", () => {
+ test("names the URL's run with its full id in the top bar", () => {
+ renderAt("/workflows/wpid_abc/studio?wr=wr_556219201027773764");
+ expect(tab("View Run: wr_556219201027773764")).toBeTruthy();
+ });
+
+ test("the tab's copy affordance copies the run link without opening the selector", async () => {
+ copyTextMock.mockResolvedValue(true);
+ renderAt("/workflows/wpid_abc/studio?wr=wr_556219201027773764");
+
+ fireEvent.click(screen.getByRole("button", { name: "Copy run link" }));
+
+ await waitFor(() =>
+ expect(copyTextMock).toHaveBeenCalledWith(
+ `${window.location.origin}/agents/wpid_abc/studio?wr=wr_556219201027773764`,
+ ),
+ );
+ // The click must not bubble into the popover trigger.
+ expect(screen.queryByText("Past runs")).toBeNull();
+ });
+
+ test("no copy affordance renders while no run is inspected", () => {
+ renderAt();
+ expect(screen.queryByRole("button", { name: "Copy run link" })).toBeNull();
+ });
+
+ test("names the latest run when the URL names none", () => {
+ runsQueryMock.mockReturnValue({
+ data: [{ workflow_run_id: "wr_late", status: Status.Completed }],
+ });
+ renderAt();
+ expect(tab(/^View Run: wr_late/)).toBeTruthy();
+ });
+
+ test("reads 'Past Runs' while no run exists to inspect", () => {
+ renderAt();
+ expect(tab(/^Past Runs/)).toBeTruthy();
+ });
+});
+
describe("StudioPaneToggles run selector", () => {
test("the Past Runs tab is enabled even with no runs", () => {
renderAt();
- expect(tab(/^Past Runs/).disabled).toBe(false);
+ expect(runsTab().disabled).toBe(false);
});
test("clicking the Past Runs tab opens the selector without toggling the pane", async () => {
renderAt("/workflows/wpid_abc/studio?panes=copilot");
- fireEvent.click(tab(/^Past Runs/));
+ fireEvent.click(runsTab());
// The selector popover opens (its "Past runs" header renders)...
expect(await screen.findByText("Past runs")).toBeTruthy();
// ...and the run pane is never toggled onto the stage by opening it.
@@ -190,7 +244,7 @@ describe("StudioPaneToggles run selector", () => {
);
// A different current run so the picked row is clickable (not the current).
renderAt("/workflows/wpid_abc/studio?panes=copilot&wr=wr_other");
- fireEvent.click(tab(/^Past Runs/));
+ fireEvent.click(runsTab());
fireEvent.click(await screen.findByText("wr_pick"));
// Selecting opens the run pane (overview). The row's switchRun also sets
@@ -214,7 +268,7 @@ describe("StudioPaneToggles run selector", () => {
]),
);
renderAt("/workflows/wpid_abc/studio?panes=copilot&wr=wr_same");
- fireEvent.click(tab(/^Past Runs/));
+ fireEvent.click(runsTab());
fireEvent.click(await screen.findByText("wr_same"));
expect(currentPanes()?.split(",")).toContain("overview");
@@ -225,27 +279,27 @@ describe("StudioPaneToggles run-status dot", () => {
test("shows a status-colored dot for a finalized run", () => {
runsQueryMock.mockReturnValue({ data: [{ status: Status.Completed }] });
renderAt();
- const dot = tab(/^Past Runs/).querySelector(
+ const dot = runsTab().querySelector(
"span.absolute.-right-0\\.5",
) as HTMLElement | null;
expect(dot).not.toBeNull();
expect(dot?.className).toContain("bg-badge-success");
});
- test("includes the finalized run status in the Past Runs tab accessible name", () => {
- runsQueryMock.mockReturnValue({ data: [{ status: Status.TimedOut }] });
+ test("includes the finalized run status in the run tab accessible name", () => {
+ runsQueryMock.mockReturnValue({
+ data: [{ workflow_run_id: "wr_tab", status: Status.TimedOut }],
+ });
renderAt();
expect(
- screen.getByRole("button", { name: "Past Runs, timed out" }),
+ screen.getByRole("button", { name: "View Run: wr_tab, timed out" }),
).toBeTruthy();
});
test("omits the dot while the run is still in flight", () => {
runsQueryMock.mockReturnValue({ data: [{ status: Status.Running }] });
renderAt();
- expect(
- tab(/^Past Runs/).querySelector("span.absolute.-right-0\\.5"),
- ).toBeNull();
+ expect(runsTab().querySelector("span.absolute.-right-0\\.5")).toBeNull();
});
});
@@ -293,8 +347,8 @@ describe("StudioPaneToggles keyboard navigation", () => {
fireEvent.keyDown(tab(/^Editor/), { key: "ArrowRight" });
expect(document.activeElement).toBe(tab(/^Browser/));
fireEvent.keyDown(tab(/^Browser/), { key: "ArrowRight" });
- expect(document.activeElement).toBe(tab(/^Past Runs/));
- fireEvent.keyDown(tab(/^Past Runs/), { key: "ArrowRight" });
+ expect(document.activeElement).toBe(runsTab());
+ fireEvent.keyDown(runsTab(), { key: "ArrowRight" });
expect(document.activeElement).toBe(tab(/^Copilot/));
});
@@ -302,8 +356,8 @@ describe("StudioPaneToggles keyboard navigation", () => {
renderAt();
tab(/^Copilot/).focus();
fireEvent.keyDown(tab(/^Copilot/), { key: "ArrowLeft" });
- expect(document.activeElement).toBe(tab(/^Past Runs/));
- fireEvent.keyDown(tab(/^Past Runs/), { key: "Home" });
+ expect(document.activeElement).toBe(runsTab());
+ fireEvent.keyDown(runsTab(), { key: "Home" });
expect(document.activeElement).toBe(tab(/^Copilot/));
});
diff --git a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.tsx b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.tsx
index f6bc4ec65..03c1533ac 100644
--- a/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/StudioPaneToggles.tsx
@@ -1,11 +1,19 @@
import { useEffect, useState, type KeyboardEvent } from "react";
+import { CheckIcon, CopyIcon } from "@radix-ui/react-icons";
+import { useWorkflowPermanentId } from "@/routes/workflows/WorkflowPermanentIdContext";
import { Status } from "@/api/types";
+import { copyText } from "@/util/copyText";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";
import { cn } from "@/util/utils";
@@ -65,9 +73,10 @@ function useLabelsCollapsed(): boolean {
/**
* The studio's pane toggles, top-center in the top bar. Copilot, Editor and
* Browser are peer TOGGLES (multi-active — each opens or closes its pane). The
- * run pane's tab is different: it's the "Past Runs" selector — clicking always
- * opens a run-history popover (it never toggles the pane), and picking a run
- * opens/retargets the run pane. Labels collapse to icons below xl so the
+ * run pane's tab is different: it's the run selector — labeled with the
+ * inspected run ("View Run: wr_…", falling back to "Past Runs"), clicking
+ * always opens a run-history popover (it never toggles the pane), and picking
+ * a run opens/retargets the run pane. Labels collapse to icons below xl so the
* cluster never crowds the title or the run actions.
*/
export function StudioPaneToggles() {
@@ -78,9 +87,24 @@ export function StudioPaneToggles() {
);
const clearBrowserActivity = useStudioBrowserStore((s) => s.clearActivity);
- const { runStatus } = useStudioRunSignals();
+ const { runId, runStatus } = useStudioRunSignals();
+ const workflowPermanentId = useWorkflowPermanentId();
const labelsCollapsed = useLabelsCollapsed();
const [runsSelectorOpen, setRunsSelectorOpen] = useState(false);
+ const [runLinkCopied, setRunLinkCopied] = useState(false);
+
+ // Copies the run's shareable deep link (?wr= names the run) — the thing
+ // people actually paste around — not just the raw id.
+ const copyRunLink = async () => {
+ if (!runId || runLinkCopied) {
+ return;
+ }
+ await copyText(
+ `${window.location.origin}/agents/${workflowPermanentId}/studio?wr=${runId}`,
+ );
+ setRunLinkCopied(true);
+ setTimeout(() => setRunLinkCopied(false), 1500);
+ };
// Picking a run in the selector opens/retargets the run pane. The row's own
// handler pushes ?wr= first; openPane then merges against the live URL, so
@@ -136,9 +160,9 @@ export function StudioPaneToggles() {
>
{STUDIO_PANE_IDS.map((id) => {
const { icon: Icon } = STUDIO_PANE_META[id];
- // The run pane's tab reads the static "Past Runs" (railLabel); the
- // dynamic "Run: wr_…" label lives in the pane header, not the rail.
- const label = railLabel(id);
+ // The run pane's tab names the inspected run ("View Run: wr_…") so the
+ // run id reads from the top bar; railLabel falls back to "Past Runs".
+ const label = railLabel(id, runId);
const open = panes.includes(id);
const blockedByDeletion = paneBlockedByDeletion(id);
const isRunSelector = id === "overview";
@@ -197,14 +221,55 @@ export function StudioPaneToggles() {
aria-label={ariaLabel}
tabIndex={id === tabStopId ? 0 : -1}
onFocus={() => setFocusedId(id)}
- className={buttonClassName}
+ className={cn(buttonClassName, "group")}
>
{iconAndDot}
+ {runId ? (
+ // Hover affordance beside the (fully visible) run id: copy
+ // the run's URL without opening the selector popover. A span
+ // because buttons can't nest; stopPropagation keeps the
+ // popover closed.
+ <span
+ role="button"
+ tabIndex={0}
+ aria-label="Copy run link"
+ title="Copy run link"
+ onPointerDown={(event) => event.stopPropagation()}
+ onClick={(event) => {
+ event.stopPropagation();
+ event.preventDefault();
+ void copyRunLink();
+ }}
+ onKeyDown={(event) => {
+ if (event.key === "Enter" || event.key === " ") {
+ event.stopPropagation();
+ event.preventDefault();
+ void copyRunLink();
+ }
+ }}
+ className={cn(
+ "hidden rounded p-0.5 opacity-0 transition-opacity xl:inline-flex",
+ "text-muted-foreground hover:text-foreground",
+ "group-focus-within:opacity-100 group-hover:opacity-100",
+ "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
+ runLinkCopied && "text-foreground opacity-100",
+ )}
+ >
+ {runLinkCopied ? (
+ <CheckIcon className="size-3" aria-hidden />
+ ) : (
+ <CopyIcon className="size-3" aria-hidden />
+ )}
+ </span>
+ ) : null}
</button>
</PopoverTrigger>
);
- const tip =
- runStatus && !showActivityDot
+ const tip = runId
+ ? `View Run: ${runId}${
+ runStatus ? ` · ${runStatusLabel(runStatus)}` : ""
+ }`
+ : runStatus
? `${label} · ${runStatusLabel(runStatus)}`
: label;
return (
@@ -213,8 +278,14 @@ export function StudioPaneToggles() {
open={runsSelectorOpen}
onOpenChange={setRunsSelectorOpen}
>
+ {/* Icon-collapsed keeps a label tooltip, composed straight onto
+ the (never-disabled) button so aria-describedby reaches it;
+ with labels visible the full id is already in the tab. */}
{labelsCollapsed ? (
- <ControlTooltip content={tip}>{trigger}</ControlTooltip>
+ <Tooltip>
+ <TooltipTrigger asChild>{trigger}</TooltipTrigger>
+ <TooltipContent side="bottom">{tip}</TooltipContent>
+ </Tooltip>
) : (
trigger
)}
diff --git a/skyvern-frontend/src/routes/workflows/studio/paneMeta.test.ts b/skyvern-frontend/src/routes/workflows/studio/paneMeta.test.ts
index dc8a11a27..fe6defca5 100644
--- a/skyvern-frontend/src/routes/workflows/studio/paneMeta.test.ts
+++ b/skyvern-frontend/src/routes/workflows/studio/paneMeta.test.ts
@@ -44,14 +44,22 @@ describe("paneAccessibleName", () => {
});
describe("railLabel", () => {
- test("the run pane's rail tab is the 'Past Runs' selector", () => {
+ test("the run pane's rail tab names the inspected run with its full id", () => {
+ // Untruncated on purpose: the top bar is where run ids are read and copied.
+ expect(railLabel("overview", "wr_556219201027773764")).toBe(
+ "View Run: wr_556219201027773764",
+ );
+ });
+
+ test("falls back to the 'Past Runs' selector name with no run", () => {
expect(railLabel("overview")).toBe("Past Runs");
+ expect(railLabel("overview", null)).toBe("Past Runs");
});
- test("other tabs match their pane's accessible name", () => {
+ test("other tabs match their pane's accessible name, ignoring the run id", () => {
expect(railLabel("copilot")).toBe("Copilot");
expect(railLabel("editor")).toBe("Editor");
- expect(railLabel("browser")).toBe("Browser");
+ expect(railLabel("browser", "wr_5538abcdef")).toBe("Browser");
});
});
diff --git a/skyvern-frontend/src/routes/workflows/studio/paneMeta.ts b/skyvern-frontend/src/routes/workflows/studio/paneMeta.ts
index 414972098..9e0d31317 100644
--- a/skyvern-frontend/src/routes/workflows/studio/paneMeta.ts
+++ b/skyvern-frontend/src/routes/workflows/studio/paneMeta.ts
@@ -48,9 +48,16 @@ export function paneAccessibleName(id: StudioPaneId): string {
return paneLabel(id);
}
-// The rail tab / stage-launcher tile label. The run pane's tab is the "Past
-// Runs" selector (it opens the run history rather than toggling a pane), so it
-// reads "Past Runs"; every other tab matches its pane's accessible name.
-export function railLabel(id: StudioPaneId): string {
- return id === "overview" ? "Past Runs" : paneAccessibleName(id);
+// The rail tab / stage-launcher tile label. The run pane's tab is the run
+// selector (it opens the run history rather than toggling a pane): it names the
+// inspected run with its FULL id ("View Run: wr_55380…" — the top bar is where
+// people read and copy run ids, so no truncation) when callers pass one, and
+// reads "Past Runs" otherwise (no run inspected, or surfaces like the stage
+// launcher that don't resolve a run). Every other tab matches its pane's
+// accessible name.
+export function railLabel(id: StudioPaneId, runId?: string | null): string {
+ if (id === "overview") {
+ return runId ? `View Run: ${runId}` : "Past Runs";
+ }
+ return paneAccessibleName(id);
}
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunPaneHeader.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunPaneHeader.tsx
index 1616d2855..eb935646e 100644
--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunPaneHeader.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunPaneHeader.tsx
@@ -2,6 +2,7 @@ import { useCallback, useState } from "react";
import {
ActivityLogIcon,
CodeIcon,
+ DotsHorizontalIcon,
FileTextIcon,
ListBulletIcon,
ReloadIcon,
@@ -11,6 +12,12 @@ import { useWorkflowPermanentId } from "@/routes/workflows/WorkflowPermanentIdCo
import { ApiWebhookActionsMenu } from "@/components/ApiWebhookActionsMenu";
import { WebhookReplayDialog } from "@/components/WebhookReplayDialog";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
import {
Tooltip,
TooltipContent,
@@ -38,9 +45,10 @@ import { useStudioPanes } from "../useStudioPanes";
import { ViewToggle } from "../ViewToggle";
/**
- * Left header cluster of the Overview pane: the Timeline / Inputs / Outputs /
- * Code view toggles, plus the Live handoff chip while the run executes. The
- * selected view lives in useRunPaneViewStore; RunView renders the body.
+ * Left header cluster of the Overview pane: the Timeline / Inputs / Outputs
+ * view toggles plus a "…" overflow menu holding the Code view, and the Live
+ * handoff chip while the run executes. The selected view lives in
+ * useRunPaneViewStore; RunView renders the body.
*/
export function RunPaneViewToggles() {
const compact = useStudioPaneCompact();
@@ -127,25 +135,51 @@ export function RunPaneViewToggles() {
label="Outputs"
icon={<FileTextIcon className="h-3 w-3" />}
/>
- <ViewToggle
- active={view === "code"}
- onClick={() => setView("code")}
- compact={compact}
- label="Code"
- title={
- codeGenerating ? "Generating cached code for this run" : undefined
- }
- icon={
- codeGenerating ? (
- <ReloadIcon
- data-testid="code-generating-spinner"
- className="h-3 w-3 animate-spin"
- />
- ) : (
+ <DropdownMenu>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <DropdownMenuTrigger asChild>
+ <button
+ type="button"
+ aria-label="More views"
+ aria-pressed={view === "code"}
+ className={cn(
+ "inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-[11px] font-medium",
+ "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
+ view === "code"
+ ? "bg-accent text-foreground"
+ : "text-muted-foreground hover:bg-accent/50 hover:text-foreground",
+ )}
+ >
+ {codeGenerating ? (
+ <ReloadIcon
+ data-testid="code-generating-spinner"
+ className="h-3 w-3 animate-spin"
+ />
+ ) : (
+ <DotsHorizontalIcon className="h-3 w-3" />
+ )}
+ </button>
+ </DropdownMenuTrigger>
+ </TooltipTrigger>
+ <TooltipContent side="bottom">
+ {codeGenerating
+ ? "Generating cached code for this run"
+ : "More views"}
+ </TooltipContent>
+ </Tooltip>
+ {/* Sized to the pane-header control grammar (11px, h-7 rows) so the
+ menu reads as part of the toggle cluster, not a full-size menu. */}
+ <DropdownMenuContent align="start" sideOffset={6} className="min-w-0">
+ <DropdownMenuItem
+ onSelect={() => setView("code")}
+ className="cursor-pointer gap-1.5 rounded px-2 py-1.5 pr-3 text-[11px] font-medium text-muted-foreground focus:text-foreground"
+ >
<CodeIcon className="h-3 w-3" />
- )
- }
- />
+ Code
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
</div>
{showLive
? (() => {
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunSummaryStrip.test.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunSummaryStrip.test.tsx
index d5aa47a6e..c6763154b 100644
--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunSummaryStrip.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunSummaryStrip.test.tsx
@@ -1,6 +1,12 @@
// @vitest-environment jsdom
-import { cleanup, render, screen } from "@testing-library/react";
+import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ within,
+} from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { afterEach, describe, expect, test } from "vitest";
@@ -8,6 +14,7 @@ import {
Status,
type WorkflowRunStatusApiResponseWithWorkflow,
} from "@/api/types";
+import { TooltipProvider } from "@/components/ui/tooltip";
import { RunSummaryStrip } from "./RunSummaryStrip";
@@ -33,7 +40,10 @@ function makeRun(
function renderStrip(run: WorkflowRunStatusApiResponseWithWorkflow) {
return render(
<MemoryRouter>
- <RunSummaryStrip workflowRun={run} />
+ {/* The studio shell provides this in production (StudioShell root). */}
+ <TooltipProvider delayDuration={0}>
+ <RunSummaryStrip workflowRun={run} />
+ </TooltipProvider>
</MemoryRouter>,
);
}
@@ -60,41 +70,61 @@ describe("RunSummaryStrip browser session/profile links", () => {
expect(screen.queryByTitle("Browser profile")).toBeNull();
});
- test("renders the run id but no resource links when the run has neither", () => {
+ test("renders no id chips at all when the run has neither", () => {
+ // The run id itself lives in the top bar's "View Run" tab, not the strip.
renderStrip(makeRun());
- expect(screen.getByText("wr_123")).toBeTruthy();
+ expect(screen.queryByText("wr_123")).toBeNull();
expect(screen.queryByRole("link")).toBeNull();
});
- test("groups the run id with the browser session and profile ids", () => {
+ test("groups the session and profile chips without the run id", () => {
renderStrip(
makeRun({
browser_session_id: "pbs_abc",
browser_profile_id: "bp_def",
}),
);
- expect(screen.getByText("wr_123")).toBeTruthy();
+ expect(screen.queryByText("wr_123")).toBeNull();
expect(screen.getByText("pbs_abc")).toBeTruthy();
expect(screen.getByText("bp_def")).toBeTruthy();
});
});
-describe("RunSummaryStrip visible dates", () => {
- test("shows started and finished as separate chips for a finalized run", () => {
+describe("RunSummaryStrip duration", () => {
+ test("shows a single elapsed chip for a finalized run", () => {
renderStrip(makeRun());
- expect(screen.getByText(/^Started /)).toBeTruthy();
- expect(screen.getByText(/^Finished /)).toBeTruthy();
+ expect(screen.getByText("Ran for 5m 0s")).toBeTruthy();
+ expect(screen.queryByText(/^Started /)).toBeNull();
+ expect(screen.queryByText(/^Finished /)).toBeNull();
+ });
+
+ test("hovering/focusing the chip breaks down all four run times", async () => {
+ renderStrip(makeRun());
+ fireEvent.focus(screen.getByText("Ran for 5m 0s"));
+ const tooltip = await screen.findByRole("tooltip");
+ const breakdown = within(tooltip);
+ expect(breakdown.getByText(/Created /)).toBeTruthy();
+ expect(breakdown.getByText(/Queued /)).toBeTruthy();
+ expect(breakdown.getByText(/Started /)).toBeTruthy();
+ expect(breakdown.getByText(/Finished /)).toBeTruthy();
});
- test("shows started without finished while the run is not finalized", () => {
+ test("shows started without an elapsed chip while the run is not finalized", () => {
renderStrip(makeRun({ status: Status.Running }));
expect(screen.getByText(/^Started /)).toBeTruthy();
- expect(screen.queryByText(/^Finished /)).toBeNull();
+ expect(screen.queryByText(/^Ran for /)).toBeNull();
+ });
+
+ test("a finalized run that never started falls back to the raw chips", () => {
+ renderStrip(makeRun({ status: Status.Failed, started_at: null }));
+ expect(screen.getByText(/^Finished /)).toBeTruthy();
+ expect(screen.queryByText(/^Ran for /)).toBeNull();
});
test("renders no dates when the run has not started", () => {
renderStrip(makeRun({ status: Status.Running, started_at: null }));
expect(screen.queryByText(/^Started /)).toBeNull();
+ expect(screen.queryByText(/^Ran for /)).toBeNull();
});
});
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunSummaryStrip.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunSummaryStrip.tsx
index e8d633ccc..c3f5b03f2 100644
--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunSummaryStrip.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunSummaryStrip.tsx
@@ -4,9 +4,16 @@ import { type WorkflowRunStatusApiResponseWithWorkflow } from "@/api/types";
import { CopyButton } from "@/components/CopyButton";
import { FailureCategoryBadge } from "@/components/FailureCategoryBadge";
import { StatusBadge } from "@/components/StatusBadge";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
import { statusIsFinalized } from "@/routes/tasks/types";
import { compactLocalDateTime } from "@/util/timeFormat";
+import { formatElapsed, formatRunTimesTooltip } from "../runProjections";
+
type RunSummaryStripProps = {
workflowRun: WorkflowRunStatusApiResponseWithWorkflow;
};
@@ -44,15 +51,21 @@ function RunIdChip({
}
/**
- * Two compact meta rows atop the Timeline view. Row one: the status badge next
- * to the run's started/finished timestamps. Row two: the run id — plus its
- * browser session/profile when present — as copyable, truncating chips. Both
- * rows wrap gracefully under width pressure (dates stack rather than mangle
- * mid-word; ids truncate with the full value on hover/copy). Elapsed time and
- * the counts (blocks/actions/steps/credits) live in the timeline's own header.
+ * Compact meta rows atop the Timeline view. Row one: the status badge next to
+ * the run's duration ("Ran for 50m 12s"), whose hover breaks down the full
+ * created/queued/started/finished times; runs the duration can't describe yet
+ * (still running, or finalized without both endpoints) fall back to the raw
+ * started/finished chips. Row two, only when the run has one: the browser
+ * session/profile as copyable, truncating chips — the run id itself lives in
+ * the top bar's "View Run" tab. The counts (blocks/actions/steps/credits)
+ * live in the timeline's own header.
*/
export function RunSummaryStrip({ workflowRun }: RunSummaryStripProps) {
const finalized = statusIsFinalized(workflowRun);
+ const ranFor =
+ finalized && workflowRun.started_at && workflowRun.finished_at
+ ? formatElapsed(workflowRun.started_at, workflowRun.finished_at)
+ : null;
const dateChips = [
workflowRun.started_at
? `Started ${compactLocalDateTime(workflowRun.started_at)}`
@@ -71,32 +84,51 @@ export function RunSummaryStrip({ workflowRun }: RunSummaryStripProps) {
failureCategory={workflowRun.failure_category}
/>
) : null}
- {dateChips.map((chip) => (
- <span
- key={chip}
- className="whitespace-nowrap text-xs text-muted-foreground"
- >
- {chip}
- </span>
- ))}
- </div>
- <div className="flex min-w-0 flex-wrap items-center gap-x-4 gap-y-1">
- <RunIdChip label="Run" id={workflowRun.workflow_run_id} />
- {workflowRun.browser_session_id ? (
- <RunIdChip
- label="Browser session"
- id={workflowRun.browser_session_id}
- to={`/browser-session/${workflowRun.browser_session_id}/stream`}
- />
- ) : null}
- {workflowRun.browser_profile_id ? (
- <RunIdChip
- label="Browser profile"
- id={workflowRun.browser_profile_id}
- to={`/browser-profiles/${workflowRun.browser_profile_id}`}
- />
- ) : null}
+ {ranFor ? (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ {/* tabIndex keeps the breakdown reachable from the keyboard —
+ the chip is plain text, not a control. */}
+ <span
+ tabIndex={0}
+ className="cursor-default whitespace-nowrap text-xs text-muted-foreground"
+ >
+ Ran for {ranFor}
+ </span>
+ </TooltipTrigger>
+ <TooltipContent side="bottom" className="text-left">
+ {formatRunTimesTooltip(workflowRun)}
+ </TooltipContent>
+ </Tooltip>
+ ) : (
+ dateChips.map((chip) => (
+ <span
+ key={chip}
+ className="whitespace-nowrap text-xs text-muted-foreground"
+ >
+ {chip}
+ </span>
+ ))
+ )}
</div>
+ {workflowRun.browser_session_id || workflowRun.browser_profile_id ? (
+ <div className="flex min-w-0 flex-wrap items-center gap-x-4 gap-y-1">
+ {workflowRun.browser_session_id ? (
+ <RunIdChip
+ label="Browser session"
+ id={workflowRun.browser_session_id}
+ to={`/browser-session/${workflowRun.browser_session_id}/stream`}
+ />
+ ) : null}
+ {workflowRun.browser_profile_id ? (
+ <RunIdChip
+ label="Browser profile"
+ id={workflowRun.browser_profile_id}
+ to={`/browser-profiles/${workflowRun.browser_profile_id}`}
+ />
+ ) : null}
+ </div>
+ ) : null}
</div>
);
}
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx
index c17933a14..7e147f001 100644
--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx
@@ -1,7 +1,13 @@
// @vitest-environment jsdom
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { cleanup, fireEvent, render, within } from "@testing-library/react";
+import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ within,
+} from "@testing-library/react";
import { MemoryRouter, Route, Routes, useLocation } from "react-router-dom";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import { type ReactNode } from "react";
@@ -62,6 +68,16 @@ vi.mock("@/components/ui/scroll-area", () => ({
<div>{children}</div>
),
}));
+// The header's "…" menu (Radix DropdownMenu) scrolls its focused item into
+// view on open; jsdom implements neither that nor ResizeObserver.
+Element.prototype.scrollIntoView = () => {};
+if (typeof globalThis.ResizeObserver === "undefined") {
+ globalThis.ResizeObserver = class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ };
+}
vi.mock("posthog-js/react", () => ({
usePostHog: () => ({ capture: vi.fn() }),
}));
@@ -320,9 +336,10 @@ describe("RunView view toggles", () => {
const { container } = renderRunView();
const scope = within(container);
- // status · duration · run id — the counts live in the timeline's own
- // header row, so the strip carries no stat boxes.
- expect(scope.getByText("wr_1")).not.toBeNull();
+ // status · duration — the run id lives in the top bar's "View Run" tab,
+ // and the counts live in the timeline's own header row, so the strip
+ // carries no id chip and no stat boxes.
+ expect(scope.queryByText("wr_1")).toBeNull();
expect(
scope.getAllByText("completed", { exact: false }).length,
).toBeGreaterThan(0);
@@ -380,22 +397,27 @@ describe("RunView view toggles", () => {
expect(scope.queryByText("TOTP identifier")).toBeNull();
});
- test("Code view renders the shared WorkflowRunCode surface", () => {
+ test("the '…' menu's Code item renders the shared WorkflowRunCode surface", async () => {
seedCompletedRun();
const { container } = renderRunView();
const scope = within(container);
expect(scope.queryByTestId("workflow-run-code")).toBeNull();
- fireEvent.click(scope.getByRole("button", { name: "Code" }));
+ // The Code view lives in the header's "…" overflow menu, not a toggle.
+ fireEvent.pointerDown(scope.getByRole("button", { name: "More views" }), {
+ button: 0,
+ ctrlKey: false,
+ });
+ fireEvent.click(await screen.findByRole("menuitem", { name: "Code" }));
expect(scope.queryByTestId("workflow-run-code")).not.toBeNull();
- // The Code toggle exposes aria-pressed once it's the active view, matching
- // the sibling view toggles (defends the shared ViewToggle disabled-prop add).
+ // The menu trigger exposes aria-pressed while Code is the active view,
+ // matching the sibling view toggles.
expect(
- scope.getByRole("button", { name: "Code", pressed: true }),
+ scope.getByRole("button", { name: "More views", pressed: true }),
).not.toBeNull();
});
- test("the Code toggle shows a spinner while cached code is generating", () => {
+ test("the '…' trigger shows a spinner while cached code is generating", () => {
seedCompletedRun();
mocks.codeGenerating = true;
const { container } = renderRunView();
@@ -609,10 +631,44 @@ describe("RunView failure banner", () => {
"Login page rejected the credentials",
);
- fireEvent.click(scope.getByRole("button", { name: "Retry as-is" }));
+ fireEvent.click(scope.getByRole("button", { name: "Retry" }));
expect(onRetry).toHaveBeenCalledTimes(1);
});
+ test("splits the banner into a headline and de-emphasized detail", () => {
+ seedCompletedRun({
+ status: Status.Failed,
+ failure_reason:
+ "for_loop block failed. failure reason: Failed to execute code block. Reason: Exception: boom",
+ });
+ const { container } = renderRunView();
+ const scope = within(container);
+
+ const headline = scope.getByText("for_loop block failed");
+ expect(headline.className).toContain("font-semibold");
+ expect(
+ scope.getByText(/Failed to execute code block\. Reason: Exception: boom/),
+ ).not.toBeNull();
+ // Short detail → no expand toggle.
+ expect(scope.queryByRole("button", { name: "Show more" })).toBeNull();
+ });
+
+ test("long failure detail clamps behind a Show more toggle", () => {
+ seedCompletedRun({
+ status: Status.Failed,
+ failure_reason: `for_loop block failed. failure reason: ${"x".repeat(300)}`,
+ });
+ const { container } = renderRunView();
+ const scope = within(container);
+
+ const detail = scope.getByText(/^x+$/);
+ expect(detail.className).toContain("line-clamp-3");
+ fireEvent.click(scope.getByRole("button", { name: "Show more" }));
+ expect(scope.getByText(/^x+$/).className).not.toContain("line-clamp-3");
+ fireEvent.click(scope.getByRole("button", { name: "Show less" }));
+ expect(scope.getByText(/^x+$/).className).toContain("line-clamp-3");
+ });
+
test("dismiss hides the failure banner", () => {
seedCompletedRun({
status: Status.Failed,
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx
index ee11f829d..bba45b58f 100644
--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.tsx
@@ -13,7 +13,7 @@ import { useRunPaneViewStore } from "@/store/useRunPaneViewStore";
import { useRunViewStore } from "@/store/RunViewStore";
import { useStudioBrowserStore } from "@/store/useStudioBrowserStore";
import { useWorkflowBlockSearchStore } from "@/store/WorkflowBlockSearchStore";
-import { isRecord } from "@/util/utils";
+import { cn, isRecord } from "@/util/utils";
import { useWorkflowRunTimelineQuery } from "../../hooks/useWorkflowRunTimelineQuery";
import { useWorkflowRunWithWorkflowQuery } from "../../hooks/useWorkflowRunWithWorkflowQuery";
@@ -35,6 +35,10 @@ import {
import { toReadableSearch } from "../panes";
import { useStudioPanes } from "../useStudioPanes";
import { collectBlockPrompts } from "./blockPrompts";
+import {
+ failureDetailIsLong,
+ formatFailureReason,
+} from "./failureReasonFormat";
import { matchFailureTips } from "./failureTips";
import { buildRunFixMessage } from "./runFixMessage";
import { RunInputsSection, type RunInputMeta } from "./RunInputsSection";
@@ -104,6 +108,7 @@ export function RunView({
const view = useRunPaneViewStore((s) => s.view);
const resetPaneView = useRunPaneViewStore((s) => s.reset);
const [failureDismissed, setFailureDismissed] = useState(false);
+ const [failureDetailExpanded, setFailureDetailExpanded] = useState(false);
const [outputSummary, setOutputSummary] = useState<string | null>(null);
// A pinned frame belongs to one run; drop it when the run changes, then re-seed
@@ -113,6 +118,7 @@ export function RunView({
setOutputSummary(null);
resetPaneView();
setFailureDismissed(false);
+ setFailureDetailExpanded(false);
const active = searchParamsRef.current.get("active");
if (active) {
pinFrame(active);
@@ -380,6 +386,12 @@ export function RunView({
finalized ? (workflowRun.finished_at ?? null) : null,
);
const elapsedTitle = formatRunTimesTooltip(workflowRun);
+ const failureReason = formatFailureReason(
+ workflowRun.failure_reason ?? "The run failed.",
+ );
+ const failureDetailLong = failureReason.detail
+ ? failureDetailIsLong(failureReason.detail)
+ : false;
return (
<div className="flex h-full min-h-0 w-full flex-col">
@@ -396,21 +408,44 @@ export function RunView({
{failed && !failureDismissed && view === "timeline" ? (
<div className="shrink-0 rounded-lg border border-destructive/40 bg-slate-elevation1 p-4">
- <div className="flex items-start gap-2 text-sm font-semibold text-foreground">
+ <div className="flex items-start gap-2">
<ExclamationTriangleIcon className="mt-0.5 h-4 w-4 shrink-0 text-destructive" />
- <span className="min-w-0 flex-1">
- {workflowRun.failure_reason ?? "The run failed."}
+ <div className="min-w-0 flex-1">
+ <div className="text-sm font-semibold text-foreground">
+ {failureReason.headline}
+ </div>
+ {failureReason.detail ? (
+ <>
+ <p
+ className={cn(
+ "mt-1 whitespace-pre-wrap break-words text-xs leading-relaxed text-muted-foreground",
+ !failureDetailExpanded && "line-clamp-3",
+ )}
+ >
+ {failureReason.detail}
+ </p>
+ {failureDetailLong ? (
+ <button
+ type="button"
+ onClick={() => setFailureDetailExpanded((v) => !v)}
+ className="mt-1 text-xs font-medium text-muted-foreground underline-offset-2 hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
+ >
+ {failureDetailExpanded ? "Show less" : "Show more"}
+ </button>
+ ) : null}
+ </>
+ ) : null}
{matchFailureTips(workflowRun.failure_reason ?? null).map(
(tip) => (
<span
key={tip}
- className="mt-1.5 block text-xs font-normal italic text-muted-foreground"
+ className="mt-1.5 block text-xs italic text-muted-foreground"
>
{tip}
</span>
),
)}
- </span>
+ </div>
<button
type="button"
onClick={() => setFailureDismissed(true)}
@@ -430,7 +465,7 @@ export function RunView({
) : null}
{onRetry ? (
<Button size="sm" variant="secondary" onClick={onRetry}>
- Retry as-is
+ Retry
</Button>
) : null}
</div>
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/failureReasonFormat.test.ts b/skyvern-frontend/src/routes/workflows/studio/runview/failureReasonFormat.test.ts
new file mode 100644
index 000000000..39c926ad1
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/failureReasonFormat.test.ts
@@ -0,0 +1,58 @@
+import { describe, expect, test } from "vitest";
+
+import {
+ failureDetailIsLong,
+ formatFailureReason,
+} from "./failureReasonFormat";
+
+describe("formatFailureReason", () => {
+ test("splits the block headline from the nested failure-reason payload", () => {
+ const raw =
+ "for_loop block failed. failure reason: Failed to execute code block. " +
+ "Reason: Exception: select_payer failed for 'Demo Payer' target='DEMO PAYER'";
+ expect(formatFailureReason(raw)).toEqual({
+ headline: "for_loop block failed",
+ detail:
+ "Failed to execute code block. " +
+ "Reason: Exception: select_payer failed for 'Demo Payer' target='DEMO PAYER'",
+ });
+ });
+
+ test("unescapes literal \\n sequences into real line breaks", () => {
+ const raw =
+ "task block failed. failure reason: Timeout 30000ms exceeded.\\nCall log:\\n - waiting";
+ const { detail } = formatFailureReason(raw);
+ expect(detail).toContain("exceeded.\nCall log:\n - waiting");
+ expect(detail).not.toContain("\\n");
+ });
+
+ test("falls back to a first-sentence headline for generic prose", () => {
+ const raw =
+ "Login page rejected the credentials. The site returned a 403 after the second attempt and locked the account form.";
+ expect(formatFailureReason(raw)).toEqual({
+ headline: "Login page rejected the credentials",
+ detail:
+ "The site returned a 403 after the second attempt and locked the account form.",
+ });
+ });
+
+ test("keeps a short single-sentence reason as the headline alone", () => {
+ expect(formatFailureReason("Login page rejected the credentials")).toEqual({
+ headline: "Login page rejected the credentials",
+ detail: null,
+ });
+ });
+
+ test("does not split on periods inside URLs or decimals", () => {
+ const raw = "Navigation to https://example.com/checkout timed out";
+ expect(formatFailureReason(raw).headline).toBe(raw);
+ });
+});
+
+describe("failureDetailIsLong", () => {
+ test("flags payloads the three-line clamp would cut", () => {
+ expect(failureDetailIsLong("x".repeat(221))).toBe(true);
+ expect(failureDetailIsLong("a\nb\nc\nd")).toBe(true);
+ expect(failureDetailIsLong("short detail")).toBe(false);
+ });
+});
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/failureReasonFormat.ts b/skyvern-frontend/src/routes/workflows/studio/runview/failureReasonFormat.ts
new file mode 100644
index 000000000..94ecd5cb7
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/failureReasonFormat.ts
@@ -0,0 +1,36 @@
+export type FormattedFailureReason = {
+ headline: string;
+ detail: string | null;
+};
+
+// Failure reasons arrive as one nested blob — "for_loop block failed. failure
+// reason: Failed to execute code block. Reason: Exception: … \n …" — with
+// literal escape sequences. Split a short headline from the technical detail
+// so the banner can lead with what failed and de-emphasize the payload.
+export function formatFailureReason(raw: string): FormattedFailureReason {
+ const text = raw.replace(/\\n/g, "\n").replace(/\\t/g, " ").trim();
+
+ const nested = text.match(/^(.{0,120}?)[.:]\s*failure reason:\s*/i);
+ if (nested?.[1]) {
+ const detail = text.slice(nested[0].length).trim();
+ return { headline: nested[1].trim(), detail: detail || null };
+ }
+
+ // Generic shape: lead with the first sentence when a meaningful remainder
+ // follows it. The whitespace lookahead keeps URLs and decimals intact.
+ const sentence = text.match(/^(.{10,120}?[.!])\s+(?=\S)/);
+ if (sentence?.[1]) {
+ const detail = text.slice(sentence[0].length).trim();
+ if (detail) {
+ return { headline: sentence[1].replace(/[.!]$/, ""), detail };
+ }
+ }
+
+ return { headline: text, detail: null };
+}
+
+// Gate for the detail's Show more / Show less toggle: only payloads that the
+// collapsed three-line clamp would actually cut.
+export function failureDetailIsLong(detail: string): boolean {
+ return detail.length > 220 || detail.split("\n").length > 3;
+}
diff --git a/skyvern-frontend/src/routes/workflows/studio/useStudioRunSignals.ts b/skyvern-frontend/src/routes/workflows/studio/useStudioRunSignals.ts
index 398bac48e..0abec8e11 100644
--- a/skyvern-frontend/src/routes/workflows/studio/useStudioRunSignals.ts
+++ b/skyvern-frontend/src/routes/workflows/studio/useStudioRunSignals.ts
@@ -6,9 +6,11 @@ import { finalizedRunStatus } from "./runProjections";
import { useStudioRunId } from "./useStudioRunId";
/**
- * The run facts the shell keys UI off: Run-tab gating, the toggle status dot,
- * and the first-visit pane default. `knownHasRuns` stays undefined until the
- * runs page-1 probe has data, so callers can tell "no runs" from "not loaded".
+ * The run facts the shell keys UI off: Run-tab gating, the toggle status dot
+ * and label, and the first-visit pane default. `runId` is the inspected run —
+ * the URL's run or the latest-run fallback — so the tab's label and status dot
+ * always describe the same run. `knownHasRuns` stays undefined until the runs
+ * page-1 probe has data, so callers can tell "no runs" from "not loaded".
*/
export function useStudioRunSignals() {
const urlRunId = useStudioRunId();
@@ -24,6 +26,7 @@ export function useStudioRunSignals() {
const knownHasRuns = runs === undefined ? undefined : runs.length > 0;
return {
hasRun: Boolean(urlRunId) || knownHasRuns === true,
+ runId: urlRunId ?? runs?.[0]?.workflow_run_id,
runStatus: finalizedRunStatus(
urlRunId ? urlRun?.status : runs?.[0]?.status,
),
diff --git a/skyvern/webeye/utils/page.py b/skyvern/webeye/utils/page.py
index ee8738e6f..09c26f205 100644
--- a/skyvern/webeye/utils/page.py
+++ b/skyvern/webeye/utils/page.py
@@ -88,37 +88,9 @@ def _wrap_js_in_isolated_scope(script: str) -> str:
# lexical binding with the same name. Scope the script in an IIFE and export via
# property writes, which never collide; typeof guards drop names the column-0 regex
# matched inside block comments.
- # Export via defineProperty, never a bare assignment. A page that installs a setter on one of
- # these globals BEFORE injection has `globalThis.x = x` hand it our genuine function
- # synchronously, letting it serve a wrapper from a getter and drive our own builder with
- # arguments we never passed (SKY-12875 M2: forcing destination capture on in disabled mode).
- # defineProperty redefines the slot instead of invoking a setter.
names = sorted(set(_JS_TOP_LEVEL_DECL_RE.findall(script)))
- exporter = """
-const __skyvernExport = (name, value) => {
- const existing = Object.getOwnPropertyDescriptor(globalThis, name);
- if (existing && !existing.configurable) {
- // A page's own top-level `var element = ...` makes a non-configurable WRITABLE data property,
- // and several exported names are ordinary words — so this case is ordinary pages, not attack,
- // and a plain write is correct there (a data property has no setter to invoke). A locked
- // ACCESSOR is the interposition this export exists to refuse, and a locked read-only slot
- // would silently leave the page's value in place; both fail loudly instead.
- if (existing.get || existing.set || !existing.writable) {
- throw new Error("skyvern: refusing to export over locked global " + name);
- }
- globalThis[name] = value;
- return;
- }
- Object.defineProperty(globalThis, name, {
- value,
- writable: true,
- enumerable: true,
- configurable: true,
- });
-};
-"""
- exports = "\n".join(f'if (typeof {name} !== "undefined") __skyvernExport("{name}", {name});' for name in names)
- return f"(() => {{\n{script}\n{exporter}\n{exports}\n}})();"
+ exports = "\n".join(f'if (typeof {name} !== "undefined") globalThis.{name} = {name};' for name in names)
+ return f"(() => {{\n{script}\n{exports}\n}})();"
def load_js_script() -> str:
diff --git a/tests/unit/test_destination_facts_capture.py b/tests/unit/test_destination_facts_capture.py
index bd484a8ef..1b9b39724 100644
--- a/tests/unit/test_destination_facts_capture.py
+++ b/tests/unit/test_destination_facts_capture.py
@@ -20,7 +20,7 @@ from unittest.mock import AsyncMock, MagicMock
import pytest
from skyvern.webeye.scraper.scraper import build_element_dict, hash_element
-from skyvern.webeye.utils.page import SkyvernFrame, load_js_script, pop_destination_facts
+from skyvern.webeye.utils.page import SkyvernFrame, pop_destination_facts
_REPO_ROOT = Path(__file__).parent.parent.parent
_PAGE_MODULE = _REPO_ROOT / "skyvern" / "webeye" / "utils" / "page.py"
@@ -305,19 +305,3 @@ class TestDestinationFactsJs:
timeout=30,
)
assert result.returncode == 0, f"Failed:\n{result.stdout}\n{result.stderr}"
-
-
-class TestInjectionExportsCannotBeIntercepted:
- """Gate finding M2: the wrapper exported entry points with `globalThis.x = x`, so a page that
- installed a SETTER on one of those globals before injection was handed our genuine builder
- synchronously and could then drive it with arguments we never passed — forcing destination
- capture on with the policy disabled.
-
- The behavior lives in tests/unit/test_domutils_injection_scope.js (run by
- test_dom_scrape_crash_guards.py), which drives the real generated script in a vm against all
- three descriptor shapes. This pins only that no bare-assignment export can come back."""
-
- def test_no_export_is_a_bare_assignment(self) -> None:
- script = load_js_script()
- assert "__skyvernExport(" in script
- assert "globalThis.buildTreeFromBody = buildTreeFromBody" not in script
diff --git a/tests/unit/test_domutils_injection_scope.js b/tests/unit/test_domutils_injection_scope.js
index 6b4f9ae6a..0ea3030f3 100644
--- a/tests/unit/test_domutils_injection_scope.js
+++ b/tests/unit/test_domutils_injection_scope.js
@@ -120,68 +120,4 @@ check("loaded script is re-injectable and exports all entry points", () => {
}
});
-// SKY-12875 M2: exports must not be interceptable. `globalThis.x = x` invokes a page-installed
-// setter and hands it our genuine function, which let a page serve a wrapper from a getter and
-// drive our own builder with arguments we never passed (forcing destination capture on while the
-// policy was disabled). These drive the real generated script, not its source text.
-
-check("a page setter never receives an exported function", () => {
- const ctx = makeContext();
- vm.runInContext(
- `globalThis.__stolen = null;
- Object.defineProperty(globalThis, "buildTreeFromBody", {
- configurable: true,
- get() { return globalThis.__stolen; },
- set(value) { globalThis.__stolen = value; },
- });`,
- ctx,
- );
- indirectEval(ctx, wrappedScript);
- assert.strictEqual(
- ctx.__stolen,
- null,
- "the page's setter was invoked by the export",
- );
- assert.strictEqual(
- typeof ctx.buildTreeFromBody,
- "function",
- "the export did not install our function",
- );
-});
-
-check("a non-configurable writable global does not break the export", () => {
- // This is the descriptor a real page's top-level `var element = 1` produces, and several
- // exported names are ordinary words — so it is ordinary sites, not attack, and refusing it
- // would break scraping everywhere. Written as an explicit descriptor because `var` inside a vm
- // context is configurable, unlike a browser's; the real-browser case is covered by a Chromium
- // probe.
- const ctx = makeContext();
- vm.runInContext(
- `Object.defineProperty(globalThis, "buildTreeFromBody", {
- value: 1, writable: true, enumerable: true, configurable: false,
- });`,
- ctx,
- );
- indirectEval(ctx, wrappedScript);
- assert.strictEqual(typeof ctx.buildTreeFromBody, "function");
-});
-
-check("a locked accessor on an exported global fails injection loudly", () => {
- const ctx = makeContext();
- vm.runInContext(
- `Object.defineProperty(globalThis, "buildTreeFromBody", {
- configurable: false,
- get() { return undefined; },
- set(value) { globalThis.__stolen = value; },
- });`,
- ctx,
- );
- assert.throws(
- () => indirectEval(ctx, wrappedScript),
- /refusing to export over locked global/,
- "injection must refuse rather than run through an interposed global",
- );
- assert.strictEqual(ctx.__stolen, undefined, "the page captured our function");
-});
-
process.exit(failures ? 1 : 0);