@@ -43,6 +43,19 @@ def ledger_paths(tmp_path, monkeypatch):
4343 monkeypatch .setattr (service , "_UPLOADED_DIR" , stage / "uploaded" )
4444 monkeypatch .setattr (service , "_PENDING_FILE" , stage / "pending.jsonl" )
4545 stage .mkdir (parents = True , exist_ok = True )
46+
47+ # Keep CI fully offline: model a verified private remote by default.
48+ class PrivateHubInfo :
49+ private = True
50+
51+ class FakeHfApi :
52+ def __init__ (self , * args , ** kwargs ):
53+ pass
54+
55+ def dataset_info (self , * args , ** kwargs ):
56+ return PrivateHubInfo ()
57+
58+ monkeypatch .setattr (service , "HfApi" , FakeHfApi , raising = False )
4659 return stage / "training_integrity_ledger.sqlite3"
4760
4861
@@ -457,3 +470,90 @@ def push_to_hub(self, **kwargs):
457470 service .flush_queue ()
458471
459472 assert any (item .get ("integrity_hash" ) == row ["integrity_hash" ] for item in pushed )
473+
474+
475+
476+ def test_private_visibility_is_verified_and_allowed (monkeypatch ):
477+ class Info :
478+ private = True
479+
480+ class Api :
481+ def __init__ (self , * args , ** kwargs ):
482+ pass
483+
484+ def dataset_info (self , * args , ** kwargs ):
485+ return Info ()
486+
487+ monkeypatch .setattr (service , "HfApi" , Api , raising = False )
488+ monkeypatch .setattr (service , "OMNI_HF_DATASET_PRIVATE" , True )
489+ assert service ._verify_remote_dataset_privacy () is True
490+
491+
492+ def test_public_remote_dataset_is_blocked_when_privacy_is_required (monkeypatch ):
493+ class Info :
494+ private = False
495+
496+ class Api :
497+ def __init__ (self , * args , ** kwargs ):
498+ pass
499+
500+ def dataset_info (self , * args , ** kwargs ):
501+ return Info ()
502+
503+ monkeypatch .setattr (service , "HfApi" , Api , raising = False )
504+ monkeypatch .setattr (service , "OMNI_HF_DATASET_PRIVATE" , True )
505+ monkeypatch .setattr (service , "_dataset_private_env" , None )
506+ with pytest .raises (RuntimeError , match = "private dataset required but remote dataset is public" ):
507+ service ._verify_remote_dataset_privacy ()
508+
509+
510+ def test_public_visibility_requires_explicit_opt_in_and_metadata_only (monkeypatch ):
511+ class Info :
512+ private = False
513+
514+ class Api :
515+ def __init__ (self , * args , ** kwargs ):
516+ pass
517+
518+ def dataset_info (self , * args , ** kwargs ):
519+ return Info ()
520+
521+ monkeypatch .setattr (service , "HfApi" , Api , raising = False )
522+ monkeypatch .setattr (service , "_dataset_private_env" , "false" )
523+ monkeypatch .setattr (service , "OMNI_HF_DATASET_PRIVATE" , False )
524+ monkeypatch .setattr (service , "OMNI_HF_EXPORT_RAW_TEXT" , False )
525+ assert service ._verify_remote_dataset_privacy () is False
526+
527+ monkeypatch .setattr (service , "OMNI_HF_EXPORT_RAW_TEXT" , True )
528+ with pytest .raises (RuntimeError , match = "incompatible with" ):
529+ service ._verify_remote_dataset_privacy ()
530+
531+
532+ def test_privacy_verification_failure_fails_closed (monkeypatch ):
533+ class Api :
534+ def __init__ (self , * args , ** kwargs ):
535+ pass
536+
537+ def dataset_info (self , * args , ** kwargs ):
538+ raise ConnectionError ("visibility endpoint unavailable" )
539+
540+ monkeypatch .setattr (service , "HfApi" , Api , raising = False )
541+ monkeypatch .setattr (service , "OMNI_HF_DATASET_PRIVATE" , True )
542+ with pytest .raises (RuntimeError , match = "privacy could not be verified" ):
543+ service ._verify_remote_dataset_privacy ()
544+
545+
546+ def test_unknown_visibility_fails_closed (monkeypatch ):
547+ class Info :
548+ private = None
549+
550+ class Api :
551+ def __init__ (self , * args , ** kwargs ):
552+ pass
553+
554+ def dataset_info (self , * args , ** kwargs ):
555+ return Info ()
556+
557+ monkeypatch .setattr (service , "HfApi" , Api , raising = False )
558+ with pytest .raises (RuntimeError , match = "privacy is unknown" ):
559+ service ._verify_remote_dataset_privacy ()
0 commit comments