mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-08 06:23:59 -05:00
hotfix(frontend): validate git changes response is array before mapping (#12208)
This commit is contained in:
18
frontend/__tests__/api/v1-git-service.test.ts
Normal file
18
frontend/__tests__/api/v1-git-service.test.ts
Normal file
@@ -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");
|
||||||
|
});
|
||||||
@@ -53,6 +53,13 @@ class V1GitService {
|
|||||||
// V1 API returns V1GitChangeStatus types, we need to map them to V0 format
|
// V1 API returns V1GitChangeStatus types, we need to map them to V0 format
|
||||||
const { data } = await axios.get<V1GitChange[]>(url, { headers });
|
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
|
// Map V1 statuses to V0 format for compatibility
|
||||||
return data.map((change) => ({
|
return data.map((change) => ({
|
||||||
status: mapV1ToV0Status(change.status),
|
status: mapV1ToV0Status(change.status),
|
||||||
|
|||||||
Reference in New Issue
Block a user