fix(cv-import): bound source retention and guard worker recovery
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user