Skip to content

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.

Declared-polls probe: count only requests this Studio serves (#13690)

Daniel Hana5300554ebbd
diff --git a/tests/studio/playwright_declared_polls.py b/tests/studio/playwright_declared_polls.py
index 88b65267c49..db03aac04c1 100644
--- a/tests/studio/playwright_declared_polls.py
+++ b/tests/studio/playwright_declared_polls.py
@@ -107,6 +107,19 @@ def normalize(url: str) -> str:
return urlsplit(url).path
+def studio_path(url: str, base: str) -> str | None:
+ """The path of a request this Studio serves, or None for any other origin.
+
+ The budget is about lines in this server's log. The Hub calls huggingface.co straight from
+ the browser (@huggingface/hub listModels / modelInfo), and Hugging Face's own /api/models
+ shares a path with nothing here; counted by path alone it read as an undeclared Studio poll.
+ """
+ request, studio = urlsplit(url), urlsplit(base)
+ if (request.scheme, request.netloc) != (studio.scheme, studio.netloc):
+ return None
+ return normalize(url)
+
+
def main() -> int:
declared = set(ALL_POLLS)
@@ -164,8 +177,8 @@ def main() -> int:
def on_request(request) -> None:
if not counting:
return
- path = normalize(request.url)
- if path.startswith("/api/"):
+ path = studio_path(request.url, BASE)
+ if path and path.startswith("/api/"):
seen[path] += 1
dwell_counts[path] += 1
diff --git a/tests/studio/test_declared_polls_counts_only_studio.py b/tests/studio/test_declared_polls_counts_only_studio.py
new file mode 100644
index 00000000000..6c2a5033cad
--- /dev/null
+++ b/tests/studio/test_declared_polls_counts_only_studio.py
@@ -0,0 +1,57 @@
+"""The declared-polls probe counts only requests this Studio serves.
+
+``playwright_declared_polls.py`` fails CI on any /api/ path the app polls that the log budget
+does not declare. It keyed on the path alone, so the Hub's direct calls to
+``https://huggingface.co/api/models`` (from @huggingface/hub) counted as a Studio poll of
+``/api/models``, a route Studio does not have, and failed the lane on whichever run caught
+enough Hub search traffic in one dwell.
+"""
+
+import ast
+from pathlib import Path
+from urllib.parse import urlsplit
+
+_SCRIPT = Path(__file__).resolve().parent / "playwright_declared_polls.py"
+
+
+def _helpers():
+ tree = ast.parse(_SCRIPT.read_text(encoding = "utf-8"))
+ wanted = [
+ node
+ for node in tree.body
+ if isinstance(node, ast.FunctionDef) and node.name in ("normalize", "studio_path")
+ ]
+ assert {node.name for node in wanted} == {"normalize", "studio_path"}
+ namespace = {"urlsplit": urlsplit}
+ exec(compile(ast.Module(body = wanted, type_ignores = []), str(_SCRIPT), "exec"), namespace)
+ return namespace["studio_path"]
+
+
+BASE = "http://127.0.0.1:18894"
+
+
+def test_a_studio_request_keeps_its_path_without_the_query():
+ studio_path = _helpers()
+ assert studio_path(f"{BASE}/api/engines?_=1", BASE) == "/api/engines"
+
+
+def test_hugging_face_api_models_is_not_a_studio_poll():
+ studio_path = _helpers()
+ assert studio_path("https://huggingface.co/api/models?search=gemma&limit=20", BASE) is None
+ assert studio_path("https://huggingface.co/api/models/unsloth/gemma-3-270m-it", BASE) is None
+
+
+def test_another_port_or_scheme_on_the_same_host_is_not_this_studio():
+ studio_path = _helpers()
+ assert studio_path("http://127.0.0.1:18895/api/engines", BASE) is None
+ assert studio_path("https://127.0.0.1:18894/api/engines", BASE) is None
+
+
+def test_the_request_handler_counts_through_studio_path():
+ source = _SCRIPT.read_text(encoding = "utf-8")
+ handler = source[
+ source.index("def on_request(") : source.index('page.on("request", on_request)')
+ ]
+ assert (
+ "studio_path(request.url, BASE)" in handler
+ ), "on_request must filter by origin before counting, or cross-origin /api/ paths read as Studio polls"