@@ -16,11 +16,6 @@ const STATE_FILE: &str = "ref-maintenance.json";
1616const LOCK_FILE : & str = "mutation-cursor.lock" ;
1717const RECONCILIATION_DETAIL_PREFIX : & str = "Snapshot ref reconciliation" ;
1818
19- const AUTH_DB_TEST_SECRET : & str = "doctor-cli-test-secret" ;
20- const UNREADABLE_AUTH_DB : & [ u8 ] = b"not an encrypted auth database" ;
21-
22- const TELEMETRY_ENABLED_CONFIG : & str = r#"{"telemetry":{"enabled":true}}"# ;
23- const TELEMETRY_OPT_IN_NOTE : & str = "Managed telemetry export is off because telemetry.enabled is not true; set telemetry.enabled: true in the global SCE config to resume it." ;
2419const EXIT_SUCCESS : & str = "success" ;
2520const EXIT_FAILURE : & str = "failure" ;
2621
@@ -143,12 +138,6 @@ impl Sandbox {
143138 . expect ( "state JSON" )
144139 }
145140
146- fn telemetry_enabled_config ( & self ) -> String {
147- let path = self . dir . path ( ) . join ( "telemetry-enabled.json" ) ;
148- std:: fs:: write ( & path, TELEMETRY_ENABLED_CONFIG ) . expect ( "telemetry config" ) ;
149- path. to_string_lossy ( ) . into_owned ( )
150- }
151-
152141 fn run ( & self , args : & [ & str ] ) -> CliRun {
153142 self . run_with_env ( args, & [ ] )
154143 }
@@ -612,180 +601,3 @@ async fn doctor_fix_recovers_from_every_initial_maintenance_state_condition() {
612601 ) ;
613602 }
614603}
615-
616- fn global_state_warnings ( report : & Value ) -> Vec < Value > {
617- report[ "problems" ]
618- . as_array ( )
619- . expect ( "problems array" )
620- . iter ( )
621- . filter ( |problem| problem[ "category" ] == "global_state" && problem[ "severity" ] == "warning" )
622- . cloned ( )
623- . collect ( )
624- }
625-
626- #[ tokio:: test( flavor = "multi_thread" ) ]
627- async fn doctor_on_fresh_state_reports_unconfigured_telemetry_without_a_warning ( ) {
628- let sandbox = Sandbox :: new ( "https://example.invalid/org/repo-a.git" ) ;
629- let auth_dir = sandbox. state_root ( ) . join ( "sce" ) ;
630- let config = sandbox. telemetry_enabled_config ( ) ;
631-
632- let report = sandbox
633- . run_with_env (
634- & [ "doctor" , "--format" , "json" ] ,
635- & [
636- ( AUTH_DB_ENCRYPTION_KEY_ENV , "" ) ,
637- ( "SCE_CONFIG_FILE" , config. as_str ( ) ) ,
638- ] ,
639- )
640- . json ( ) ;
641-
642- assert_eq ! ( report[ "managed_telemetry" ] [ "state" ] , "not_configured" ) ;
643- let warnings = global_state_warnings ( & report) ;
644- assert ! ( warnings. is_empty( ) , "{warnings:#?}" ) ;
645- assert ! ( !auth_dir. join( "auth.db" ) . exists( ) ) ;
646- }
647-
648- #[ tokio:: test( flavor = "multi_thread" ) ]
649- async fn doctor_fix_reports_unreadable_telemetry_credentials_without_auth_side_effects ( ) {
650- let sandbox = Sandbox :: new ( "https://example.invalid/org/repo-a.git" ) ;
651- let auth_dir = sandbox. state_root ( ) . join ( "sce" ) ;
652- std:: fs:: create_dir_all ( & auth_dir) . expect ( "auth dir" ) ;
653- let auth_db = auth_dir. join ( "auth.db" ) ;
654- std:: fs:: write ( & auth_db, UNREADABLE_AUTH_DB ) . expect ( "auth DB" ) ;
655- let config = sandbox. telemetry_enabled_config ( ) ;
656- let env = [
657- ( AUTH_DB_ENCRYPTION_KEY_ENV , AUTH_DB_TEST_SECRET ) ,
658- ( "SCE_CONFIG_FILE" , config. as_str ( ) ) ,
659- ] ;
660-
661- let fix = sandbox. run_with_env ( & [ "doctor" , "--fix" , "--format" , "json" ] , & env) ;
662- let report = fix. json ( ) ;
663-
664- assert_eq ! (
665- report[ "managed_telemetry" ] ,
666- serde_json:: json!( {
667- "state" : "disabled" ,
668- "reason" : "database_error" ,
669- "kind" : "managed_telemetry_database_error" ,
670- "severity" : "warning" ,
671- "next_action" : "manual_steps" ,
672- } ) ,
673- "{}" ,
674- fix. stdout
675- ) ;
676- let warnings = global_state_warnings ( & report) ;
677- assert_eq ! ( warnings. len( ) , 1 , "{}" , fix. stdout) ;
678- assert_eq ! ( warnings[ 0 ] [ "fixability" ] , "manual_only" ) ;
679- assert_eq ! ( warnings[ 0 ] [ "remediation" ] [ "next_action" ] , "manual_steps" ) ;
680- let summary = warnings[ 0 ] [ "summary" ] . as_str ( ) . expect ( "summary" ) ;
681- let fixes = report[ "fix_results" ]
682- . as_array ( )
683- . expect ( "fix_results array" )
684- . iter ( )
685- . filter ( |entry| {
686- entry[ "category" ] == "global_state"
687- && entry[ "detail" ]
688- . as_str ( )
689- . is_some_and ( |detail| detail. starts_with ( summary) )
690- } )
691- . collect :: < Vec < _ > > ( ) ;
692- assert_eq ! ( fixes. len( ) , 1 , "{}" , fix. stdout) ;
693- assert_eq ! ( fixes[ 0 ] [ "outcome" ] , "manual" ) ;
694- assert_eq ! (
695- std:: fs:: read( & auth_db) . expect( "auth DB kept" ) ,
696- UNREADABLE_AUTH_DB
697- ) ;
698- assert ! ( !fix. stdout. contains( AUTH_DB_TEST_SECRET ) ) ;
699- assert ! ( !fix. stderr. contains( AUTH_DB_TEST_SECRET ) ) ;
700- }
701-
702- #[ tokio:: test( flavor = "multi_thread" ) ]
703- async fn doctor_reports_post_commit_auto_sync_disabled_when_auth_is_disabled ( ) {
704- let sandbox = Sandbox :: new ( "https://example.invalid/org/repo-a.git" ) ;
705- let config_dir = sandbox. repo . join ( ".sce" ) ;
706- std:: fs:: create_dir_all ( & config_dir) . expect ( "config dir" ) ;
707- let config = config_dir. join ( "config.json" ) ;
708-
709- std:: fs:: write ( & config, r#"{"agent_trace":{"auto_sync":true}}"# ) . expect ( "config" ) ;
710- let allowed = sandbox. run ( & [ "doctor" , "--format" , "json" ] ) . json ( ) ;
711- assert_eq ! ( allowed[ "post_commit_auto_sync" ] [ "enabled" ] , true ) ;
712- assert_ne ! ( allowed[ "post_commit_auto_sync" ] [ "state" ] , "disabled" ) ;
713-
714- std:: fs:: write (
715- & config,
716- r#"{"agent_trace":{"auto_sync":true},"auth":{"mode":"disabled"}}"# ,
717- )
718- . expect ( "config" ) ;
719- let report = sandbox. run ( & [ "doctor" , "--format" , "json" ] ) . json ( ) ;
720- assert_eq ! (
721- report[ "post_commit_auto_sync" ] ,
722- serde_json:: json!( {
723- "state" : "disabled" ,
724- "enabled" : false ,
725- "source" : "config_file" ,
726- "config_source" : "default_discovered_local" ,
727- } )
728- ) ;
729- let text = sandbox. run ( & [ "doctor" ] ) ;
730- assert ! (
731- text. stdout
732- . contains( "[PASS] Post-commit Agent Trace auto-sync (disabled by config)\n " ) ,
733- "{}" ,
734- text. stdout
735- ) ;
736- }
737-
738- #[ tokio:: test( flavor = "multi_thread" ) ]
739- async fn doctor_with_telemetry_disabled_by_config_never_reads_the_auth_db ( ) {
740- let sandbox = Sandbox :: new ( "https://example.invalid/org/repo-a.git" ) ;
741- let auth_dir = sandbox. state_root ( ) . join ( "sce" ) ;
742- let env = [ ( AUTH_DB_ENCRYPTION_KEY_ENV , "" ) ] ;
743-
744- let fresh = sandbox. run_with_env ( & [ "doctor" ] , & env) ;
745- assert ! (
746- fresh
747- . stdout
748- . contains( "[PASS] Managed telemetry (disabled by config)\n " ) ,
749- "{}" ,
750- fresh. stdout
751- ) ;
752- assert ! (
753- !fresh. stdout. contains( TELEMETRY_OPT_IN_NOTE ) ,
754- "{}" ,
755- fresh. stdout
756- ) ;
757- assert ! ( !auth_dir. join( "auth.db" ) . exists( ) ) ;
758-
759- std:: fs:: create_dir_all ( & auth_dir) . expect ( "auth dir" ) ;
760- let auth_db = auth_dir. join ( "auth.db" ) ;
761- std:: fs:: write ( & auth_db, UNREADABLE_AUTH_DB ) . expect ( "auth DB" ) ;
762-
763- let report = sandbox
764- . run_with_env ( & [ "doctor" , "--format" , "json" ] , & env)
765- . json ( ) ;
766- assert_eq ! (
767- report[ "managed_telemetry" ] ,
768- serde_json:: json!( {
769- "state" : "disabled_by_config" ,
770- "reason" : "disabled_by_config" ,
771- "kind" : null,
772- "severity" : null,
773- "next_action" : null,
774- } )
775- ) ;
776- let warnings = global_state_warnings ( & report) ;
777- assert ! ( warnings. is_empty( ) , "{warnings:#?}" ) ;
778-
779- let text = sandbox. run_with_env ( & [ "doctor" ] , & env) ;
780- assert ! (
781- text. stdout. contains( & format!(
782- "[PASS] Managed telemetry (disabled by config)\n {TELEMETRY_OPT_IN_NOTE}\n "
783- ) ) ,
784- "{}" ,
785- text. stdout
786- ) ;
787- assert_eq ! (
788- std:: fs:: read( & auth_db) . expect( "auth DB kept" ) ,
789- UNREADABLE_AUTH_DB
790- ) ;
791- }
0 commit comments