@@ -1559,6 +1559,37 @@ def test_restatement_plan_ignores_changes(init_and_plan_context: t.Callable):
15591559 context .apply (plan )
15601560
15611561
1562+ @freeze_time ("2023-01-08 15:00:00" )
1563+ def test_plan_against_expired_environment (init_and_plan_context : t .Callable ):
1564+ context , plan = init_and_plan_context ("examples/sushi" )
1565+ context .apply (plan )
1566+
1567+ model = context .get_model ("sushi.waiter_revenue_by_day" )
1568+ context .upsert_model (add_projection_to_model (t .cast (SqlModel , model )))
1569+
1570+ modified_models = {model .fqn , context .get_model ("sushi.top_waiters" ).fqn }
1571+
1572+ plan = context .plan ("dev" , no_prompts = True )
1573+ assert plan .has_changes
1574+ assert set (plan .context_diff .modified_snapshots ) == modified_models
1575+ assert plan .missing_intervals
1576+ context .apply (plan )
1577+
1578+ # Make sure there are no changes when comparing against the existing environment.
1579+ plan = context .plan ("dev" , no_prompts = True )
1580+ assert not plan .has_changes
1581+ assert not plan .context_diff .modified_snapshots
1582+ assert not plan .missing_intervals
1583+
1584+ # Invalidate the environment and make sure that the plan detects the changes.
1585+ context .invalidate_environment ("dev" )
1586+ plan = context .plan ("dev" , no_prompts = True )
1587+ assert plan .has_changes
1588+ assert set (plan .context_diff .modified_snapshots ) == modified_models
1589+ assert not plan .missing_intervals
1590+ context .apply (plan )
1591+
1592+
15621593def test_plan_twice_with_star_macro_yields_no_diff (tmp_path : Path ):
15631594 init_example_project (tmp_path , dialect = "duckdb" )
15641595
0 commit comments