Skip to content

πŸ™Œ OpenHands: AI-Driven Development

hotfix(frontend): validate git changes response is array before mapping (#12208)

sp.wack103e3ead0a8c
diff --git a/frontend/__tests__/api/v1-git-service.test.ts b/frontend/__tests__/api/v1-git-service.test.ts
new file mode 100644
index 0000000000..495a395c81
--- /dev/null
+++ b/frontend/__tests__/api/v1-git-service.test.ts
@@ -0,0 +1,18 @@
+import { test, expect, vi } from "vitest";
+import axios from "axios";
+import V1GitService from "../../src/api/git-service/v1-git-service.api";
+
+vi.mock("axios");
+
+test("getGitChanges throws when response is not an array (dead runtime returns HTML)", async () => {
+ const htmlResponse = "<!DOCTYPE html><html>...</html>";
+ vi.mocked(axios.get).mockResolvedValue({ data: htmlResponse });
+
+ await expect(
+ V1GitService.getGitChanges(
+ "http://localhost:3000/api/conversations/123",
+ "test-api-key",
+ "/workspace",
+ ),
+ ).rejects.toThrow("Invalid response from runtime");
+});
diff --git a/frontend/src/api/git-service/v1-git-service.api.ts b/frontend/src/api/git-service/v1-git-service.api.ts
index ce8f2030fd..0c874825aa 100644
--- a/frontend/src/api/git-service/v1-git-service.api.ts
+++ b/frontend/src/api/git-service/v1-git-service.api.ts
@@ -53,6 +53,13 @@ class V1GitService {
// V1 API returns V1GitChangeStatus types, we need to map them to V0 format
const { data } = await axios.get<V1GitChange[]>(url, { headers });
+ // Validate response is an array (could be HTML error page if runtime is dead)
+ if (!Array.isArray(data)) {
+ throw new Error(
+ "Invalid response from runtime - runtime may be unavailable",
+ );
+ }
+
// Map V1 statuses to V0 format for compatibility
return data.map((change) => ({
status: mapV1ToV0Status(change.status),