@@ -82,3 +82,44 @@ def test_zero_exit_marks_completed(
8282 _run_entrypoint (waiting_evaluation , 0 )
8383 waiting_evaluation .refresh_from_db ()
8484 assert waiting_evaluation .state == NixEvaluation .EvaluationState .COMPLETED
85+
86+
87+ @pytest .mark .xfail (strict = True , reason = "Not implemented" )
88+ @pytest .mark .django_db (transaction = True )
89+ def test_already_completed_evaluation_is_not_re_run (
90+ make_evaluation : Callable [..., NixEvaluation ],
91+ ) -> None :
92+ completed = make_evaluation (state = NixEvaluation .EvaluationState .COMPLETED )
93+ perform_mock = AsyncMock ()
94+
95+ process = MagicMock ()
96+ stdout = MagicMock ()
97+ stdout .readline = AsyncMock (return_value = b"" )
98+ process .stdout = stdout
99+ process .wait = AsyncMock (return_value = 0 )
100+ perform_mock .return_value = process
101+
102+ mock_repo = MagicMock ()
103+ mock_repo .update_from_ref = AsyncMock ()
104+
105+ mock_file = MagicMock ()
106+ mock_file .fileno = MagicMock (return_value = 1 )
107+ mock_aiofiles_open = MagicMock ()
108+ mock_aiofiles_open .__aenter__ = AsyncMock (return_value = mock_file )
109+ mock_aiofiles_open .__aexit__ = AsyncMock (return_value = None )
110+
111+ with (
112+ patch ("shared.listeners.nix_evaluation.perform_evaluation" , perform_mock ),
113+ patch (
114+ "shared.listeners.nix_evaluation.GitRepo" , MagicMock (return_value = mock_repo )
115+ ),
116+ patch (
117+ "shared.listeners.nix_evaluation.aiofiles.open" ,
118+ return_value = mock_aiofiles_open ,
119+ ),
120+ ):
121+ asyncio .run (evaluation_entrypoint (0.0 , completed ))
122+
123+ perform_mock .assert_not_called ()
124+ completed .refresh_from_db ()
125+ assert completed .state == NixEvaluation .EvaluationState .COMPLETED
0 commit comments