diff --git a/src/Titano.Data/Postgres/PgConnector.cs b/src/Titano.Data/Postgres/PgConnector.cs index 59c5f38d..21c2bf52 100644 --- a/src/Titano.Data/Postgres/PgConnector.cs +++ b/src/Titano.Data/Postgres/PgConnector.cs @@ -427,21 +427,21 @@ internal sealed class PgConnector : IAsyncDisposable WritePassword(PgMd5.Response(_settings.Username, RequirePassword(), payload.Slice(4, 4))); return scram; case 10: - { - var mechanisms = new List(); - var pos = 4; - while (pos < payload.Length && payload[pos] != 0) mechanisms.Add(ReadCString(payload, ref pos)); - if (!mechanisms.Contains(ScramSha256.Mechanism)) - throw new NotSupportedException($"The server offers SASL mechanisms {string.Join(", ", mechanisms)}; only {ScramSha256.Mechanism} is supported."); - scram = new ScramSha256(RequirePassword()); - var first = scram.ClientFirstMessage(); - _write.StartMessage('p'); - _write.WriteCString(ScramSha256.Mechanism); - _write.WriteInt32(first.Length); - _write.Write(first); - _write.EndMessage(); - return scram; - } + { + var mechanisms = new List(); + var pos = 4; + while (pos < payload.Length && payload[pos] != 0) mechanisms.Add(ReadCString(payload, ref pos)); + if (!mechanisms.Contains(ScramSha256.Mechanism)) + throw new NotSupportedException($"The server offers SASL mechanisms {string.Join(", ", mechanisms)}; only {ScramSha256.Mechanism} is supported."); + scram = new ScramSha256(RequirePassword()); + var first = scram.ClientFirstMessage(); + _write.StartMessage('p'); + _write.WriteCString(ScramSha256.Mechanism); + _write.WriteInt32(first.Length); + _write.Write(first); + _write.EndMessage(); + return scram; + } case 11: var final = (scram ?? throw ProtocolViolation((byte)'R')).ClientFinalMessage(payload[4..]); _write.StartMessage('p'); @@ -846,20 +846,20 @@ internal sealed class PgConnector : IAsyncDisposable LogNotice(); continue; case (byte)'S': - { - var pos = 0; - var name = ReadCString(Payload, ref pos); - _serverParameters[name] = ReadCString(Payload, ref pos); - continue; - } + { + var pos = 0; + var name = ReadCString(Payload, ref pos); + _serverParameters[name] = ReadCString(Payload, ref pos); + continue; + } case (byte)'A': - { - var pos = 4; - var channel = ReadCString(Payload, ref pos); - var payload = ReadCString(Payload, ref pos); - NotificationReceived?.Invoke(new PgNotification(BinaryPrimitives.ReadInt32BigEndian(Payload), channel, payload)); - continue; - } + { + var pos = 4; + var channel = ReadCString(Payload, ref pos); + var payload = ReadCString(Payload, ref pos); + NotificationReceived?.Invoke(new PgNotification(BinaryPrimitives.ReadInt32BigEndian(Payload), channel, payload)); + continue; + } default: return type; } diff --git a/src/Titano.Data/Postgres/PgTypes.cs b/src/Titano.Data/Postgres/PgTypes.cs index 0f8d3302..1f06cd9b 100644 --- a/src/Titano.Data/Postgres/PgTypes.cs +++ b/src/Titano.Data/Postgres/PgTypes.cs @@ -105,17 +105,17 @@ internal static class PgTypes WriteCopyEscaped(s, writer); return; case byte[] bytes: - { - var span = writer.GetSpan(3 + bytes.Length * 2); - "\\\\x"u8.CopyTo(span); - for (var i = 0; i < bytes.Length; i++) { - span[3 + 2 * i] = HexDigits[bytes[i] >> 4]; - span[4 + 2 * i] = HexDigits[bytes[i] & 0xF]; + var span = writer.GetSpan(3 + bytes.Length * 2); + "\\\\x"u8.CopyTo(span); + for (var i = 0; i < bytes.Length; i++) + { + span[3 + 2 * i] = HexDigits[bytes[i] >> 4]; + span[4 + 2 * i] = HexDigits[bytes[i] & 0xF]; + } + writer.Advance(3 + bytes.Length * 2); + return; } - writer.Advance(3 + bytes.Length * 2); - return; - } case int or long or double or bool or Guid or DateTimeOffset: case DateTime { Kind: DateTimeKind.Unspecified }: writer.Advance(FormatText(value, writer.GetSpan(64))); diff --git a/tests/Titano.Data.Tests/Repositories/CatalogRepositoryTests.cs b/tests/Titano.Data.Tests/Repositories/CatalogRepositoryTests.cs index 340fe506..6c0e1277 100644 --- a/tests/Titano.Data.Tests/Repositories/CatalogRepositoryTests.cs +++ b/tests/Titano.Data.Tests/Repositories/CatalogRepositoryTests.cs @@ -32,11 +32,26 @@ public abstract class CatalogRepositoryTests(TestContext context) : RepositoryTe await db.Archives.UpsertAsync(archive, Ct); var sequence = TestData.Sequence(archive.Id, new DateTime(2026, 9, 28, 18, 30, 15, 250), "Harbour sunset") with { - CameraSerial = "0123", Lens = "RF 24-70", FrameCount = 1200, MedianInterval = 5.0, TotalBytes = 30_000_000_000, - Status = SequenceStatus.AnalyzedLight | SequenceStatus.ThumbsBuilt, RenderedCount = 0, VerifiedAt = TestData.Now, - HeroFrameId = Guid.CreateVersion7(), Rating = 4, Notes = "windy", SettingsJson = "{\"fps\": 25, \"deflicker\": true}", - AnalysisJson = "{\"ev\": [12.5, 13]}", Origin = SequenceOrigin.Server, SyncState = SyncState.LocalAhead, - SettingsVersion = 3, FramesVersion = 7, OwnerUserId = Guid.CreateVersion7(), WarningCount = 2, Tags = ["Sunset", "harbour", "SUNSET"], + CameraSerial = "0123", + Lens = "RF 24-70", + FrameCount = 1200, + MedianInterval = 5.0, + TotalBytes = 30_000_000_000, + Status = SequenceStatus.AnalyzedLight | SequenceStatus.ThumbsBuilt, + RenderedCount = 0, + VerifiedAt = TestData.Now, + HeroFrameId = Guid.CreateVersion7(), + Rating = 4, + Notes = "windy", + SettingsJson = "{\"fps\": 25, \"deflicker\": true}", + AnalysisJson = "{\"ev\": [12.5, 13]}", + Origin = SequenceOrigin.Server, + SyncState = SyncState.LocalAhead, + SettingsVersion = 3, + FramesVersion = 7, + OwnerUserId = Guid.CreateVersion7(), + WarningCount = 2, + Tags = ["Sunset", "harbour", "SUNSET"], }; await db.Sequences.UpsertAsync(sequence, Ct); @@ -120,7 +135,8 @@ public abstract class CatalogRepositoryTests(TestContext context) : RepositoryTe await db.Archives.UpsertAsync(archive, Ct); var all = Enumerable.Range(0, 23).Select(i => TestData.Sequence(archive.Id, i % 5 == 4 ? null : new DateTime(2024 + i % 3, 1, 1, 12, 0, 0), - i % 4 == 0 ? null : "T" + (i % 6)) with { FrameCount = i % 3, TotalBytes = i % 4 * 1000L }) + i % 4 == 0 ? null : "T" + (i % 6)) with + { FrameCount = i % 3, TotalBytes = i % 4 * 1000L }) .ToList(); foreach (var s in all) await db.Sequences.UpsertAsync(s, Ct); @@ -208,9 +224,19 @@ public abstract class CatalogRepositoryTests(TestContext context) : RepositoryTe var frames = Enumerable.Range(0, 250).Select(i => TestData.Frame(sequence.Id, i)).ToList(); frames[7] = frames[7] with { - OriginalFileName = "DSC_7.NEF", CapturedAt = new DateTime(2026, 9, 28, 18, 0, 35, 123), UtcOffsetMinutes = 120, ExposureBias = -0.3, - WhiteBalance = 5600, Orientation = 6, PreviewOffset = 1024, PreviewLength = 65536, MeanLogLuminance = -2.5, ClipLow = 0.01, - ClipHigh = 0.02, Flags = FrameFlags.Excluded, Sha256 = "AB" + new string('c', 62), + OriginalFileName = "DSC_7.NEF", + CapturedAt = new DateTime(2026, 9, 28, 18, 0, 35, 123), + UtcOffsetMinutes = 120, + ExposureBias = -0.3, + WhiteBalance = 5600, + Orientation = 6, + PreviewOffset = 1024, + PreviewLength = 65536, + MeanLogLuminance = -2.5, + ClipLow = 0.01, + ClipHigh = 0.02, + Flags = FrameFlags.Excluded, + Sha256 = "AB" + new string('c', 62), }; Assert.Equal(250L, await db.Frames.BulkInsertAsync(frames, Ct)); var copy = TestData.Frame(sequence.Id, 1000) with { Sha256 = frames[7].Sha256 }; diff --git a/tests/Titano.Data.Tests/Repositories/JobRepositoryTests.cs b/tests/Titano.Data.Tests/Repositories/JobRepositoryTests.cs index b4c661ec..cacf4de9 100644 --- a/tests/Titano.Data.Tests/Repositories/JobRepositoryTests.cs +++ b/tests/Titano.Data.Tests/Repositories/JobRepositoryTests.cs @@ -13,10 +13,22 @@ public abstract class JobRepositoryTests(TestContext context) : RepositoryTest(c var db = await OpenTitanoAsync(); var job = TestData.Job(JobKind.Render, JobPriority.User) with { - TargetIds = [Guid.CreateVersion7(), Guid.CreateVersion7()], TargetLabel = "Harbour sunset", ParametersJson = "{\"preset\": \"4K\"}", - ProgressDone = 5, ProgressTotal = 10, ItemsPerSecond = 2.5, Eta = TimeSpan.FromSeconds(2), Checkpoint = "frame:5", - LogTail = "line 1\nline 2", CreatedBy = Guid.CreateVersion7(), NodeId = "node-a", Attempts = 1, Error = "boom", - State = JobState.Failed, Started = TestData.Now.AddMinutes(1), Finished = TestData.Now.AddMinutes(2), + TargetIds = [Guid.CreateVersion7(), Guid.CreateVersion7()], + TargetLabel = "Harbour sunset", + ParametersJson = "{\"preset\": \"4K\"}", + ProgressDone = 5, + ProgressTotal = 10, + ItemsPerSecond = 2.5, + Eta = TimeSpan.FromSeconds(2), + Checkpoint = "frame:5", + LogTail = "line 1\nline 2", + CreatedBy = Guid.CreateVersion7(), + NodeId = "node-a", + Attempts = 1, + Error = "boom", + State = JobState.Failed, + Started = TestData.Now.AddMinutes(1), + Finished = TestData.Now.AddMinutes(2), }; await db.Jobs.EnqueueAsync(job, Ct); var read = Assert.NotNull(await db.Jobs.GetAsync(job.Id, Ct)); diff --git a/tests/Titano.Data.Tests/Repositories/ServerRepositoryTests.cs b/tests/Titano.Data.Tests/Repositories/ServerRepositoryTests.cs index 61dd5c2c..6b3521f1 100644 --- a/tests/Titano.Data.Tests/Repositories/ServerRepositoryTests.cs +++ b/tests/Titano.Data.Tests/Repositories/ServerRepositoryTests.cs @@ -131,8 +131,15 @@ public abstract class ServerRepositoryTests(TestContext context) : RepositoryTes var user = Guid.CreateVersion7(); var entries = Enumerable.Range(0, 9).Select(i => new AuditEntry { - Id = Guid.CreateVersion7(), At = TestData.Now.AddSeconds(i / 2), Action = "sequence.delete", UserId = i % 3 == 0 ? user : null, - Username = "alice", TargetKind = "sequence", TargetId = Guid.CreateVersion7().ToString(), Details = "{\"frames\": 10}", RemoteAddress = "10.0.0.1", + Id = Guid.CreateVersion7(), + At = TestData.Now.AddSeconds(i / 2), + Action = "sequence.delete", + UserId = i % 3 == 0 ? user : null, + Username = "alice", + TargetKind = "sequence", + TargetId = Guid.CreateVersion7().ToString(), + Details = "{\"frames\": 10}", + RemoteAddress = "10.0.0.1", }).ToList(); foreach (var e in entries) await db.Audit.AppendAsync(e, Ct);