Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: always send param to git branches search (#157)

Hiep Le9aebb35cfad0
diff --git a/__tests__/api/cloud/git-service.test.ts b/__tests__/api/cloud/git-service.test.ts
new file mode 100644
index 0000000000..075e65901c
--- /dev/null
+++ b/__tests__/api/cloud/git-service.test.ts
@@ -0,0 +1,71 @@
+import axios from "axios";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import {
+ __resetActiveStoreForTests,
+ setActiveSelection,
+ setRegisteredBackends,
+} from "#/api/backend-registry/active-store";
+import type { Backend } from "#/api/backend-registry/types";
+import { getCloudRepositoryBranches } from "#/api/cloud/git-service.api";
+
+vi.mock("axios");
+
+const cloudBackend: Backend = {
+ id: "prod",
+ name: "Production",
+ host: "https://app.all-hands.dev",
+ apiKey: "bearer-token",
+ kind: "cloud",
+};
+
+const emptyBranchPage = {
+ data: { items: [], next_page_id: null },
+};
+
+beforeEach(() => {
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
+ setRegisteredBackends([cloudBackend]);
+ setActiveSelection({ backendId: cloudBackend.id });
+ vi.mocked(axios.post).mockReset();
+});
+
+afterEach(() => {
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
+});
+
+describe("getCloudRepositoryBranches", () => {
+ it("includes an empty query parameter when listing all branches so the upstream schema is satisfied", async () => {
+ // Arrange
+ vi.mocked(axios.post).mockResolvedValueOnce(emptyBranchPage);
+
+ // Act
+ await getCloudRepositoryBranches({
+ provider: "github",
+ repository: "hieptl/hieptl",
+ });
+
+ // Assert
+ const [, body] = vi.mocked(axios.post).mock.calls[0]!;
+ const path = (body as { path: string }).path;
+ expect(path).toMatch(/[?&]query=(&|$)/);
+ });
+
+ it("forwards a non-empty query parameter when searching branches", async () => {
+ // Arrange
+ vi.mocked(axios.post).mockResolvedValueOnce(emptyBranchPage);
+
+ // Act
+ await getCloudRepositoryBranches({
+ provider: "github",
+ repository: "hieptl/hieptl",
+ query: "feature/login",
+ });
+
+ // Assert
+ const [, body] = vi.mocked(axios.post).mock.calls[0]!;
+ const path = (body as { path: string }).path;
+ expect(path).toContain("query=feature%2Flogin");
+ });
+});
diff --git a/package-lock.json b/package-lock.json
index d826e4cbc8..e4f70dd1ff 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6625,6 +6625,64 @@
"node": ">=14.0.0"
}
},
+ "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/core": {
+ "version": "1.8.1",
+ "inBundle": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@emnapi/wasi-threads": "1.1.0",
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/runtime": {
+ "version": "1.8.1",
+ "inBundle": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/wasi-threads": {
+ "version": "1.1.0",
+ "inBundle": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@napi-rs/wasm-runtime": {
+ "version": "1.1.1",
+ "inBundle": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@emnapi/core": "^1.7.1",
+ "@emnapi/runtime": "^1.7.1",
+ "@tybys/wasm-util": "^0.10.1"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/Brooooooklyn"
+ }
+ },
+ "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@tybys/wasm-util": {
+ "version": "0.10.1",
+ "inBundle": true,
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "tslib": "^2.4.0"
+ }
+ },
+ "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/tslib": {
+ "version": "2.8.1",
+ "inBundle": true,
+ "license": "0BSD",
+ "optional": true
+ },
"node_modules/@tailwindcss/oxide-win32-arm64-msvc": {
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.2.4.tgz",
diff --git a/src/api/cloud/git-service.api.ts b/src/api/cloud/git-service.api.ts
index 7903475e62..8a60209235 100644
--- a/src/api/cloud/git-service.api.ts
+++ b/src/api/cloud/git-service.api.ts
@@ -85,7 +85,7 @@ export async function getCloudRepositoryBranches(args: {
params.set("provider", args.provider);
params.set("repository", args.repository);
params.set("limit", String(args.limit ?? 30));
- if (args.query) params.set("query", args.query);
+ params.set("query", args.query ?? "");
if (args.pageId) params.set("page_id", args.pageId);
const data = await callCloudProxy<{