Owner review 6 asks Chronos to recognise the same time-lapse held under different ids on the server and on this PC, compare the copies, and keep them apart or integrate and sync them. This lays the shared foundation the later parcels build on, without any UI or detection yet. - Migration 0012 adds found_copies (local-server and local-local pairs with evidence, scores, answer, policy and the 404 record) and copy_probes; every existing link with a local sequence becomes a Linked pair, so a server deletion and the per-link policy have a place. - FoundCopyStore keeps the pairs: upserts that never touch the answer, a compare-and-set of the state with an Integrating backstop (a failed or cancelled job reads as the previous state), link promotion and demotion, the once-per-refresh 404 count, the merge's links stage (session keys, links reset, pairs moved, refused when both are linked on one server), the local overlap queries and the probes. SyncLinkStore.RekeyAsync moves pairs and probes with the links in the same transaction. - Contracts for detection, review, plans, the Integrate and MergeSequences jobs (kinds 25/26, High level, new detail steps) and the Upload all rule that keeps suspected, kept-apart, deleted, busy and server-born sequences here. - Wire: POST photos/lookup, uploads into a target (IntoTarget/Copied, trailing and optional), frames/delete on the client, capabilities photo-lookup and upload-into, cached per remote. - The trash plans and deletes accept the job that holds the sequence (its own hold is not Busy) and a frames version checked under the lease; a Background job never interrupts a running one. - Settings for linking, the photo policy and projects; the en and it keys of design section 9. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
4.5 KiB
C#
73 lines
4.5 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Nodes;
|
|
using Chronos.Protocol;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Server.Tests.Api;
|
|
|
|
/// <summary>
|
|
/// The wire shapes of found copies (owner review 6, #73): the photo lookup in camelCase with nulls left out, and the upload
|
|
/// members added trailing and optional, so a client or server of before reads and writes them as it did.
|
|
/// </summary>
|
|
public sealed class CopyContractTests
|
|
{
|
|
private static readonly Guid SequenceId = Guid.Parse("01890000-0000-7000-8000-000000000002");
|
|
private static readonly DateTime Captured = new(2026, 10, 1, 18, 0, 0, 123, DateTimeKind.Unspecified);
|
|
|
|
[Test]
|
|
public void ALookupTravelsAsProbesAndHits()
|
|
{
|
|
var hash = new string('a', 64);
|
|
var request = new PhotoLookupRequest(
|
|
[
|
|
new PhotoProbe("p1", [hash], [new PhotoKeyDto(25_000_001, Captured)], "upload-1"),
|
|
new PhotoProbe("p2", [hash]),
|
|
]);
|
|
var json = JsonNode.Parse(JsonSerializer.Serialize(request, ProtocolJson.Default.PhotoLookupRequest))!.AsObject();
|
|
Assert.SequenceEqual(["probes"], json.Select(p => p.Key));
|
|
Assert.SequenceEqual(["key", "sha256", "unhashed", "sessionKey"], json["probes"]![0]!.AsObject().Select(p => p.Key));
|
|
Assert.SequenceEqual(["key", "sha256"], json["probes"]![1]!.AsObject().Select(p => p.Key));
|
|
Assert.SequenceEqual(["size", "capturedAt"], json["probes"]![0]!["unhashed"]![0]!.AsObject().Select(p => p.Key));
|
|
var back = JsonSerializer.Deserialize(json.ToJsonString(), ProtocolJson.Default.PhotoLookupRequest)!;
|
|
Assert.Equal(2, back.Probes.Count);
|
|
Assert.Equal(("p1", "upload-1", Captured), (back.Probes[0].Key, back.Probes[0].SessionKey, back.Probes[0].Unhashed![0].CapturedAt));
|
|
Assert.Null(back.Probes[1].Unhashed);
|
|
// The limit counts hashes, unhashed keys and session keys; the count is never sent.
|
|
Assert.Equal(4, request.CountItems());
|
|
Assert.Equal((200, 20_000), (PhotoLookupRequest.MaxProbes, PhotoLookupRequest.MaxItems));
|
|
|
|
var response = new PhotoLookupResponse([new ProbeResult("p1", [new PhotoLookupHit(SequenceId, 1, 0, 1, true)]), new ProbeResult("p2", [])]);
|
|
var answer = JsonNode.Parse(JsonSerializer.Serialize(response, ProtocolJson.Default.PhotoLookupResponse))!.AsObject();
|
|
Assert.SequenceEqual(["sequenceId", "hashes", "removed", "unhashed", "sessionKey"], answer["results"]![0]!["hits"]![0]!.AsObject().Select(p => p.Key));
|
|
var read = JsonSerializer.Deserialize(answer.ToJsonString(), ProtocolJson.Default.PhotoLookupResponse)!;
|
|
Assert.Equal(response.Results[0].Hits[0], read.Results[0].Hits[0]);
|
|
Assert.Empty(read.Results[1].Hits);
|
|
Assert.Equal(("photo-lookup", "upload-into"), (ServerCapabilities.PhotoLookup, ServerCapabilities.UploadInto));
|
|
}
|
|
|
|
[Test]
|
|
public void AnUploadIntoATargetIsAnOptionalTrailingFlag()
|
|
{
|
|
// A client of before sends no flag: an upload as before.
|
|
var old = JsonSerializer.Deserialize(
|
|
"""{ "sequenceId": null, "fileName": "IMG_0001.JPG", "size": 10, "sha256": "ab", "capturedAt": null, "sessionKey": "upload-1" }""",
|
|
ProtocolJson.Default.StartUploadRequest)!;
|
|
Assert.Equal((false, false), (old.Restore, old.IntoTarget));
|
|
var into = new StartUploadRequest(SequenceId, "IMG_0001.JPG", 10, "ab", null, null, IntoTarget: true);
|
|
var json = JsonNode.Parse(JsonSerializer.Serialize(into, ProtocolJson.Default.StartUploadRequest))!.AsObject();
|
|
Assert.Equal("intoTarget", json.Last().Key);
|
|
Assert.True(json["intoTarget"]!.GetValue<bool>());
|
|
Assert.True(JsonSerializer.Deserialize(json.ToJsonString(), ProtocolJson.Default.StartUploadRequest)!.IntoTarget);
|
|
|
|
// A server of before answers without Copied.
|
|
var answer = JsonSerializer.Deserialize("""{ "uploadId": null, "chunkSize": 0, "received": [], "alreadyExists": true, "frameId": null }""",
|
|
ProtocolJson.Default.StartUploadResponse)!;
|
|
Assert.False(answer.Copied);
|
|
var copied = new StartUploadResponse(null, 0, [], true, SequenceId, Copied: true);
|
|
var copiedJson = JsonNode.Parse(JsonSerializer.Serialize(copied, ProtocolJson.Default.StartUploadResponse))!.AsObject();
|
|
Assert.Equal("copied", copiedJson.Last().Key);
|
|
var back = JsonSerializer.Deserialize(copiedJson.ToJsonString(), ProtocolJson.Default.StartUploadResponse)!;
|
|
Assert.Equal(((Guid?)SequenceId, true, true), (back.FrameId, back.AlreadyExists, back.Copied));
|
|
}
|
|
}
|