@@ -6224,6 +6224,11 @@ def plan_with_output(ctx: Context, environment: str):
62246224
62256225 return output
62266226
6227+ def assert_environments (ctx : Context , input_env : str , promote_env : str , diff_env : str ):
6228+ plan_builder = ctx .plan_builder (input_env )
6229+ assert plan_builder .environment_naming_info .name == promote_env
6230+ assert plan_builder .build ().context_diff .environment == diff_env
6231+
62276232 models_dir = tmp_path / "models"
62286233
62296234 logger = logging .getLogger ("sqlmesh.core.state_sync.db.facade" )
@@ -6239,25 +6244,23 @@ def plan_with_output(ctx: Context, environment: str):
62396244 output = plan_with_output (ctx , "dev" )
62406245
62416246 assert """`dev` environment will be initialized""" in output .stdout
6247+ assert_environments (ctx , input_env = "dev" , promote_env = "dev" , diff_env = "dev" )
62426248
62436249 # Case 2: Prod does not exist, so dev is updated
62446250 create_temp_file (
62456251 tmp_path , models_dir / "a.sql" , "MODEL (name test.a, kind FULL); SELECT 5 AS col"
62466252 )
62476253
6248- plan = ctx .plan_builder ("dev" ).build ()
6249-
6250- assert plan .context_diff .initial_environment == "dev"
6251- assert plan .context_diff .environment == "dev"
6252-
62536254 output = plan_with_output (ctx , "dev" )
62546255
6256+ assert_environments (ctx , input_env = "dev" , promote_env = "dev" , diff_env = "dev" )
62556257 assert "Differences from the `dev` environment" in output .stdout
62566258
62576259 # Case 3: Prod is initialized, so plan comparisons moving forward should be against prod
62586260 output = plan_with_output (ctx , "prod" )
62596261
62606262 assert "`prod` environment will be initialized" in output .stdout
6263+ assert_environments (ctx , input_env = "prod" , promote_env = "prod" , diff_env = "prod" )
62616264
62626265 # Case 4: Dev is updated with a breaking change, so plan comparisons moving forward should be against prod
62636266 create_temp_file (
@@ -6267,8 +6270,7 @@ def plan_with_output(ctx: Context, environment: str):
62676270
62686271 plan = ctx .plan_builder ("dev" ).build ()
62696272
6270- assert plan .context_diff .initial_environment == "dev"
6271- assert plan .context_diff .environment == "prod"
6273+ assert_environments (ctx , input_env = "dev" , promote_env = "dev" , diff_env = "prod" )
62726274
62736275 assert (
62746276 next (iter (plan .context_diff .snapshots .values ())).change_category
@@ -6290,8 +6292,7 @@ def plan_with_output(ctx: Context, environment: str):
62906292
62916293 plan = ctx .plan_builder ("dev" ).build ()
62926294
6293- assert plan .context_diff .initial_environment == "dev"
6294- assert plan .context_diff .environment == "prod"
6295+ assert_environments (ctx , input_env = "dev" , promote_env = "dev" , diff_env = "prod" )
62956296
62966297 assert (
62976298 next (iter (plan .context_diff .snapshots .values ())).change_category
@@ -6313,3 +6314,8 @@ def plan_with_output(ctx: Context, environment: str):
63136314+ 10 AS col"""
63146315 in output .stdout
63156316 )
6317+
6318+ # Case 6: Check that we can still run Context::diff() against any environment
6319+ for environment in ["dev" , "prod" ]:
6320+ context_diff = ctx ._context_diff (environment )
6321+ assert context_diff .environment == environment
0 commit comments