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

This commit is contained in:
sp.wack
2025-12-30 16:33:09 +04:00
committed by GitHub
parent d5e83d0f06
commit 103e3ead0a
2 changed files with 25 additions and 0 deletions

View 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");
});

View File

@@ -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),