Spaces:
Sleeping
Sleeping
Sync app from GitHub Actions (feature/project-state-security-privacy-review)
Browse files
src/ui/app_factory.py
CHANGED
|
@@ -70,6 +70,10 @@ VALIDATION_QUEUE_COMPLETE_CARD_NOTE = "Select a row manually to review or correc
|
|
| 70 |
VALIDATION_QUEUE_COMPLETE_STATUS = (
|
| 71 |
f"{VALIDATION_QUEUE_COMPLETE_CARD_TITLE}. {VALIDATION_QUEUE_COMPLETE_CARD_NOTE}"
|
| 72 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
class _AudioFetchResultProtocol(Protocol):
|
|
@@ -2963,6 +2967,14 @@ def _validator_name_from_session(session: object) -> str:
|
|
| 2963 |
return str(getattr(session, "username", "") or "").strip()
|
| 2964 |
|
| 2965 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2966 |
def _save_selected_validation(
|
| 2967 |
validation_service: _ValidationServiceProtocol,
|
| 2968 |
audio_service: _AudioServiceProtocol,
|
|
@@ -2974,11 +2986,14 @@ def _save_selected_validation(
|
|
| 2974 |
notes: str,
|
| 2975 |
cache_key: str,
|
| 2976 |
corrected_species: str | None = None,
|
| 2977 |
-
) -> tuple[str, str,
|
| 2978 |
validator_name = validator.strip()
|
| 2979 |
if not validator_name:
|
| 2980 |
return "Provide validator name before saving", cache_key, None
|
| 2981 |
|
|
|
|
|
|
|
|
|
|
| 2982 |
try:
|
| 2983 |
detection_key = _extract_detection_key(rows=rows, selected_index=selected_index)
|
| 2984 |
expected_version = _extract_expected_version(rows=rows, selected_index=selected_index)
|
|
@@ -3006,6 +3021,29 @@ def _save_selected_validation(
|
|
| 3006 |
return f"Failed to save validation: {exc}", cache_key, None
|
| 3007 |
|
| 3008 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3009 |
def _save_selected_validation_with_refresh(
|
| 3010 |
validation_service: _ValidationServiceProtocol,
|
| 3011 |
audio_service: _AudioServiceProtocol,
|
|
@@ -3026,8 +3064,20 @@ def _save_selected_validation_with_refresh(
|
|
| 3026 |
updated_after: object,
|
| 3027 |
show_conflicts_only: bool,
|
| 3028 |
corrected_species: str | None = None,
|
| 3029 |
-
) -> tuple[str, str,
|
| 3030 |
prior_rows = _normalize_rows(rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3031 |
selected_was_last_row = bool(prior_rows) and int(selected_index) >= len(prior_rows) - 1
|
| 3032 |
selected_key = ""
|
| 3033 |
try:
|
|
@@ -6246,16 +6296,17 @@ def create_app() -> gr.Blocks:
|
|
| 6246 |
)
|
| 6247 |
|
| 6248 |
approve_event.then(
|
| 6249 |
-
fn=lambda project_slug, repo, rows, idx, cache_key, session:
|
| 6250 |
audio_service=audio_service,
|
| 6251 |
dataset_repo=repo,
|
| 6252 |
rows=rows,
|
| 6253 |
selected_index=int(idx),
|
| 6254 |
cache_key=cache_key,
|
|
|
|
| 6255 |
allow_demo_fallback=False,
|
| 6256 |
hf_token=_project_fetch_token(project_slug, session),
|
| 6257 |
),
|
| 6258 |
-
inputs=[selected_project_state, selected_dataset_repo_state, table, selected_index, cache_key_state, session_state],
|
| 6259 |
outputs=[selected_index, audio_player, cache_key_state, status, spectrogram_image, spectrogram_title],
|
| 6260 |
).then(
|
| 6261 |
fn=lambda rows, idx: _mark_selected_row(rows, int(idx)),
|
|
@@ -6276,16 +6327,17 @@ def create_app() -> gr.Blocks:
|
|
| 6276 |
)
|
| 6277 |
|
| 6278 |
reject_event.then(
|
| 6279 |
-
fn=lambda project_slug, repo, rows, idx, cache_key, session:
|
| 6280 |
audio_service=audio_service,
|
| 6281 |
dataset_repo=repo,
|
| 6282 |
rows=rows,
|
| 6283 |
selected_index=int(idx),
|
| 6284 |
cache_key=cache_key,
|
|
|
|
| 6285 |
allow_demo_fallback=False,
|
| 6286 |
hf_token=_project_fetch_token(project_slug, session),
|
| 6287 |
),
|
| 6288 |
-
inputs=[selected_project_state, selected_dataset_repo_state, table, selected_index, cache_key_state, session_state],
|
| 6289 |
outputs=[selected_index, audio_player, cache_key_state, status, spectrogram_image, spectrogram_title],
|
| 6290 |
).then(
|
| 6291 |
fn=lambda rows, idx: _mark_selected_row(rows, int(idx)),
|
|
@@ -6306,16 +6358,17 @@ def create_app() -> gr.Blocks:
|
|
| 6306 |
)
|
| 6307 |
|
| 6308 |
uncertain_event.then(
|
| 6309 |
-
fn=lambda project_slug, repo, rows, idx, cache_key, session:
|
| 6310 |
audio_service=audio_service,
|
| 6311 |
dataset_repo=repo,
|
| 6312 |
rows=rows,
|
| 6313 |
selected_index=int(idx),
|
| 6314 |
cache_key=cache_key,
|
|
|
|
| 6315 |
allow_demo_fallback=False,
|
| 6316 |
hf_token=_project_fetch_token(project_slug, session),
|
| 6317 |
),
|
| 6318 |
-
inputs=[selected_project_state, selected_dataset_repo_state, table, selected_index, cache_key_state, session_state],
|
| 6319 |
outputs=[selected_index, audio_player, cache_key_state, status, spectrogram_image, spectrogram_title],
|
| 6320 |
).then(
|
| 6321 |
fn=lambda rows, idx: _mark_selected_row(rows, int(idx)),
|
|
@@ -6336,16 +6389,17 @@ def create_app() -> gr.Blocks:
|
|
| 6336 |
)
|
| 6337 |
|
| 6338 |
skip_event.then(
|
| 6339 |
-
fn=lambda project_slug, repo, rows, idx, cache_key, session:
|
| 6340 |
audio_service=audio_service,
|
| 6341 |
dataset_repo=repo,
|
| 6342 |
rows=rows,
|
| 6343 |
selected_index=int(idx),
|
| 6344 |
cache_key=cache_key,
|
|
|
|
| 6345 |
allow_demo_fallback=False,
|
| 6346 |
hf_token=_project_fetch_token(project_slug, session),
|
| 6347 |
),
|
| 6348 |
-
inputs=[selected_project_state, selected_dataset_repo_state, table, selected_index, cache_key_state, session_state],
|
| 6349 |
outputs=[selected_index, audio_player, cache_key_state, status, spectrogram_image, spectrogram_title],
|
| 6350 |
).then(
|
| 6351 |
fn=lambda rows, idx: _mark_selected_row(rows, int(idx)),
|
|
|
|
| 70 |
VALIDATION_QUEUE_COMPLETE_STATUS = (
|
| 71 |
f"{VALIDATION_QUEUE_COMPLETE_CARD_TITLE}. {VALIDATION_QUEUE_COMPLETE_CARD_NOTE}"
|
| 72 |
)
|
| 73 |
+
VALIDATION_REJECT_CORRECTION_REQUIRED_STATUS = (
|
| 74 |
+
"Corrected species is required before rejecting this segment. "
|
| 75 |
+
"Choose the corrected species, Noise, or Undetermined, then reject again."
|
| 76 |
+
)
|
| 77 |
|
| 78 |
|
| 79 |
class _AudioFetchResultProtocol(Protocol):
|
|
|
|
| 2967 |
return str(getattr(session, "username", "") or "").strip()
|
| 2968 |
|
| 2969 |
|
| 2970 |
+
def _reject_requires_corrected_species(status_value: str, corrected_species: str | None) -> bool:
|
| 2971 |
+
return (status_value or "").strip().lower() == "negative" and not (corrected_species or "").strip()
|
| 2972 |
+
|
| 2973 |
+
|
| 2974 |
+
def _is_reject_correction_required_status(status_value: object) -> bool:
|
| 2975 |
+
return str(status_value or "").strip().startswith(VALIDATION_REJECT_CORRECTION_REQUIRED_STATUS)
|
| 2976 |
+
|
| 2977 |
+
|
| 2978 |
def _save_selected_validation(
|
| 2979 |
validation_service: _ValidationServiceProtocol,
|
| 2980 |
audio_service: _AudioServiceProtocol,
|
|
|
|
| 2986 |
notes: str,
|
| 2987 |
cache_key: str,
|
| 2988 |
corrected_species: str | None = None,
|
| 2989 |
+
) -> tuple[str, str, object]:
|
| 2990 |
validator_name = validator.strip()
|
| 2991 |
if not validator_name:
|
| 2992 |
return "Provide validator name before saving", cache_key, None
|
| 2993 |
|
| 2994 |
+
if _reject_requires_corrected_species(status_value, corrected_species):
|
| 2995 |
+
return VALIDATION_REJECT_CORRECTION_REQUIRED_STATUS, cache_key, gr.update()
|
| 2996 |
+
|
| 2997 |
try:
|
| 2998 |
detection_key = _extract_detection_key(rows=rows, selected_index=selected_index)
|
| 2999 |
expected_version = _extract_expected_version(rows=rows, selected_index=selected_index)
|
|
|
|
| 3021 |
return f"Failed to save validation: {exc}", cache_key, None
|
| 3022 |
|
| 3023 |
|
| 3024 |
+
def _advance_after_validation_with_title(
|
| 3025 |
+
audio_service: _AudioServiceProtocol,
|
| 3026 |
+
dataset_repo: str,
|
| 3027 |
+
rows: object,
|
| 3028 |
+
selected_index: int,
|
| 3029 |
+
cache_key: str,
|
| 3030 |
+
save_status: object,
|
| 3031 |
+
allow_demo_fallback: bool = False,
|
| 3032 |
+
hf_token: str | None = None,
|
| 3033 |
+
) -> tuple[int, object, str, object, object, object]:
|
| 3034 |
+
if _is_reject_correction_required_status(save_status):
|
| 3035 |
+
return int(selected_index), gr.update(), cache_key, save_status, gr.update(), gr.update()
|
| 3036 |
+
return _advance_to_next_row_with_title(
|
| 3037 |
+
audio_service=audio_service,
|
| 3038 |
+
dataset_repo=dataset_repo,
|
| 3039 |
+
rows=rows,
|
| 3040 |
+
selected_index=selected_index,
|
| 3041 |
+
cache_key=cache_key,
|
| 3042 |
+
allow_demo_fallback=allow_demo_fallback,
|
| 3043 |
+
hf_token=hf_token,
|
| 3044 |
+
)
|
| 3045 |
+
|
| 3046 |
+
|
| 3047 |
def _save_selected_validation_with_refresh(
|
| 3048 |
validation_service: _ValidationServiceProtocol,
|
| 3049 |
audio_service: _AudioServiceProtocol,
|
|
|
|
| 3064 |
updated_after: object,
|
| 3065 |
show_conflicts_only: bool,
|
| 3066 |
corrected_species: str | None = None,
|
| 3067 |
+
) -> tuple[str, str, object, list[list[object]], int, int, str, str]:
|
| 3068 |
prior_rows = _normalize_rows(rows)
|
| 3069 |
+
if _reject_requires_corrected_species(status_value, corrected_species):
|
| 3070 |
+
return (
|
| 3071 |
+
VALIDATION_REJECT_CORRECTION_REQUIRED_STATUS,
|
| 3072 |
+
cache_key,
|
| 3073 |
+
gr.update(),
|
| 3074 |
+
prior_rows,
|
| 3075 |
+
int(page),
|
| 3076 |
+
int(selected_index),
|
| 3077 |
+
"",
|
| 3078 |
+
"",
|
| 3079 |
+
)
|
| 3080 |
+
|
| 3081 |
selected_was_last_row = bool(prior_rows) and int(selected_index) >= len(prior_rows) - 1
|
| 3082 |
selected_key = ""
|
| 3083 |
try:
|
|
|
|
| 6296 |
)
|
| 6297 |
|
| 6298 |
approve_event.then(
|
| 6299 |
+
fn=lambda project_slug, repo, rows, idx, cache_key, session, save_status: _advance_after_validation_with_title(
|
| 6300 |
audio_service=audio_service,
|
| 6301 |
dataset_repo=repo,
|
| 6302 |
rows=rows,
|
| 6303 |
selected_index=int(idx),
|
| 6304 |
cache_key=cache_key,
|
| 6305 |
+
save_status=save_status,
|
| 6306 |
allow_demo_fallback=False,
|
| 6307 |
hf_token=_project_fetch_token(project_slug, session),
|
| 6308 |
),
|
| 6309 |
+
inputs=[selected_project_state, selected_dataset_repo_state, table, selected_index, cache_key_state, session_state, status],
|
| 6310 |
outputs=[selected_index, audio_player, cache_key_state, status, spectrogram_image, spectrogram_title],
|
| 6311 |
).then(
|
| 6312 |
fn=lambda rows, idx: _mark_selected_row(rows, int(idx)),
|
|
|
|
| 6327 |
)
|
| 6328 |
|
| 6329 |
reject_event.then(
|
| 6330 |
+
fn=lambda project_slug, repo, rows, idx, cache_key, session, save_status: _advance_after_validation_with_title(
|
| 6331 |
audio_service=audio_service,
|
| 6332 |
dataset_repo=repo,
|
| 6333 |
rows=rows,
|
| 6334 |
selected_index=int(idx),
|
| 6335 |
cache_key=cache_key,
|
| 6336 |
+
save_status=save_status,
|
| 6337 |
allow_demo_fallback=False,
|
| 6338 |
hf_token=_project_fetch_token(project_slug, session),
|
| 6339 |
),
|
| 6340 |
+
inputs=[selected_project_state, selected_dataset_repo_state, table, selected_index, cache_key_state, session_state, status],
|
| 6341 |
outputs=[selected_index, audio_player, cache_key_state, status, spectrogram_image, spectrogram_title],
|
| 6342 |
).then(
|
| 6343 |
fn=lambda rows, idx: _mark_selected_row(rows, int(idx)),
|
|
|
|
| 6358 |
)
|
| 6359 |
|
| 6360 |
uncertain_event.then(
|
| 6361 |
+
fn=lambda project_slug, repo, rows, idx, cache_key, session, save_status: _advance_after_validation_with_title(
|
| 6362 |
audio_service=audio_service,
|
| 6363 |
dataset_repo=repo,
|
| 6364 |
rows=rows,
|
| 6365 |
selected_index=int(idx),
|
| 6366 |
cache_key=cache_key,
|
| 6367 |
+
save_status=save_status,
|
| 6368 |
allow_demo_fallback=False,
|
| 6369 |
hf_token=_project_fetch_token(project_slug, session),
|
| 6370 |
),
|
| 6371 |
+
inputs=[selected_project_state, selected_dataset_repo_state, table, selected_index, cache_key_state, session_state, status],
|
| 6372 |
outputs=[selected_index, audio_player, cache_key_state, status, spectrogram_image, spectrogram_title],
|
| 6373 |
).then(
|
| 6374 |
fn=lambda rows, idx: _mark_selected_row(rows, int(idx)),
|
|
|
|
| 6389 |
)
|
| 6390 |
|
| 6391 |
skip_event.then(
|
| 6392 |
+
fn=lambda project_slug, repo, rows, idx, cache_key, session, save_status: _advance_after_validation_with_title(
|
| 6393 |
audio_service=audio_service,
|
| 6394 |
dataset_repo=repo,
|
| 6395 |
rows=rows,
|
| 6396 |
selected_index=int(idx),
|
| 6397 |
cache_key=cache_key,
|
| 6398 |
+
save_status=save_status,
|
| 6399 |
allow_demo_fallback=False,
|
| 6400 |
hf_token=_project_fetch_token(project_slug, session),
|
| 6401 |
),
|
| 6402 |
+
inputs=[selected_project_state, selected_dataset_repo_state, table, selected_index, cache_key_state, session_state, status],
|
| 6403 |
outputs=[selected_index, audio_player, cache_key_state, status, spectrogram_image, spectrogram_title],
|
| 6404 |
).then(
|
| 6405 |
fn=lambda rows, idx: _mark_selected_row(rows, int(idx)),
|
tests/integration/test_validation_flow_integration.py
CHANGED
|
@@ -152,6 +152,7 @@ def test_stale_version_returns_conflict_and_marks_conflict_row(tmp_path: Path) -
|
|
| 152 |
status_filter="all",
|
| 153 |
updated_after=None,
|
| 154 |
show_conflicts_only=False,
|
|
|
|
| 155 |
)
|
| 156 |
|
| 157 |
assert "Concurrency conflict" in status
|
|
|
|
| 152 |
status_filter="all",
|
| 153 |
updated_after=None,
|
| 154 |
show_conflicts_only=False,
|
| 155 |
+
corrected_species="Noise",
|
| 156 |
)
|
| 157 |
|
| 158 |
assert "Concurrency conflict" in status
|
tests/unit/test_app_factory_audio_helpers.py
CHANGED
|
@@ -23,6 +23,7 @@ from src.ui.app_factory import (
|
|
| 23 |
_post_validation_queue_anchor,
|
| 24 |
_save_selected_validation,
|
| 25 |
_save_selected_validation_with_refresh,
|
|
|
|
| 26 |
_selected_dataframe_row_index,
|
| 27 |
_selected_segment_card,
|
| 28 |
_reapply_last_conflict_validation_with_refresh,
|
|
@@ -47,6 +48,7 @@ from src.ui.app_factory import (
|
|
| 47 |
_species_status_dropdown_script,
|
| 48 |
_species_status_payload,
|
| 49 |
_species_dropdown_choices,
|
|
|
|
| 50 |
)
|
| 51 |
from src.auth.auth_service import AuthService
|
| 52 |
from src.config.runtime_config import RuntimeConfig
|
|
@@ -140,13 +142,13 @@ class FakeValidationService:
|
|
| 140 |
corrected_species: str | None = None,
|
| 141 |
expected_version: int | None = None,
|
| 142 |
) -> dict[str, str]:
|
| 143 |
-
_ = corrected_species
|
| 144 |
payload = {
|
| 145 |
"project_slug": project_slug,
|
| 146 |
"detection_key": detection_key,
|
| 147 |
"status": status,
|
| 148 |
"validator": validator,
|
| 149 |
"notes": notes,
|
|
|
|
| 150 |
"expected_version": str(expected_version),
|
| 151 |
}
|
| 152 |
self.calls.append(payload)
|
|
@@ -559,7 +561,7 @@ def test_build_validation_export_rows_keep_detections_metadata_and_current_valid
|
|
| 559 |
],
|
| 560 |
{
|
| 561 |
"0000000000000001": {
|
| 562 |
-
"status": "
|
| 563 |
"corrected_species": "Corrected species",
|
| 564 |
"notes": "Checked twice",
|
| 565 |
"validator": "scientist",
|
|
@@ -585,7 +587,8 @@ def test_build_validation_export_rows_keep_detections_metadata_and_current_valid
|
|
| 585 |
]
|
| 586 |
assert columns[8:10] == ["source_Common Name", "source_Latitude"]
|
| 587 |
assert rows[0]["detection_key"] == "0000000000000001"
|
| 588 |
-
assert rows[0]["validation_status"] == "
|
|
|
|
| 589 |
assert rows[0]["validation_effective_species"] == "Corrected species"
|
| 590 |
assert rows[0]["validation_version"] == 2
|
| 591 |
assert rows[0]["validation_conflict"] is True
|
|
@@ -1078,6 +1081,92 @@ def test_save_selected_validation_with_refresh_success() -> None:
|
|
| 1078 |
assert conflict_key == ""
|
| 1079 |
|
| 1080 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1081 |
def test_save_selected_validation_advances_to_highest_confidence_pending_row() -> None:
|
| 1082 |
class QueueAfterSave:
|
| 1083 |
def list_all_detections(self, **kwargs: object) -> list[object]:
|
|
|
|
| 23 |
_post_validation_queue_anchor,
|
| 24 |
_save_selected_validation,
|
| 25 |
_save_selected_validation_with_refresh,
|
| 26 |
+
_advance_after_validation_with_title,
|
| 27 |
_selected_dataframe_row_index,
|
| 28 |
_selected_segment_card,
|
| 29 |
_reapply_last_conflict_validation_with_refresh,
|
|
|
|
| 48 |
_species_status_dropdown_script,
|
| 49 |
_species_status_payload,
|
| 50 |
_species_dropdown_choices,
|
| 51 |
+
VALIDATION_REJECT_CORRECTION_REQUIRED_STATUS,
|
| 52 |
)
|
| 53 |
from src.auth.auth_service import AuthService
|
| 54 |
from src.config.runtime_config import RuntimeConfig
|
|
|
|
| 142 |
corrected_species: str | None = None,
|
| 143 |
expected_version: int | None = None,
|
| 144 |
) -> dict[str, str]:
|
|
|
|
| 145 |
payload = {
|
| 146 |
"project_slug": project_slug,
|
| 147 |
"detection_key": detection_key,
|
| 148 |
"status": status,
|
| 149 |
"validator": validator,
|
| 150 |
"notes": notes,
|
| 151 |
+
"corrected_species": corrected_species or "",
|
| 152 |
"expected_version": str(expected_version),
|
| 153 |
}
|
| 154 |
self.calls.append(payload)
|
|
|
|
| 561 |
],
|
| 562 |
{
|
| 563 |
"0000000000000001": {
|
| 564 |
+
"status": "negative",
|
| 565 |
"corrected_species": "Corrected species",
|
| 566 |
"notes": "Checked twice",
|
| 567 |
"validator": "scientist",
|
|
|
|
| 587 |
]
|
| 588 |
assert columns[8:10] == ["source_Common Name", "source_Latitude"]
|
| 589 |
assert rows[0]["detection_key"] == "0000000000000001"
|
| 590 |
+
assert rows[0]["validation_status"] == "negative"
|
| 591 |
+
assert rows[0]["validation_corrected_species"] == "Corrected species"
|
| 592 |
assert rows[0]["validation_effective_species"] == "Corrected species"
|
| 593 |
assert rows[0]["validation_version"] == 2
|
| 594 |
assert rows[0]["validation_conflict"] is True
|
|
|
|
| 1081 |
assert conflict_key == ""
|
| 1082 |
|
| 1083 |
|
| 1084 |
+
def test_reject_validation_requires_corrected_species_before_saving_or_advancing() -> None:
|
| 1085 |
+
audio_service = FakeAudioService()
|
| 1086 |
+
validation_service = FakeValidationService()
|
| 1087 |
+
rows = [["dkey_01", "audio_11", "sp", 0.9, 0.0, 1.0, "pending", 0]]
|
| 1088 |
+
|
| 1089 |
+
status, cache_key, audio_output, refreshed_rows, refreshed_page, refreshed_index, pending_status, conflict_key = _save_selected_validation_with_refresh(
|
| 1090 |
+
validation_service=validation_service,
|
| 1091 |
+
audio_service=audio_service,
|
| 1092 |
+
queue_service=FakeQueueService(),
|
| 1093 |
+
snapshot_reader=FakeSnapshotReader(),
|
| 1094 |
+
project_slug="demo-project",
|
| 1095 |
+
rows=rows,
|
| 1096 |
+
selected_index=0,
|
| 1097 |
+
status_value="negative",
|
| 1098 |
+
validator="validator-demo",
|
| 1099 |
+
notes="wrong species",
|
| 1100 |
+
cache_key="cache:audio_11",
|
| 1101 |
+
page=1,
|
| 1102 |
+
scientific_name="sp",
|
| 1103 |
+
min_confidence=0.0,
|
| 1104 |
+
validator_filter="",
|
| 1105 |
+
status_filter="all",
|
| 1106 |
+
updated_after="",
|
| 1107 |
+
show_conflicts_only=False,
|
| 1108 |
+
corrected_species="",
|
| 1109 |
+
)
|
| 1110 |
+
advanced_index, advanced_audio, advanced_cache_key, advanced_status, spectrogram, title = _advance_after_validation_with_title(
|
| 1111 |
+
audio_service=audio_service,
|
| 1112 |
+
dataset_repo="org/dataset",
|
| 1113 |
+
rows=refreshed_rows,
|
| 1114 |
+
selected_index=refreshed_index,
|
| 1115 |
+
cache_key=cache_key,
|
| 1116 |
+
save_status=status,
|
| 1117 |
+
)
|
| 1118 |
+
|
| 1119 |
+
assert status == VALIDATION_REJECT_CORRECTION_REQUIRED_STATUS
|
| 1120 |
+
assert validation_service.calls == []
|
| 1121 |
+
assert audio_service.cleaned == []
|
| 1122 |
+
assert cache_key == "cache:audio_11"
|
| 1123 |
+
assert refreshed_rows == rows
|
| 1124 |
+
assert refreshed_page == 1
|
| 1125 |
+
assert refreshed_index == 0
|
| 1126 |
+
assert pending_status == ""
|
| 1127 |
+
assert conflict_key == ""
|
| 1128 |
+
assert isinstance(audio_output, dict)
|
| 1129 |
+
assert advanced_index == 0
|
| 1130 |
+
assert isinstance(advanced_audio, dict)
|
| 1131 |
+
assert advanced_cache_key == "cache:audio_11"
|
| 1132 |
+
assert advanced_status == VALIDATION_REJECT_CORRECTION_REQUIRED_STATUS
|
| 1133 |
+
assert isinstance(spectrogram, dict)
|
| 1134 |
+
assert isinstance(title, dict)
|
| 1135 |
+
|
| 1136 |
+
|
| 1137 |
+
def test_reject_validation_saves_corrected_species_when_provided() -> None:
|
| 1138 |
+
audio_service = FakeAudioService()
|
| 1139 |
+
validation_service = FakeValidationService()
|
| 1140 |
+
rows = [["dkey_01", "audio_11", "sp", 0.9, 0.0, 1.0, "pending", 0]]
|
| 1141 |
+
|
| 1142 |
+
status, cache_key, _, _, _, _, _, _ = _save_selected_validation_with_refresh(
|
| 1143 |
+
validation_service=validation_service,
|
| 1144 |
+
audio_service=audio_service,
|
| 1145 |
+
queue_service=FakeQueueService(),
|
| 1146 |
+
snapshot_reader=FakeSnapshotReader(),
|
| 1147 |
+
project_slug="demo-project",
|
| 1148 |
+
rows=rows,
|
| 1149 |
+
selected_index=0,
|
| 1150 |
+
status_value="negative",
|
| 1151 |
+
validator="validator-demo",
|
| 1152 |
+
notes="wrong species",
|
| 1153 |
+
cache_key="cache:audio_11",
|
| 1154 |
+
page=1,
|
| 1155 |
+
scientific_name="sp",
|
| 1156 |
+
min_confidence=0.0,
|
| 1157 |
+
validator_filter="",
|
| 1158 |
+
status_filter="all",
|
| 1159 |
+
updated_after="",
|
| 1160 |
+
show_conflicts_only=False,
|
| 1161 |
+
corrected_species="Correct Species",
|
| 1162 |
+
)
|
| 1163 |
+
|
| 1164 |
+
assert "Validation saved" in status
|
| 1165 |
+
assert cache_key == ""
|
| 1166 |
+
assert validation_service.calls[0]["status"] == "negative"
|
| 1167 |
+
assert validation_service.calls[0]["corrected_species"] == "Correct Species"
|
| 1168 |
+
|
| 1169 |
+
|
| 1170 |
def test_save_selected_validation_advances_to_highest_confidence_pending_row() -> None:
|
| 1171 |
class QueueAfterSave:
|
| 1172 |
def list_all_detections(self, **kwargs: object) -> list[object]:
|