Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-18729 Demonstrate task: keep a skipped sensitive-field step in the step list (#8972)
Cindy Li7f0edf3b1925
diff --git a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.demonstration.test.tsx b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.demonstration.test.tsxindex 37d14d464..33e19d23f 100644--- a/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.demonstration.test.tsx+++ b/skyvern-frontend/src/routes/workflows/copilot/WorkflowCopilotChat.demonstration.test.tsx@@ -681,7 +681,7 @@ describe("WorkflowCopilotChat demonstration", () => {act(() => {call.onMessage({type: "demonstration_action",- seq: 2,+ seq: 1,label: 'Fill password from "Saved login"',tool_name: "fill_credential_field",});@@ -699,8 +699,15 @@ describe("WorkflowCopilotChat demonstration", () => {await waitFor(() =>expect(screen.queryByLabelText("Sign-in request")).toBeNull(),);+ expect(screen.queryByText(/value not recorded/)).toBeNull();act(() => {+ call.onMessage({+ type: "demonstration_action",+ seq: 2,+ label: 'Type "Test Applicant"',+ tool_name: "type_text",+ });call.onMessage({type: "demonstration_sensitive_field",field: "other",@@ -718,7 +725,13 @@ describe("WorkflowCopilotChat demonstration", () => {act(() => {call.onMessage({type: "demonstration_action",- seq: 5,+ seq: 3,+ label: "Fill sensitive field (value not recorded)",+ tool_name: "type_text",+ });+ call.onMessage({+ type: "demonstration_action",+ seq: 4,label: "Submit form",tool_name: "click",});@@ -729,13 +742,59 @@ describe("WorkflowCopilotChat demonstration", () => {const demonstration = screen.getByRole("group", {name: "Your demonstration",});- expect(within(demonstration).getAllByRole("listitem")).toHaveLength(5);+ expect(within(demonstration).getAllByRole("listitem")).toHaveLength(4);expect(within(demonstration).getByText(/Fill password from/)).toBeTruthy();+ expect(+ within(demonstration).getByText('Type "Test Applicant"'),+ ).toBeTruthy();expect(within(demonstration).getByText(/Fill sensitive field/),).toBeTruthy();});+ it("keeps a sensitive step the stop flush streams after Done", async () => {+ await renderChat({ liveBrowserSessionId: "browser-1" });+ const call = await startDemonstration();+ act(() => {+ call.onMessage({+ type: "demonstration_action",+ seq: 1,+ label: "Open form",+ tool_name: "click",+ });+ });+ sansApiPost.mockResolvedValueOnce({ data: { seq: 1, action_count: 2 } });++ fireEvent.click(+ await screen.findByRole("button", { name: "Done, build the workflow" }),+ );+ await waitFor(() =>+ expect(sansApiPost).toHaveBeenCalledWith(+ "/workflow/copilot/demonstration/control",+ { demonstration_id: "demonstration-1", action: "stop" },+ ),+ );+ act(() => {+ call.onMessage({+ type: "demonstration_action",+ seq: 2,+ label: "Fill password (value not recorded)",+ tool_name: "type_text",+ });+ });++ await waitFor(() =>+ expect(streamCalls.some((item) => item.path.endsWith("/chat-post"))).toBe(+ true,+ ),+ );+ const card = screen.getByRole("group", { name: "Your demonstration" });+ fireEvent.click(within(card).getByRole("button", { expanded: false }));+ expect(+ within(card).getByText("Fill password (value not recorded)"),+ ).toBeTruthy();+ });+it("keeps the type-it-yourself path when saved credential filling is unavailable", async () => {await renderChat({ liveBrowserSessionId: "browser-1" });const call = await startDemonstration({ canFillCredentials: false });diff --git a/skyvern-frontend/src/routes/workflows/copilot/useDemonstrationRecorder.ts b/skyvern-frontend/src/routes/workflows/copilot/useDemonstrationRecorder.tsindex 7d5b057df..a55bbd480 100644--- a/skyvern-frontend/src/routes/workflows/copilot/useDemonstrationRecorder.ts+++ b/skyvern-frontend/src/routes/workflows/copilot/useDemonstrationRecorder.ts@@ -118,22 +118,6 @@ export function useDemonstrationRecorder({setSensitiveField(null);return false;case "demonstration_sensitive_field":- {- const seq =- Math.max(0, ...actionsRef.current.map((action) => action.seq)) +- 1;- const fieldLabel =- frame.field === "other" ? "sensitive field" : frame.field;- actionsRef.current = [- ...actionsRef.current,- {- seq,- label: `Fill ${fieldLabel} (value not recorded)`,- },- ];- setActions(actionsRef.current);- setActionCount((current) => Math.max(current, seq));- }if (frame.field === "other") {setHasSkippedSensitiveField(true);}@@ -333,8 +317,18 @@ export function useDemonstrationRecorder({try {if (phaseRef.current === "recording") {const stopped = await sendControl({ action: "stop" }, id);- streamControllerRef.current?.abort();+ const stream = streamControllerRef.current;streamControllerRef.current = null;+ // The stop flush can stream its last rows after the stop request returns.+ for (+ let waited = 0;+ waited < 20 &&+ actionsRef.current.length < (stopped?.action_count ?? 0);+ waited+++ ) {+ await new Promise((resolve) => setTimeout(resolve, 100));+ }+ stream?.abort();setSensitiveField(null);updatePhase("stopped");setHasSkippedSensitiveField(false);diff --git a/skyvern/forge/sdk/copilot/demonstration_recorder.py b/skyvern/forge/sdk/copilot/demonstration_recorder.pyindex fbc2eb77b..44a878e93 100644--- a/skyvern/forge/sdk/copilot/demonstration_recorder.py+++ b/skyvern/forge/sdk/copilot/demonstration_recorder.py@@ -744,10 +744,20 @@ class DemonstrationRecorder:if kind == "secret_select":stored["control"] = "select"stored["label"] = "Select a sensitive option"+ else:+ field_name = {"password": "password", "totp": "one-time code"}.get(+ str(stored.get("field")), "sensitive field"+ )+ stored["label"] = f"Fill {field_name} (value not recorded)"seq = await self._append_event(stored)- if seq is not None and kind == "secret_select":+ if seq is not None:await self.stream.send(- {"type": "demonstration_action", "seq": seq, "label": stored["label"], "tool_name": "select_option"}+ {+ "type": "demonstration_action",+ "seq": seq,+ "label": stored["label"],+ "tool_name": "select_option" if kind == "secret_select" else "type_text",+ })returnlabel = _event_label(stored)diff --git a/tests/unit/test_copilot_demonstration.py b/tests/unit/test_copilot_demonstration.pyindex ca440a4a7..e9d801f82 100644--- a/tests/unit/test_copilot_demonstration.py+++ b/tests/unit/test_copilot_demonstration.py@@ -583,9 +583,11 @@ async def test_recorder_persists_tap_actions_controls_and_stops(monkeypatch: pytaction_frames = [frame for frame in stream.frames if frame.get("type") == "demonstration_action"]assert [(frame["seq"], frame["tool_name"]) for frame in action_frames] == [(1, "click"),+ (2, "type_text"),(3, "gap"),(4, "navigate_browser"),]+ assert action_frames[1]["label"] == second["label"] == "Fill password (value not recorded)"sensitive_frame = next(frame for frame in stream.frames if frame.get("type") == "demonstration_sensitive_field")assert sensitive_frame == {"type": "demonstration_sensitive_field",