@@ -60,6 +60,7 @@ def test_runtime_command_config_rejects_whitespace_only_command(self) -> None:
6060 self .assertFalse (has_runtime_command_config ({"aiCommand" : ["" , " " ]}, "" ))
6161 self .assertTrue (has_runtime_command_config ({"aiCommand" : [" claude " ]}, "" ))
6262 self .assertTrue (has_runtime_command_config ({"aiCommand" : " " }, 'agentConfig:\n defaultPrimary: "codex"\n ' ))
63+ self .assertFalse (has_runtime_command_config ({"aiCommand" : " " }, ' agentConfig:\n defaultPrimary: "codex"\n ' ))
6364 self .assertFalse (has_runtime_command_config ({"aiCommand" : " " }, "agentConfig:\n defaultPrimary:\n " ))
6465 self .assertFalse (has_runtime_command_config ({"aiCommand" : " " }, "agentConfig:\n complexityOverrides:\n - medium:\n " ))
6566
@@ -247,6 +248,31 @@ def test_state_update_still_allows_non_status_updates(self) -> None:
247248 self .assertEqual (payload , {"ok" : True , "updated" : ["aiCommand" ]})
248249 self .assertIn ("aiCommand: claude --resume" , state_file .read_text (encoding = "utf-8" ))
249250
251+ def test_state_update_only_rewrites_frontmatter (self ) -> None :
252+ state_file = self ._build_state_config (status = "COMPLETE" )
253+ text = state_file .read_text (encoding = "utf-8" ).replace ("currentStep: null\n " , "currentStep: step-old\n " , 1 )
254+ state_file .write_text (text + "\n status: body-marker\n currentStep: body-step\n " , encoding = "utf-8" )
255+
256+ code , payload = self ._state_update_args (state_file , ["--set" , "status=COMPLETE" , "--set" , "currentStep=step-next" ])
257+
258+ self .assertEqual (code , 0 )
259+ self .assertEqual (payload , {"ok" : True , "updated" : ["status" , "currentStep" ]})
260+ text = state_file .read_text (encoding = "utf-8" )
261+ frontmatter = text .split ("---" , 2 )[1 ]
262+ body = text .split ("---" , 2 )[2 ]
263+ self .assertIn ("status: COMPLETE" , frontmatter )
264+ self .assertIn ("currentStep: step-next" , frontmatter )
265+ self .assertIn ("status: body-marker" , body )
266+ self .assertIn ("currentStep: body-step" , body )
267+
268+ def test_state_update_strips_set_key_whitespace (self ) -> None :
269+ state_file = self ._build_state_config (status = "READY" )
270+
271+ code , payload = self ._state_update (state_file , " status=COMPLETE" )
272+
273+ self .assertEqual (code , 1 )
274+ self .assertEqual (payload ["error" ], "invalid_status_transition" )
275+
250276 def _validate_state (self , state_file : Path ) -> dict [str , object ]:
251277 stdout = io .StringIO ()
252278 with patch_env (self .project_root ), redirect_stdout (stdout ):
0 commit comments