package spindle import ( "log/slog" "testing" "github.com/bluesky-social/indigo/atproto/syntax" "tangled.org/core/api/org_tangled" "tangled.org/core/tapc" ) func TestBackfilledRecordsOfAServedRepoLeaveItsMarkToTheCatchUp(t *testing.T) { env := newEnsureEnv(t) env.serve("repo", testBob) env.ensure(t) b := newBackfill(env.s, slog.Default(), shortTempDir(t)) before := env.knot.count() manifest := markEvent(testRepoDid, env.spindleDid(), testOwner) collaborator := recordEvent(testRepoDid, org_tangled.GraphCollaboratorNSID, testBob.String(), tapc.RecordCreateAction, map[string]string{}) handleBackfilled(t, b, manifest, collaborator) requireMarked(t, env.s.db, testRepoDid, false, "a served repo's backfilled records marked it") if got := env.knot.count(); got != before { t.Fatalf("backfilled records cost %d knot requests", got-before) } handleBackfilled(t, b, declarationEvent(testOwner, testRepoDid, tapc.RecordCreateAction)) requireMarked(t, env.s.db, testRepoDid, false, "a served repo's backfilled declaration marked it") } func TestABackfilledDeclarationOfARepoNotServedYetStillMarksIt(t *testing.T) { env := newEnsureEnv(t) b := newBackfill(env.s, slog.Default(), shortTempDir(t)) handleBackfilled(t, b, declarationEvent(testOwner, testRepoDid, tapc.RecordCreateAction)) requireMarked(t, env.s.db, testRepoDid, true, "a new repo's backfilled declaration left no mark") } func TestABackfilledDeclarationThatNamesAnotherRepoStillMarksIt(t *testing.T) { env := newEnsureEnv(t) env.serve("repo", testBob) env.ensure(t) b := newBackfill(env.s, slog.Default(), shortTempDir(t)) other := syntax.DID("did:plc:otherrepo") handleBackfilled(t, b, declarationEvent(testOwner, other, tapc.RecordCreateAction)) requireMarked(t, env.s.db, other, true, "a backfilled declaration naming another repo left no mark") } func TestAServedRepoWhoseBackfillFailedIsMarkedAnyway(t *testing.T) { f := &fakeHydrant{} failOn(f, pendingRepo) b := catchUpBackfill(t, f) if err := b.CatchUp(); err != nil { t.Fatal(err) } runRound(t, b) requireMarked(t, b.s.db, pendingRepo, true, "the served repo wasn't marked after its backfill failed") if got := pendingDids(t, b); len(got) == 0 { t.Fatal("the failed repo left the pending list, it has to stay for the next round") } }