Melika Kheirieh commited on
Commit
1fa9a31
·
1 Parent(s): dcc30f0

tests: fix import-time KeyError by ensuring OPENAI_ in conftest and lazy-import router in test_ambiguity

Browse files
app/routers/nl2sql.py CHANGED
@@ -25,18 +25,21 @@ if os.getenv("DB_MODE", "sqlite") == "postgres":
25
  else:
26
  _db = SQLiteAdapter("data/chinook.db")
27
 
28
- # --- Composition Root ---
29
- _llm = OpenAIProvider()
 
 
 
30
  # _db = SQLiteAdapter("data/chinook.db")
31
  _executor = Executor(_db)
32
  _verifier = Verifier()
33
- _repair = Repair(_llm)
34
 
35
 
36
  _pipeline = Pipeline(
37
  detector=AmbiguityDetector(),
38
- planner=Planner(_llm),
39
- generator=Generator(_llm),
40
  safety=Safety(),
41
  executor=_executor,
42
  verifier=_verifier,
 
25
  else:
26
  _db = SQLiteAdapter("data/chinook.db")
27
 
28
+
29
+ def get_llm():
30
+ return OpenAIProvider()
31
+
32
+
33
  # _db = SQLiteAdapter("data/chinook.db")
34
  _executor = Executor(_db)
35
  _verifier = Verifier()
36
+ _repair = Repair(get_llm())
37
 
38
 
39
  _pipeline = Pipeline(
40
  detector=AmbiguityDetector(),
41
+ planner=Planner(get_llm()),
42
+ generator=Generator(get_llm()),
43
  safety=Safety(),
44
  executor=_executor,
45
  verifier=_verifier,
tests/conftest.py CHANGED
@@ -3,5 +3,16 @@ from dotenv import load_dotenv
3
 
4
  ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
5
  ENV_PATH = os.path.join(ROOT_DIR, ".env")
6
-
7
  load_dotenv(dotenv_path=ENV_PATH)
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
5
  ENV_PATH = os.path.join(ROOT_DIR, ".env")
 
6
  load_dotenv(dotenv_path=ENV_PATH)
7
+
8
+
9
+ # --- add: make tests independent of real OPENAI_* in CI ---
10
+ def _ensure_openai_env_for_tests():
11
+ # map PROXY_* -> OPENAI_* or set a harmless dummy
12
+ if not os.getenv("OPENAI_API_KEY"):
13
+ os.environ["OPENAI_API_KEY"] = os.getenv("PROXY_API_KEY", "DUMMY_TEST_KEY")
14
+ if not os.getenv("OPENAI_BASE_URL") and os.getenv("PROXY_BASE_URL"):
15
+ os.environ["OPENAI_BASE_URL"] = os.environ["PROXY_BASE_URL"]
16
+
17
+
18
+ _ensure_openai_env_for_tests()
tests/test_ambiguity.py CHANGED
@@ -1,6 +1,5 @@
1
  from nl2sql.ambiguity_detector import AmbiguityDetector
2
  from nl2sql.types import StageResult
3
- from app.routers import nl2sql
4
 
5
 
6
  def test_detects_ambiguous_terms():
@@ -17,6 +16,8 @@ def test_not_false_positive():
17
 
18
 
19
  def test_ambiguity_response():
 
 
20
  fake_result = StageResult(
21
  ok=True, data={"ambiguous": True, "questions": ["Clarify column?"]}
22
  )
 
1
  from nl2sql.ambiguity_detector import AmbiguityDetector
2
  from nl2sql.types import StageResult
 
3
 
4
 
5
  def test_detects_ambiguous_terms():
 
16
 
17
 
18
  def test_ambiguity_response():
19
+ from app.routers import nl2sql
20
+
21
  fake_result = StageResult(
22
  ok=True, data={"ambiguous": True, "questions": ["Clarify column?"]}
23
  )