Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-11567): guard workflow document editor against absent values (#6905)
Aaron Perez779bcd31f5ce
diff --git a/skyvern-frontend/src/routes/workflows/components/BulkActionBar.tsx b/skyvern-frontend/src/routes/workflows/components/BulkActionBar.tsxindex d016e1d8a..b1f0def91 100644--- a/skyvern-frontend/src/routes/workflows/components/BulkActionBar.tsx+++ b/skyvern-frontend/src/routes/workflows/components/BulkActionBar.tsx@@ -305,6 +305,7 @@ function BulkActionBar({showRemove={selectedWorkflows.some((workflow) => workflow.folder_id !== null,)}+ disabled={isOperating}onSelect={(folderId) => void onMoveToFolder(folderId)}/></DropdownMenuSubContent>diff --git a/skyvern-frontend/src/routes/workflows/components/CodeEditor.largeJson.test.tsx b/skyvern-frontend/src/routes/workflows/components/CodeEditor.largeJson.test.tsxindex de5a5d80c..b3b536c2e 100644--- a/skyvern-frontend/src/routes/workflows/components/CodeEditor.largeJson.test.tsx+++ b/skyvern-frontend/src/routes/workflows/components/CodeEditor.largeJson.test.tsx@@ -66,6 +66,11 @@ describe("isOversizedDocument", () => {const value = JSON.stringify({ note: "[".repeat(500) }, null, 2);expect(isOversizedDocument(value)).toBe(false);});++ it("treats an absent (undefined/null) document as not oversized", () => {+ expect(isOversizedDocument(undefined)).toBe(false);+ expect(isOversizedDocument(null)).toBe(false);+ });});describe("CodeEditor large-document guard", () => {@@ -96,4 +101,12 @@ describe("CodeEditor large-document guard", () => {render(<CodeEditor value={value} language="json" />),).not.toThrow();});++ it("renders without throwing when the document value is absent", () => {+ expect(() =>+ render(+ <CodeEditor value={undefined as unknown as string} language="json" />,+ ),+ ).not.toThrow();+ });});diff --git a/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx b/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsxindex ec3c39fb2..7e6468caf 100644--- a/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx+++ b/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx@@ -66,9 +66,14 @@ function CodeEditorImpl({extraExtensions,...restProps}: Props) {+ // `value` is typed `string`, but workflow document panels can pass an+ // absent/incomplete payload at runtime (SKY-11567). Normalize to a string so+ // the editor and the oversized-document guard never read `.length` of+ // undefined.+ const safeValue = value ?? "";const viewRef = useRef<EditorView | null>(null);- const [internalValue, setInternalValue] = useState(value);- const latestValueRef = useRef(value);+ const [internalValue, setInternalValue] = useState(safeValue);+ const latestValueRef = useRef(safeValue);// Defer EditorView creation until the container is in (or near) the// viewport. Block editors mount many CodeEditors at once (script-mode@@ -103,9 +108,9 @@ function CodeEditorImpl({}, [shouldMount]);useEffect(() => {- setInternalValue(value);- latestValueRef.current = value;- }, [value]);+ setInternalValue(safeValue);+ latestValueRef.current = safeValue;+ }, [safeValue]);// Capture the latest onChange in a ref so the debounced callback below// (and the React.memo wrapper export) stay referentially stable acrossdiff --git a/skyvern-frontend/src/routes/workflows/components/FolderPickerCommand.test.tsx b/skyvern-frontend/src/routes/workflows/components/FolderPickerCommand.test.tsxindex 7510a07ae..def145187 100644--- a/skyvern-frontend/src/routes/workflows/components/FolderPickerCommand.test.tsx+++ b/skyvern-frontend/src/routes/workflows/components/FolderPickerCommand.test.tsx@@ -81,4 +81,20 @@ describe("FolderPickerCommand", () => {expect(onSelect).toHaveBeenCalledWith(null);});++ it("does not select while disabled (guards an in-flight bulk move)", () => {+ foldersResult.data = [folder("f1", "Prospects")];+ const onSelect = vi.fn();+ render(+ <FolderPickerCommand+ currentFolderId={null}+ disabled+ onSelect={onSelect}+ />,+ );++ fireEvent.click(screen.getByText("Prospects"));++ expect(onSelect).not.toHaveBeenCalled();+ });});diff --git a/skyvern-frontend/src/routes/workflows/components/FolderPickerCommand.tsx b/skyvern-frontend/src/routes/workflows/components/FolderPickerCommand.tsxindex 36ad4006a..9d3505703 100644--- a/skyvern-frontend/src/routes/workflows/components/FolderPickerCommand.tsx+++ b/skyvern-frontend/src/routes/workflows/components/FolderPickerCommand.tsx@@ -16,6 +16,9 @@ type Props = {currentFolderId: string | null;// Force-show "Remove from folder" independent of currentFolderId (bulk: any selected has a folder).showRemove?: boolean;+ // While a bulk move is in flight, freeze the picker so a second pick can't+ // start a competing move for the same selection.+ disabled?: boolean;onSelect: (folderId: string | null) => void;};@@ -23,7 +26,12 @@ const FOLDER_PICKER_PAGE_SIZE = 50;// Compact cmdk folder list for the row context menu. Server-side search keeps it// usable past the page cap; "Remove from folder" shows only when the agent has one.-function FolderPickerCommand({ currentFolderId, showRemove, onSelect }: Props) {+function FolderPickerCommand({+ currentFolderId,+ showRemove,+ disabled,+ onSelect,+}: Props) {const [query, setQuery] = React.useState("");const [debouncedQuery] = useDebounce(query, 300);const inputRef = React.useRef<HTMLInputElement>(null);@@ -60,7 +68,11 @@ function FolderPickerCommand({ currentFolderId, showRemove, onSelect }: Props) {<CommandList>{(showRemove ?? currentFolderId !== null) ? (<CommandGroup>- <CommandItem value="__remove__" onSelect={() => onSelect(null)}>+ <CommandItem+ value="__remove__"+ disabled={disabled}+ onSelect={() => onSelect(null)}+ ><Cross2Icon className="mr-2 h-4 w-4 text-destructive" />Remove from folder</CommandItem>@@ -78,7 +90,7 @@ function FolderPickerCommand({ currentFolderId, showRemove, onSelect }: Props) {<CommandItemkey={folder.folder_id}value={`folder-${folder.folder_id}`}- disabled={isCurrent}+ disabled={isCurrent || disabled}onSelect={() => onSelect(folder.folder_id)}><FolderIcon className="mr-2 h-4 w-4 shrink-0 text-blue-400" />diff --git a/skyvern-frontend/src/routes/workflows/components/oversizedDocument.ts b/skyvern-frontend/src/routes/workflows/components/oversizedDocument.tsindex 2f0805cb9..41206de76 100644--- a/skyvern-frontend/src/routes/workflows/components/oversizedDocument.ts+++ b/skyvern-frontend/src/routes/workflows/components/oversizedDocument.ts@@ -43,7 +43,10 @@ function getMaxStructureDepth(text: string, cap: number): number {* call stack (SKY-11432). Above these bounds the editor falls back to plain,* unwrapped text instead of syntax-highlighted, wrapped rendering.*/-export function isOversizedDocument(value: string): boolean {+export function isOversizedDocument(value: string | null | undefined): boolean {+ if (typeof value !== "string") {+ return false;+ }if (value.length > LARGE_DOCUMENT_CHAR_THRESHOLD) {return true;}