Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): fix apiAccess wiping sibling API + doc rate clamp
Adam Eivy39d54810ccfd
diff --git a/client/src/components/settings/ApiAccessTab.jsx b/client/src/components/settings/ApiAccessTab.jsxindex a0c6015263..0a980483cc 100644--- a/client/src/components/settings/ApiAccessTab.jsx+++ b/client/src/components/settings/ApiAccessTab.jsx@@ -84,7 +84,11 @@ export function ApiAccessTab() {setAccess((a) => ({ ...a, [id]: next }));setSavingId(id);try {- await updateSettings({ apiAccess: { [id]: next } }, { silent: true });+ // PUT /api/settings shallow-merges only TOP-LEVEL keys, so sending just+ // `{ apiAccess: { [id]: next } }` would REPLACE the whole apiAccess object+ // and wipe the other API's persisted flags. Send the full merged map so+ // every API's entry survives.+ await updateSettings({ apiAccess: { ...access, [id]: next } }, { silent: true });loadSpec(); // exposed-set changed → refresh the documented paths} catch (err) {setAccess((a) => ({ ...a, [id]: prev })); // revertdiff --git a/client/src/components/settings/ApiAccessTab.test.jsx b/client/src/components/settings/ApiAccessTab.test.jsxnew file mode 100644index 0000000000..c6e1684dae--- /dev/null+++ b/client/src/components/settings/ApiAccessTab.test.jsx@@ -0,0 +1,87 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { render, screen, fireEvent, waitFor } from '@testing-library/react';++vi.mock('../../services/apiSystem', () => ({+ getSettings: vi.fn(),+ updateSettings: vi.fn(),+ getOpenApiSpec: vi.fn(),+}));+vi.mock('../ui/Toast', () => ({+ default: Object.assign(vi.fn(), {+ success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn(),+ }),+}));+// copyToClipboard is unused in these tests but imported by the component.+vi.mock('../../lib/clipboard', () => ({ copyToClipboard: vi.fn() }));++import { getSettings, updateSettings, getOpenApiSpec } from '../../services/apiSystem';+import { ApiAccessTab } from './ApiAccessTab';++beforeEach(() => {+ vi.clearAllMocks();+ getOpenApiSpec.mockResolvedValue({ paths: {} });+ updateSettings.mockResolvedValue({});+});++const renderTab = async () => {+ render(<ApiAccessTab />);+ // Wait for the loading spinner to clear (cards render post-load).+ await waitFor(() => expect(screen.getByText('Voice / TTS')).toBeTruthy());+};++describe('ApiAccessTab', () => {+ it('renders a card per registry API with current state', async () => {+ getSettings.mockResolvedValue({ apiAccess: { voice: { exposed: true, requireAuth: false }, sdapi: { exposed: false, requireAuth: false } } });+ await renderTab();+ expect(screen.getByText('Voice / TTS')).toBeTruthy();+ expect(screen.getByText('Image Gen (A1111-compatible)')).toBeTruthy();+ // voice exposed + no auth → a "passwordless" status chip is present+ // ("passwordless" also appears in the intro copy, hence getAllByText);+ // sdapi not exposed → "not exposed".+ expect(screen.getAllByText('passwordless').length).toBeGreaterThan(0);+ expect(screen.getByText('not exposed')).toBeTruthy();+ });++ it('CONTRACT: toggling one API preserves the other API\'s persisted flags', async () => {+ // The server PUT /api/settings shallow-merges top-level keys, so the client+ // MUST send the full apiAccess map. Toggling voice must not wipe sdapi.+ getSettings.mockResolvedValue({+ apiAccess: {+ voice: { exposed: false, requireAuth: false },+ sdapi: { exposed: true, requireAuth: true },+ },+ });+ await renderTab();++ // Toggle voice's "Expose on the network" on.+ const exposeToggles = screen.getAllByLabelText(/Expose on the network/i);+ fireEvent.click(exposeToggles[0]); // first card = voice++ await waitFor(() => expect(updateSettings).toHaveBeenCalled());+ const sentBody = updateSettings.mock.calls[0][0];+ // sdapi's flags must be included verbatim, not dropped.+ expect(sentBody.apiAccess.sdapi).toEqual({ exposed: true, requireAuth: true });+ expect(sentBody.apiAccess.voice.exposed).toBe(true);+ });++ it('reverts optimistic state when the save fails', async () => {+ getSettings.mockResolvedValue({ apiAccess: { voice: { exposed: false, requireAuth: false }, sdapi: { exposed: false, requireAuth: false } } });+ updateSettings.mockRejectedValue(new Error('boom'));+ await renderTab();+ const exposeToggles = screen.getAllByLabelText(/Expose on the network/i);+ fireEvent.click(exposeToggles[0]);+ await waitFor(() => expect(updateSettings).toHaveBeenCalled());+ // After the rejection, voice expose should revert to unchecked.+ await waitFor(() => {+ const toggles = screen.getAllByLabelText(/Expose on the network/i);+ expect(toggles[0].checked).toBe(false);+ });+ });++ it('falls back to defaults (not-exposed) when apiAccess is absent', async () => {+ getSettings.mockResolvedValue({});+ await renderTab();+ // Both cards show "not exposed".+ expect(screen.getAllByText('not exposed').length).toBe(2);+ });+});diff --git a/server/lib/openapiSpec.js b/server/lib/openapiSpec.jsindex 9db8892c7d..ee9bcdf4bb 100644--- a/server/lib/openapiSpec.js+++ b/server/lib/openapiSpec.js@@ -31,7 +31,11 @@ const synthesizeBodySchema = z.object({text: z.string().trim().min(1).max(4000),engine: z.enum(['kokoro', 'piper']).optional(),voice: z.string().max(128).optional(),- rate: z.number().min(0.25).max(4).optional(),+ // Range 0.25–4 is the validated bound (Piper honors the full range). Kokoro+ // clamps speed to 0.5–2.0 internally (tts-kokoro.js), so values outside that+ // are silently clamped when engine=kokoro — documented here so callers know.+ rate: z.number().min(0.25).max(4).optional()+ .describe('Speech rate. Validated 0.25–4 (Piper). Kokoro clamps to 0.5–2.0.'),});const jsonSchema = (schema) => {diff --git a/server/lib/openapiSpec.test.js b/server/lib/openapiSpec.test.jsindex c8c20c69d3..c3a31681ce 100644--- a/server/lib/openapiSpec.test.js+++ b/server/lib/openapiSpec.test.js@@ -64,11 +64,20 @@ describe('buildOpenApiSpec', () => {it('synthesize body schema stays in sync with the route schema (parity)', () => {// The lib keeps a light copy of the route's schema (so it doesn't pull the// heavy TTS chain). Assert the documented body matches the route's actual- // validation shape — properties + required — so the two can't drift.+ // VALIDATION shape — every property's type/bounds + the required set — so+ // the two can't drift. `description` is doc-only (the lib copy adds a+ // per-engine rate note the route schema doesn't carry); strip it before+ // comparing so a deliberate doc annotation isn't read as a contract drift.+ const stripDescriptions = (props) =>+ Object.fromEntries(Object.entries(props).map(([k, v]) => {+ // eslint-disable-next-line no-unused-vars+ const { description, ...rest } = v;+ return [k, rest];+ }));const spec = buildOpenApiSpec(exposed({ voice: { exposed: true, requireAuth: false } }), {});const documented = spec.paths['/api/voice/public/synthesize'].post.requestBody.content['application/json'].schema;const route = z.toJSONSchema(routeSchema);- expect(documented.properties).toEqual(route.properties);+ expect(stripDescriptions(documented.properties)).toEqual(stripDescriptions(route.properties));expect((documented.required || []).sort()).toEqual((route.required || []).sort());});});