Skip to content

πŸ™Œ OpenHands: AI-Driven Development

test: cover observation results (#17329)

aivong-openhands3cc83c5e7c9b
diff --git a/__tests__/components/conversation-events/chat/event-content-helpers/get-observation-result.test.ts b/__tests__/components/conversation-events/chat/event-content-helpers/get-observation-result.test.ts
index 40a23e5c35..eb6ac80f27 100644
--- a/__tests__/components/conversation-events/chat/event-content-helpers/get-observation-result.test.ts
+++ b/__tests__/components/conversation-events/chat/event-content-helpers/get-observation-result.test.ts
@@ -39,7 +39,9 @@ describe("getACPToolCallResult", () => {
it("maps is_error β†’ error even when status is completed", () => {
expect(
- getACPToolCallResult(makeACPEvent({ status: "completed", is_error: true })),
+ getACPToolCallResult(
+ makeACPEvent({ status: "completed", is_error: true }),
+ ),
).toBe("error");
});
@@ -51,7 +53,9 @@ describe("getACPToolCallResult", () => {
);
it("maps null status β†’ undefined (running card)", () => {
- expect(getACPToolCallResult(makeACPEvent({ status: null }))).toBeUndefined();
+ expect(
+ getACPToolCallResult(makeACPEvent({ status: null })),
+ ).toBeUndefined();
});
});
@@ -67,7 +71,118 @@ const makeObs = (
observation,
});
+const makeMetadata = (exitCode: number) => ({
+ exit_code: exitCode,
+ pid: 123,
+ username: "openhands",
+ hostname: "runtime",
+ working_dir: "/workspace",
+ py_interpreter_path: null,
+ prefix: "",
+ suffix: "",
+});
+
describe("getObservationResult", () => {
+ it("maps bash exit codes from either top-level output or metadata", () => {
+ const bash = (exitCode: number | null, metadataExitCode: number) =>
+ makeObs({
+ kind: "ExecuteBashObservation",
+ content: [],
+ command: "test",
+ exit_code: exitCode,
+ error: false,
+ timeout: false,
+ metadata: makeMetadata(metadataExitCode),
+ });
+
+ expect(getObservationResult(bash(-1, 0))).toBe("timeout");
+ expect(getObservationResult(bash(null, -1))).toBe("timeout");
+ expect(getObservationResult(bash(0, 1))).toBe("success");
+ expect(getObservationResult(bash(null, 0))).toBe("success");
+ expect(getObservationResult(bash(2, 2))).toBe("error");
+ });
+
+ it("maps terminal timeouts, failures, and successful fallback states", () => {
+ const terminal = (
+ exitCode: number | null | undefined,
+ metadataExitCode: number | null,
+ overrides: { timeout?: boolean; is_error?: boolean } = {},
+ ) =>
+ makeObs({
+ kind: "TerminalObservation",
+ content: [],
+ command: "test",
+ exit_code: exitCode,
+ is_error: overrides.is_error ?? false,
+ timeout: overrides.timeout ?? false,
+ metadata: makeMetadata(metadataExitCode as number),
+ } as unknown as ObservationEvent["observation"]);
+
+ expect(getObservationResult(terminal(1, 1, { timeout: true }))).toBe(
+ "timeout",
+ );
+ expect(getObservationResult(terminal(-1, 0))).toBe("timeout");
+ expect(getObservationResult(terminal(0, 1))).toBe("success");
+ expect(getObservationResult(terminal(0, 1, { is_error: true }))).toBe(
+ "success",
+ );
+ expect(getObservationResult(terminal(null, 0))).toBe("success");
+ expect(getObservationResult(terminal(2, 2, { is_error: true }))).toBe(
+ "error",
+ );
+ expect(getObservationResult(terminal(undefined, null))).toBe("success");
+ });
+
+ it("maps editor errors and successful editor outcomes", () => {
+ const editor = (kind: string, error: string | null) =>
+ makeObs({
+ kind,
+ command: "view",
+ output: "",
+ path: "/workspace/file.ts",
+ prev_exist: true,
+ old_content: null,
+ new_content: null,
+ error,
+ } as ObservationEvent["observation"]);
+
+ expect(
+ getObservationResult(editor("FileEditorObservation", "Not found")),
+ ).toBe("error");
+ expect(
+ getObservationResult(editor("StrReplaceEditorObservation", null)),
+ ).toBe("success");
+ expect(
+ getObservationResult(
+ editor("StrReplaceEditorObservation", "Replacement failed"),
+ ),
+ ).toBe("error");
+ });
+
+ it("maps MCP and model-switch error flags", () => {
+ const mcp = (isError: boolean) =>
+ makeObs({
+ kind: "MCPToolObservation",
+ content: [],
+ is_error: isError,
+ tool_name: "search",
+ });
+ const modelSwitch = (isError: boolean) =>
+ makeObs({
+ kind: "SwitchLLMObservation",
+ content: [],
+ is_error: isError,
+ profile_name: "reviewer",
+ reason: null,
+ active_model: null,
+ });
+
+ expect(getObservationResult(mcp(true))).toBe("error");
+ expect(getObservationResult(mcp(false))).toBe("success");
+ expect(getObservationResult(modelSwitch(true))).toBe("error");
+ expect(getObservationResult(modelSwitch(false))).toBe("success");
+ });
+
it("maps InvokeSkillObservation is_error β†’ error, otherwise success", () => {
expect(
getObservationResult(
@@ -119,4 +234,10 @@ describe("getObservationResult", () => {
),
).toBe("success");
});
+
+ it("treats observation kinds without failure semantics as successful", () => {
+ expect(
+ getObservationResult(makeObs({ kind: "ThinkObservation", content: [] })),
+ ).toBe("success");
+ });
});