merge: integration branch claude/keen-knuth-uhxv8w (remote editor after review) into the Library workstream
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
81 files changed
+3827
-263
No files matched your search
@@ -0,0 +1,108 @@
|
||||
using Titano.Core.Diagnostics.Synthetic;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Data.Repositories;
|
||||
using Titano.Data.Tests.Infrastructure;
|
||||
using Titano.Data.Tests.Processing;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Data.Tests.Repositories;
|
||||
|
||||
/// <summary>Client edits of a sequence row (<see cref="SequenceRepository.EditAsync"/>) on both dialects: the hero frame the Library shows.</summary>
|
||||
public abstract class SequenceEditTests(TestContext context) : RepositoryTest(context)
|
||||
{
|
||||
[Test]
|
||||
public async Task TheHeroFrameIsSetKeptAndCleared()
|
||||
{
|
||||
var db = await OpenTitanoAsync();
|
||||
var archive = TestData.Archive();
|
||||
await db.Archives.UpsertAsync(archive, Ct);
|
||||
var sequence = TestData.Sequence(archive.Id);
|
||||
await db.Sequences.UpsertAsync(sequence, Ct);
|
||||
var frames = Enumerable.Range(0, 5).Select(i => TestData.Frame(sequence.Id, i)).ToList();
|
||||
await db.Frames.BulkInsertAsync(frames, Ct);
|
||||
|
||||
var set = await db.Sequences.EditAsync(sequence.Id, new SequenceEdit { SettingsJson = "{\"heroFrame\":3}", HeroFrameId = frames[3].Id }, null, Ct);
|
||||
Assert.Equal(SequenceEditOutcome.Updated, set.Outcome);
|
||||
Assert.Equal(frames[3].Id, set.Sequence!.HeroFrameId);
|
||||
Assert.Equal(frames[3].Id, (await db.Sequences.GetAsync(sequence.Id, Ct))!.HeroFrameId);
|
||||
|
||||
var kept = await db.Sequences.EditAsync(sequence.Id, new SequenceEdit { Rating = 4 }, set.Sequence.SettingsVersion, Ct);
|
||||
Assert.Equal(frames[3].Id, kept.Sequence!.HeroFrameId, "an edit without a hero leaves it alone");
|
||||
|
||||
var cleared = await db.Sequences.EditAsync(sequence.Id, new SequenceEdit { HeroFrameId = Guid.Empty }, null, Ct);
|
||||
Assert.Null(cleared.Sequence!.HeroFrameId, "Guid.Empty goes back to the first frame");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFrameOfAnotherSequenceIsNotAHero()
|
||||
{
|
||||
var db = await OpenTitanoAsync();
|
||||
var archive = TestData.Archive();
|
||||
await db.Archives.UpsertAsync(archive, Ct);
|
||||
var mine = TestData.Sequence(archive.Id, title: "Mine");
|
||||
var other = TestData.Sequence(archive.Id, title: "Other");
|
||||
await db.Sequences.UpsertAsync(mine, Ct);
|
||||
await db.Sequences.UpsertAsync(other, Ct);
|
||||
var own = TestData.Frame(mine.Id, 0);
|
||||
var foreign = TestData.Frame(other.Id, 0);
|
||||
await db.Frames.BulkInsertAsync([own, foreign], Ct);
|
||||
|
||||
await db.Sequences.EditAsync(mine.Id, new SequenceEdit { HeroFrameId = own.Id }, null, Ct);
|
||||
var result = await db.Sequences.EditAsync(mine.Id, new SequenceEdit { HeroFrameId = foreign.Id }, null, Ct);
|
||||
Assert.Equal(SequenceEditOutcome.Updated, result.Outcome);
|
||||
Assert.Equal(own.Id, result.Sequence!.HeroFrameId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AConflictLeavesTheHeroAsItWas()
|
||||
{
|
||||
var db = await OpenTitanoAsync();
|
||||
var archive = TestData.Archive();
|
||||
await db.Archives.UpsertAsync(archive, Ct);
|
||||
var sequence = TestData.Sequence(archive.Id);
|
||||
await db.Sequences.UpsertAsync(sequence, Ct);
|
||||
var frame = TestData.Frame(sequence.Id, 0);
|
||||
await db.Frames.BulkInsertAsync([frame], Ct);
|
||||
|
||||
var result = await db.Sequences.EditAsync(sequence.Id, new SequenceEdit { HeroFrameId = frame.Id }, sequence.SettingsVersion + 7, Ct);
|
||||
Assert.Equal(SequenceEditOutcome.Conflict, result.Outcome);
|
||||
Assert.Null((await db.Sequences.GetAsync(sequence.Id, Ct))!.HeroFrameId);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SqliteSequenceEditTests(TestContext context) : SequenceEditTests(context)
|
||||
{
|
||||
protected override Backend Backend => Backend.SqliteMemory;
|
||||
}
|
||||
|
||||
[RequiresEnvironment(PgTestServer.Variable)]
|
||||
public sealed class PostgresSequenceEditTests(TestContext context) : SequenceEditTests(context)
|
||||
{
|
||||
protected override Backend Backend => Backend.Postgres;
|
||||
}
|
||||
|
||||
/// <summary>Project writes of the engine (advice, sync) carry the project's hero frame to the index, so the Library shows it.</summary>
|
||||
public sealed class ProjectStoreHeroTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public async Task AdviceThatPicksAHeroReachesTheIndex()
|
||||
{
|
||||
await using var fixture = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fixture.AddAsync(SyntheticSequence.Create(new SyntheticSequenceOptions { Width = 64, Height = 48, FrameCount = 6 }));
|
||||
var frames = await fixture.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fixture.Ct);
|
||||
var store = new ProjectStore(fixture.Db, new SequenceWriter(new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) }));
|
||||
|
||||
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { HeroFrame = 4 }, fixture.Ct));
|
||||
Assert.Equal(frames[4].Id, (await fixture.Db.Sequences.GetAsync(sequence.Id, fixture.Ct))!.HeroFrameId);
|
||||
|
||||
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.5 } }, fixture.Ct));
|
||||
Assert.Equal(frames[4].Id, (await fixture.Db.Sequences.GetAsync(sequence.Id, fixture.Ct))!.HeroFrameId, "other changes keep the hero");
|
||||
|
||||
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { HeroFrame = null }, fixture.Ct));
|
||||
Assert.Null((await fixture.Db.Sequences.GetAsync(sequence.Id, fixture.Ct))!.HeroFrameId);
|
||||
|
||||
Assert.True(await store.UpdateAsync(fixture.Archive.Paths, sequence, p => p with { HeroFrame = 99 }, fixture.Ct));
|
||||
Assert.Null((await fixture.Db.Sequences.GetAsync(sequence.Id, fixture.Ct))!.HeroFrameId, "an index past the last frame shows the first");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user