fix(projects): never revert a server's index settings to an older project.json

Before phase 5b the server's settings PATCH wrote the index alone, and every
desktop edit of a linked sequence arrives as one, so an upgraded server holds
sequences whose index settings are newer than their project.json. Main's birth
read project.json first and mirrored it over the index; sequenceChanged then
carried the loss to the desktops' linked copies.

ArchiveServiceOptions.IndexSettingsMayLead, set by the server, keeps both: Main
is born with project.json's settings as version 1 and the index's as version 2,
in force and mirrored (on a read-only archive both go to the index only). A Main
the sidecars already hold, met with no mirror known, keeps index settings that
none of its versions hold as an External version below what project.json gives
(the head again as a Restore, a merge, or the file's). The desktop is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 13:35:47 +01:00
1 parent ccc10ec8b8
commit ab6cad51b2
11 files changed
+245 -18

No files matched your search

@@ -177,6 +177,98 @@ public abstract class ProjectRecoveryTests(TestContext context) : DatabaseTest(c
Assert.SequenceEqual([0], Settings(fx, sequence).ExcludedFrames);
}
/// <summary>The settings of an index that may hold newer ones than <c>project.json</c>, as the server's does (an earlier release's PATCH wrote the index alone).</summary>
private async Task<ArchiveFixture> ServerFixtureAsync() =>
Own(await CreateAsync(Context, database: await NewOptionsAsync(multiConnection: true),
configure: _ => new ArchiveServiceOptions { Owner = "server", LeaseWait = TimeSpan.FromSeconds(20), IndexSettingsMayLead = true }));
private static ProjectSettings Exposure(double ev) => new() { Exposure = new ExposureSettings { ExposureOffsetEv = ev } };
private static double Ev(string json) => ProjectSettings.FromJson(json).Exposure.ExposureOffsetEv;
[Test]
public async Task OnThisPcMainIsBornFromProjectJsonAloneWhenTheIndexDiffers()
{
var fx = await FixtureAsync();
var (sequence, _) = await UploadedAsync(fx, 3);
var folder = fx.Paths.Sequence(sequence.Folder);
Directory.CreateDirectory(folder.MetaDirectory);
File.WriteAllText(folder.ProjectPath, Exposure(0.2).ToJson());
await WriteSettingsAsync(fx, sequence.Id, Exposure(0.7));
// The desktop's every writer writes the file: an index that differs is an old copy, brought up to it.
var main = await fx.Service.Projects.MainAsync(sequence.Id, fx.Ct);
var history = await fx.Service.Projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
Assert.Equal((1, ProjectVersionKind.Imported), (history.Single().Number, history.Single().Kind));
Assert.Equal(0.2, Ev(history.Single().SettingsJson));
Assert.Equal(0.2, Ev((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!));
Assert.Equal(0.2, Settings(fx, sequence).Exposure.ExposureOffsetEv);
}
[Test]
public async Task OnAServerMainIsBornWithTheIndexsNewerSettingsInForceAndProjectJsonsKept()
{
foreach (var readOnly in new[] { false, true })
{
var fx = await ServerFixtureAsync();
var (sequence, _) = await UploadedAsync(fx, 3);
var folder = fx.Paths.Sequence(sequence.Folder);
Directory.CreateDirectory(folder.MetaDirectory);
File.WriteAllText(folder.ProjectPath, Exposure(0.2).ToJson());
// A settings PATCH of an earlier release: the index alone.
await WriteSettingsAsync(fx, sequence.Id, Exposure(0.7));
var projects = fx.Service.Projects;
if (readOnly)
{
// On a read-only archive Main is made in the index only, both versions in it, nothing written; its sidecars
// and the mirror follow once the archive takes writes.
projects.Availability = _ => ArchiveAvailability.ReadOnly;
Assert.Equal(2, (await projects.ListAsync(sequence.Id, fx.Ct)).Single().HeadNumber);
Assert.False(Directory.Exists(folder.ProjectsDirectory));
Assert.Equal(0.2, Settings(fx, sequence).Exposure.ExposureOffsetEv);
projects.Availability = ArchiveVolume.Probe;
}
var main = await projects.MainAsync(sequence.Id, fx.Ct);
var history = await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
Assert.SequenceEqual([(2, ProjectVersionKind.External), (1, ProjectVersionKind.Imported)], history.Select(v => (v.Number, v.Kind)));
Assert.Equal((0.7, 0.2), (Ev(history[0].SettingsJson), Ev(history[1].SettingsJson)));
Assert.Equal(0.7, Ev((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!));
Assert.Equal(0.7, Settings(fx, sequence).Exposure.ExposureOffsetEv);
// In step now: read again, nothing is added.
await projects.ListAsync(sequence.Id, fx.Ct);
Assert.Count(2, await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct));
Assert.Equal(main.Id, ProjectFolders(folder).Select(d => Guid.ParseExact(Path.GetFileName(d), "N")).Single());
}
}
[Test]
public async Task OnAServerAnIndexMeetingMainKeepsItsOwnSettingsAsAVersion()
{
var fx = await ServerFixtureAsync();
var (sequence, frames) = await UploadedAsync(fx, 3);
var projects = fx.Service.Projects;
var main = await projects.MainAsync(sequence.Id, fx.Ct);
var pushed = (await projects.PushAsync(main.Id, Draft(await projects.HeadAsync(main.Id, fx.Ct), Exposure(0.4), frames), fx.Ct)).Version!;
// The index meets Main with no mirror known and its own settings, which no version holds: which is newer cannot be
// told, so both are kept, the index's as a version and project.json's (the pushed head) in force on top of it.
var row = await WriteSettingsAsync(fx, sequence.Id, Exposure(0.7));
await fx.Db.Projects.SetMirroredAsync(main.Id, null, row.SettingsVersion, fx.Ct);
var history = await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
Assert.SequenceEqual([(4, ProjectVersionKind.Restore), (3, ProjectVersionKind.External), (2, ProjectVersionKind.Commit)],
history.Take(3).Select(v => (v.Number, v.Kind)));
Assert.Equal((0.4, 0.7, pushed.Id), (Ev(history[0].SettingsJson), Ev(history[1].SettingsJson), history[0].RestoredFrom));
Assert.Equal(0.4, Ev((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!));
Assert.Equal(0.4, Settings(fx, sequence).Exposure.ExposureOffsetEv);
// An index copy a version holds already (a backup's) adds nothing: the head is mirrored.
row = await WriteSettingsAsync(fx, sequence.Id, Exposure(0.7));
await fx.Db.Projects.SetMirroredAsync(main.Id, null, row.SettingsVersion, fx.Ct);
Assert.Count(4, await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct));
Assert.Equal(0.4, Ev((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!));
}
[Test]
public async Task AMirrorACrashCutShortBeforeProjectJsonIsCompletedAfterARebuild()
{