diff options
Diffstat (limited to 'tests/SomhairlesDream.Server.Tests/ApiTests.fs')
| -rw-r--r-- | tests/SomhairlesDream.Server.Tests/ApiTests.fs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/SomhairlesDream.Server.Tests/ApiTests.fs b/tests/SomhairlesDream.Server.Tests/ApiTests.fs index cc8a3da..f51ca3d 100644 --- a/tests/SomhairlesDream.Server.Tests/ApiTests.fs +++ b/tests/SomhairlesDream.Server.Tests/ApiTests.fs @@ -53,6 +53,14 @@ type private BlockingBridge(gate: ManualResetEventSlim) = gate.Wait() (TestBridge() :> IArtifactBridge).Export(request, fun () -> ()) +type private StepGatedBridge(gate: ManualResetEventSlim) = + interface IArtifactBridge with + member _.Export(request, _) = + if request.Step.Index > 0 then + gate.Wait() + + (TestBridge() :> IArtifactBridge).Export(request, fun () -> ()) + let private requestBody runId = $"{{\"projectId\":\"{ids.ProjectId}\",\"runId\":\"{runId}\",\"baseId\":\"{ids.BaseId}\",\"targetId\":\"{ids.TargetId}\"}}" @@ -204,6 +212,61 @@ let ``manifest endpoint reports active runs as conflicts`` () = gate.Dispose() [<Fact>] +let ``step artifacts stream while a run is still active`` () = + let gate = new ManualResetEventSlim(false) + + try + withAppUsing + (fun () -> StepGatedBridge(gate) :> IArtifactBridge) + (fun client coordinator -> + let runId = "run-api-steps" + use content = new StringContent(requestBody runId, Encoding.UTF8, "application/json") + let start = client.PostAsync("/api/runs/start", content).GetAwaiter().GetResult() + Assert.Equal(HttpStatusCode.Accepted, start.StatusCode) + + Assert.True( + waitFor (fun () -> + coordinator.TryFind(ids.ProjectId, runId) + |> Option.exists (fun store -> + let snapshot = store.Snapshot() + snapshot.Status = "running" && snapshot.CompletedSteps.Length = 1))) + + let glbPath = Uri.EscapeDataString("steps/01-foundation.glb") + let stepsUrl = $"/api/artifacts/steps?projectId={ids.ProjectId}&runId={runId}&path={glbPath}" + + let stepArtifact = + client.GetAsync(stepsUrl).GetAwaiter().GetResult() + + Assert.Equal(HttpStatusCode.OK, stepArtifact.StatusCode) + Assert.Equal("model/gltf-binary", stepArtifact.Content.Headers.ContentType.MediaType) + + let traversalPath = Uri.EscapeDataString("../manifest.json") + let traversalUrl = $"/api/artifacts/steps?projectId={ids.ProjectId}&runId={runId}&path={traversalPath}" + + let traversal = + client.GetAsync(traversalUrl).GetAwaiter().GetResult() + + Assert.Equal(HttpStatusCode.BadRequest, traversal.StatusCode) + + let missingPath = Uri.EscapeDataString("steps/03-cabin.glb") + let missingUrl = $"/api/artifacts/steps?projectId={ids.ProjectId}&runId={runId}&path={missingPath}" + + let missing = + client.GetAsync(missingUrl).GetAwaiter().GetResult() + + Assert.Equal(HttpStatusCode.NotFound, missing.StatusCode) + gate.Set() + + Assert.True( + waitFor (fun () -> + coordinator.TryFind(ids.ProjectId, runId) + |> Option.exists (fun store -> store.Snapshot().Status = "complete"))) + ) + finally + gate.Set() + gate.Dispose() + +[<Fact>] let ``events endpoint streams only the selected run`` () = withApp (fun client _ -> let runId = "run-api-events" |
