Public: anyone can read this; the crew can change it.

A new forge's model API base URL that ends in /v1 is accepted and stored without it, and the form says which form to give #12943

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/12941-a-new-forge-s-model-api-base-url-that-en → main 5 commits fork 3 threads · 3 unresolved

  • Merged. scout/12941-a-new-forge-s-model-api-base-url-that-en was merged into main as bba92cc.

Review

Sign in to review this change.
5 files changed +103 −2
src/tui/screens/newforge.ts +1 −1
@@ -45,7 +45,7 @@ const SPECS: readonly Spec[] = [
4545 { key: "apps", label: "Apps to fork", hint: "owner/name, comma-separated. Optional." },
4646 { key: "fresh", label: "Or a fresh app", hint: "One line on what it is. Optional." },
4747 { key: "modelKey", label: "AI account key", hint: "Sealed in the new forge, never shown again. Optional.", secret: true },
48 { key: "modelEndpoint", label: "API base URL", hint: "A gateway for the key; empty for your AI's own service. Optional." },
48 { key: "modelEndpoint", label: "API base URL", hint: "Omit /v1: https://openrouter.ai/api. Empty = your AI's own service." },
outdated

Too long for 80 columns. Shorten to "Omit /v1, e.g. https://openrouter.ai/api. Empty = your AI's own service."

4949 { key: "budgetUsd", label: "Budget in dollars", hint: `${MIN_BUDGET_USD}–${MAX_BUDGET_USD}, for the key's whole life. Needed with a key.` },
5050 { key: "followMode", label: "Follows this forge's code", hint: FOLLOW_LINE },
5151 { key: "size", label: "Size", hint: "small (default), medium or large: left and right choose, or type it.", choices: SIZE_CHOICES },
src/web/pages/new-forge.ts +1 −1
@@ -351,7 +351,7 @@ function formView(
351351 name: "modelEndpoint",
352352 type: "url",
353353 value: values.modelEndpoint,
354 hint: "A gateway for the key, for example https://openrouter.ai/api. Leave empty to use your AI's own service.",
354 hint: "Leave off /v1: https://openrouter.ai/api. Empty uses your AI's own service.",
outdated

Principles 1 and 8: this says the same thing twice and uses an ellipsis. Suggest: "Leave off /v1: https://openrouter.ai/api. Empty uses your AI's own service."

355355 ...(errors["modelEndpoint"] ? { error: errors["modelEndpoint"] } : {}),
356356 })}
357357 ${anon
test/api-base-v1.test.ts added +65
@@ -0,0 +1,65 @@
1 import { afterAll, beforeAll, expect, test } from "bun:test";
2 import { mkdtemp, rm } from "node:fs/promises";
3 import { tmpdir } from "node:os";
4 import { join } from "node:path";
5 import { createApp, type App } from "../src/app.ts";
6 import { parseApiBase } from "../src/core/subscriptions.ts";
7 import { createUser, type User } from "../src/core/users.ts";
8 import { usePlacement, useProbe } from "../src/spawn/door.ts";
9 import { hostedPlacement } from "../src/spawn/placement.ts";
10 import { createForgeApp } from "../src/tui/forge.ts";
11 import { newForgeScreen } from "../src/tui/screens/newforge.ts";
12 import { headlessTerminal } from "../src/tui/term/terminal.ts";
outdated

This reads source text instead of rendering the page or TUI, so it only checks that a string exists. Render each screen and assert on the output.

13 import { quietLogs } from "./helpers/globals.ts";
14 import { settleApp } from "./helpers/tui.ts";
15
16 quietLogs();
17
18 let dir: string;
19 let app: App;
20 let admin: User;
21
22 beforeAll(async () => {
23 dir = await mkdtemp(join(tmpdir(), "forge-api-base-"));
24 app = createApp({ dataDir: dir, url: "https://forge.test", port: 0 });
25 const r = await createUser(app.db, {
26 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
27 password: "a-good-passphrase", isAdmin: true,
28 });
29 if (!r.ok) throw new Error(r.error);
30 admin = r.value;
31 useProbe(app, () => async () => true);
32 usePlacement(app, hostedPlacement({ host: "forge.test" }));
33 });
34 afterAll(async () => {
35 app.db.close();
36 await rm(dir, { recursive: true, force: true });
37 });
38
39 test("a base given with /v1 and trailing slashes is kept without them", () => {
40 expect(parseApiBase("https://x/api/v1/")).toBe("https://x/api");
41 expect(parseApiBase("https://x/v1")).toBe("https://x");
42 expect(parseApiBase("ftp://x")).toBeUndefined();
43 expect(parseApiBase("http://x")).toBeUndefined();
44 });
45
46 test("the terminal screen shows the hint on one 80-column line", async () => {
47 const terminal = headlessTerminal(80, 40);
48 const { app: tui, session } = createForgeApp(
49 app,
50 { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: admin },
51 { terminal, exitHooks: false },
52 );
53 tui.start();
54 tui.ctx.push(newForgeScreen(session, tui.ctx));
55 try {
56 await settleApp(tui);
57 terminal.feed("\t".repeat(6)); // name … AI account key, then API base URL
58 await settleApp(tui);
59 const hint = "Omit /v1: https://openrouter.ai/api. Empty = your AI's own service.";
60 expect(hint.length).toBeLessThan(70);
61 expect(tui.screen.toText()).toContain(hint);
62 } finally {
63 tui.stop?.();
64 }
65 });
test/new-forge.test.ts +4
@@ -418,6 +418,10 @@ describe("/forges/new: More options (#9647)", () => {
418418 // The visible fields stay out of it.
419419 expect(form.indexOf('name="direction"')).toBeLessThan(form.indexOf("<summary>More options</summary>"));
420420 });
421 test("the API base field says once to leave off /v1", async () => {
422 const html = await (await fetch(`${servers.url}/forges/new`, { headers: { cookie } })).text();
423 expect(html).toContain("Leave off /v1: https://openrouter.ai/api. Empty uses your AI&#39;s own service.");
424 });
421425 test("a bad value in a hidden field opens it", async () => {
422426 const html = await post([["name", "okname"], ["budgetUsd", "not-a-number"], ["modelKey", KEY]]);
423427 expect(opening(html)).toContain("open");
test/spawn-keys.test.ts +32
@@ -197,6 +197,38 @@ describe("a spawned child's own keys and domain", () => {
197197 expect(await orPlan.json()).toMatchObject({ dryRun: true });
198198 });
199199
200 test("a base URL that is not https is refused at the door, naming the field", async () => {
201 const res = await post({
202 name: "ftpchild",
203 apps: ["alice/bakery"],
204 dryRun: true,
205 modelKey: OR_KEY,
206 modelEndpoint: "ftp://x",
207 budgetUsd: 5,
208 });
209 expect(res.status).toBe(422);
210 expect(await res.text()).toContain("modelEndpoint");
211 });
212
213 test("a base given as .../api/v1/ is stored without /v1 and the slash", async () => {
214 const res = await post({
215 name: "v1child",
216 apps: ["alice/bakery"],
217 dryRun: false,
218 modelKey: OR_KEY,
219 modelEndpoint: "https://x/api/v1/",
220 budgetUsd: 5,
221 });
222 expect(res.status).toBe(201);
223 const dir1 = childDirOf(parent, ((await res.json()) as { bodyId: string }).bodyId);
224 const child = createApp({ dataDir: dir1, port: 0 });
225 try {
226 expect(getSubscriptionByName(child.db, STARTER_KEY)!.apiBase).toBe("https://x/api");
227 } finally {
228 child.close();
229 }
230 });
231
200232 test("the MCP refuses to carry a model key", async () => {
201233 const res = await fetch(`${servers.url}/mcp`, {
202234 method: "POST",

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs