π OpenHands: AI-Driven Development
Fix Jupyter tab not showing input commands (#9533)
Graham Neubigb132348d22b6
diff --git a/frontend/__tests__/services/actions.test.tsx b/frontend/__tests__/services/actions.test.tsxnew file mode 100644index 0000000000..644d2c02cb--- /dev/null+++ b/frontend/__tests__/services/actions.test.tsx@@ -0,0 +1,95 @@+import { describe, it, expect, vi, beforeEach } from "vitest";+import ActionType from "#/types/action-type";+import { ActionMessage } from "#/types/message";++// Mock the store and actions+const mockDispatch = vi.fn();+const mockAppendInput = vi.fn();+const mockAppendJupyterInput = vi.fn();++vi.mock("#/store", () => ({+ default: {+ dispatch: mockDispatch,+ },+}));++vi.mock("#/state/command-slice", () => ({+ appendInput: mockAppendInput,+}));++vi.mock("#/state/jupyter-slice", () => ({+ appendJupyterInput: mockAppendJupyterInput,+}));++describe("handleActionMessage", () => {+ beforeEach(() => {+ // Clear all mocks before each test+ vi.clearAllMocks();+ });++ it("should handle RUN actions by adding input to terminal", async () => {+ const { handleActionMessage } = await import("#/services/actions");++ const runAction: ActionMessage = {+ id: 1,+ source: "agent",+ action: ActionType.RUN,+ args: {+ command: "ls -la",+ },+ message: "Running command: ls -la",+ timestamp: "2023-01-01T00:00:00Z",+ };++ // Handle the action+ handleActionMessage(runAction);++ // Check that appendInput was called with the command+ expect(mockDispatch).toHaveBeenCalledWith(mockAppendInput("ls -la"));+ expect(mockAppendJupyterInput).not.toHaveBeenCalled();+ });++ it("should handle RUN_IPYTHON actions by adding input to Jupyter", async () => {+ const { handleActionMessage } = await import("#/services/actions");++ const ipythonAction: ActionMessage = {+ id: 2,+ source: "agent",+ action: ActionType.RUN_IPYTHON,+ args: {+ code: "print('Hello from Jupyter!')",+ },+ message: "Running Python code interactively: print('Hello from Jupyter!')",+ timestamp: "2023-01-01T00:00:00Z",+ };++ // Handle the action+ handleActionMessage(ipythonAction);++ // Check that appendJupyterInput was called with the code+ expect(mockDispatch).toHaveBeenCalledWith(mockAppendJupyterInput("print('Hello from Jupyter!')"));+ expect(mockAppendInput).not.toHaveBeenCalled();+ });++ it("should not process hidden actions", async () => {+ const { handleActionMessage } = await import("#/services/actions");++ const hiddenAction: ActionMessage = {+ id: 3,+ source: "agent",+ action: ActionType.RUN,+ args: {+ command: "secret command",+ hidden: "true",+ },+ message: "Running command: secret command",+ timestamp: "2023-01-01T00:00:00Z",+ };++ // Handle the action+ handleActionMessage(hiddenAction);++ // Check that nothing was dispatched+ expect(mockDispatch).not.toHaveBeenCalled();+ });+});diff --git a/frontend/src/services/actions.ts b/frontend/src/services/actions.tsindex f0c02086d1..dd5c92eaba 100644--- a/frontend/src/services/actions.ts+++ b/frontend/src/services/actions.ts@@ -11,6 +11,7 @@ import {} from "#/types/message";import { handleObservationMessage } from "./observations";import { appendInput } from "#/state/command-slice";+import { appendJupyterInput } from "#/state/jupyter-slice";import { queryClient } from "#/query-client-config";export function handleActionMessage(message: ActionMessage) {@@ -32,6 +33,10 @@ export function handleActionMessage(message: ActionMessage) {store.dispatch(appendInput(message.args.command));}+ if (message.action === ActionType.RUN_IPYTHON) {+ store.dispatch(appendJupyterInput(message.args.code));+ }+if ("args" in message && "security_risk" in message.args) {store.dispatch(appendSecurityAnalyzerInput(message));}