merge: sync and project position fixes (V-9, V-10, V-21, V-29, CD-2)

Merge branch fix2/sync-positions into the verification branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 17:10:58 +00:00
commit 51acc7f91b
32 files changed
+1843 -153

No files matched your search

@@ -1,7 +1,9 @@
using System.Net;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using Titano.Data;
using Titano.Protocol;
using Titano.Server.Api;
using Titano.Testing;
namespace Titano.Server.Tests.Api;
@@ -60,6 +62,32 @@ public sealed class SequenceTests(TestContext context)
await invalid.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_settings");
}
[Test]
public async Task SettingsWrittenAgainstFramesThatChangedAreRefused()
{
await using var server = await TestServer.StartAsync(context);
var (editor, _, _) = await server.UserAsync("alberto", "editor");
var first = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 41), "a.CR3", sessionKey: "k");
using var read = await editor.GetAsync($"/api/v1/sequences/{first.SequenceId}");
var sequence = await read.ReadAsync(ProtocolJson.Default.SequenceDto);
// Another photo arrives after this client read the frames its positions name.
await Uploads.UploadAsync(editor, Uploads.Photo(2000, 42), "b.CR3", sessionKey: "k");
using (var stale = await editor.PatchAsJsonAsync($"/api/v1/sequences/{sequence.Id}",
new UpdateSequenceRequest(null, null, null, null, """{"excludedFrames":[0]}""", sequence.SettingsVersion, ExpectedFramesVersion: sequence.FramesVersion),
ProtocolJson.Default.UpdateSequenceRequest))
{
var error = await stale.ExpectErrorAsync(HttpStatusCode.Conflict, "frames_conflict");
Assert.Equal((sequence.FramesVersion + 1).ToString(System.Globalization.CultureInfo.InvariantCulture), error.Details);
}
using var fresh = await editor.PatchAsJsonAsync($"/api/v1/sequences/{sequence.Id}",
new UpdateSequenceRequest(null, null, null, null, """{"excludedFrames":[1]}""", sequence.SettingsVersion, ExpectedFramesVersion: sequence.FramesVersion + 1),
ProtocolJson.Default.UpdateSequenceRequest);
await fresh.ExpectAsync(HttpStatusCode.OK);
Assert.Equal(sequence.SettingsVersion + 1, (await fresh.ReadAsync(ProtocolJson.Default.SequenceDto)).SettingsVersion);
}
[Test]
public async Task TheManifestCarriesHashesAndAnEtag()
{
@@ -88,6 +116,59 @@ public sealed class SequenceTests(TestContext context)
Assert.Count(3, (await changed.ReadAsync(ProtocolJson.Default.SequenceManifest)).Frames);
}
[Test]
public async Task TheManifestListsTheFramesOfOneFramesVersion()
{
await using var server = await TestServer.StartAsync(context);
await FramesOfOneVersionAsync(server);
}
/// <summary>The manifest's frames are read again while frames are committed, then under the row lock (also run on PostgreSQL).</summary>
internal static async Task FramesOfOneVersionAsync(TestServer server)
{
var (editor, _, _) = await server.UserAsync("alberto", "editor");
var first = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 51), "a.CR3", sessionKey: "k");
var db = server.Database;
var id = first.SequenceId;
var start = (await db.Sequences.GetAsync(id))!.FramesVersion;
// Frames are committed while the first listing is read: it is read again.
var listings = new List<int>();
var snapshot = await SequenceEndpoints.SnapshotAsync(db, id, async (_, sequence, ct) =>
{
listings.Add(sequence.FramesVersion);
if (listings.Count == 1) await db.Sequences.RefreshStatsAsync(id, ct);
return [];
}, CancellationToken.None);
Assert.SequenceEqual([start, start + 1], listings);
Assert.Equal(start + 1, Assert.NotNull(snapshot).Sequence.FramesVersion);
// Commits keep landing: the last listing is read while none can.
Task? waiting = null;
listings.Clear();
var locked = await SequenceEndpoints.SnapshotAsync(db, id, async (on, sequence, ct) =>
{
listings.Add(sequence.FramesVersion);
if (listings.Count <= 3)
{
await db.Sequences.RefreshStatsAsync(id, ct);
return [];
}
// Listed on the transaction that holds the row (on SQLite, the only connection that may while it writes).
Assert.True(on is TitanoTransaction, "the frames are listed inside the locking transaction");
Assert.Count(1, await on.Frames.ListBySequenceAsync(id, cancellationToken: ct));
waiting = db.Sequences.RefreshStatsAsync(id, ct);
await Task.WhenAny(waiting, Task.Delay(300, ct));
Assert.False(waiting.IsCompleted, "a commit of frames waits until the frames are listed");
return [];
}, CancellationToken.None);
await Assert.NotNull(waiting);
Assert.SequenceEqual([start + 1, start + 2, start + 3, start + 4], listings);
Assert.Equal(start + 4, Assert.NotNull(locked).Sequence.FramesVersion);
Assert.Equal(start + 5, (await db.Sequences.GetAsync(id))!.FramesVersion);
Assert.Null(await SequenceEndpoints.SnapshotAsync(db, Guid.NewGuid(), (_, _, _) => Task.FromResult(new List<ManifestFrame>()), CancellationToken.None));
}
[Test]
public async Task ListingFiltersAndPagesWithACursor()
{