fix(cv-import): bound source retention and guard worker recovery

This commit is contained in:
cesnimda
2026-10-26 14:41:53 +01:00
parent e8f76a9dea
commit 9e1726c61d
14 changed files with 115 additions and 9 deletions
@@ -25,11 +25,19 @@ public class CvImportRetentionTests
await using var db = TestHostFactory.CreateInMemoryDb();
var file = Path.Combine(paths.CvArtifactsRoot, "synthetic.pdf");
await File.WriteAllTextAsync(file, "Synthetic source");
var orphanDirectory = Directory.CreateDirectory(Path.Combine(paths.CvArtifactsRoot, "user-1")).FullName;
var orphan = Path.Combine(orphanDirectory, "20260101010101-" + Guid.NewGuid().ToString("N") + ".pdf");
await File.WriteAllTextAsync(orphan, "Interrupted upload");
File.SetLastWriteTimeUtc(orphan, DateTime.UtcNow.AddDays(-8));
var unrelated = Path.Combine(orphanDirectory, "unrelated.pdf");
await File.WriteAllTextAsync(unrelated, "Preserve unrelated file");
var now = DateTimeOffset.UtcNow;
var run = new CvExtractionRun { OwnerUserId = "user-1", ParserVersion = "docling-v1", Trigger = "document_import", Status = status, StartedAtUtc = now.AddDays(-days), RawExtractedText = "Source", DocumentJson = "{}", StructuredProfileJson = "{}", Artifact = new() { OwnerUserId = "user-1", StoragePath = file } };
db.CvExtractionRuns.Add(run);
await db.SaveChangesAsync();
await CvImportRetentionHostedService.SweepAsync(db, paths, now, default);
Assert.False(File.Exists(orphan));
Assert.True(File.Exists(unrelated));
Assert.Equal(!expires, File.Exists(file));
Assert.Equal(expires, run.DocumentJson is null);
Assert.Equal(expires && status == "pending_review" ? "expired" : status, run.Status);