using Omika.Core.Observability.External; using Omika.Diagnostics.Import; namespace Omika.Diagnostics.Tests.Fakes; /// /// Source JSONL en mémoire : modèle un flux de /// avec un checkpoint (LineIndex = index du dernier enregistrement lu). Permet de /// tester l'importeur et son avancement de checkpoint sans PostgreSQL. /// public sealed class FakeDiagnosticJsonlSource : IDiagnosticJsonlSource { private readonly List _records; private DiagnosticImportCheckpoint? _checkpoint; public FakeDiagnosticJsonlSource(IReadOnlyList records) { _records = records.ToList(); } public int CommitCount { get; private set; } public DiagnosticImportCheckpoint? LastCommitted { get; private set; } public DiagnosticImportCheckpoint? LoadCheckpoint() => _checkpoint; public DiagnosticJsonlReadResult ReadNext(DiagnosticImportCheckpoint? after, int maxCount) { int start = after is null ? 0 : after.LineIndex + 1; if (start >= _records.Count) { return new DiagnosticJsonlReadResult { ReachedEnd = true }; } int count = Math.Min(maxCount, _records.Count - start); List records = _records.GetRange(start, count); var next = new DiagnosticImportCheckpoint { FileName = "fake.jsonl", LineIndex = start + count - 1 }; return new DiagnosticJsonlReadResult { Records = records, NextPosition = next, ReachedEnd = start + count >= _records.Count }; } public void Commit(DiagnosticImportCheckpoint position) { _checkpoint = position; LastCommitted = position; CommitCount++; } }