@@ -116,14 +116,15 @@ def test_explicit_fake_and_saas_opt_in(self):
116116 self .assertEqual (C .Backend (d , "saas" , 4242 ).workspace_id , 4242 )
117117
118118 def test_publish_replace_requires_workspace_id_and_honors_precedence (self ):
119- cases = [(None , None , None ), ("4242" , None , 4242 ), (None , "5252" , 5252 ),
120- ("4242" , "5252" , 5252 ), ("invalid" , "5252" , 5252 )]
121- for env_id , cli_id , expected in cases :
122- with self .subTest (env_id = env_id , cli_id = cli_id ), tempfile .TemporaryDirectory () as d , ExitStack () as stack :
119+ missing = object ()
120+ cases = [("saas" , None , None , missing ), ("fake" , None , None , None ), ("saas" , "4242" , None , 4242 ),
121+ ("saas" , None , "5252" , 5252 ), ("saas" , "4242" , "5252" , 5252 ), ("fake" , "invalid" , "5252" , 5252 )]
122+ for backend_mode , env_id , cli_id , expected in cases :
123+ with self .subTest (backend = backend_mode , env_id = env_id , cli_id = cli_id ), tempfile .TemporaryDirectory () as d , ExitStack () as stack :
123124 final = Path (d ) / "playbooks/final.md"
124125 final .parent .mkdir ()
125126 final .write_text ("approved lessons" )
126- argv = ["publish_replace.py" , d , "--backend" , "fake" ]
127+ argv = ["publish_replace.py" , d , "--backend" , backend_mode ]
127128 if cli_id is not None :
128129 argv += ["--workspace-id" , cli_id ]
129130 stack .enter_context (patch .object (sys , "argv" , argv ))
@@ -132,17 +133,17 @@ def test_publish_replace_requires_workspace_id_and_honors_precedence(self):
132133 backend = stack .enter_context (patch .object (C , "Backend" ))
133134 publish = stack .enter_context (patch .object (PR , "publish" ))
134135 error = stack .enter_context (patch .object (sys , "stderr" , new_callable = io .StringIO ))
135- if expected is None :
136+ if expected is missing :
136137 with self .assertRaises (SystemExit ) as caught :
137138 PR .main ()
138139 self .assertNotEqual (caught .exception .code , 0 )
139- self .assertIn ("provide --workspace-id or set WORKSPACE_ID" , error .getvalue ())
140+ self .assertIn ("--backend saas requires --workspace-id or WORKSPACE_ID" , error .getvalue ())
140141 approved .assert_not_called ()
141142 backend .assert_not_called ()
142143 publish .assert_not_called ()
143144 else :
144145 PR .main ()
145- backend .assert_called_once_with (d , "fake" , expected )
146+ backend .assert_called_once_with (d , backend_mode , expected )
146147 publish .assert_called_once ()
147148
148149 def events (self ):
@@ -259,6 +260,22 @@ def test_ablation_rejects_failed_reflection(self):
259260 A .main ()
260261 self .assertFalse ((Path (d ) / "playbook-nofeedback.md" ).exists ())
261262
263+ def test_ablation_rejects_cross_run_reuse_before_resetting_learning (self ):
264+ with tempfile .TemporaryDirectory () as d , tempfile .TemporaryDirectory () as other , ExitStack () as stack :
265+ candidate = Path (d ) / "work/maint-ablation/candidate.json"
266+ candidate .parent .mkdir (parents = True )
267+ candidate .write_text ("[]" )
268+ archived = Path (d ) / "learn-history-ablation/history/kept.json"
269+ archived .parent .mkdir (parents = True )
270+ archived .write_text ("{}" )
271+ stack .enter_context (patch .object (sys , "argv" , ["ablation.py" , "--run-dir" , d , "--from-loop" , other ]))
272+ for name in ("require_learn" , "require_dbt" ):
273+ stack .enter_context (patch .object (C , name ))
274+ with self .assertRaisesRegex (SystemExit , "--from-loop must be the run dir itself" ):
275+ A .main ()
276+ self .assertTrue (candidate .exists ())
277+ self .assertTrue (archived .exists ())
278+
262279 def test_ablation_retry_resets_learning_and_preserves_pass_accumulation (self ):
263280 with tempfile .TemporaryDirectory () as d , ExitStack () as stack :
264281 maint = Path (d ) / "work/maint-ablation"
0 commit comments