test(sync): upload, download, resume, proxies and live events against the real server
The first original of an upload now creates the server sequence through its session key (the archive ingest files API-created empty sequences nowhere), and settings sent after an upload are retried when the server's own analysis edits the new sequence meanwhile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
9 files changed
+420
-49
No files matched your search
@@ -14,6 +14,7 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
{
|
||||
private readonly Lock _gate = new();
|
||||
private readonly Channel<ServerEvent> _events = Channel.CreateUnbounded<ServerEvent>();
|
||||
private readonly Dictionary<string, FakeSequence> _sessions = [];
|
||||
|
||||
public string Server => "https://nas.test:8443";
|
||||
|
||||
@@ -83,12 +84,6 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
lock (_gate) return Task.FromResult<IReadOnlyList<FrameDto>>([.. Find(sequenceId).Frames.Select((f, i) => f.Dto(sequenceId, i))]);
|
||||
}
|
||||
|
||||
public Task<SequenceDto> CreateSequenceAsync(CreateSequenceRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var sequence = Add(request.Title, []);
|
||||
return Task.FromResult(sequence.Dto());
|
||||
}
|
||||
|
||||
public Task<SequenceDto> UpdateSequenceAsync(Guid id, UpdateSequenceRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
lock (_gate)
|
||||
@@ -107,18 +102,27 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CompleteUploadResponse?> UploadFileAsync(string path, Guid sequenceId, string sha256, DateTime? capturedAt, CancellationToken cancellationToken)
|
||||
/// <summary>Like the server: content it already holds anywhere is not stored again; a session key files the first original into a new sequence.</summary>
|
||||
public async Task<CompleteUploadResponse?> UploadFileAsync(string path, Guid? sequenceId, string? sessionKey, string sha256, DateTime? capturedAt,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var bytes = await File.ReadAllBytesAsync(path, cancellationToken);
|
||||
if (Convert.ToHexStringLower(SHA256.HashData(bytes)) != sha256)
|
||||
throw new TitanoApiException(HttpStatusCode.BadRequest, new ApiError("hash_mismatch", "hash"));
|
||||
lock (_gate)
|
||||
{
|
||||
var s = Find(sequenceId);
|
||||
var existing = s.Frames.FindIndex(f => f.Sha256 == sha256);
|
||||
if (existing >= 0) return new CompleteUploadResponse(s.Frames[existing].Id, sequenceId, existing);
|
||||
var frame = s.AddFrame(bytes, Path.GetFileName(path), capturedAt);
|
||||
return new CompleteUploadResponse(frame.Id, sequenceId, s.Frames.Count - 1);
|
||||
if (Sequences.Values.SelectMany(s => s.Frames).FirstOrDefault(f => f.Sha256 == sha256) is { } existing)
|
||||
return new CompleteUploadResponse(existing.Id, sequenceId ?? Guid.Empty, -1);
|
||||
FakeSequence target;
|
||||
if (sequenceId is { } id) target = Find(id);
|
||||
else if (!_sessions.TryGetValue(sessionKey!, out target!))
|
||||
{
|
||||
target = new FakeSequence { Id = Guid.CreateVersion7() };
|
||||
Sequences[target.Id] = target;
|
||||
_sessions[sessionKey!] = target;
|
||||
}
|
||||
var frame = target.AddFrame(bytes, Path.GetFileName(path), capturedAt);
|
||||
return new CompleteUploadResponse(frame.Id, target.Id, target.Frames.Count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -267,11 +267,11 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
public Task<IReadOnlyList<SequenceDto>> ListSequencesAsync(CancellationToken cancellationToken) => inner.ListSequencesAsync(cancellationToken);
|
||||
public Task<SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken) => inner.GetManifestAsync(id, cancellationToken);
|
||||
public Task<IReadOnlyList<FrameDto>> ListFramesAsync(Guid sequenceId, CancellationToken cancellationToken) => inner.ListFramesAsync(sequenceId, cancellationToken);
|
||||
public Task<SequenceDto> CreateSequenceAsync(CreateSequenceRequest request, CancellationToken cancellationToken) => inner.CreateSequenceAsync(request, cancellationToken);
|
||||
public Task<SequenceDto> UpdateSequenceAsync(Guid id, UpdateSequenceRequest request, CancellationToken cancellationToken) => inner.UpdateSequenceAsync(id, request, cancellationToken);
|
||||
|
||||
public Task<CompleteUploadResponse?> UploadFileAsync(string path, Guid sequenceId, string sha256, DateTime? capturedAt, CancellationToken cancellationToken) =>
|
||||
inner.UploadFileAsync(path, sequenceId, sha256, capturedAt, cancellationToken);
|
||||
public Task<CompleteUploadResponse?> UploadFileAsync(string path, Guid? sequenceId, string? sessionKey, string sha256, DateTime? capturedAt,
|
||||
CancellationToken cancellationToken) =>
|
||||
inner.UploadFileAsync(path, sequenceId, sessionKey, sha256, capturedAt, cancellationToken);
|
||||
|
||||
public Task DownloadFrameAsync(Guid frameId, string kind, Stream destination, CancellationToken cancellationToken) =>
|
||||
inner.DownloadFrameAsync(frameId, kind, destination, cancellationToken);
|
||||
|
||||
Reference in new issue
Block a user