Kyryll Kochkin commited on
Commit
e67fe58
·
unverified ·
2 Parent(s): ca0c2ec 7b72c0a

Add regression coverage for /v1/models response

Browse files

Add regression coverage for /v1/models response. alert:vibe-coded

Files changed (1) hide show
  1. tests/test_openai_compat.py +45 -1
tests/test_openai_compat.py CHANGED
@@ -7,7 +7,8 @@ from pathlib import Path
7
  import asyncio
8
 
9
  import pytest
10
- from fastapi import HTTPException
 
11
  import pydantic
12
 
13
  fake_pydantic_settings = types.ModuleType("pydantic_settings")
@@ -115,6 +116,7 @@ sys.modules.setdefault("yaml", fake_yaml)
115
 
116
  sys.path.append(str(Path(__file__).resolve().parents[1]))
117
 
 
118
  from app.core.model_registry import ModelMetadata, ModelSpec
119
  from app.routers import chat, completions, embeddings, models
120
  from app.schemas.chat import ChatCompletionRequest
@@ -127,6 +129,48 @@ def test_list_models() -> None:
127
  assert payload["data"] == []
128
 
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  def test_completions_non_stream(monkeypatch: pytest.MonkeyPatch) -> None:
131
  class DummyResult:
132
  prompt_tokens = 5
 
7
  import asyncio
8
 
9
  import pytest
10
+ from fastapi import FastAPI, HTTPException
11
+ from fastapi.testclient import TestClient
12
  import pydantic
13
 
14
  fake_pydantic_settings = types.ModuleType("pydantic_settings")
 
116
 
117
  sys.path.append(str(Path(__file__).resolve().parents[1]))
118
 
119
+ from app.core import model_registry as model_registry_module
120
  from app.core.model_registry import ModelMetadata, ModelSpec
121
  from app.routers import chat, completions, embeddings, models
122
  from app.schemas.chat import ChatCompletionRequest
 
129
  assert payload["data"] == []
130
 
131
 
132
+ def test_models_endpoint_returns_default_payload(monkeypatch: pytest.MonkeyPatch) -> None:
133
+ class DummySettings:
134
+ def __init__(self) -> None:
135
+ self.model_allow_list = None
136
+ self.include_default_models = True
137
+ self.model_registry_path = None
138
+
139
+ def model_dump(self) -> dict:
140
+ return {
141
+ "model_registry_path": self.model_registry_path,
142
+ "include_default_models": self.include_default_models,
143
+ }
144
+
145
+ app = FastAPI()
146
+ app.include_router(models.router)
147
+ monkeypatch.setattr(
148
+ model_registry_module,
149
+ "get_settings",
150
+ lambda: DummySettings(),
151
+ raising=False,
152
+ )
153
+
154
+ with TestClient(app) as client:
155
+ model_registry_module._registry.clear()
156
+ try:
157
+ resp = client.get("/v1/models")
158
+ assert resp.status_code == 200
159
+ body = resp.json()
160
+ assert body["object"] == "list"
161
+ data = body["data"]
162
+ assert data, "Default models should be present"
163
+ ids = {item["id"] for item in data}
164
+ assert "GPT3-dev-350m-2805" in ids
165
+ sample = next(item for item in data if item["id"] == "GPT3-dev-350m-2805")
166
+ assert (
167
+ sample["metadata"].get("huggingface_repo")
168
+ == "k050506koch/GPT3-dev-350m-2805"
169
+ )
170
+ finally:
171
+ model_registry_module._registry.clear()
172
+
173
+
174
  def test_completions_non_stream(monkeypatch: pytest.MonkeyPatch) -> None:
175
  class DummyResult:
176
  prompt_tokens = 5