jrrribeiro commited on
Commit
47559a7
·
1 Parent(s): 9b4331d

test/docs: cover conflict refresh flow and update sprint status

Browse files
README.md CHANGED
@@ -55,3 +55,4 @@ Estrutura base criada por projeto/dataset:
55
  - Sprint 3 (inicial): persistencia append-only de validacoes em eventos JSONL + snapshot current por detection_key
56
  - Sprint 3 (UI): tabela exibe status atual da validacao por detection_key e botao de relatorio por projeto
57
  - Sprint 3 (concorrencia): controle otimista por versao esperada com deteccao de conflito e bloqueio de sobrescrita silenciosa
 
 
55
  - Sprint 3 (inicial): persistencia append-only de validacoes em eventos JSONL + snapshot current por detection_key
56
  - Sprint 3 (UI): tabela exibe status atual da validacao por detection_key e botao de relatorio por projeto
57
  - Sprint 3 (concorrencia): controle otimista por versao esperada com deteccao de conflito e bloqueio de sobrescrita silenciosa
58
+ - Sprint 3 (UX conflito): refresh automatico da tabela em conflito e foco na deteccao impactada para resolucao rapida
tests/unit/test_app_factory_audio_helpers.py CHANGED
@@ -8,9 +8,11 @@ from src.ui.app_factory import (
8
  _cleanup_selected_audio,
9
  _extract_audio_id,
10
  _extract_detection_key,
 
11
  _fetch_selected_audio,
12
  _page_to_table,
13
  _save_selected_validation,
 
14
  )
15
 
16
 
@@ -263,3 +265,71 @@ def test_page_to_table_includes_validation_status() -> None:
263
  assert rows[0][0] == "dkey_01"
264
  assert rows[0][6] == "positive"
265
  assert rows[0][7] == 2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  _cleanup_selected_audio,
9
  _extract_audio_id,
10
  _extract_detection_key,
11
+ _find_detection_row_index,
12
  _fetch_selected_audio,
13
  _page_to_table,
14
  _save_selected_validation,
15
+ _save_selected_validation_with_refresh,
16
  )
17
 
18
 
 
265
  assert rows[0][0] == "dkey_01"
266
  assert rows[0][6] == "positive"
267
  assert rows[0][7] == 2
268
+
269
+
270
+ def test_find_detection_row_index() -> None:
271
+ rows = [["dkey_00", "audio_00"], ["dkey_01", "audio_01"]]
272
+
273
+ assert _find_detection_row_index(rows, "dkey_01") == 1
274
+ assert _find_detection_row_index(rows, "missing") == 0
275
+
276
+
277
+ def test_save_selected_validation_with_refresh_success() -> None:
278
+ audio_service = FakeAudioService()
279
+ validation_service = FakeValidationService()
280
+ rows = [["dkey_01", "audio_11", "sp", 0.9, 0.0, 1.0, "pending", 0]]
281
+
282
+ status, cache_key, audio_path, refreshed_rows, refreshed_page, refreshed_index = _save_selected_validation_with_refresh(
283
+ validation_service=validation_service,
284
+ audio_service=audio_service,
285
+ queue_service=FakeQueueService(),
286
+ snapshot_reader=FakeSnapshotReader(),
287
+ project_slug="demo-project",
288
+ rows=rows,
289
+ selected_index=0,
290
+ status_value="positive",
291
+ validator="validator-demo",
292
+ notes="ok",
293
+ cache_key="cache:audio_11",
294
+ page=1,
295
+ scientific_name="",
296
+ min_confidence=0.0,
297
+ )
298
+
299
+ assert "Validacao salva" in status
300
+ assert cache_key == ""
301
+ assert audio_path is None
302
+ assert refreshed_page == 1
303
+ assert refreshed_index == 0
304
+ assert refreshed_rows[0][0] == "dkey_01"
305
+
306
+
307
+ def test_save_selected_validation_with_refresh_conflict() -> None:
308
+ audio_service = FakeAudioService()
309
+ validation_service = FakeConflictValidationService()
310
+ rows = [["dkey_01", "audio_11", "sp", 0.9, 0.0, 1.0, "pending", 0]]
311
+
312
+ status, cache_key, audio_path, refreshed_rows, refreshed_page, refreshed_index = _save_selected_validation_with_refresh(
313
+ validation_service=validation_service,
314
+ audio_service=audio_service,
315
+ queue_service=FakeQueueService(),
316
+ snapshot_reader=FakeSnapshotReader(),
317
+ project_slug="demo-project",
318
+ rows=rows,
319
+ selected_index=0,
320
+ status_value="positive",
321
+ validator="validator-demo",
322
+ notes="ok",
323
+ cache_key="cache:audio_11",
324
+ page=1,
325
+ scientific_name="",
326
+ min_confidence=0.0,
327
+ )
328
+
329
+ assert "Conflito de concorrencia" in status
330
+ assert "Tabela recarregada" in status
331
+ assert cache_key == "cache:audio_11"
332
+ assert audio_path is None
333
+ assert refreshed_page == 1
334
+ assert refreshed_index == 0
335
+ assert refreshed_rows[0][0] == "dkey_01"