@@ -166,6 +166,45 @@ async def fake_dispatch_queue_item(queue_item, passed_session):
166166 assert response .json ()["status" ] == TaskHistoryStatusEnum .RUNNING .value
167167
168168
169+ def test_the_log_stream_reconciliation_is_refused_for_a_non_admin (
170+ bearer_client : TestClient , created_task_with_history
171+ ) -> None :
172+ """Refuse the task-history reconciliation for a non-admin.
173+
174+ It is a genuine write — it persists ``status``, ``started_at`` and
175+ ``finished_at`` — so it stays gated rather than joining the exemption
176+ allowlist. The SEP log stream that triggers it is open to any authenticated
177+ user, which is why that caller sends the internal token instead.
178+ """
179+ response = bearer_client .post (
180+ f"/history/{ created_task_with_history .id } /sync/" , headers = BEARER_HEADERS
181+ )
182+
183+ assert response .status_code == status .HTTP_403_FORBIDDEN
184+
185+
186+ def test_the_log_stream_reconciliation_is_accepted_for_the_service_principal (
187+ bearer_client : TestClient ,
188+ created_task_with_history ,
189+ mock_executor : AsyncMock ,
190+ mocker : MockerFixture ,
191+ ) -> None :
192+ """Accept the same reconciliation when it carries the internal token.
193+
194+ This is the identity the SEP log stream sends, so a non-admin's stream still
195+ reaches its finish frame.
196+ """
197+ mocker .patch .object (settings , "SEP_INTERNAL_TOKEN" , SecretStr (SERVICE_TOKEN ))
198+ mock_executor .sync_task_history .return_value = created_task_with_history
199+
200+ response = bearer_client .post (
201+ f"/history/{ created_task_with_history .id } /sync/" ,
202+ headers = {"Authorization" : f"Bearer { SERVICE_TOKEN } " },
203+ )
204+
205+ assert response .status_code == status .HTTP_200_OK
206+
207+
169208def test_the_batch_read_stays_reachable_for_a_non_admin (
170209 bearer_client : TestClient ,
171210) -> None :
0 commit comments