diff --git a/scripts/check-browser-manifest.mjs b/scripts/check-browser-manifest.mjs index 9224e9e43..0eac89e94 100644 --- a/scripts/check-browser-manifest.mjs +++ b/scripts/check-browser-manifest.mjs @@ -58,6 +58,7 @@ const welcomeExempt = new Set([ "bilingual_defaults.mjs", "canvas_clipboard_order.mjs", "first_run.mjs", + "first_run_added_models.mjs", "model_editor_hosts.mjs", ]); for (const entry of entries) { diff --git a/scripts/run-browser-suite.mjs b/scripts/run-browser-suite.mjs index ec4ccaf17..884047389 100644 --- a/scripts/run-browser-suite.mjs +++ b/scripts/run-browser-suite.mjs @@ -85,6 +85,7 @@ const workflows = [ env: { PYTHON: "python" }, }, { name: "first-run setup", script: "tests/browser/first_run.mjs" }, + { name: "first-run added models", script: "tests/browser/first_run_added_models.mjs" }, { name: "selection toolbar hover", script: "tests/browser/selection_toolbar_hover.mjs" }, { name: "model editor hosts", script: "tests/browser/model_editor_hosts.mjs" }, { name: "motion studio", script: "tests/browser/motion_studio.mjs" }, diff --git a/src/canvas/WelcomeScreen.tsx b/src/canvas/WelcomeScreen.tsx index 5abcec8a1..b811cc349 100644 --- a/src/canvas/WelcomeScreen.tsx +++ b/src/canvas/WelcomeScreen.tsx @@ -98,6 +98,8 @@ export function WelcomeScreen({ catalog, projectId, onEnterWorkspace, onCreate, const [direction, setDirection] = useState<"forward" | "back">("forward"); const [importReturns, setImportReturns] = useState(0); const [editing, setEditing] = useState(null); + const [addedModels, setAddedModels] = useState([]); + const focusAddedModel = useRef(false); const [lockedEditor, setLockedEditor] = useState(null); const [assistant, setAssistant] = useState(null); const [tasks, setTasks] = useState>>({}); @@ -155,6 +157,13 @@ export function WelcomeScreen({ catalog, projectId, onEnterWorkspace, onCreate, heading.current?.focus(); if (dialog.current) dialog.current.scrollTop = 0; }, [screen, editing]); + useLayoutEffect(() => { + if (!focusAddedModel.current || screen !== "language") return; + focusAddedModel.current = false; + const [first] = addedModels; + if (!first) return; + dialog.current?.querySelector(`[data-first-run-agent="${CSS.escape(first)}"]`)?.focus(); + }, [screen, addedModels]); useLayoutEffect(() => { const pending = taskFocus.current; if (!pending || !isTaskStep) return; @@ -225,32 +234,41 @@ export function WelcomeScreen({ catalog, projectId, onEnterWorkspace, onCreate, savingNow.current = true; setSaving(true); setAssistantError(""); + setAddedModels([]); try { - const status = await chatRuntimeStatus(projectId, runtime); - if (status.status !== "ready" || !status.available || (status.modelSource === "settings" && !agent)) { - setAssistantError(t("firstRun.assistantUnavailable")); - return; - } const { conversation: stored, activeTurnId } = await conversation(projectId); if (activeTurnId) { setAssistantError(t("firstRun.assistantBusy")); return; } + const previousRuntime = stored.runtime && stored.runtime !== "default" ? stored.runtime : null; + const keepHarness = runtime === "default" && previousRuntime !== null; + const effective = keepHarness ? previousRuntime : runtime; + const status = await chatRuntimeStatus(projectId, effective); + if (status.status !== "ready" || !status.available || (status.modelSource === "settings" && !agent)) { + setAssistantError(t("firstRun.assistantUnavailable")); + return; + } const selected = restoreAgentSelection(projectId, stored); const { messages, ...draft } = stored; - const runtimeModel = runtime !== "default" && status.modelSource === "cli" - ? selected.harnessModels?.[runtime] ?? (selected.runtime === runtime ? selected.runtimeModel : null) ?? null + const runtimeModel = effective !== "default" && status.modelSource === "cli" + ? selected.harnessModels?.[effective] ?? (selected.runtime === effective ? selected.runtimeModel : null) ?? null : null; - const next = { - ...draft, - runtime, - runtimeModel, - harnessModels: { - ...selected.harnessModels, - ...(runtime === "default" ? {} : { [runtime]: agent?.id ?? runtimeModel }), - }, - modelSelections: { ...draft.modelSelections, agent: agent?.id ?? draft.modelSelections.agent }, - }; + const next = keepHarness + ? { + ...draft, + modelSelections: { ...draft.modelSelections, agent: agent?.id ?? draft.modelSelections.agent }, + } + : { + ...draft, + runtime: effective, + runtimeModel, + harnessModels: { + ...selected.harnessModels, + ...(effective === "default" ? {} : { [effective]: agent?.id ?? runtimeModel }), + }, + modelSelections: { ...draft.modelSelections, agent: agent?.id ?? draft.modelSelections.agent }, + }; await saveChatDraft(projectId, next); rememberAgentSelection(projectId, { ...next, messages }); setAssistant(label); @@ -314,7 +332,7 @@ export function WelcomeScreen({ catalog, projectId, onEnterWorkspace, onCreate, } } - function finishModelSetup(capability: FirstRunCapability, saved: ModelConfig[]) { + function finishModelSetup(capability: FirstRunCapability, saved: ModelConfig[], edited = false) { closeModelSetup(capability); const [item] = saved; if (capability !== "text_response") { @@ -323,9 +341,18 @@ export function WelcomeScreen({ catalog, projectId, onEnterWorkspace, onCreate, } } else { navigate("language"); - if (saved.length === 1 && firstRunModelIssue(item, "text_response") === null) { - void connect(item.modelId, "default", item); + const usable = saved.filter((model) => firstRunModelIssue(model, "text_response") === null); + if (edited) { + setAddedModels([]); + focusAddedModel.current = false; + return; + } + if (usable.length === 1) { + void connect(usable[0].modelId, "default", usable[0]); + return; } + setAddedModels(usable.map((model) => model.id)); + focusAddedModel.current = usable.length > 0; } } @@ -365,7 +392,7 @@ export function WelcomeScreen({ catalog, projectId, onEnterWorkspace, onCreate, }} onLockChange={updateEditorLock} onClose={() => closeModelSetup(editor.capability)} - onSaved={(saved) => finishModelSetup(editor.capability, saved)} + onSaved={(saved) => finishModelSetup(editor.capability, saved, Boolean(editor.existing))} />; } @@ -485,11 +512,23 @@ export function WelcomeScreen({ catalog, projectId, onEnterWorkspace, onCreate, ) : screen === "language" || screen === "harness" ? ( <>

{t(screen === "language" ? "firstRun.languageListHint" : "firstRun.harnessHint")}

+ {screen === "language" && addedModels.length > 0 && ( +

+ {t("firstRun.pickAddedModel", { count: addedModels.length })} +

+ )}
{screen === "language" ? agents.map((agent) => ( - )) : runtimes.map((item) => { if (item.id === "default") return null; diff --git a/src/canvas/welcome-screen.css b/src/canvas/welcome-screen.css index aba621074..5e3cefa13 100644 --- a/src/canvas/welcome-screen.css +++ b/src/canvas/welcome-screen.css @@ -109,6 +109,17 @@ html[data-desktop-platform="win32"]:not([data-desktop-fullscreen]) .cw-welcome { .cw-welcome-intro { grid-template-columns: minmax(0, 1fr); min-height: auto; gap: 24px; padding: clamp(32px, 7vh, 68px) 0 24px; } } .cw-welcome-description { margin: 12px 0 20px; color: var(--settings-muted); font-size: 14px; line-height: 1.6; } +.cw-welcome-added-hint { + margin: 0 0 12px; + padding: 10px 14px; + border: 1px solid var(--cw-control-accent, var(--settings-border)); + border-radius: 8px; + color: var(--settings-text); + font-size: 13px; + line-height: 1.5; + background: var(--settings-hover); +} +.cw-welcome-option small.cw-welcome-new-model { color: var(--cw-control-accent, var(--settings-text)); font-weight: 600; } .cw-welcome-options { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; } .cw-welcome-mode-connected { margin: 8px 0 28px; color: var(--settings-muted); overflow-wrap: anywhere; } .cw-welcome-modes { gap: 10px; } diff --git a/src/i18n/messages/en-US/firstRun.ts b/src/i18n/messages/en-US/firstRun.ts index e953974d5..99fc3ca0f 100644 --- a/src/i18n/messages/en-US/firstRun.ts +++ b/src/i18n/messages/en-US/firstRun.ts @@ -16,6 +16,8 @@ export const firstRun = { "firstRun.languageTitle": "Set up a language model", "firstRun.languageListHint": "Choose a saved chat model or add a new one.", "firstRun.useSavedModel": "Use this saved language model", + "firstRun.pickAddedModel": "Added {count} language models. Pick one to continue to step 2.", + "firstRun.modelJustAdded": "New · pick to continue", "firstRun.addLanguageModel": "Add a language model", "firstRun.harnessAction": "Use an existing harness", "firstRun.harnessTitle": "Choose an existing harness", diff --git a/src/i18n/messages/zh-CN/firstRun.ts b/src/i18n/messages/zh-CN/firstRun.ts index 10ac5d065..3c942d7df 100644 --- a/src/i18n/messages/zh-CN/firstRun.ts +++ b/src/i18n/messages/zh-CN/firstRun.ts @@ -16,6 +16,8 @@ export const firstRun = { "firstRun.languageTitle": "配置语言模型", "firstRun.languageListHint": "选择一个已配置的对话模型,或添加一个新模型。", "firstRun.useSavedModel": "使用这个已保存的语言模型", + "firstRun.pickAddedModel": "已添加 {count} 个语言模型,点选其中一个继续到第 2 步。", + "firstRun.modelJustAdded": "新添加 · 点选继续", "firstRun.addLanguageModel": "添加语言模型", "firstRun.harnessAction": "使用已有Harness", "firstRun.harnessTitle": "选择已有 Harness", diff --git a/tests/browser/first_run.mjs b/tests/browser/first_run.mjs index b69f06545..6d0c201a2 100644 --- a/tests/browser/first_run.mjs +++ b/tests/browser/first_run.mjs @@ -33,6 +33,7 @@ try { modelOverride: true, available: true, status: "ready", }; const claude = { ...codex, id: "claude", label: "Claude Code", status: "needs_login" }; + const opencode = { ...codex, id: "opencode", label: "OpenCode", status: "ready" }; const defaultAgent = { ...codex, id: "default", label: "Default", group: "default", modelSource: "settings", modelOverride: false }; const slowHarness = { ...codex, id: "deepseek", label: "DeepSeek Harness", status: "checking" }; const probe = Promise.withResolvers(); @@ -41,11 +42,16 @@ try { await route.fulfill({ json: { ...slowHarness, status: "unknown" } }).catch(() => {}); }); await page.route(/\/assistant\/runtimes\?probe=false$/, (route) => - route.fulfill({ json: [slowHarness, { ...codex, status: "checking" }, claude] })); - await page.route(/\/assistant\/runtimes\/(codex|claude)\/status$/, (route) => - route.fulfill({ json: route.request().url().includes("codex") ? codex : claude })); + route.fulfill({ json: [slowHarness, { ...codex, status: "checking" }, claude, opencode] })); + const harnessStatus = { codex, claude, opencode }; + await page.route(/\/assistant\/runtimes\/(codex|claude|opencode)\/status$/, (route) => { + const id = route.request().url().match(/runtimes\/([^/]+)\/status$/)?.[1] ?? "codex"; + return route.fulfill({ json: harnessStatus[id] }); + }); await page.route("**/assistant/runtimes/default/status", (route) => route.fulfill({ json: defaultAgent })); const languageModel = `first-run-agent-${projectId.slice(0, 8)}`; + const secondLanguageModel = `first-run-agent-kept-${projectId.slice(0, 8)}`; + const unavailableHarnessModel = `first-run-agent-down-${projectId.slice(0, 8)}`; const videoModels = ["alpha", "beta"].map((suffix) => `first-run-video-${projectId.slice(0, 8)}-${suffix}`); const imageModel = `first-run-image-${projectId.slice(0, 8)}`; const chatImageModel = `chat-canvas-image-${projectId.slice(0, 8)}`; @@ -61,6 +67,7 @@ try { const response = await route.fetch(); const configs = await response.json(); const models = configs.filter((item) => item.modelId === languageModel || item.modelId === chatImageModel || + item.modelId === secondLanguageModel || item.modelId === unavailableHarnessModel || (!onlyLanguage && !showBlockedImage && (videoModels.includes(item.modelId) || item.modelId === imageModel))); if (showBlockedImage && !onlyLanguage) { const image = configs.find((item) => item.modelId === "fixture-image"); @@ -157,6 +164,8 @@ try { const [savedLanguage] = await languageReceipt.json(); configuredIds.push(savedLanguage.id); await welcome.getByRole("heading", { name: "Choose how to create" }).waitFor(); + const firstAssistant = await (await page.request.get(base + projectPath + "/assistant", { headers })).json(); + assert.equal(firstAssistant.runtime, "default"); assert.ok(await agentMode.isVisible() && await canvasMode.isVisible()); assert.equal(await welcome.getByRole("checkbox").count(), 0); assert.equal(await welcome.getByRole("button", { name: "Import media" }).count(), 0); @@ -184,6 +193,59 @@ try { assert.ok(assistant.ok(), await assistant.text()); assert.equal((await assistant.json()).runtime, "codex"); + await welcome.getByRole("button", { name: "Back", exact: true }).click(); + await assistantTitle.waitFor(); + await configureLanguage.click(); + await welcome.getByRole("button", { name: "Add a language model", exact: true }).click(); + await welcome.getByLabel("Service URL (Base URL)").fill("http://127.0.0.1:12345/v1"); + await welcome.getByRole("button", { name: "Add manually" }).click(); + await welcome.getByLabel(manualModelId, { exact: true }).fill(secondLanguageModel); + await welcome.getByRole("button", { name: "Add", exact: true }).click(); + const savingSecond = page.waitForResponse((response) => response.url().endsWith("/api/model-configs/batch")); + await welcome.getByRole("button", { name: "Save and continue", exact: true }).click(); + const secondReceipt = await savingSecond; + assert.ok(secondReceipt.ok(), await secondReceipt.text()); + const [savedSecond] = await secondReceipt.json(); + configuredIds.push(savedSecond.id); + await welcome.getByRole("heading", { name: "Choose how to create" }).waitFor(); + const keptHarness = await (await page.request.get(base + projectPath + "/assistant", { headers })).json(); + assert.equal(keptHarness.runtime, "codex"); + assert.equal(keptHarness.modelSelections.agent, savedSecond.id); + + harnessStatus.codex = { ...codex, available: false }; + await welcome.getByRole("button", { name: "Back", exact: true }).click(); + await assistantTitle.waitFor(); + await welcome.getByRole("button", { name: "Use an existing harness", exact: true }).click(); + await welcome.getByRole("button", { name: "Reload", exact: true }).click(); + await page.waitForFunction(() => [...document.querySelectorAll("dialog.cw-welcome button")] + .some((button) => button.textContent?.trim().startsWith("Codex") && button.disabled)); + await welcome.getByRole("button", { name: "Back", exact: true }).click(); + await assistantTitle.waitFor(); + await configureLanguage.click(); + await welcome.getByRole("button", { name: "Add a language model", exact: true }).click(); + await welcome.getByLabel("Service URL (Base URL)").fill("http://127.0.0.1:12345/v1"); + await welcome.getByRole("button", { name: "Add manually" }).click(); + await welcome.getByLabel(manualModelId, { exact: true }).fill(unavailableHarnessModel); + await welcome.getByRole("button", { name: "Add", exact: true }).click(); + const savingUnavailable = page.waitForResponse((response) => response.url().endsWith("/api/model-configs/batch")); + await welcome.getByRole("button", { name: "Save and continue", exact: true }).click(); + const unavailableReceipt = await savingUnavailable; + assert.ok(unavailableReceipt.ok(), await unavailableReceipt.text()); + configuredIds.push(...(await unavailableReceipt.json()).map((model) => model.id)); + await welcome.getByRole("alert") + .getByText("This assistant isn’t available right now. Check its setup or choose another way to connect.").waitFor(); + const stoppedHarness = await (await page.request.get(base + projectPath + "/assistant", { headers })).json(); + assert.equal(stoppedHarness.runtime, "codex"); + assert.equal(stoppedHarness.modelSelections.agent, savedSecond.id); + harnessStatus.codex = codex; + await welcome.getByRole("button", { name: "Back", exact: true }).click(); + await assistantTitle.waitFor(); + await welcome.getByRole("button", { name: "Use an existing harness", exact: true }).click(); + await welcome.getByRole("button", { name: /^OpenCode/ }).click(); + await welcome.getByRole("heading", { name: "Choose how to create" }).waitFor(); + const switchedHarness = await (await page.request.get(base + projectPath + "/assistant", { headers })).json(); + assert.equal(switchedHarness.runtime, "opencode"); + assert.equal(await welcome.getByRole("checkbox", { checked: true }).count(), 0); await canvasMode.click(); const videoTask = welcome.getByRole("checkbox", { name: "Make a video" }); diff --git a/tests/browser/first_run_added_models.mjs b/tests/browser/first_run_added_models.mjs new file mode 100644 index 000000000..7effd0888 --- /dev/null +++ b/tests/browser/first_run_added_models.mjs @@ -0,0 +1,188 @@ +import assert from "node:assert/strict"; +import { launchBrowser } from "./engine.mjs"; + +const base = process.env.CREATION_WEB_URL ?? "http://127.0.0.1:5179"; +const headers = { "X-OpenDirector-Request": "1", "Content-Type": "application/json" }; +const health = await fetch(base + "/api/creation-test-health", { headers }); +assert.ok(health.ok && (await health.json()).isolated, "Requires an isolated creation API"); + +const projectId = crypto.randomUUID(); +const projectPath = `/api/creation/projects/${projectId}`; +const create = await fetch(base + projectPath + "/commands", { + method: "POST", headers, + body: JSON.stringify({ + projectId, commandId: crypto.randomUUID(), type: "project.create", + payload: { name: `First-run added models ${projectId.slice(0, 8)}` }, + }), +}); +assert.ok(create.ok, await create.text()); + +const browser = await launchBrowser(); +const configuredIds = []; +try { + const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }); + await page.addInitScript(() => { + if (localStorage.getItem("opendirector.locale.v1") === null) + localStorage.setItem("opendirector.locale.v1", "en-US"); + }); + page.setDefaultTimeout(15000); + const errors = []; + page.on("pageerror", (error) => errors.push(error.message)); + const defaultAgent = { + id: "default", label: "Default", group: "default", modelSource: "settings", + modelOverride: false, available: true, status: "ready", + }; + await page.route("**/assistant/runtimes/default/status", (route) => route.fulfill({ json: defaultAgent })); + const languageModel = `first-run-added-models-${projectId.slice(0, 8)}`; + const addedLanguageModels = ["first-run-added-a", "first-run-added-b"].map((name) => `${name}-${projectId.slice(0, 8)}`); + const freshLanguageModels = ["first-run-fresh-a", "first-run-fresh-b"].map((name) => `${name}-${projectId.slice(0, 8)}`); + let blockedModel; + await page.route(/\/api\/model-configs$/, async (route) => { + const response = await route.fetch(); + const configs = await response.json(); + const models = configs.filter((item) => item.modelId === languageModel || addedLanguageModels.includes(item.modelId) || freshLanguageModels.includes(item.modelId)); + if (blockedModel !== undefined) { + const index = models.findIndex((item) => item.modelId === blockedModel); + models[index] = { + ...models[index], + availability: { + ...models[index].availability, + operations: models[index].availability.operations.map((operation) => operation.profile === "text_response" + ? { ...operation, status: "unavailable", reasonCode: "execution_paused", checkedAt: null, expiresAt: null } + : operation), + }, + }; + } + await route.fulfill({ response, json: models }); + }); + await page.route("**/api/model-configs/discover", (route) => route.fulfill({ json: { models: [...addedLanguageModels, ...freshLanguageModels] } })); + + const url = `${base}/ai-tool/ai-canvas/${projectId}`; + const welcome = page.locator("dialog.cw-welcome"); + const welcomeTitle = welcome.getByRole("heading", { name: "Welcome to OpenDirector" }); + const assistantTitle = welcome.getByRole("heading", { name: "Connect an LLM" }); + const configureLanguage = welcome.getByRole("button", { name: "Set up a language model", exact: true }); + const serviceUrl = welcome.getByLabel("Service URL (Base URL)"); + const manualModelId = "Model ID (the service's served-model-name)"; + await page.goto(`${url}?setup=welcome&from=onboarding`); + await welcomeTitle.waitFor(); + await welcome.getByRole("button", { name: "Get started", exact: true }).click(); + await assistantTitle.waitFor(); + await configureLanguage.click(); + await serviceUrl.fill("http://127.0.0.1:12345/v1"); + await welcome.getByRole("button", { name: "Add manually" }).click(); + await welcome.getByLabel(manualModelId, { exact: true }).fill(languageModel); + await welcome.getByRole("button", { name: "Add", exact: true }).click(); + const firstSave = page.waitForResponse((response) => response.url().endsWith("/api/model-configs/batch")); + await welcome.getByRole("button", { name: "Save and continue", exact: true }).click(); + const firstReceipt = await firstSave; + assert.ok(firstReceipt.ok(), await firstReceipt.text()); + const [savedLanguage] = await firstReceipt.json(); + configuredIds.push(savedLanguage.id); + await welcome.getByRole("heading", { name: "Choose how to create" }).waitFor(); + + await welcome.getByRole("button", { name: "Back", exact: true }).click(); + await assistantTitle.waitFor(); + await configureLanguage.click(); + await welcome.getByRole("button", { name: "Add a language model", exact: true }).click(); + await serviceUrl.fill("http://127.0.0.1:12345/v1"); + await welcome.getByRole("button", { name: "Fetch models", exact: true }).click(); + for (const model of addedLanguageModels) await welcome.getByRole("checkbox", { name: model, exact: true }).check(); + const addingLanguages = page.waitForResponse((response) => response.url().endsWith("/api/model-configs/batch")); + await welcome.getByRole("button", { name: "Save and continue", exact: true }).click(); + const addingReceipt = await addingLanguages; + assert.ok(addingReceipt.ok(), await addingReceipt.text()); + const addedLanguages = await addingReceipt.json(); + assert.equal(addedLanguages.length, 2); + configuredIds.push(...addedLanguages.map((item) => item.id)); + await welcome.getByRole("heading", { name: "Set up a language model" }).waitFor(); + await welcome.getByText("Added 2 language models. Pick one to continue to step 2.").waitFor(); + assert.equal(await welcome.getByText("New · pick to continue", { exact: true }).count(), 2); + assert.equal(await page.evaluate(() => document.activeElement?.getAttribute("data-first-run-agent")), addedLanguages[0].id); + const addedOption = welcome.getByRole("button").filter({ hasText: addedLanguages[0].modelId }); + await addedOption.waitFor(); + assert.equal(await welcome.getByRole("heading", { name: "Choose how to create" }).count(), 0); + const beforePick = await (await page.request.get(base + projectPath + "/assistant", { headers })).json(); + assert.equal(beforePick.modelSelections.agent, savedLanguage.id); + await addedOption.click(); + await welcome.getByRole("heading", { name: "Choose how to create" }).waitFor(); + const afterPick = await (await page.request.get(base + projectPath + "/assistant", { headers })).json(); + assert.equal(afterPick.modelSelections.agent, addedLanguages[0].id); + + blockedModel = addedLanguages[1].modelId; + await page.goto(`${url}?setup=welcome&from=onboarding`); + await welcomeTitle.waitFor(); + await welcome.getByRole("button", { name: "Get started", exact: true }).click(); + await assistantTitle.waitFor(); + await configureLanguage.click(); + const blocked = welcome.getByRole("listitem").filter({ hasText: addedLanguages[1].modelId }); + await blocked.getByText("Service paused").waitFor(); + await blocked.getByRole("button", { name: "Edit service", exact: true }).click(); + await welcome.getByRole("form", { name: "Edit service" }).waitFor(); + blockedModel = undefined; + const editingModels = page.waitForResponse((response) => response.url().endsWith("/api/model-configs/batch")); + await welcome.getByRole("button", { name: "Save and continue", exact: true }).click(); + const editingReceipt = await editingModels; + assert.ok(editingReceipt.ok(), await editingReceipt.text()); + configuredIds.push(...(await editingReceipt.json()).map((model) => model.id)); + await welcome.getByRole("heading", { name: "Set up a language model" }).waitFor(); + assert.equal(await welcome.getByText(/Added \d+ language models/).count(), 0); + assert.equal(await welcome.getByText("New · pick to continue", { exact: true }).count(), 0); + + blockedModel = addedLanguages[1].modelId; + await page.goto(`${url}?setup=welcome&from=onboarding`); + await welcomeTitle.waitFor(); + await welcome.getByRole("button", { name: "Get started", exact: true }).click(); + await assistantTitle.waitFor(); + await configureLanguage.click(); + const stillPaused = welcome.getByRole("listitem").filter({ hasText: addedLanguages[1].modelId }); + await stillPaused.getByText("Service paused").waitFor(); + await welcome.getByRole("button", { name: "Add a language model", exact: true }).click(); + await serviceUrl.fill("http://127.0.0.1:12345/v1"); + await welcome.getByRole("button", { name: "Fetch models", exact: true }).click(); + for (const model of freshLanguageModels) await welcome.getByRole("checkbox", { name: model, exact: true }).check(); + const freshSave = page.waitForResponse((response) => response.url().endsWith("/api/model-configs/batch")); + await welcome.getByRole("button", { name: "Save and continue", exact: true }).click(); + const freshReceipt = await freshSave; + assert.ok(freshReceipt.ok(), await freshReceipt.text()); + configuredIds.push(...(await freshReceipt.json()).map((item) => item.id)); + await welcome.getByRole("heading", { name: "Set up a language model" }).waitFor(); + await welcome.getByText("Added 2 language models. Pick one to continue to step 2.").waitFor(); + assert.equal(await welcome.getByText("New · pick to continue", { exact: true }).count(), 2); + await stillPaused.getByText("Service paused").waitFor(); + await stillPaused.getByRole("button", { name: "Edit service", exact: true }).click(); + await welcome.getByRole("form", { name: "Edit service" }).waitFor(); + blockedModel = undefined; + const staleEdit = page.waitForResponse((response) => response.url().endsWith("/api/model-configs/batch")); + await welcome.getByRole("button", { name: "Save and continue", exact: true }).click(); + assert.ok((await staleEdit).ok()); + await welcome.getByRole("heading", { name: "Set up a language model" }).waitFor(); + assert.equal(await welcome.getByText(/Added \d+ language models/).count(), 0); + assert.equal(await welcome.getByText("New · pick to continue", { exact: true }).count(), 0); + + blockedModel = savedLanguage.modelId; + await page.goto(`${url}?setup=welcome&from=onboarding`); + await welcomeTitle.waitFor(); + await welcome.getByRole("button", { name: "Get started", exact: true }).click(); + await assistantTitle.waitFor(); + await configureLanguage.click(); + const singlePaused = welcome.getByRole("listitem").filter({ hasText: savedLanguage.modelId }); + await singlePaused.getByText("Service paused").waitFor(); + await singlePaused.getByRole("button", { name: "Edit service", exact: true }).click(); + await welcome.getByRole("form", { name: "Edit service" }).waitFor(); + blockedModel = undefined; + const singleEdit = page.waitForResponse((response) => response.url().endsWith("/api/model-configs/batch")); + await welcome.getByRole("button", { name: "Save and continue", exact: true }).click(); + assert.ok((await singleEdit).ok()); + await welcome.getByRole("heading", { name: "Set up a language model" }).waitFor(); + assert.equal(await welcome.getByRole("heading", { name: "Choose how to create" }).count(), 0); + assert.equal(await welcome.getByText(/Added \d+ language models/).count(), 0); + assert.equal(await welcome.getByText("New · pick to continue", { exact: true }).count(), 0); + const afterSingleEdit = await (await page.request.get(base + projectPath + "/assistant", { headers })).json(); + assert.equal(afterSingleEdit.modelSelections.agent, addedLanguages[0].id); + assert.deepEqual(errors, []); + console.log("First-run multi-model guidance and edit path passed"); +} finally { + await browser.close(); + for (const id of configuredIds) await fetch(base + "/api/model-configs/" + id, { method: "DELETE", headers }); +} diff --git a/tests/browser/manifest.json b/tests/browser/manifest.json index fc5ca1dcc..d5444bc77 100644 --- a/tests/browser/manifest.json +++ b/tests/browser/manifest.json @@ -177,6 +177,12 @@ "lanes": ["gate"], "note": "First launch: workspace mode, assistant prerequisite, task-specific model setup and direct access to examples." }, + { + "file": "first_run_added_models.mjs", + "previewSafe": true, + "lanes": ["gate"], + "note": "First launch: guidance for several newly saved language models, the focus target, and the neutral edit path." + }, { "file": "selection_toolbar_hover.mjs", "lanes": ["gate"],