test: let print workflows own their worktrees
Prepare / prepare (push) Successful in 11s
Test Multi Jobs / first (push) Successful in 0s
Test Multi Jobs / second (push) Successful in 0s

This commit is contained in:
csh
2026-07-20 09:37:00 +08:00
parent 94d2d5b042
commit 4d02a87806
4 changed files with 88 additions and 44 deletions
+12 -4
View File
@@ -21,12 +21,11 @@ class WorkflowPipelineTest(unittest.TestCase):
self.assertNotIn("/tmp/reused-repo", workflow)
self.assertNotIn("git clone", workflow)
def test_prepare_creates_persistent_print_worktrees(self) -> None:
def test_prepare_leaves_worktree_ownership_to_consumers(self) -> None:
workflow = self.read_workflow("prepare.yml")
self.assertIn('ensure_worktree "print1"', workflow)
self.assertIn('ensure_worktree "print2"', workflow)
self.assertIn('worktree add --detach "$worktree_dir" "$HEAD_SHA"', workflow)
self.assertNotIn("ensure_worktree", workflow)
self.assertNotIn("worktree add", workflow)
self.assertNotIn("worktree remove", workflow)
def assert_print_workflow(self, filename: str, role: str) -> None:
@@ -37,7 +36,16 @@ class WorkflowPipelineTest(unittest.TestCase):
self.assertIn(f'group: {role}-${{{{ github.repository }}}}', workflow)
self.assertIn('cancel-in-progress: false', workflow)
self.assertIn('HEAD_SHA="${{ github.event.workflow_run.head_sha }}"', workflow)
self.assertIn('REPOSITORY_DIR="${WORKSPACE_ROOT}/${REPO_NAME}/repository.git"', workflow)
self.assertIn(f'WORKTREE_DIR="${{WORKSPACE_ROOT}}/${{REPO_NAME}}/worktrees/{role}"', workflow)
self.assertIn('WORKTREE_LOCK="${WORKSPACE_ROOT}/${REPO_NAME}/worktree-admin.lock"', workflow)
self.assertGreaterEqual(workflow.count('if [ ! -f "$WORKTREE_DIR/.git" ]; then'), 2)
self.assertIn('exec 9>"$WORKTREE_LOCK"', workflow)
self.assertIn("flock 9", workflow)
self.assertIn(
'git --git-dir="$REPOSITORY_DIR" worktree add --detach "$WORKTREE_DIR" "$HEAD_SHA"',
workflow,
)
self.assertIn('git -C "$WORKTREE_DIR" checkout --detach --force "$HEAD_SHA"', workflow)
self.assertIn('git -C "$WORKTREE_DIR" reset --hard "$HEAD_SHA"', workflow)
self.assertIn('git -C "$WORKTREE_DIR" clean -ffdx', workflow)