@@ -849,5 +849,79 @@ def test_prog_name_resolution(self) -> None:
849849 sys .argv = orig
850850
851851
852+ class PublishOnAccept (unittest .TestCase ):
853+ """Accept → publish by default + publish visibility (issue #97)."""
854+
855+ def setUp (self ) -> None :
856+ self .tmp = Path (tempfile .mkdtemp ())
857+ self .cfg = _stub_config (self .tmp )
858+
859+ def tearDown (self ) -> None :
860+ shutil .rmtree (self .tmp , ignore_errors = True )
861+
862+ def _accepted_ready (self , iid : str ) -> Path :
863+ d = self .cfg .bundle (iid )
864+ leaves .do_plan (d , self .cfg )
865+ driver .run_issue (d , self .cfg ) # → AWAITING_SIGNOFF (§6 open from the stub reviewer)
866+ summ = d / "SUMMARY.md"
867+ summ .write_text (summ .read_text ().replace ("- [ ]" , "- [x]" ), encoding = "utf-8" ) # clear §6
868+ return d
869+
870+ def _accept_args (self , iid : str , no_publish : bool = False ) -> SimpleNamespace :
871+ return SimpleNamespace (issue_id = iid , accept = True , iterate_do = False ,
872+ iterate_plan = False , discontinue = False , by = "" , delta = "" ,
873+ no_publish = no_publish )
874+
875+ def test_accept_publishes_by_default (self ) -> None :
876+ from pdca_harness import publish
877+ calls , orig = [], publish .publish
878+ publish .publish = lambda cfg , iid , ** kw : calls .append (iid ) or 0
879+ try :
880+ self ._accepted_ready ("ACC" )
881+ self .assertEqual (cli ._signoff (self .cfg , self ._accept_args ("ACC" )), 0 )
882+ finally :
883+ publish .publish = orig
884+ self .assertEqual (calls , ["ACC" ]) # standalone accept publishes (#97)
885+
886+ def test_no_publish_opts_out (self ) -> None :
887+ from pdca_harness import publish
888+ calls , orig = [], publish .publish
889+ publish .publish = lambda cfg , iid , ** kw : calls .append (iid ) or 0
890+ try :
891+ self ._accepted_ready ("NOP" )
892+ cli ._signoff (self .cfg , self ._accept_args ("NOP" , no_publish = True ))
893+ finally :
894+ publish .publish = orig
895+ self .assertEqual (calls , []) # --no-publish ⇒ deliberately unpublished
896+
897+ def test_accept_publish_failure_is_loud (self ) -> None :
898+ import io
899+ from contextlib import redirect_stderr
900+ from pdca_harness import publish
901+ orig = publish .publish
902+ publish .publish = lambda cfg , iid , ** kw : 1 # publish fails
903+ try :
904+ self ._accepted_ready ("FAILP" )
905+ buf = io .StringIO ()
906+ with redirect_stderr (buf ):
907+ rc = cli ._signoff (self .cfg , self ._accept_args ("FAILP" ))
908+ finally :
909+ publish .publish = orig
910+ self .assertEqual (rc , 1 ) # failure surfaced as the return
911+ self .assertIn ("NOT" , buf .getvalue ()) # and printed loudly
912+
913+ def test_status_publish_flag (self ) -> None :
914+ d = self .cfg .bundle ("ST" )
915+ d .mkdir (parents = True )
916+ (d / "patch.diff" ).write_text ("diff --git a/x b/x\n " , encoding = "utf-8" )
917+ self .assertEqual (cli ._publish_flag (d ), " [unpublished]" ) # no publish.json
918+ (d / "publish.json" ).write_text ('{"pr_url": "https://x/pr/1"}' , encoding = "utf-8" )
919+ self .assertEqual (cli ._publish_flag (d ), " [PR https://x/pr/1]" )
920+ d2 = self .cfg .bundle ("ST2" )
921+ d2 .mkdir (parents = True )
922+ (d2 / "patch.diff" ).write_text ("" , encoding = "utf-8" ) # close/no-fix → no PR expected
923+ self .assertEqual (cli ._publish_flag (d2 ), " [close: no PR]" )
924+
925+
852926if __name__ == "__main__" :
853927 unittest .main ()
0 commit comments