jrrribeiro commited on
Commit
5e3e3bc
·
verified ·
1 Parent(s): 065c56b

Sync app from GitHub Actions (feature/project-state-security-privacy-review)

Browse files
src/ui/app_factory.py CHANGED
@@ -64,9 +64,10 @@ VALIDATION_UNCERTAIN_LABEL = "← Uncertain"
64
  VALIDATION_SKIP_LABEL = "→ Skip"
65
  VALIDATION_FAVORITE_LABEL = "␣ Favorite"
66
  VALIDATION_FAVORITED_LABEL = "␣ Favorited"
 
 
67
  VALIDATION_QUEUE_COMPLETE_STATUS = (
68
- "All segments for this species have been validated. "
69
- "Select a row manually to review or correct it."
70
  )
71
 
72
 
@@ -2332,18 +2333,22 @@ def _autofetch_first_row(
2332
  ) -> tuple[int, str | None, str, str, str | None]:
2333
  normalized_rows = _normalize_rows(rows)
2334
  if not normalized_rows:
2335
- return 0, None, "", "No detections available to auto-load audio", None
 
 
 
 
2336
 
2337
  audio_path, updated_cache_key, status, spectrogram_path = _fetch_selected_audio_with_spectrogram(
2338
  audio_service=audio_service,
2339
  dataset_repo=dataset_repo,
2340
  rows=normalized_rows,
2341
- selected_index=0,
2342
  previous_cache_key=cache_key,
2343
  allow_demo_fallback=allow_demo_fallback,
2344
  hf_token=hf_token,
2345
  )
2346
- return 0, audio_path, updated_cache_key, status, spectrogram_path
2347
 
2348
 
2349
  def _select_and_fetch_audio(
@@ -2458,7 +2463,15 @@ def _mark_selected_row(rows: object, selected_index: int) -> list[list[object]]:
2458
 
2459
  def _selected_segment_card(rows: object, selected_index: int) -> str:
2460
  normalized_rows = _normalize_rows(rows)
2461
- if not normalized_rows or int(selected_index) < 0:
 
 
 
 
 
 
 
 
2462
  return selected_segment_html(None)
2463
  safe_index = max(0, min(int(selected_index), len(normalized_rows) - 1))
2464
  return selected_segment_html(normalized_rows[safe_index], safe_index, len(normalized_rows))
 
64
  VALIDATION_SKIP_LABEL = "→ Skip"
65
  VALIDATION_FAVORITE_LABEL = "␣ Favorite"
66
  VALIDATION_FAVORITED_LABEL = "␣ Favorited"
67
+ VALIDATION_QUEUE_COMPLETE_CARD_TITLE = "All segments for this species have been validated"
68
+ VALIDATION_QUEUE_COMPLETE_CARD_NOTE = "Select a row manually to review or correct it."
69
  VALIDATION_QUEUE_COMPLETE_STATUS = (
70
+ f"{VALIDATION_QUEUE_COMPLETE_CARD_TITLE}. {VALIDATION_QUEUE_COMPLETE_CARD_NOTE}"
 
71
  )
72
 
73
 
 
2333
  ) -> tuple[int, str | None, str, str, str | None]:
2334
  normalized_rows = _normalize_rows(rows)
2335
  if not normalized_rows:
2336
+ return -1, None, "", "No detections available to auto-load audio", None
2337
+
2338
+ pending_index = _pending_row_index_or_none(normalized_rows)
2339
+ if pending_index is None:
2340
+ return -1, None, "", VALIDATION_QUEUE_COMPLETE_STATUS, None
2341
 
2342
  audio_path, updated_cache_key, status, spectrogram_path = _fetch_selected_audio_with_spectrogram(
2343
  audio_service=audio_service,
2344
  dataset_repo=dataset_repo,
2345
  rows=normalized_rows,
2346
+ selected_index=pending_index,
2347
  previous_cache_key=cache_key,
2348
  allow_demo_fallback=allow_demo_fallback,
2349
  hf_token=hf_token,
2350
  )
2351
+ return pending_index, audio_path, updated_cache_key, status, spectrogram_path
2352
 
2353
 
2354
  def _select_and_fetch_audio(
 
2463
 
2464
  def _selected_segment_card(rows: object, selected_index: int) -> str:
2465
  normalized_rows = _normalize_rows(rows)
2466
+ if not normalized_rows:
2467
+ return selected_segment_html(None)
2468
+ if int(selected_index) < 0:
2469
+ if _pending_row_index_or_none(normalized_rows) is None:
2470
+ return selected_segment_html(
2471
+ None,
2472
+ empty_title=VALIDATION_QUEUE_COMPLETE_CARD_TITLE,
2473
+ empty_note=VALIDATION_QUEUE_COMPLETE_CARD_NOTE,
2474
+ )
2475
  return selected_segment_html(None)
2476
  safe_index = max(0, min(int(selected_index), len(normalized_rows) - 1))
2477
  return selected_segment_html(normalized_rows[safe_index], safe_index, len(normalized_rows))
src/ui/components.py CHANGED
@@ -266,13 +266,19 @@ def inline_hint_html(text: str, tone: str = "info") -> str:
266
  return f"<div class='bn-inline-hint{tone_class}'>{escape(text)}</div>"
267
 
268
 
269
- def selected_segment_html(row: list[object] | None, selected_index: int | None = None, total_rows: int | None = None) -> str:
 
 
 
 
 
 
270
  if not row:
271
  return (
272
  "<div class='bn-selected-card'>"
273
  "<div class='bn-brand-kicker'>Selected segment</div>"
274
- "<div class='bn-empty-title'>No segment loaded</div>"
275
- "<div class='bn-compact-note'>Choose a species and apply filters to load the validation queue.</div>"
276
  "</div>"
277
  )
278
 
 
266
  return f"<div class='bn-inline-hint{tone_class}'>{escape(text)}</div>"
267
 
268
 
269
+ def selected_segment_html(
270
+ row: list[object] | None,
271
+ selected_index: int | None = None,
272
+ total_rows: int | None = None,
273
+ empty_title: str = "No segment loaded",
274
+ empty_note: str = "Choose a species and apply filters to load the validation queue.",
275
+ ) -> str:
276
  if not row:
277
  return (
278
  "<div class='bn-selected-card'>"
279
  "<div class='bn-brand-kicker'>Selected segment</div>"
280
+ f"<div class='bn-empty-title'>{escape(empty_title)}</div>"
281
+ f"<div class='bn-compact-note'>{escape(empty_note)}</div>"
282
  "</div>"
283
  )
284
 
tests/unit/test_app_factory_audio_helpers.py CHANGED
@@ -13,6 +13,7 @@ from src.ui.app_factory import (
13
  _build_validation_report,
14
  _cleanup_selected_audio,
15
  _advance_to_next_row_with_title,
 
16
  _extract_audio_id,
17
  _extract_detection_key,
18
  _find_detection_row_index,
@@ -22,6 +23,7 @@ from src.ui.app_factory import (
22
  _save_selected_validation,
23
  _save_selected_validation_with_refresh,
24
  _selected_dataframe_row_index,
 
25
  _reapply_last_conflict_validation_with_refresh,
26
  _batch_validate_conflicts,
27
  create_app,
@@ -931,6 +933,45 @@ def test_advance_to_next_row_wraps_to_first_pending_row() -> None:
931
  assert cache_key == "key:audio_02"
932
 
933
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
934
  def test_save_selected_validation_with_refresh_success() -> None:
935
  audio_service = FakeAudioService()
936
  validation_service = FakeValidationService()
 
13
  _build_validation_report,
14
  _cleanup_selected_audio,
15
  _advance_to_next_row_with_title,
16
+ _autofetch_first_row,
17
  _extract_audio_id,
18
  _extract_detection_key,
19
  _find_detection_row_index,
 
23
  _save_selected_validation,
24
  _save_selected_validation_with_refresh,
25
  _selected_dataframe_row_index,
26
+ _selected_segment_card,
27
  _reapply_last_conflict_validation_with_refresh,
28
  _batch_validate_conflicts,
29
  create_app,
 
933
  assert cache_key == "key:audio_02"
934
 
935
 
936
+ def test_autofetch_first_row_stops_when_filtered_species_is_complete() -> None:
937
+ service = FakeAudioService()
938
+ rows = [
939
+ ["dkey_01", "audio_01", "sp", 0.9, 0.0, 1.0, "positive"],
940
+ ["dkey_02", "audio_02", "sp", 0.8, 1.0, 2.0, "negative"],
941
+ ]
942
+
943
+ selected_index, audio_path, cache_key, status, spectrogram_path = _autofetch_first_row(
944
+ audio_service=service,
945
+ dataset_repo="org/dataset",
946
+ rows=rows,
947
+ cache_key="cache:old",
948
+ )
949
+
950
+ assert selected_index == -1
951
+ assert audio_path is None
952
+ assert cache_key == ""
953
+ assert spectrogram_path is None
954
+ assert "All segments for this species have been validated" in status
955
+
956
+
957
+ def test_selected_segment_card_shows_complete_species_message_only_when_all_rows_reviewed() -> None:
958
+ complete_rows = [
959
+ ["dkey_01", "audio_01", "sp", 0.9, 0.0, 1.0, "positive"],
960
+ ["dkey_02", "audio_02", "sp", 0.8, 1.0, 2.0, "negative"],
961
+ ]
962
+ pending_rows = [
963
+ ["dkey_01", "audio_01", "sp", 0.9, 0.0, 1.0, "pending"],
964
+ ]
965
+
966
+ complete_html = _selected_segment_card(complete_rows, -1)
967
+ pending_html = _selected_segment_card(pending_rows, -1)
968
+
969
+ assert "All segments for this species have been validated" in complete_html
970
+ assert "Select a row manually to review or correct it." in complete_html
971
+ assert "No segment loaded" in pending_html
972
+ assert "All segments for this species have been validated" not in pending_html
973
+
974
+
975
  def test_save_selected_validation_with_refresh_success() -> None:
976
  audio_service = FakeAudioService()
977
  validation_service = FakeValidationService()