@@ -2239,23 +2239,31 @@ def test_format_leading_comma_default(runner: CliRunner, tmp_path: Path):
22392239 del os .environ ["SQLMESH__FORMAT__LEADING_COMMA" ]
22402240
22412241
2242- def _setup_local_only_project (tmp_path , mocker ):
2243- create_example_project (tmp_path , template = ProjectTemplate .EMPTY )
2244- config_path = tmp_path / "config.yaml"
2242+ def _create_local_only_project (path : Path , project : str ) -> None :
2243+ path .mkdir (parents = True , exist_ok = True )
2244+ create_example_project (path , template = ProjectTemplate .EMPTY )
2245+ config_path = path / "config.yaml"
22452246 existing = config_path .read_text (encoding = "utf-8" )
2246- config_path .write_text ("project: cli_test \n \n " + existing , encoding = "utf-8" )
2247+ config_path .write_text (f "project: { project } \n \n " + existing , encoding = "utf-8" )
22472248
2248- (tmp_path / "models" / "example.sql" ).write_text (
2249- "MODEL(name local .example, dialect 'duckdb'); SELECT 1 AS col\n " ,
2249+ (path / "models" / "example.sql" ).write_text (
2250+ f "MODEL(name { project } .example, dialect 'duckdb'); SELECT 1 AS col\n " ,
22502251 encoding = "utf-8" ,
22512252 )
22522253
2254+
2255+ def _patch_state_access (mocker ):
22532256 return mocker .patch (
22542257 "sqlmesh.core.state_sync.db.facade.EngineAdapterStateSync.get_versions" ,
22552258 side_effect = RuntimeError ("state should not be accessed" ),
22562259 )
22572260
22582261
2262+ def _setup_local_only_project (tmp_path , mocker ):
2263+ _create_local_only_project (tmp_path , "cli_test" )
2264+ return _patch_state_access (mocker )
2265+
2266+
22592267def test_format_runs_without_state (runner : CliRunner , tmp_path : Path , mocker ):
22602268 mock = _setup_local_only_project (tmp_path , mocker )
22612269 result = runner .invoke (cli , ["--paths" , str (tmp_path ), "format" ])
@@ -2270,6 +2278,23 @@ def test_lint_runs_without_state(runner: CliRunner, tmp_path: Path, mocker):
22702278 mock .assert_not_called ()
22712279
22722280
2281+ @pytest .mark .parametrize ("command" , ["format" , "lint" ])
2282+ def test_local_only_commands_skip_state_multiple_paths (
2283+ runner : CliRunner , tmp_path : Path , mocker , command : str
2284+ ):
2285+ project_a = tmp_path / "a"
2286+ project_b = tmp_path / "b"
2287+ _create_local_only_project (project_a , "proj_a" )
2288+ _create_local_only_project (project_b , "proj_b" )
2289+ mock = _patch_state_access (mocker )
2290+
2291+ result = runner .invoke (cli , ["--paths" , str (project_a ), "--paths" , str (project_b ), command ])
2292+ assert result .exit_code == 0 , (
2293+ f"{ command } failed: { result .output } \n Exception: { result .exception } "
2294+ )
2295+ mock .assert_not_called ()
2296+
2297+
22732298def test_plan_still_loads_state (runner : CliRunner , tmp_path : Path , mocker ):
22742299 """Guard that `plan` explicitly passes `load_state=True` and still reaches state sync."""
22752300 mock = _setup_local_only_project (tmp_path , mocker )
0 commit comments