mikeboone Claude Fable 5 commited on
Commit
80facca
·
1 Parent(s): 21ee86d

fix(e2e): resolve Snowflake database from model TML in schema check

Browse files

check_snowflake_schema hardcoded DEMOBUILD; demos now live in the rotating
<base>_<YYYY_MM> database, so the check reported "Object does not exist" on
runs that succeeded. The database now comes from the same model-TML resolution
that supplies the schema (with get_demo_database() as the session-log path's
source), and the check refuses to guess when neither is available.

Verified against live run ed0dfa99: DEMOBUILD_2026_08.TST_TRE_08102144_P6D_sch,
10,037 rows / 7 tables found.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Files changed (1) hide show
  1. tests/e2e_quality.py +19 -7
tests/e2e_quality.py CHANGED
@@ -757,7 +757,7 @@ def resolve_schema_from_model(run_context: dict) -> dict:
757
  db, schema = extract_db_schema_from_tml_docs(tml_docs)
758
  if not schema:
759
  return {"found": False, "reason": "model/associated table TML did not expose physical schema"}
760
- return {"found": True, "database": db or "DEMOBUILD", "schema": schema}
761
  except Exception as e:
762
  return {"found": False, "reason": str(e)}
763
 
@@ -1597,22 +1597,27 @@ def fetch_monitor_diagnostics(start_time: float, test_tag: str = "") -> dict:
1597
  return {"found": False, "reason": f"Monitor diagnostics query failed: {e}"}
1598
 
1599
 
1600
- def check_snowflake_schema(company: str, start_time: float, schema_override: str = None) -> dict:
 
1601
  """
1602
  Get row counts for the Snowflake schema created during this test run.
1603
- Requires an explicit schema resolved from the exact ThoughtSpot model.
1604
- Never guesses by company/date prefix.
 
1605
  """
1606
  try:
1607
  from snowflake_auth import get_snowflake_connection
1608
 
1609
  if not schema_override:
1610
  return {"found": False, "reason": "No explicit schema provided; refusing to guess"}
 
 
1611
  conn = get_snowflake_connection()
1612
  cursor = conn.cursor()
1613
 
1614
  schema = schema_override
1615
- cursor.execute(f'SHOW TABLES IN SCHEMA DEMOBUILD."{schema}"')
 
1616
  tables = cursor.fetchall()
1617
 
1618
  table_info = []
@@ -1620,7 +1625,7 @@ def check_snowflake_schema(company: str, start_time: float, schema_override: str
1620
  for t in tables:
1621
  tname = t[1]
1622
  try:
1623
- cursor.execute(f'SELECT COUNT(*) FROM DEMOBUILD."{schema}"."{tname}"')
1624
  count = cursor.fetchone()[0]
1625
  total_rows += count
1626
  table_info.append({"table": tname, "rows": count})
@@ -1838,7 +1843,14 @@ def run_single_test(page: Page, test_case: dict, config: dict) -> dict:
1838
  print(f" ⚠️ Could not resolve schema from model: {schema_resolution.get('reason')}")
1839
  if schema_source == "session_logs":
1840
  print(f" 🧭 Schema from exact-tag session logs: {known_schema}")
1841
- sf = check_snowflake_schema(result["company"], start, schema_override=known_schema)
 
 
 
 
 
 
 
1842
  result["snowflake_check"] = sf
1843
  if sf.get("found"):
1844
  print(f" 📦 Snowflake: {sf['schema']} ({sf['total_rows']} rows, {len(sf['tables'])} tables)")
 
757
  db, schema = extract_db_schema_from_tml_docs(tml_docs)
758
  if not schema:
759
  return {"found": False, "reason": "model/associated table TML did not expose physical schema"}
760
+ return {"found": True, "database": db, "schema": schema}
761
  except Exception as e:
762
  return {"found": False, "reason": str(e)}
763
 
 
1597
  return {"found": False, "reason": f"Monitor diagnostics query failed: {e}"}
1598
 
1599
 
1600
+ def check_snowflake_schema(company: str, start_time: float, schema_override: str = None,
1601
+ database_override: str = None) -> dict:
1602
  """
1603
  Get row counts for the Snowflake schema created during this test run.
1604
+ Requires an explicit database + schema resolved from the exact ThoughtSpot
1605
+ model (demos live in a rotating <base>_<YYYY_MM> database, so the database
1606
+ must come from the model TML too). Never guesses by company/date prefix.
1607
  """
1608
  try:
1609
  from snowflake_auth import get_snowflake_connection
1610
 
1611
  if not schema_override:
1612
  return {"found": False, "reason": "No explicit schema provided; refusing to guess"}
1613
+ if not database_override:
1614
+ return {"found": False, "reason": "No explicit database provided; refusing to guess"}
1615
  conn = get_snowflake_connection()
1616
  cursor = conn.cursor()
1617
 
1618
  schema = schema_override
1619
+ database = database_override
1620
+ cursor.execute(f'SHOW TABLES IN SCHEMA "{database}"."{schema}"')
1621
  tables = cursor.fetchall()
1622
 
1623
  table_info = []
 
1625
  for t in tables:
1626
  tname = t[1]
1627
  try:
1628
+ cursor.execute(f'SELECT COUNT(*) FROM "{database}"."{schema}"."{tname}"')
1629
  count = cursor.fetchone()[0]
1630
  total_rows += count
1631
  table_info.append({"table": tname, "rows": count})
 
1843
  print(f" ⚠️ Could not resolve schema from model: {schema_resolution.get('reason')}")
1844
  if schema_source == "session_logs":
1845
  print(f" 🧭 Schema from exact-tag session logs: {known_schema}")
1846
+ known_database = schema_resolution.get("database")
1847
+ if not known_database and known_schema:
1848
+ # Schema came from session logs (model export failed): this run just
1849
+ # wrote to the active rotating demo database, so that IS its database.
1850
+ from snowflake_auth import get_demo_database
1851
+ known_database = get_demo_database()
1852
+ sf = check_snowflake_schema(result["company"], start, schema_override=known_schema,
1853
+ database_override=known_database)
1854
  result["snowflake_check"] = sf
1855
  if sf.get("found"):
1856
  print(f" 📦 Snowflake: {sf['schema']} ({sf['total_rows']} rows, {len(sf['tables'])} tables)")