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>
101 lines
2.3 KiB
Go
101 lines
2.3 KiB
Go
package jobs
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestStore_CreateGetUpdate(t *testing.T) {
|
|
store, err := NewStore("")
|
|
if err != nil {
|
|
t.Fatalf("NewStore: %v", err)
|
|
}
|
|
job := Job{ID: "abc", Status: StatusQueued, RepoOwner: "o", RepoName: "r", CreatedAt: time.Now().UTC()}
|
|
if err := store.Create(job); err != nil {
|
|
t.Fatalf("Create: %v", err)
|
|
}
|
|
|
|
got, ok := store.Get("abc")
|
|
if !ok {
|
|
t.Fatal("Get: not found")
|
|
}
|
|
if got.Status != StatusQueued {
|
|
t.Fatalf("Status = %q, want queued", got.Status)
|
|
}
|
|
|
|
if err := store.Update("abc", func(j *Job) { j.Status = StatusDone }); err != nil {
|
|
t.Fatalf("Update: %v", err)
|
|
}
|
|
got, _ = store.Get("abc")
|
|
if got.Status != StatusDone {
|
|
t.Fatalf("Status after update = %q, want done", got.Status)
|
|
}
|
|
|
|
if err := store.Update("missing", func(j *Job) {}); err == nil {
|
|
t.Fatal("Update on a missing job should error")
|
|
}
|
|
|
|
if _, ok := store.Get("missing"); ok {
|
|
t.Fatal("Get on a missing job should report not-found")
|
|
}
|
|
}
|
|
|
|
func TestStore_PersistenceSurvivesReload(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "jobs.json")
|
|
|
|
store, err := NewStore(path)
|
|
if err != nil {
|
|
t.Fatalf("NewStore: %v", err)
|
|
}
|
|
job := Job{ID: "xyz", Status: StatusCloning, RepoOwner: "o", RepoName: "r", CreatedAt: time.Now().UTC()}
|
|
if err := store.Create(job); err != nil {
|
|
t.Fatalf("Create: %v", err)
|
|
}
|
|
|
|
reloaded, err := NewStore(path)
|
|
if err != nil {
|
|
t.Fatalf("NewStore (reload): %v", err)
|
|
}
|
|
got, ok := reloaded.Get("xyz")
|
|
if !ok {
|
|
t.Fatal("job did not survive reload")
|
|
}
|
|
if got.Status != StatusCloning {
|
|
t.Fatalf("Status after reload = %q, want cloning", got.Status)
|
|
}
|
|
}
|
|
|
|
func TestNewID_Unique(t *testing.T) {
|
|
a, err := NewID()
|
|
if err != nil {
|
|
t.Fatalf("NewID: %v", err)
|
|
}
|
|
b, err := NewID()
|
|
if err != nil {
|
|
t.Fatalf("NewID: %v", err)
|
|
}
|
|
if a == b {
|
|
t.Fatal("NewID produced the same id twice")
|
|
}
|
|
if a == "" {
|
|
t.Fatal("NewID produced an empty id")
|
|
}
|
|
}
|
|
|
|
func TestStatusTerminal(t *testing.T) {
|
|
for status, want := range map[Status]bool{
|
|
StatusQueued: false,
|
|
StatusCreatingRepo: false,
|
|
StatusCloning: false,
|
|
StatusPushing: false,
|
|
StatusDone: true,
|
|
StatusFailed: true,
|
|
} {
|
|
if got := status.Terminal(); got != want {
|
|
t.Errorf("Status(%q).Terminal() = %v, want %v", status, got, want)
|
|
}
|
|
}
|
|
}
|