|
|
|
@@ -13,6 +13,7 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"knowledge-governance/internal/governance"
|
|
|
|
|
"knowledge-governance/internal/jobs"
|
|
|
|
|
"knowledge-governance/internal/platform/weknora"
|
|
|
|
|
"knowledge-governance/internal/readiness"
|
|
|
|
|
"knowledge-governance/internal/weknoraaccess"
|
|
|
|
@@ -60,6 +61,7 @@ type fakeReconciliationStore struct {
|
|
|
|
|
removeHit bool
|
|
|
|
|
requeueDoc string
|
|
|
|
|
orphan bool
|
|
|
|
|
enqueued []jobs.EnqueueRequest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *fakeReconciliationStore) ReapStaleReconciliationRuns(context.Context, time.Time, time.Duration) (int64, error) {
|
|
|
|
@@ -133,6 +135,11 @@ func (f *fakeReconciliationStore) MarkReconciliationOrphanRemoved(context.Contex
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *fakeReconciliationStore) Enqueue(_ context.Context, request jobs.EnqueueRequest, _ time.Time) (*jobs.Job, error) {
|
|
|
|
|
f.enqueued = append(f.enqueued, request)
|
|
|
|
|
return &jobs.Job{ID: request.ID}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type fakeReconciliationRemote struct {
|
|
|
|
|
items []weknora.Knowledge
|
|
|
|
|
missing map[string]bool
|
|
|
|
@@ -538,3 +545,38 @@ func TestExecuteRunR6UsesRemovalCandidatesViewOnly(t *testing.T) {
|
|
|
|
|
t.Fatalf("run counts R6 = %#v", store.completedRun)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestCreateRunEnqueuesJobWithinJobIDLimit freezes the queue contract: jobs.id is
|
|
|
|
|
// VARCHAR(36), and the run id ("rec-" + 32 hex) already fills it. Deriving the job
|
|
|
|
|
// id from the run id overflowed the column, so every batch was created `failed`
|
|
|
|
|
// with queue_unavailable before a worker ever saw it.
|
|
|
|
|
func TestCreateRunEnqueuesJobWithinJobIDLimit(t *testing.T) {
|
|
|
|
|
now := time.Date(2026, 12, 1, 12, 0, 0, 0, time.UTC)
|
|
|
|
|
store := &fakeReconciliationStore{
|
|
|
|
|
run: governance.ReconciliationRun{ID: "rec-unused", KBID: "kb-1", State: "running", Trigger: "manual", StartedAt: now},
|
|
|
|
|
}
|
|
|
|
|
service, err := New(Config{Store: store, Queue: store, Remote: &fakeReconciliationRemote{},
|
|
|
|
|
Now: func() time.Time { return now }, Grace: 30 * time.Minute, StallAfter: 2 * time.Hour,
|
|
|
|
|
StaleAfter: 6 * time.Hour, ConfirmConcurrency: 1, KeepRuns: 30, MaxAge: 90 * 24 * time.Hour,
|
|
|
|
|
WeKnoraWebBase: func(context.Context) string { return "https://test.example/" }})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
run, err := service.CreateRun(context.Background(), "kb-1", "manual")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("CreateRun error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if len(store.enqueued) != 1 {
|
|
|
|
|
t.Fatalf("enqueued %d jobs", len(store.enqueued))
|
|
|
|
|
}
|
|
|
|
|
request := store.enqueued[0]
|
|
|
|
|
if len(request.ID) != 36 {
|
|
|
|
|
t.Fatalf("job id %q length = %d, want exactly 36 (VARCHAR(36))", request.ID, len(request.ID))
|
|
|
|
|
}
|
|
|
|
|
if request.Type != "reconciliation.run" || request.IdempotencyKey != "reconciliation-run:"+run.ID {
|
|
|
|
|
t.Fatalf("enqueue request = %#v", request)
|
|
|
|
|
}
|
|
|
|
|
if string(request.Payload) != `{"run_id":"`+run.ID+`"}` {
|
|
|
|
|
t.Fatalf("payload = %s", request.Payload)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|