π OpenHands: AI-Driven Development
fix: forward disabled_skills to cloud proxy on skills toggle save (#173)
Hiep Le593bdc9bbc1f
diff --git a/__tests__/api/cloud/settings-service.test.ts b/__tests__/api/cloud/settings-service.test.tsindex fbf4454884..0a56a5f40e 100644--- a/__tests__/api/cloud/settings-service.test.ts+++ b/__tests__/api/cloud/settings-service.test.ts@@ -10,6 +10,7 @@ import {fetchCloudSettings,saveCloudSettings,} from "#/api/cloud/settings-service.api";+import SettingsService from "#/api/settings-service/settings-service.api";vi.mock("axios");@@ -110,6 +111,29 @@ describe("cloud settings via local proxy", () => {expect(proxiedBody).not.toHaveProperty("conversation_settings");});+ it("SettingsService.saveSettings forwards disabled_skills to the cloud proxy when active backend is cloud", async () => {+ // Arrange: cloud backend already active via beforeEach; mock proxy response.+ vi.mocked(axios.post).mockResolvedValue({ data: {} });++ // Act: save a skills-only update β previously this short-circuited and+ // sent nothing at all, leaving the toggle un-persisted.+ await SettingsService.saveSettings({+ disabled_skills: ["SSH Microagent"],+ });++ // Assert: a single proxied POST /api/v1/settings reached the wire with+ // disabled_skills as a top-level field on the upstream body.+ expect(vi.mocked(axios.post)).toHaveBeenCalledTimes(1);+ const [, envelope] = vi.mocked(axios.post).mock.calls[0]!;+ expect(envelope).toMatchObject({+ method: "POST",+ path: "/api/v1/settings",+ });+ expect((envelope as { body: Record<string, unknown> }).body).toEqual({+ disabled_skills: ["SSH Microagent"],+ });+ });+it("saveCloudSettings omits an empty conversation_settings_diff (LLM-only save)", async () => {vi.mocked(axios.post).mockResolvedValue({ data: {} });diff --git a/__tests__/api/settings-service.test.ts b/__tests__/api/settings-service.test.tsindex 2370609b0b..0a5bbf3bf1 100644--- a/__tests__/api/settings-service.test.ts+++ b/__tests__/api/settings-service.test.ts@@ -104,6 +104,26 @@ describe("SettingsService", () => {fetchSpy.mockRestore();});+ it("skips PATCH for a skills-only save against a local backend", async () => {+ // Arrange: skills are a cloud-only feature. The local agent-server's+ // PATCH /api/settings rejects payloads without agent/conversation diffs+ // (the MSW handler returns 400 in that case), so a successful no-op here+ // also confirms disabled_skills is not leaked to the local backend.+ const fetchSpy = vi.spyOn(SettingsService, "fetchSettingsFromApi");++ // Act+ const result = await SettingsService.saveSettings({+ disabled_skills: ["SSH Microagent"],+ });++ // Assert: returns true and never fires the PATCH (no fetch invalidation+ // either, because the cache wasn't cleared).+ expect(result).toBe(true);+ expect(fetchSpy).not.toHaveBeenCalled();++ fetchSpy.mockRestore();+ });+it("derives provider_tokens_set from locally stored git provider tokens", async () => {// Arrange: simulate post-save state. SecretsService.addGitProvider writes to// this localStorage key after the server PUT /api/settings/secrets succeeds.diff --git a/src/api/cloud/settings-service.api.ts b/src/api/cloud/settings-service.api.tsindex 90f59d06a1..54ac94603a 100644--- a/src/api/cloud/settings-service.api.ts+++ b/src/api/cloud/settings-service.api.ts@@ -149,6 +149,7 @@ export async function fetchCloudSettings(): Promise<Partial<Settings>> {export async function saveCloudSettings(diff: {agent_settings_diff?: Record<string, SettingsValue>;conversation_settings_diff?: Record<string, SettingsValue>;+ disabled_skills?: string[];}): Promise<void> {const backend = getActiveCloudBackend();const body: Record<string, unknown> = {};@@ -164,6 +165,10 @@ export async function saveCloudSettings(diff: {) {body.conversation_settings_diff = diff.conversation_settings_diff;}+ // Use !== undefined so re-enabling every skill (empty array) round-trips.+ if (diff.disabled_skills !== undefined) {+ body.disabled_skills = diff.disabled_skills;+ }await callCloudProxy<unknown>({backend,method: "POST",diff --git a/src/api/settings-service/settings-service.api.ts b/src/api/settings-service/settings-service.api.tsindex 25ccab27bb..6b22888a93 100644--- a/src/api/settings-service/settings-service.api.ts+++ b/src/api/settings-service/settings-service.api.ts@@ -31,6 +31,7 @@ export interface SettingsApiResponse {export interface SettingsUpdateRequest {agent_settings_diff?: Record<string, SettingsValue>;conversation_settings_diff?: Record<string, SettingsValue>;+ disabled_skills?: string[];}/**@@ -337,16 +338,40 @@ class SettingsService {payload.conversation_settings_diff = conversationSettingsDiff;}+ // Extract disabled_skills (cloud-only β local agent-server has no skills concept)+ const disabledSkills = settings.disabled_skills as string[] | undefined;+ if (Array.isArray(disabledSkills)) {+ payload.disabled_skills = disabledSkills;+ }+// Only call API if we have something to update- if (!payload.agent_settings_diff && !payload.conversation_settings_diff) {+ if (+ !payload.agent_settings_diff &&+ !payload.conversation_settings_diff &&+ payload.disabled_skills === undefined+ ) {return true;}if (getActiveBackend().backend.kind === "cloud") {await withRetry(() => saveCloudSettings(payload));} else {+ // The local agent-server PATCH /api/settings rejects unknown fields and+ // requires at least one of the two diff fields. Strip disabled_skills+ // and skip the request entirely if nothing else was changed.+ const { disabled_skills: _droppedDisabledSkills, ...localPayload } =+ payload;+ if (+ !localPayload.agent_settings_diff &&+ !localPayload.conversation_settings_diff+ ) {+ return true;+ }await withRetry(() =>- createHttpClient().patch<SettingsApiResponse>("/api/settings", payload),+ createHttpClient().patch<SettingsApiResponse>(+ "/api/settings",+ localPayload,+ ),);}