@@ -680,3 +680,49 @@ def test_get_program_name_extracted(self):
680680 def test_read_program_state_extracted (self ):
681681 # read_program_state exists in the workflow but depends on file I/O
682682 assert "read_program_state" in _funcs
683+
684+
685+ # ---------------------------------------------------------------------------
686+ # Workflow step ordering — repo-memory must be available before scheduling
687+ # ---------------------------------------------------------------------------
688+
689+ class TestWorkflowStepOrdering :
690+ """Verify that the repo-memory clone step appears before the scheduling step.
691+
692+ The scheduling pre-step reads persisted state from repo-memory. If the
693+ clone happens after scheduling, the script cannot see previous-run state,
694+ causing incorrect selection/skip behaviour.
695+ """
696+
697+ CLONE_STEP = "Clone repo-memory for scheduling"
698+ SCHED_STEP = "Check which programs are due"
699+
700+ def _load_steps (self ):
701+ """Return the list of pre-step names from workflows/autoloop.md."""
702+ import os
703+ import re
704+
705+ wf_path = os .path .join (os .path .dirname (__file__ ), ".." , "workflows" , "autoloop.md" )
706+ with open (wf_path ) as f :
707+ content = f .read ()
708+ step_names = []
709+ for m in re .finditer (r'^\s*-\s*name:\s*(.+)$' , content , re .MULTILINE ):
710+ step_names .append (m .group (1 ).strip ())
711+ return step_names
712+
713+ def test_clone_step_exists (self ):
714+ """A step that clones repo-memory for scheduling must exist."""
715+ steps = self ._load_steps ()
716+ assert self .CLONE_STEP in steps , (
717+ f"Expected step '{ self .CLONE_STEP } ' not found. Steps: { steps } "
718+ )
719+
720+ def test_clone_before_scheduling (self ):
721+ """The repo-memory clone step must come before 'Check which programs are due'."""
722+ steps = self ._load_steps ()
723+ clone_idx = steps .index (self .CLONE_STEP )
724+ sched_idx = steps .index (self .SCHED_STEP )
725+ assert clone_idx < sched_idx , (
726+ f"'{ self .CLONE_STEP } ' (index { clone_idx } ) must come before "
727+ f"'{ self .SCHED_STEP } ' (index { sched_idx } ). Steps: { steps } "
728+ )
0 commit comments