Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(api): authenticate the capabilities route, and correct two stale expectations
Alexander Eichhorn7c03da6d581d
diff --git a/invokeai/app/api/routers/model_manager.py b/invokeai/app/api/routers/model_manager.pyindex 7870595d5e..60857d6bfe 100644--- a/invokeai/app/api/routers/model_manager.py+++ b/invokeai/app/api/routers/model_manager.py@@ -163,7 +163,7 @@ example_model_input = {operation_id="list_architecture_capabilities",responses={200: {"description": "What each model architecture supports"}},)-async def list_architecture_capabilities() -> list[ArchitectureCapabilities]:+async def list_architecture_capabilities(current_user: CurrentUserOrDefault) -> list[ArchitectureCapabilities]:"""What each model architecture can generate, and which generation features it supports.A static table, the same for every install and every user, derived from what the architectures@@ -171,8 +171,10 @@ async def list_architecture_capabilities() -> list[ArchitectureCapabilities]:records locally: look up `(base, variant)`, fall back to `(base, null)`.Deliberately not a field on the model records themselves — it is the same for every model of an- architecture, and putting it there would add these fields to all 115 config schemas. No auth- dependency for the same reason: there is nothing user- or install-specific in it.+ architecture, and putting it there would add these fields to all 115 config schemas.++ Authenticated like every other route here even though the response holds nothing user-specific:+ the allowlist for public routes is short and deliberate, and this is not a reason to lengthen it."""return architecture_capabilities()diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.jsonindex a111b8f1d0..eb8cc5e4a2 100644--- a/invokeai/frontend/web/openapi.json+++ b/invokeai/frontend/web/openapi.json@@ -608,7 +608,7 @@"get": {"tags": ["model_manager"],"summary": "List Architecture Capabilities",- "description": "What each model architecture can generate, and which generation features it supports.\n\nA static table, the same for every install and every user, derived from what the architectures\ndeclare under `invokeai/backend/architectures/defs/`. Fetch it once and join it against model\nrecords locally: look up `(base, variant)`, fall back to `(base, null)`.\n\nDeliberately not a field on the model records themselves \u2014 it is the same for every model of an\narchitecture, and putting it there would add these fields to all 115 config schemas. No auth\ndependency for the same reason: there is nothing user- or install-specific in it.",+ "description": "What each model architecture can generate, and which generation features it supports.\n\nA static table, the same for every install and every user, derived from what the architectures\ndeclare under `invokeai/backend/architectures/defs/`. Fetch it once and join it against model\nrecords locally: look up `(base, variant)`, fall back to `(base, null)`.\n\nDeliberately not a field on the model records themselves \u2014 it is the same for every model of an\narchitecture, and putting it there would add these fields to all 115 config schemas.\n\nAuthenticated like every other route here even though the response holds nothing user-specific:\nthe allowlist for public routes is short and deliberate, and this is not a reason to lengthen it.","operationId": "list_architecture_capabilities","responses": {"200": {@@ -625,7 +625,12 @@}}}- }+ },+ "security": [+ {+ "HTTPBearer": []+ }+ ]}},"/api/v2/models/": {diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.tsindex aeb89c6b66..2c428fc03e 100644--- a/invokeai/frontend/web/src/services/api/schema.ts+++ b/invokeai/frontend/web/src/services/api/schema.ts@@ -400,8 +400,10 @@ export type paths = {* records locally: look up `(base, variant)`, fall back to `(base, null)`.** Deliberately not a field on the model records themselves — it is the same for every model of an- * architecture, and putting it there would add these fields to all 115 config schemas. No auth- * dependency for the same reason: there is nothing user- or install-specific in it.+ * architecture, and putting it there would add these fields to all 115 config schemas.+ *+ * Authenticated like every other route here even though the response holds nothing user-specific:+ * the allowlist for public routes is short and deliberate, and this is not a reason to lengthen it.*/get: operations["list_architecture_capabilities"];put?: never;diff --git a/tests/app/routers/test_architecture_capabilities.py b/tests/app/routers/test_architecture_capabilities.pyindex 372f14f177..fcd79e3837 100644--- a/tests/app/routers/test_architecture_capabilities.py+++ b/tests/app/routers/test_architecture_capabilities.py@@ -1,20 +1,43 @@"""GET /api/v2/models/capabilities — the static architecture table.-It touches no service and no database: the rows come from what the architectures declare at import-time. That is what lets this test use a bare client, and it is also the property worth pinning —-a later version that reaches for `ApiDependencies.invoker` would fail here rather than in production.+The rows come from what the architectures declare at import time — no service, no database, the same+response for every install. The route is still authenticated like every other one in this router,+which is the only reason these tests need `ApiDependencies` patched at all."""+from typing import Any, Iterator+from unittest.mock import MagicMock++import pytestfrom fastapi.testclient import TestClient+from invokeai.app.api.dependencies import ApiDependenciesfrom invokeai.app.api_app import app+from invokeai.app.services.invoker import Invokerfrom invokeai.backend.architectures import architecture_capabilities, generative_bases-client = TestClient(app)URL = "/api/v2/models/capabilities"-def test_it_serves_a_row_for_every_architecture() -> None:+class _MockApiDependencies(ApiDependencies):+ def __init__(self, invoker: Invoker) -> None:+ self.invoker = invoker # type: ignore[misc]+++def client(monkeypatch: Any, mock_invoker: Invoker) -> Iterator[TestClient]:+ """A client whose auth dependency can resolve a default user.++ The route itself needs nothing from the invoker; `CurrentUserOrDefault` does.+ """+ mock_invoker.services.users = MagicMock()+ mock_deps = _MockApiDependencies(mock_invoker)+ for module in ("invokeai.app.api_app", "invokeai.app.api.auth_dependencies"):+ monkeypatch.setattr(f"{module}.ApiDependencies", mock_deps)+ yield TestClient(app)+++def test_it_serves_a_row_for_every_architecture(client: TestClient) -> None:response = client.get(URL)assert response.status_code == 200@@ -24,7 +47,7 @@ def test_it_serves_a_row_for_every_architecture() -> None:assert len(base_rows) == len(generative_bases()), "one row per architecture, no duplicates"-def test_variant_rows_override_their_base_row() -> None:+def test_variant_rows_override_their_base_row(client: TestClient) -> None:"""FLUX is the clearest case: three variants, three genuinely different answers."""rows = client.get(URL).json()flux = {r["variant"]: r for r in rows if r["base"] == "flux"}@@ -35,26 +58,32 @@ def test_variant_rows_override_their_base_row() -> None:assert flux[None]["defaults"]["steps"] == 28, "the base row is dev"-def test_the_variant_is_the_value_a_client_holds() -> None:+def test_the_variant_is_the_value_a_client_holds(client: TestClient) -> None:"""Not `str(enum)`, which would serialize as `FluxVariantType.DevFill`."""variants = {r["variant"] for r in client.get(URL).json() if r["variant"] is not None}assert all("." not in v for v in variants), variantsassert "dev_fill" in variants-def test_it_needs_no_services() -> None:- """No auth, no invoker, no database — the same table for every install and every user."""+def test_the_rows_come_from_the_registry_not_a_service(client: TestClient, mock_invoker: Invoker) -> None:+ """The response is the same table for every install. Nothing about it is looked up.++ Asserted by the model manager service never being touched: if a later version resolved+ capabilities per model record, this is where it would show.+ """+ mock_invoker.services.model_manager = MagicMock()assert client.get(URL).status_code == 200+ mock_invoker.services.model_manager.assert_not_called()-def test_the_response_matches_what_the_registry_renders() -> None:+def test_the_response_matches_what_the_registry_renders(client: TestClient) -> None:"""The route is a pass-through; anything it added would be a second source of truth."""served = client.get(URL).json()rendered = [row.model_dump(mode="json") for row in architecture_capabilities()]assert served == rendered-def test_the_rows_are_ordered_stably() -> None:+def test_the_rows_are_ordered_stably(client: TestClient) -> None:"""Sorted by base, so a client diffing two responses sees only real changes."""rows = client.get(URL).json()bases = [r["base"] for r in rows]diff --git a/tests/model_identification/test_identification.py b/tests/model_identification/test_identification.pyindex 8a4d220f5c..75038c95eb 100644--- a/tests/model_identification/test_identification.py+++ b/tests/model_identification/test_identification.py@@ -40,7 +40,10 @@ def test_controlnet_t2i_default_settings(model_name: str, preprocessor: str | No(BaseModelType.StableDiffusion1, {"width": 512, "height": 512}),(BaseModelType.StableDiffusion2, {"width": 768, "height": 768}),(BaseModelType.StableDiffusionXL, {"width": 1024, "height": 1024}),- (BaseModelType.StableDiffusionXLRefiner, None),+ # The refiner refines an SDXL latent, so it shares SDXL's canvas — but not its steps or CFG,+ # which the UI drives with its own refiner parameters.+ (BaseModelType.StableDiffusionXLRefiner, {"width": 1024, "height": 1024}),+ # A sentinel, not an architecture: it is never registered, so there is nothing to resolve.(BaseModelType.Any, None),],)