Skip to content

Commit 14dc2e2

Browse files
authored
Merge pull request #23 from githubnext/copilot/fix-repo-memory-scheduling
Clone repo-memory branch before scheduling pre-step
2 parents 4ea70b1 + d1dfa9a commit 14dc2e2

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

tests/test_scheduling.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
)

workflows/autoloop.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,28 @@ imports:
8181
- shared/reporting.md
8282

8383
steps:
84+
- name: Clone repo-memory for scheduling
85+
env:
86+
GH_TOKEN: ${{ github.token }}
87+
GITHUB_REPOSITORY: ${{ github.repository }}
88+
GITHUB_SERVER_URL: ${{ github.server_url }}
89+
run: |
90+
# Clone the repo-memory branch so the scheduling step can read persisted state
91+
# from previous runs. The framework-managed repo-memory clone happens after
92+
# pre-steps, so we perform an early shallow clone here.
93+
MEMORY_DIR="/tmp/gh-aw/repo-memory/autoloop"
94+
BRANCH="memory/autoloop"
95+
mkdir -p "$(dirname "$MEMORY_DIR")"
96+
REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
97+
AUTH_URL="$(echo "$REPO_URL" | sed "s|https://|https://x-access-token:${GH_TOKEN}@|")"
98+
if git ls-remote --exit-code --heads "$AUTH_URL" "$BRANCH" > /dev/null 2>&1; then
99+
git clone --single-branch --branch "$BRANCH" --depth 1 "$AUTH_URL" "$MEMORY_DIR" 2>&1
100+
echo "Cloned repo-memory branch to $MEMORY_DIR"
101+
else
102+
mkdir -p "$MEMORY_DIR"
103+
echo "No repo-memory branch found yet (first run). Created empty directory."
104+
fi
105+
84106
- name: Check which programs are due
85107
env:
86108
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)