Skip to content

Commit d7df0ab

Browse files
committed
test(api): cover Docker runtime proxy path resolution to absolute URL
Adds the test from the earlier invalid-url stash: with the Docker runtime config (relative /api/gemini), getGeminiApiBaseUrlForSettings must return an absolute URL resolved against the origin, otherwise the @google/genai SDK's internal new URL() throws 'Invalid URL'.
1 parent 3b7ac40 commit d7df0ab

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/services/api/geminiApiBaseUrl.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { afterEach, describe, expect, it } from 'vitest';
22
import {
33
getGeminiApiBaseUrlForSettings,
44
getGeminiProxyBaseUrlForSettings,
55
resolveConfiguredGeminiBaseUrl,
66
resolveLiveClientBaseUrl,
77
} from './geminiApiBaseUrl';
88

9+
const setRuntimeConfig = (config: Record<string, unknown> | undefined) => {
10+
(window as Window & { __AMC_RUNTIME_CONFIG__?: Record<string, unknown> }).__AMC_RUNTIME_CONFIG__ = config;
11+
};
12+
913
const disabledProxySettings = {
1014
useCustomApiConfig: true,
1115
useApiProxy: false,
@@ -64,4 +68,21 @@ describe('geminiApiBaseUrl', () => {
6468
}),
6569
).toBeNull();
6670
});
71+
72+
it('resolves the Docker runtime relative proxy path into an absolute URL for the SDK', () => {
73+
setRuntimeConfig({
74+
serverManagedApi: true,
75+
useCustomApiConfig: true,
76+
useApiProxy: true,
77+
apiProxyUrl: '/api/gemini',
78+
});
79+
80+
// A bare relative path would make the @google/genai SDK throw "Invalid URL"
81+
// inside new URL(baseUrl + path). It must be resolved against the origin.
82+
expect(getGeminiApiBaseUrlForSettings()).toBe('http://localhost/api/gemini');
83+
});
84+
85+
afterEach(() => {
86+
setRuntimeConfig(undefined);
87+
});
6788
});

0 commit comments

Comments
 (0)