fix(projects): never undo a deletion by a record rebuild; keep outside project.json edits
Phase 5a fix round 4, projects engine. - The reconcile reads the projects' trash before the live folders, so a deletion wins over what a sync tool has left of the live folder. A lost record is never written again while the trash holds a folder of that project; a trashed record that cannot be read holds the project back. - A lost record is written again from the index only once the folder has looked the same, file by file, on two reconciles two minutes apart, so a record a sync tool is still bringing (a rename, a newer head) wins. - IndexAsync's "behind" is the rule the heal uses: the record's head must be a version the index holds below its head. A record on another chain keeps its name. - A record written before what the index knows (its Updated time is older, e.g. a backup made before a rename) never gives its name, and the heal writes the index's name back. A record's Updated time never goes back, so a newer rename from a PC whose clock is behind is still taken. - A mirror never writes project.json over settings written there since this index last knew what it held (another PC, an older client): they are merged first (theirs win where both changed) or kept as an external version, then the result is mirrored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c5ed31bced
commit
56b8ba3c1d
4 files changed
+449
-45
No files matched your search
@@ -302,6 +302,53 @@ public abstract class MainMergeTests(TestContext context) : DatabaseTest(context
|
||||
Assert.Count(4, await fx.Service.Projects.HistoryAsync(main.Id, cancellationToken: fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnEditMadeOnlyInProjectJsonIsNeverWrittenOverByAMirror()
|
||||
{
|
||||
var fx = await FixtureAsync();
|
||||
var (sequence, frames) = await ProjectServiceTests.UploadedAsync(fx, 3);
|
||||
var projects = fx.Service.Projects;
|
||||
var main = await projects.MainAsync(sequence.Id, fx.Ct);
|
||||
var second = (await projects.PushAsync(main.Id, ProjectServiceTests.Draft(await projects.HeadAsync(main.Id, fx.Ct), new ProjectSettings { ExcludedFrames = [0] },
|
||||
frames), fx.Ct)).Version!;
|
||||
var folder = fx.Paths.Sequence(sequence.Folder);
|
||||
|
||||
// Another PC (an older client) edits project.json only, and this index has not scanned it: a push to Main merges it first.
|
||||
File.WriteAllText(folder.ProjectPath, new ProjectSettings { ExcludedFrames = [0], Exposure = new ExposureSettings { ExposureOffsetEv = 1.0 } }.ToJson());
|
||||
var third = (await projects.PushAsync(main.Id, ProjectServiceTests.Draft(second, new ProjectSettings
|
||||
{
|
||||
ExcludedFrames = [0, 2],
|
||||
Exposure = new ExposureSettings { ExposureOffsetEv = 0.5 },
|
||||
}, frames), fx.Ct)).Version!;
|
||||
var history = await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
|
||||
Assert.SequenceEqual([ProjectVersionKind.Merge, ProjectVersionKind.Commit, ProjectVersionKind.Commit, ProjectVersionKind.Imported], history.Select(v => v.Kind));
|
||||
Assert.Equal((third.Id, 0.5), (history[1].Id, ProjectSettings.FromJson(history[1].SettingsJson).Exposure.ExposureOffsetEv));
|
||||
foreach (var settings in new[] { ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!),
|
||||
ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)) })
|
||||
{
|
||||
// Where both changed the outside edit wins; the push's other change is in force too.
|
||||
Assert.Equal(1.0, settings.Exposure.ExposureOffsetEv);
|
||||
Assert.SequenceEqual([0, 2], settings.ExcludedFrames);
|
||||
}
|
||||
Assert.Count(4, await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct));
|
||||
|
||||
// The merge's mirror wrote project.json and the record but not the index (still at version 3), and project.json is
|
||||
// edited again: the mirror completing it keeps the edit as an external version.
|
||||
var head = await projects.HeadAsync(main.Id, fx.Ct);
|
||||
var stale = await ProjectServiceTests.WriteSettingsAsync(fx, sequence.Id, new ProjectSettings { ExcludedFrames = [0, 2], Exposure = new ExposureSettings { ExposureOffsetEv = 0.5 } });
|
||||
await fx.Db.Projects.SetMirroredAsync(main.Id, third.Id, stale.SettingsVersion, fx.Ct);
|
||||
File.WriteAllText(folder.ProjectPath, new ProjectSettings { ExcludedFrames = [1], Exposure = new ExposureSettings { ExposureOffsetEv = -1 } }.ToJson());
|
||||
history = await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct);
|
||||
Assert.Equal((ProjectVersionKind.External, head.Id), (history[0].Kind, history[0].ParentId));
|
||||
foreach (var settings in new[] { ProjectSettings.FromJson((await fx.Db.Sequences.GetAsync(sequence.Id))!.SettingsJson!),
|
||||
ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)) })
|
||||
{
|
||||
Assert.Equal(-1, settings.Exposure.ExposureOffsetEv);
|
||||
Assert.SequenceEqual([1], settings.ExcludedFrames);
|
||||
}
|
||||
Assert.Count(5, await projects.HistoryAsync(main.Id, cancellationToken: fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ANewerChronosHeadOfMainIsNotMergedWithSettingsWrittenMeanwhile()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user