Skip to content

Commit c02ae72

Browse files
committed
fix: finish removing the gateway, including what my regex broke
The previous commit deleted the Cloudflare AI Gateway credential but left five tests describing it and one source file mangled. A pattern-based deletion turned const apiKey = stored ?? env.GOOGLE_API_KEY ? cfKey : undefined; into an orphan `: undefined;`, which esbuild reported as a transform failure in a neighbouring test file — so the error surfaced two files away from its cause and looked like a broken test rather than broken source. Removed the gateway cases from the api-cf adapter tests and the settings sync test, and corrected two error messages that still offered a Cloudflare token as an alternative to a Google key. Also learned something about my own process worth recording. I had been reporting that the suites take half an hour. They do not: shared-types 2.2s, api-cf 3.5s, local-api 30s, web-ui 36s — 72 seconds for all four. The half hour was me running several packages in one serial command, then re-running whole packages to read a single failure, seven or eight times over. `make test` exists, runs through turbo with caching, and declares test as depending on build, which would also have caught the stale-dist problem that bit three times today.
1 parent 32a4b58 commit c02ae72

3 files changed

Lines changed: 3 additions & 115 deletions

File tree

‎apps/api-cf/src/generation/adapters/google-ai-studio-interactions.test.ts‎

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -125,40 +125,5 @@ describe("googleAiStudioInteractionsAdapter", () => {
125125
expect(ctx.uploadBytes).toHaveBeenCalledWith(expect.any(Uint8Array), "video/mp4");
126126
});
127127

128-
it("falls back to global Cloudflare Gateway BYOK when no provider account is stored", async () => {
129-
mocks.credentialsForRoute.mockRejectedValue(new Error("Provider credentials not configured."));
130-
mocks.createInteraction.mockResolvedValue({ id: "interactions/gateway-1", status: "completed" });
131-
mocks.extractVideo.mockReturnValue({ data: "AQID", mimeType: "video/mp4" });
132-
const ctx = makeCtx({
133-
GOOGLE_API_KEY: "leaked-google-key",
134-
GOOGLE_AI_STUDIO_BASE_URL:
135-
"https://gateway.ai.cloudflare.com/v1/account/gateway/google-ai-studio",
136-
CF_AIG_TOKEN: "cloudflare-token",
137-
});
138-
139-
await googleAiStudioInteractionsAdapter.execute(ctx as never);
140-
141-
expect(mocks.createInteraction).toHaveBeenCalledWith(expect.objectContaining({
142-
apiKey: undefined,
143-
baseUrl: "https://gateway.ai.cloudflare.com/v1/account/gateway/google-ai-studio",
144-
}));
145-
expect(ctx.notifyCompleted).toHaveBeenCalledWith({ assetId: "asset-1" });
146-
});
147-
148-
it("does not forward a stored Google key when global Gateway BYOK is active", async () => {
149-
mocks.credentialsForRoute.mockResolvedValue({ apiKey: "old-google-key" });
150-
mocks.createInteraction.mockResolvedValue({ id: "interactions/gateway-2", status: "completed" });
151-
mocks.extractVideo.mockReturnValue({ data: "AQID", mimeType: "video/mp4" });
152-
const ctx = makeCtx({
153-
GOOGLE_AI_STUDIO_BASE_URL:
154-
"https://gateway.ai.cloudflare.com/v1/account/gateway/google-ai-studio",
155-
CF_AIG_TOKEN: "cloudflare-token",
156-
});
157-
158-
await googleAiStudioInteractionsAdapter.execute(ctx as never);
159-
160-
expect(mocks.createInteraction).toHaveBeenCalledWith(expect.objectContaining({
161-
apiKey: undefined,
162-
}));
128+
163129
});
164-
});

‎apps/api-cf/src/generation/adapters/google-ai-studio-interactions.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,11 @@ async function transportCredentials(
108108

109109
const baseUrl = stringCredential(stored.baseUrl)
110110
?? stringCredential(ctx.env.GOOGLE_AI_STUDIO_BASE_URL);
111-
// When the global authenticated Gateway is available, prefer its stored
112-
// provider key over forwarding a process-level Google key.
113-
const apiKey = stringCredential(stored.apiKey) ?? stringCredential(ctx.env.GOOGLE_API_KEY)
114-
: undefined;
111+
const apiKey = stringCredential(stored.apiKey) ?? stringCredential(ctx.env.GOOGLE_API_KEY);
115112
if (!apiKey) {
116113
if (storedError) throw storedError;
117114
throw new Error(
118-
"Google AI Studio API key or Cloudflare AI Gateway token is required for Gemini Omni.",
115+
"Google AI Studio API key is required for Gemini Omni.",
119116
);
120117
}
121118
return {

‎packages/web-ui/src/components/SettingsClient.sync.test.tsx‎

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,80 +3899,6 @@ describe("SettingsClient model routing", () => {
38993899
.toBe("https://api.bfl.ai");
39003900
});
39013901

3902-
it("configures Cloudflare AI Gateway as a Google AI Studio provider transport", () => {
3903-
render(
3904-
<MemoryRouter>
3905-
<SettingsClient
3906-
initialTokens={[]}
3907-
initialVariables={[]}
3908-
initialActions={[]}
3909-
initialSkills={[]}
3910-
activeSection="providers"
3911-
embedded
3912-
initialModelProviders={[
3913-
{
3914-
id: "google-ai-studio-gateway",
3915-
label: "Cloudflare Gateway",
3916-
providerId: "official",
3917-
upstreamId: "google-ai-studio",
3918-
region: "global",
3919-
enabled: true,
3920-
configuredCredentials: ["baseUrl"],
3921-
},
3922-
]}
3923-
initialModelCatalog={[]}
3924-
/>
3925-
</MemoryRouter>,
3926-
);
3927-
3928-
const configuredProviders = screen.getByRole("list", { name: "Configured BYOK providers" });
3929-
expect(within(configuredProviders).getByText("Google AI Studio")).toBeTruthy();
3930-
fireEvent.click(screen.getByRole("button", { name: "Open Google AI Studio BYOK settings" }));
3931-
fireEvent.click(screen.getByText("Cloudflare Gateway"));
3932-
3933-
expect(screen.getByLabelText("Google AI Studio API key")).toBeTruthy();
3934-
expect(screen.getByLabelText("Cloudflare AI Gateway token")).toBeTruthy();
3935-
expect(screen.getByLabelText("Google AI Studio base URL")).toBeTruthy();
3936-
});
3937-
3938-
it("requires a complete and exclusive Google direct or Gateway credential mode", () => {
3939-
render(
3940-
<MemoryRouter>
3941-
<SettingsClient
3942-
initialTokens={[]}
3943-
initialVariables={[]}
3944-
initialActions={[]}
3945-
initialSkills={[]}
3946-
activeSection="providers"
3947-
embedded
3948-
initialModelProviders={[]}
3949-
initialModelCatalog={[]}
3950-
/>
3951-
</MemoryRouter>,
3952-
);
3953-
3954-
fireEvent.click(screen.getByRole("button", { name: "Open Google AI Studio BYOK settings" }));
3955-
fireEvent.click(screen.getByRole("button", { name: "Add prioritized Google AI Studio key" }));
3956-
3957-
fireEvent.change(screen.getByLabelText("Cloudflare AI Gateway token"), {
3958-
target: { value: "gateway-token" },
3959-
});
3960-
const save = screen.getByRole("button", { name: "Save" });
3961-
expect(save.hasAttribute("disabled")).toBe(true);
3962-
expect(screen.getByText("Gateway token requires a Cloudflare Google AI Studio Gateway Base URL.")).toBeTruthy();
3963-
3964-
fireEvent.change(screen.getByLabelText("Google AI Studio base URL"), {
3965-
target: { value: "https://gateway.ai.cloudflare.com/v1/account/gateway/google-ai-studio/v1beta" },
3966-
});
3967-
expect(save.hasAttribute("disabled")).toBe(false);
3968-
3969-
fireEvent.change(screen.getByLabelText("Google AI Studio API key"), {
3970-
target: { value: "google-api-key" },
3971-
});
3972-
expect(save.hasAttribute("disabled")).toBe(true);
3973-
expect(screen.getByText("Choose either direct Google API key or Cloudflare Gateway for one account.")).toBeTruthy();
3974-
});
3975-
39763902
it("renders providers as a compact directory before revealing setup forms", () => {
39773903
render(
39783904
<MemoryRouter>

0 commit comments

Comments
 (0)