

















@@ -82,6 +82,171 @@ describe("google music generation provider", () => {
8282);
8383});
848485+it("strips /v1beta suffix from configured baseUrl before passing to GoogleGenAI SDK", async () => {
86+vi.spyOn(providerAuthRuntime, "resolveApiKeyForProvider").mockResolvedValue({
87+apiKey: "google-key",
88+source: "env",
89+mode: "api-key",
90+});
91+generateContentMock.mockResolvedValue({
92+candidates: [
93+{
94+content: {
95+parts: [
96+{
97+inlineData: {
98+data: Buffer.from("mp3-bytes").toString("base64"),
99+mimeType: "audio/mpeg",
100+},
101+},
102+],
103+},
104+},
105+],
106+});
107+108+const provider = buildGoogleMusicGenerationProvider();
109+await provider.generateMusic({
110+provider: "google",
111+model: "lyria-3-clip-preview",
112+prompt: "ambient ocean",
113+cfg: {
114+models: {
115+providers: {
116+google: { baseUrl: "https://generativelanguage.googleapis.com/v1beta", models: [] },
117+},
118+},
119+},
120+instrumental: true,
121+});
122+123+expect(createGoogleGenAIMock).toHaveBeenCalledWith(
124+expect.objectContaining({
125+httpOptions: expect.objectContaining({
126+baseUrl: "https://generativelanguage.googleapis.com",
127+}),
128+}),
129+);
130+});
131+132+it("does NOT strip /v1beta when it appears mid-path (end-anchor proof)", async () => {
133+vi.spyOn(providerAuthRuntime, "resolveApiKeyForProvider").mockResolvedValue({
134+apiKey: "google-key",
135+source: "env",
136+mode: "api-key",
137+});
138+generateContentMock.mockResolvedValue({
139+candidates: [
140+{
141+content: {
142+parts: [
143+{ inlineData: { data: Buffer.from("x").toString("base64"), mimeType: "audio/mpeg" } },
144+],
145+},
146+},
147+],
148+});
149+150+const provider = buildGoogleMusicGenerationProvider();
151+await provider.generateMusic({
152+provider: "google",
153+model: "lyria-3-clip-preview",
154+prompt: "test",
155+cfg: {
156+models: {
157+providers: { google: { baseUrl: "https://proxy.example.com/v1beta/route", models: [] } },
158+},
159+},
160+instrumental: true,
161+});
162+163+expect(createGoogleGenAIMock).toHaveBeenCalledWith(
164+expect.objectContaining({
165+httpOptions: expect.objectContaining({
166+baseUrl: "https://proxy.example.com/v1beta/route",
167+}),
168+}),
169+);
170+});
171+172+it("passes baseUrl unchanged when no /v1beta suffix is present", async () => {
173+vi.spyOn(providerAuthRuntime, "resolveApiKeyForProvider").mockResolvedValue({
174+apiKey: "google-key",
175+source: "env",
176+mode: "api-key",
177+});
178+generateContentMock.mockResolvedValue({
179+candidates: [
180+{
181+content: {
182+parts: [
183+{ inlineData: { data: Buffer.from("x").toString("base64"), mimeType: "audio/mpeg" } },
184+],
185+},
186+},
187+],
188+});
189+190+const provider = buildGoogleMusicGenerationProvider();
191+await provider.generateMusic({
192+provider: "google",
193+model: "lyria-3-clip-preview",
194+prompt: "test",
195+cfg: {
196+models: {
197+providers: {
198+google: { baseUrl: "https://generativelanguage.googleapis.com", models: [] },
199+},
200+},
201+},
202+instrumental: true,
203+});
204+205+expect(createGoogleGenAIMock).toHaveBeenCalledWith(
206+expect.objectContaining({
207+httpOptions: expect.objectContaining({
208+baseUrl: "https://generativelanguage.googleapis.com",
209+}),
210+}),
211+);
212+});
213+214+it("does not set baseUrl when none is configured", async () => {
215+vi.spyOn(providerAuthRuntime, "resolveApiKeyForProvider").mockResolvedValue({
216+apiKey: "google-key",
217+source: "env",
218+mode: "api-key",
219+});
220+generateContentMock.mockResolvedValue({
221+candidates: [
222+{
223+content: {
224+parts: [
225+{ inlineData: { data: Buffer.from("x").toString("base64"), mimeType: "audio/mpeg" } },
226+],
227+},
228+},
229+],
230+});
231+232+const provider = buildGoogleMusicGenerationProvider();
233+await provider.generateMusic({
234+provider: "google",
235+model: "lyria-3-clip-preview",
236+prompt: "test",
237+cfg: {},
238+instrumental: true,
239+});
240+241+expect(createGoogleGenAIMock).toHaveBeenCalledWith(
242+expect.objectContaining({
243+httpOptions: expect.not.objectContaining({
244+baseUrl: expect.anything(),
245+}),
246+}),
247+);
248+});
249+85250it("rejects unsupported wav output on clip model", async () => {
86251vi.spyOn(providerAuthRuntime, "resolveApiKeyForProvider").mockResolvedValue({
87252apiKey: "google-key",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。