81 lines
3.7 KiB
Python
81 lines
3.7 KiB
Python
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
LEGACY_SYNC_WORKFLOW = ROOT / ".gitea" / "workflows" / "sync-superpowers.yml"
|
|
AUTO_UPDATE_WORKFLOW = ROOT / ".gitea" / "workflows" / "update-thirdparty-superpowers.yml"
|
|
AUTO_UPDATE_SCRIPT = ROOT / ".gitea" / "ci" / "update_thirdparty_superpowers.sh"
|
|
SYNC_SCRIPT = ROOT / ".gitea" / "ci" / "sync_superpowers.sh"
|
|
|
|
|
|
class SuperpowersWorkflowTests(unittest.TestCase):
|
|
def test_legacy_sync_workflow_is_removed(self):
|
|
self.assertFalse(LEGACY_SYNC_WORKFLOW.exists())
|
|
|
|
def test_auto_update_workflow_name_describes_full_pipeline(self):
|
|
text = AUTO_UPDATE_WORKFLOW.read_text(encoding="utf-8")
|
|
self.assertIn("name: Update and Sync Superpowers", text)
|
|
|
|
def test_auto_update_workflow_triggers_on_main_push(self):
|
|
text = AUTO_UPDATE_WORKFLOW.read_text(encoding="utf-8")
|
|
self.assertIn("push:", text)
|
|
self.assertIn("- main", text)
|
|
self.assertIn("workflow_dispatch:", text)
|
|
|
|
def test_auto_update_workflow_runs_daily_schedule(self):
|
|
text = AUTO_UPDATE_WORKFLOW.read_text(encoding="utf-8")
|
|
self.assertIn("schedule:", text)
|
|
self.assertIn('- cron: "@daily"', text)
|
|
|
|
def test_auto_update_workflow_runs_update_script(self):
|
|
text = AUTO_UPDATE_WORKFLOW.read_text(encoding="utf-8")
|
|
self.assertIn("bash .gitea/ci/update_thirdparty_superpowers.sh", text)
|
|
|
|
def test_auto_update_workflow_runs_sync_after_update(self):
|
|
text = AUTO_UPDATE_WORKFLOW.read_text(encoding="utf-8")
|
|
self.assertIn("update:", text)
|
|
self.assertIn("sync:", text)
|
|
self.assertIn("needs: update", text)
|
|
self.assertIn("bash .gitea/ci/sync_superpowers.sh", text)
|
|
|
|
def test_auto_update_workflow_sync_job_clears_stale_index_flags(self):
|
|
text = AUTO_UPDATE_WORKFLOW.read_text(encoding="utf-8")
|
|
self.assertIn("git update-index --no-assume-unchanged", text)
|
|
self.assertIn("--no-skip-worktree", text)
|
|
|
|
def test_auto_update_workflow_sync_job_runs_from_latest_main(self):
|
|
text = AUTO_UPDATE_WORKFLOW.read_text(encoding="utf-8")
|
|
self.assertIn('TARGET_BRANCH: "main"', text)
|
|
self.assertIn('git fetch origin "$TARGET_BRANCH"', text)
|
|
self.assertIn('git checkout -B "$TARGET_BRANCH" "origin/$TARGET_BRANCH"', text)
|
|
|
|
def test_auto_update_workflow_sync_job_uses_literal_superpowers_paths(self):
|
|
text = AUTO_UPDATE_WORKFLOW.read_text(encoding="utf-8")
|
|
self.assertIn('SUPERPOWERS_DIR: "superpowers"', text)
|
|
self.assertIn('SUPERPOWERS_LIST: "codex/skills/.sources/superpowers.list"', text)
|
|
self.assertNotIn('SUPERPOWERS_DIR: "${{ env.SUPERPOWERS_DIR }}"', text)
|
|
self.assertNotIn('SUPERPOWERS_LIST: "${{ env.SUPERPOWERS_LIST }}"', text)
|
|
|
|
def test_auto_update_script_targets_thirdparty_branch(self):
|
|
text = AUTO_UPDATE_SCRIPT.read_text(encoding="utf-8")
|
|
self.assertIn('TARGET_BRANCH="${TARGET_BRANCH:-thirdparty/skill}"', text)
|
|
self.assertIn("api.github.com/repos", text)
|
|
self.assertIn("ls-remote", text)
|
|
self.assertIn('git checkout -B "$TARGET_BRANCH" "origin/$TARGET_BRANCH"', text)
|
|
|
|
def test_ci_scripts_use_ci_bot_identity(self):
|
|
sync_text = SYNC_SCRIPT.read_text(encoding="utf-8")
|
|
update_text = AUTO_UPDATE_SCRIPT.read_text(encoding="utf-8")
|
|
|
|
self.assertIn('COMMIT_AUTHOR_NAME="${COMMIT_AUTHOR_NAME:-ci[bot]}"', sync_text)
|
|
self.assertIn('COMMIT_AUTHOR_EMAIL="${COMMIT_AUTHOR_EMAIL:-ci-bot@local}"', sync_text)
|
|
self.assertIn('COMMIT_AUTHOR_NAME="${COMMIT_AUTHOR_NAME:-ci[bot]}"', update_text)
|
|
self.assertIn(
|
|
'COMMIT_AUTHOR_EMAIL="${COMMIT_AUTHOR_EMAIL:-ci-bot@local}"',
|
|
update_text,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|