@@ -197,6 +197,11 @@ def fake_read_file_bytes_local(path: str):
197197 container_fs ["/usr/share/sonic/systemd_scripts/container_checker" ] = b"default-checker"
198198 host_fs ["/bin/container_checker" ] = b"default-checker"
199199
200+ # Provide a default service_checker.py in both filesystems so the auto-appended
201+ # SyncItem from ensure_sync() is always satisfied and is a no-op.
202+ container_fs ["/usr/share/sonic/systemd_scripts/service_checker.py" ] = b"default-service-checker"
203+ host_fs ["/usr/local/lib/python3.11/dist-packages/health_checker/service_checker.py" ] = b"default-service-checker"
204+
200205 return ss , container_fs , host_fs , commands , config_db
201206
202207
@@ -466,6 +471,10 @@ def test_ensure_sync_uses_202411_checker(ss):
466471 container_fs ["/usr/share/sonic/systemd_scripts/container_checker_202411" ] = b"checker-202411"
467472 host_fs ["/bin/container_checker" ] = b"old-checker"
468473
474+ # Also provide 202411 service_checker so it doesn't fail
475+ container_fs ["/usr/share/sonic/systemd_scripts/service_checker.py_202411" ] = b"service-checker-202411"
476+ host_fs [ss_mod .HOST_SERVICE_CHECKER ] = b"service-checker-202411"
477+
469478 # Clear SYNC_ITEMS to focus only on the container_checker logic
470479 ss_mod .SYNC_ITEMS [:] = []
471480
@@ -507,3 +516,63 @@ def test_ensure_sync_202411_missing_checker_fails(ss):
507516
508517 ok = ss_mod .ensure_sync ()
509518 assert ok is False
519+
520+
521+ # ─────────── Tests for branch-conditional service_checker.py in ensure_sync ───────────
522+
523+ def test_ensure_sync_uses_202411_service_checker (ss ):
524+ """When branch is 202411, ensure_sync uses the branch-specific service_checker.py."""
525+ ss_mod , container_fs , host_fs , commands , config_db = ss
526+
527+ ss_mod ._get_branch_name = lambda : "202411"
528+
529+ # Provide the 202411-specific service_checker in the container and a different one on host
530+ container_fs ["/usr/share/sonic/systemd_scripts/service_checker.py_202411" ] = b"service-checker-202411"
531+ host_fs [ss_mod .HOST_SERVICE_CHECKER ] = b"old-service-checker"
532+
533+ # Also provide container_checker so it doesn't fail
534+ container_fs ["/usr/share/sonic/systemd_scripts/container_checker_202411" ] = b"checker-202411"
535+ host_fs ["/bin/container_checker" ] = b"checker-202411"
536+
537+ ss_mod .SYNC_ITEMS [:] = []
538+
539+ ok = ss_mod .ensure_sync ()
540+ assert ok is True
541+ assert host_fs [ss_mod .HOST_SERVICE_CHECKER ] == b"service-checker-202411"
542+
543+
544+ def test_ensure_sync_uses_default_service_checker (ss ):
545+ """When branch is not 202411, ensure_sync uses the default service_checker.py."""
546+ ss_mod , container_fs , host_fs , commands , config_db = ss
547+
548+ # _get_branch_name already returns "202412" from fixture default
549+
550+ # Provide the default service_checker in the container and a different one on host
551+ container_fs ["/usr/share/sonic/systemd_scripts/service_checker.py" ] = b"service-checker-default"
552+ host_fs [ss_mod .HOST_SERVICE_CHECKER ] = b"old-service-checker"
553+
554+ ss_mod .SYNC_ITEMS [:] = []
555+
556+ ok = ss_mod .ensure_sync ()
557+ assert ok is True
558+ assert host_fs [ss_mod .HOST_SERVICE_CHECKER ] == b"service-checker-default"
559+
560+
561+ def test_ensure_sync_202411_missing_service_checker_fails (ss ):
562+ """When branch is 202411 but the branch-specific service_checker is missing, sync fails."""
563+ ss_mod , container_fs , host_fs , commands , config_db = ss
564+
565+ ss_mod ._get_branch_name = lambda : "202411"
566+
567+ # Provide container_checker so only service_checker causes the failure
568+ container_fs ["/usr/share/sonic/systemd_scripts/container_checker_202411" ] = b"checker-202411"
569+ host_fs ["/bin/container_checker" ] = b"checker-202411"
570+
571+ # Remove service_checker sources
572+ container_fs .pop ("/usr/share/sonic/systemd_scripts/service_checker.py_202411" , None )
573+ container_fs .pop ("/usr/share/sonic/systemd_scripts/service_checker.py" , None )
574+
575+ ss_mod .SYNC_ITEMS [:] = []
576+
577+ ok = ss_mod .ensure_sync ()
578+ assert ok is False
0 commit comments