1212from IPython .utils .capture import CapturedIO , capture_output
1313from pytest_mock .plugin import MockerFixture
1414from rich .console import Console as RichConsole
15+ from sqlglot import __version__ as SQLGLOT_VERSION
1516
1617from sqlmesh import Context , RuntimeEnv
18+ from sqlmesh ._version import __version__ as SQLMESH_VERSION
19+ from sqlmesh .core .state_sync .base import SCHEMA_VERSION , Versions
1720from sqlmesh .magics import register_magics
1821from pathlib import Path
1922
@@ -740,14 +743,19 @@ def test_info(notebook, sushi_context, convert_all_html_output_to_text, get_all_
740743
741744 assert not output .stdout
742745 assert not output .stderr
743- assert len (output .outputs ) == 6
746+ assert len (output .outputs ) == 10
747+ # No plan has been applied, so the state backend is still empty and reports the defaults.
744748 assert convert_all_html_output_to_text (output ) == [
745749 "Models: 20" ,
746750 "Macros: 8" ,
747751 "" ,
748752 "Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n pretty_sql: false\n extensions: []\n connector_config: {}\n secrets: None\n filesystems: []\n shared_connection: true" ,
749753 "Test Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n pretty_sql: false\n extensions: []\n connector_config: {}\n secrets: None\n filesystems: []\n shared_connection: true" ,
750754 "Data warehouse connection succeeded" ,
755+ "State backend versions:" ,
756+ "Schema version: 0" ,
757+ "SQLGlot version: 0.0.0" ,
758+ "SQLMesh version: 0.0.0" ,
751759 ]
752760 assert get_all_html_output (output ) == [
753761 "<pre style=\" white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\" >Models: <span style=\" color: #008080; text-decoration-color: #008080; font-weight: bold\" >20</span></pre>" ,
@@ -756,6 +764,10 @@ def test_info(notebook, sushi_context, convert_all_html_output_to_text, get_all_
756764 '<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\' DejaVu Sans Mono\' ,consolas,\' Courier New\' ,monospace">Connection: type: duckdb concurrent_tasks: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">1</span> register_comments: true pre_ping: false pretty_sql: false extensions: <span style="font-weight: bold">[]</span> connector_config: <span style="font-weight: bold">{}</span> secrets: <span style="color: #800080; text-decoration-color: #800080; font-style: italic">None</span> filesystems: <span style="font-weight: bold">[]</span> shared_connection: true</pre>' ,
757765 '<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\' DejaVu Sans Mono\' ,consolas,\' Courier New\' ,monospace">Test Connection: type: duckdb concurrent_tasks: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">1</span> register_comments: true pre_ping: false pretty_sql: false extensions: <span style="font-weight: bold">[]</span> connector_config: <span style="font-weight: bold">{}</span> secrets: <span style="color: #800080; text-decoration-color: #800080; font-style: italic">None</span> filesystems: <span style="font-weight: bold">[]</span> shared_connection: true</pre>' ,
758766 "<pre style=\" white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\" >Data warehouse connection <span style=\" color: #008000; text-decoration-color: #008000\" >succeeded</span></pre>" ,
767+ "<pre style=\" white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\" >State backend versions:</pre>" ,
768+ "<pre style=\" white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\" >Schema version: <span style=\" color: #008080; text-decoration-color: #008080; font-weight: bold\" >0</span></pre>" ,
769+ '<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\' DejaVu Sans Mono\' ,consolas,\' Courier New\' ,monospace">SQLGlot version: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">0.0</span>.<span style="color: #008080; text-decoration-color: #008080; font-weight: bold">0</span></pre>' ,
770+ '<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\' DejaVu Sans Mono\' ,consolas,\' Courier New\' ,monospace">SQLMesh version: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">0.0</span>.<span style="color: #008080; text-decoration-color: #008080; font-weight: bold">0</span></pre>' ,
759771 ]
760772
761773
@@ -768,25 +780,36 @@ def test_migrate(
768780
769781 assert not output .stdout
770782 assert not output .stderr
771- assert len (output .outputs ) == 1
783+ assert len (output .outputs ) == 5
784+ # The sushi state lives in an in-memory DuckDB database, so the state sync that `migrate`
785+ # opens starts empty and the versions move from the defaults to the running ones.
786+ empty = Versions ()
772787 assert convert_all_html_output_to_text (output ) == [
788+ "State backend versions:" ,
789+ f"Schema version: { empty .schema_version } -> { SCHEMA_VERSION } " ,
790+ f"SQLGlot version: { empty .sqlglot_version } -> { SQLGLOT_VERSION } " ,
791+ f"SQLMesh version: { empty .sqlmesh_version } -> { SQLMESH_VERSION } " ,
773792 "Migration complete" ,
774793 ]
775- assert get_all_html_output (output ) == [
776- str (
794+ # Rich highlights the numbers inside the version lines, and that markup depends on the
795+ # running versions, so only the fixed lines are compared as HTML.
796+ html_output = get_all_html_output (output )
797+ assert html_output [0 ] == str (
798+ h ("pre" , {"style" : RICH_PRE_STYLE }, "State backend versions:" , autoescape = False )
799+ )
800+ assert html_output [- 1 ] == str (
801+ h (
802+ "pre" ,
803+ {"style" : RICH_PRE_STYLE },
777804 h (
778- "pre" ,
779- {"style" : RICH_PRE_STYLE },
780- h (
781- "span" ,
782- {"style" : SUCCESS_STYLE },
783- "Migration complete" ,
784- autoescape = False ,
785- ),
805+ "span" ,
806+ {"style" : SUCCESS_STYLE },
807+ "Migration complete" ,
786808 autoescape = False ,
787- )
809+ ),
810+ autoescape = False ,
788811 )
789- ]
812+ )
790813
791814
792815# TODO: Add test for rollback
0 commit comments