Stabilise the metadata sync workflow and add offline validation

Restructure the script embedded in the scoped sync workflow into testable
functions, fix the invalid `exit 0` (now a successful run with a visible
warning when Gitea returns an invalid push mirror list) and report errors as
`ERROR: <message>` with exit code 1. Zero, several or malformed GitHub mirrors
still fail.

Add pytest-based offline tests (workflow YAML, embedded Python, credential and
mirror parsing, sync flow against a fake API) that run in a virtual
environment, and a validation workflow that runs them on pull requests and
pushes to main. Remove the manual tests/test_.ps1 probe and the duplicate
src/ copy of the workflow. Update the README and record the decisions for
tasks 1 and 3 in MIL-001.

Task: MIL-001#1
Task: MIL-001#2
Task: MIL-001#3
Task: MIL-001#4
Task: MIL-001#5
Task: MIL-001#6
Refs #1
Refs #2
Refs #3
Refs #4
Refs #5
Refs #6

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-03 20:45:57 +08:00
co-authored by Claude Sonnet 5.5
parent 72d2671978
commit cbb9688ed4
10 changed files with 554 additions and 220 deletions
+14 -3
View File
@@ -43,7 +43,18 @@ Workflows run automatically on push to `main` and on the daily schedule. To run
## 🧪 Tests
There are no automated tests yet (planned in MIL-001). `tests/test_.ps1` is a manual probe, not a test. Verify changes by running the workflow manually and checking the description and topics on the GitHub mirror.
The workflow files and the Python embedded in them are validated by offline tests that need no network access and no secrets:
```bash
python3 -m venv .venv
source .venv/bin/activate # Windows PowerShell: .venv\Scripts\Activate.ps1
python -m pip install -r tests/requirements.txt
python -m pytest -q tests
```
The same checks run on every pull request and push to `main` through [`validate-workflows.yml`](.gitea/workflows/validate-workflows.yml). They parse every workflow as YAML, compile the embedded Python, require explicit job permissions, and test credential parsing, push mirror address parsing and the sync flow against a fake API.
After a change to the sync workflow, also trigger **Sync GitHub mirror metadata** manually in Gitea and compare the description and topics on the GitHub mirror.
## 🟢 Capabilities
@@ -51,7 +62,7 @@ Only the first row is implemented. The rest is planned and tracked in the [Proje
| Capability | Status |
| --- | --- |
| Synchronize repository metadata (Gitea to GitHub mirror) | Implemented in `.gitea/scoped_workflows/`; the script there currently has a syntax error (`exit 0`) that MIL-001 fixes |
| Synchronize repository metadata (Gitea to GitHub mirror) | Implemented in `.gitea/scoped_workflows/`, with offline tests and a validation workflow |
| Configure and validate workflow credentials | Partial: secrets are checked for format only |
| Onboard a repository, manage runners, diagnose failures | Planned (MIL-002) |
| Shared quality checks | Planned (MIL-003) |
@@ -99,7 +110,7 @@ Workflow -> Gitea: GET /repos/{owner}/{repo}/push_mirrors
Gitea --> Workflow: Push mirror response
alt mirrors is not a list
Workflow --> Trigger: Workflow fails\n"Gitea returned an invalid push mirror list."
Workflow --> Trigger: Log a warning and succeed\n(GitHub metadata not synced)
else mirrors is a list
Workflow -> Workflow: Find GitHub owner and repo from remote_address