Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Repair the tests main is currently red on (#9192)
Daniel Han65bdc91a1acd
diff --git a/studio/frontend/smoke-heavy-thread-main.tsx b/studio/frontend/smoke-heavy-thread-main.tsxindex 1277e68b60b..621ea203a1e 100644--- a/studio/frontend/smoke-heavy-thread-main.tsx+++ b/studio/frontend/smoke-heavy-thread-main.tsx@@ -63,10 +63,9 @@ import { createRoot } from "react-dom/client";import "./src/index.css";// The local runtime's thread list item reports a synthetic `__LOCALID_...` remoteId, which is-// truthy, so the fork-count badge really does fire one GET per assistant message. Answering them-// here, before anything mounts, keeps that off the wire entirely; answering them from the-// Playwright side instead would put a round trip to another process inside a timed region, once-// per assistant message.+// truthy, so the fork-count badges really do ask the backend. Answering them here, before anything+// mounts, keeps that off the wire entirely; answering them from the Playwright side instead would+// put a round trip to another process inside a timed region.// An explicit allowlist, never a blanket `/api/` match. A blanket match resolves EVERY request the// measured interactions make before Playwright emits it, so `stray_api_requests` stays at zero and// the fan-out this harness exists to detect becomes invisible to it. Narrowing it is what made the@@ -76,11 +75,20 @@ import "./src/index.css";// returns, so no round trip lands inside a timed region. Anything NOT listed here goes to the// network and trips the stray counter, which is the point.const STUBBED_API: ReadonlyArray<readonly [RegExp, string]> = [- // One GET per assistant message: the synthetic `__LOCALID_...` remoteId is truthy, so the badge- // really does ask. `{ count: 0 }`, not `{}`: getForkCount returns `data.count`, and- // `undefined <= 0` is false, so an empty body renders a badge reading "undefined forks" on every- // assistant message and adds DOM in proportion to thread size, the axis being measured.- [/\/api\/chat\/threads\/[^/]+\/messages\/[^/]+\/forks$/, '{"count":0}'],+ // The fork-count badges. One GET per THREAD, not per message: fork-count-store subscribes once+ // per rendered thread and refreshes on CHAT_HISTORY_UPDATED_EVENT, which the delete action+ // fires, so the harness provokes it during seeding and again inside the measured actions.+ //+ // The endpoint used to be per message, `/threads/{id}/messages/{id}/forks` answering+ // `{"count":n}`, and that is the shape this allowlist was written against. The per-thread+ // endpoint replaced it and this entry was not moved with it, so every one of these went to the+ // dev server and the run failed its own stray-request check. Match the shape the app actually+ // requests, and answer with the body it actually returns: `getThreadForkCounts` reads+ // `data.counts` and builds a Map from it, so `{"counts":{}}` is "no message has forks" and+ // renders no badge on any message. An empty `{}` body would leave the same empty Map today, but+ // it is not what the endpoint returns, and a stub that answers a shape the endpoint never sends+ // is how this drifted in the first place.+ [/\/api\/chat\/threads\/[^/]+\/forks$/, '{"counts":{}}'],// The delete action's own persistence. deleteThreadMessage syncs the exported repository// whenever remoteId is truthy, which the synthetic id always is, so this is the fixture// maintaining itself rather than app fan-out. Left on the wire it is 3 round trips inside thediff --git a/studio/frontend/src/features/chat/utils/image-input-support.ts b/studio/frontend/src/features/chat/utils/image-input-support.tsindex 0f44e489e3b..54d2873a4bf 100644--- a/studio/frontend/src/features/chat/utils/image-input-support.ts+++ b/studio/frontend/src/features/chat/utils/image-input-support.ts@@ -4,7 +4,7 @@import type { ChatModelSummary } from "../types/runtime";import type { MmprojFallbackReason } from "../types/api";-import { isTextOnlyMmprojFallback } from "./mmproj-fallback";+import { isTextOnlyMmprojFallback } from "./mmproj-fallback.ts";function textOnlyMmprojUnavailableReason(activeModel: ChatModelSummary | undefined,diff --git a/tests/studio/test_chat_autoload_failure_gate.py b/tests/studio/test_chat_autoload_failure_gate.pyindex b95f555ef04..5a64016e294 100644--- a/tests/studio/test_chat_autoload_failure_gate.py+++ b/tests/studio/test_chat_autoload_failure_gate.py@@ -268,6 +268,10 @@ const toast: any = Object.assign(},);+function mmprojFallbackMessage(reason: string) {+ return `mmproj fallback: ${reason}`;+}+async function tryAdoptServerActiveModel() { return false; }function resolveSpeculativeSettingsForLoad() {return { speculativeType: null, specDraftNMax: 0 };diff --git a/tests/studio/test_heavy_thread_harness_contract.py b/tests/studio/test_heavy_thread_harness_contract.pyindex 3ce018e6afd..3d9ada92ece 100644--- a/tests/studio/test_heavy_thread_harness_contract.py+++ b/tests/studio/test_heavy_thread_harness_contract.py@@ -14,6 +14,7 @@ CDP counter and the Long Tasks API are Chromium-only, and the failure mode is sias "no measurement". So no growth axis and no pass/fail decision may rest on one."""+import refrom pathlib import PathROOT = Path(__file__).resolve().parents[2]@@ -177,12 +178,17 @@ def test_the_smoke_page_is_served_and_owns_its_dev_server() -> None:assert "stop_process(vite)" in text-def test_the_fork_count_stub_answers_with_a_real_zero() -> None:- # `getForkCount` returns `data.count`, and the badge's guard is `count <= 0`. `undefined <= 0`- # is false, so a `{}` body renders a badge reading "undefined forks from this message" on every- # assistant message. Measured at 25000 chars: 10 badges and 4031 DOM nodes with `{}`, 0 badges- # and 3981 with `{"count":0}`. That is DOM in proportion to thread size, on the axis this- # harness measures.+def test_the_fork_count_stub_answers_the_shape_the_endpoint_returns() -> None:+ # `getThreadForkCounts` reads `data.counts` and builds a Map from it, and the badge renders+ # nothing for a message the Map has no entry for. `{"counts":{}}` is therefore "no message has+ # forks" in the endpoint's own vocabulary. A body of some other shape leaves the Map empty by+ # accident rather than by contract, and an accident is what this stub already had once: the+ # endpoint used to be per message and answer `{"count":n}`, the allowlist kept matching that+ # older URL after the app stopped requesting it, and every fork-count GET went to the network+ # instead. Before that, `{}` against the per-message endpoint left `data.count` undefined,+ # `undefined <= 0` false, and a badge reading "undefined forks from this message" on every+ # assistant message: measured at 25000 chars, 10 badges and 4031 DOM nodes rather than 0 and+ # 3981. Either way the fixture stops being the thing the table says was measured.page = (FRONTEND / "smoke-heavy-thread-main.tsx").read_text(encoding = "utf-8")# Pin the fork-count entry to its own body rather than scanning the whole file: other# endpoints in the allowlist legitimately answer "{}", so a bare file-wide check for it@@ -192,12 +198,48 @@ def test_the_fork_count_stub_answers_with_a_real_zero() -> None:"",)assert forks, "the fork-count endpoint is no longer in the stub allowlist"- assert '{"count":0}' in forks, (- "the fork-count stub must answer with a numeric count; an empty object makes the parsed "- f"count undefined and renders a badge on every assistant message. Got: {forks.strip()!r}"+ assert '{"counts":{}}' in forks, (+ "the fork-count stub must answer the counts map the endpoint returns; another shape "+ f"leaves the parsed map empty only by accident. Got: {forks.strip()!r}")+def _stub_patterns(page: str) -> list[str]:+ """The regex literals in STUBBED_API, as Python patterns.++ They are deliberately plain -- literal path segments, `[^/]+`, `(\\?|$)`, `$` -- so the JS+ source and the Python equivalent differ only in the escaped forward slashes.+ """+ block = page[page.index("const STUBBED_API") : page.index("const stubbedApiCalls")]+ return [literal.replace("\\/", "/") for literal in re.findall(r"\[/(.+?)/,", block)]+++def test_the_stub_matches_the_fork_count_url_the_app_actually_requests() -> None:+ # The drift this file exists to catch, checked against the app rather than against a string+ # someone remembered to update. The fork-count endpoint moved from per message to per thread+ # in #8992 and this allowlist was not moved with it; the harness's own stray-request check did+ # catch it, but only in CI, and only in a job where the browser smokes reach the point of+ # running at all. A URL the app builds and the stub does not answer is a round trip inside a+ # timed region, so it is worth failing a unit test for.+ api = (FRONTEND / "src" / "features" / "chat" / "api" / "chat-api.ts").read_text(+ encoding = "utf-8"+ )+ fork_paths = re.findall(r"`(/api/chat/threads/\$\{[^`]*?\}/forks)`", api)+ assert fork_paths, "chat-api.ts no longer builds a fork-count URL this test can read"+ patterns = _stub_patterns(+ (FRONTEND / "smoke-heavy-thread-main.tsx").read_text(encoding = "utf-8")+ )+ for path in fork_paths:+ # A stand-in shaped like the synthetic remoteId the local runtime hands the smoke page.+ # `encodeURIComponent` leaves that form untouched, so the sample below is the URL the+ # harness really does produce.+ url = re.sub(r"\$\{[^}]*\}", "__LOCALID_abc123", path)+ assert any(re.search(pattern, url) for pattern in patterns), (+ f"the smoke page's STUBBED_API allowlist answers none of {url!r}, which the chat "+ "client requests; it would reach the network inside a measured action"+ )++def test_the_fetch_stub_only_intercepts_fork_counts() -> None:# A blanket `/api/` match resolves any other request a measured interaction makes before# Playwright emits it, so `measure_cell`'s listener never increments `stray_api_requests` anddiff --git a/tests/studio/test_heavy_thread_measurement_integrity.py b/tests/studio/test_heavy_thread_measurement_integrity.pyindex d9f2465b7e5..e4feb78bbb9 100644--- a/tests/studio/test_heavy_thread_measurement_integrity.py+++ b/tests/studio/test_heavy_thread_measurement_integrity.py@@ -50,6 +50,36 @@ HARNESS_SOURCE = (Path(__file__).resolve().parent / "playwright_heavy_thread.py")+def _sync_api_stub() -> types.ModuleType:+ """A `playwright.sync_api` that answers for every name a harness may import off it.++ The stub lands in `sys.modules` at collection time and stays there for the rest of the+ session, so it is not just this file's import that reads it: any later test that imports a+ harness gets these names instead of the real package's. A stub that spelled out only the+ names THIS file's harness needs therefore broke the others -- `playwright_strip_ansi_smoke`+ also imports `Page` and `expect`, and got `cannot import name 'Page' from+ 'playwright.sync_api' (unknown location)` in the CPU job, from a stub two files away.++ Every name resolves to a callable that raises, so the stub can satisfy an import without a+ harness quietly measuring a browser that is not there. Dunders are left to fail: pytest and+ inspect probe those, and answering them makes the stub look like a package.+ """+ module = types.ModuleType("playwright.sync_api")++ def __getattr__(name: str):+ if name.startswith("__") and name.endswith("__"):+ raise AttributeError(name)++ def unavailable(*args, **kwargs):+ raise RuntimeError(f"playwright is not installed: {name} needs a real browser")++ unavailable.__name__ = name+ return unavailable++ module.__getattr__ = __getattr__+ return module++def _load_harness():"""Import the harness module without needing a browser.@@ -57,15 +87,18 @@ def _load_harness():this file calls. Stubbing it keeps these tests runnable in the CPU test job, where thePlaywright package is not installed, rather than skipping the arithmetic along with thebrowser.++ The probe imports the name off the submodule rather than the top-level package: a partial+ install leaves `playwright` importable while `playwright.sync_api` resolves to an empty+ namespace, which is the same failure with a longer traceback."""os.environ.setdefault("PW_ART_DIR", str(TEMP_ROOT / "artifacts"))if "playwright.sync_api" not in sys.modules:try:- import playwright.sync_api # noqa: F401+ from playwright.sync_api import sync_playwright # noqa: F401except ImportError:package = types.ModuleType("playwright")- module = types.ModuleType("playwright.sync_api")- module.sync_playwright = None+ module = _sync_api_stub()package.sync_api = modulesys.modules["playwright"] = packagesys.modules["playwright.sync_api"] = module