POST /api/v1/repos/migrate against rithub.dev runs the clone synchronously
before answering, so a caller behind Cloudflare's edge (apps/rithub-mcp's
import_from_github tool, the rit CLI, github-backup-cli) times out on big
repos well before the clone finishes. Adds apps/rithub-async-import: a Go
sidecar that forwards the request byte-for-byte to the real engine unless
the caller opts into a new `async: true` field, in which case it creates
the destination repo empty ("[migrating] " marker), answers 202 with a
status_url immediately, then runs `git clone --mirror` + `git push --mirror`
in the background and clears the marker on success. async:true rejects
mirror:true and any issues/pull_requests/wiki/releases/milestones/labels
flag with a clear 400 (git push --mirror carries code only, not GitHub
metadata) rather than silently dropping them.
go build/vet/gofmt clean; go test ./... -race passes (request validation,
sync-passthrough proxy, async happy path, every rejection, Runner clone/
push/failure orchestration via a fake gitOps). Also hand-verified with the
real compiled binary + real `git` against a throwaway local fake-Gitea
stand-in (no railyard-box engine reachable from this sandbox): immediate
202, destination repo byte-identical to source after polling to done, bad
clone_addr fails cleanly with a sanitized error, sync passthrough relays
upstream's response verbatim.
Not deployed (out of scope for this pass) — README has the Caddy/pm2
wiring plan and the honest scope limits (no engine source fork; metadata
import still needs the sync endpoint).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package migrate
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRequestValidate(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
req Request
|
|
wantErr string // substring, "" means no error expected
|
|
}{
|
|
{
|
|
name: "minimal valid",
|
|
req: Request{CloneAddr: "https://github.com/octocat/Hello-World.git", RepoName: "hello"},
|
|
},
|
|
{
|
|
name: "missing clone_addr",
|
|
req: Request{RepoName: "hello"},
|
|
wantErr: "clone_addr",
|
|
},
|
|
{
|
|
name: "missing repo_name",
|
|
req: Request{CloneAddr: "https://github.com/octocat/Hello-World.git"},
|
|
wantErr: "repo_name",
|
|
},
|
|
{
|
|
name: "mirror rejected",
|
|
req: Request{CloneAddr: "https://github.com/octocat/Hello-World.git", RepoName: "hello", Mirror: true},
|
|
wantErr: "mirror",
|
|
},
|
|
{
|
|
name: "issues metadata rejected",
|
|
req: Request{CloneAddr: "https://github.com/octocat/Hello-World.git", RepoName: "hello", Issues: true},
|
|
wantErr: "wiki/issues",
|
|
},
|
|
{
|
|
name: "wiki metadata rejected",
|
|
req: Request{CloneAddr: "https://github.com/octocat/Hello-World.git", RepoName: "hello", Wiki: true},
|
|
wantErr: "wiki/issues",
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := tc.req.validate()
|
|
if tc.wantErr == "" {
|
|
if err != nil {
|
|
t.Fatalf("validate() = %v, want nil", err)
|
|
}
|
|
return
|
|
}
|
|
if err == nil {
|
|
t.Fatalf("validate() = nil, want error containing %q", tc.wantErr)
|
|
}
|
|
if !strings.Contains(err.Error(), tc.wantErr) {
|
|
t.Fatalf("validate() = %q, want it to contain %q", err.Error(), tc.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|