summaryrefslogtreecommitdiff
path: root/tests/SomhairlesDream.Server.Tests/StoreTests.fs
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-21 00:58:15 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-21 00:58:15 +0800
commit7b29dbff7e43e87741476f47df17ad1582b16546 (patch)
tree4c9d0832b4e4edd77e59e9cb0a88abf5e729a9f9 /tests/SomhairlesDream.Server.Tests/StoreTests.fs
parent47add3088d50f12c5f48591f26c53cdb59d8283b (diff)
downloadsomhairles-dream-fsharp-7b29dbff7e43e87741476f47df17ad1582b16546.tar.gz
feat(pipeline): add runnable artifact pipeline increment
[Change Nature] - This commit adds the first runnable increment of the F# artifact pipeline: CLI, server, frontend bundle, stage fixture, and tests. It is feature work, not a bug fix. [New Capability] - CLI `run` executes the three-step Blender fixture through the process bridge and writes GLBs, step logs, events, and a manifest; `verify` validates a manifest without Blender. - Server exposes run start, run-scoped SSE, artifact manifest/file routes, and serves the Fable frontend from its build output. - Frontend starts runs, follows run-scoped SSE progress, and links the artifact manifest on completion. [Implementation] - Shared layer holds domain, run state, replay, and artifact contracts; Modeling holds the pipeline, 120s bridge timeout, and result-file protocol; stage/blender/fixture.py owns geometry in Python (bpy owns geometry, F# owns orchestration). - Fable bundle is regenerated into public/ and copied by the server project; solution includes all projects with warnings-as-errors. - README documents build, Fable, server, interpreter/env, fixture limitations, and current verification status. [Impact] - Verified: 40/40 solution tests pass; Release build 0 warnings/errors; real CLI run with bpy 5.0.1 produced 3 GLBs, 3 logs, and a verify-clean manifest; isolated-port server smoke flow succeeded. - Not yet verified: browser end-to-end behavior and production fidelity. Artifacts and caches are gitignored.
Diffstat (limited to 'tests/SomhairlesDream.Server.Tests/StoreTests.fs')
-rw-r--r--tests/SomhairlesDream.Server.Tests/StoreTests.fs236
1 files changed, 236 insertions, 0 deletions
diff --git a/tests/SomhairlesDream.Server.Tests/StoreTests.fs b/tests/SomhairlesDream.Server.Tests/StoreTests.fs
new file mode 100644
index 0000000..4aec16f
--- /dev/null
+++ b/tests/SomhairlesDream.Server.Tests/StoreTests.fs
@@ -0,0 +1,236 @@
+namespace SomhairlesDream.Server.Tests
+
+open System
+open Xunit
+open SomhairlesDream.Shared
+open SomhairlesDream.Server
+
+module StoreTests =
+ let private at hour = DateTimeOffset(2026, 9, 20, hour, 0, 0, 0, TimeSpan.Zero)
+
+ let private artifactIds : RunIds =
+ { ProjectId = "heritage-001"
+ RunId = "run-20260920-001"
+ BaseId = "base-000"
+ TargetId = "target-003" }
+
+ let private mesh version label =
+ { Version = version
+ Label = label
+ Vertices =
+ [| { X = 0.; Y = 0.; Z = 0. }
+ { X = float version; Y = 1.; Z = 0. } |]
+ Faces = [||] }
+
+ [<Fact>]
+ let ``store publishes the latest state atomically`` () =
+ let store = RunStore("heritage-001", "run-001", TimeSpan.FromMinutes 2.)
+
+ let running = store.Start(at 9)
+ let published = store.Publish(at 9, mesh running.TargetVersion "主承力骨架")
+
+ Assert.Equal(RunStatus.Succeeded, published.Status)
+ Assert.Equal(published, store.Snapshot())
+ Assert.Equal(1, published.CurrentVersion)
+
+ [<Fact>]
+ let ``store marks an unresponsive run stale when observed`` () =
+ let store = RunStore("heritage-001", "run-001", TimeSpan.FromMinutes 2.)
+ store.Start(at 9) |> ignore
+
+ let observed = store.Observe(at 10)
+
+ Assert.Equal(RunStatus.Stale, observed.Status)
+ Assert.Equal("心跳超时,等待重连", observed.Message)
+
+ [<Fact>]
+ let ``store sends an initial snapshot and every transition to subscribers`` () =
+ let store = RunStore("heritage-001", "run-001", TimeSpan.FromMinutes 2.)
+ let reader = store.Subscribe()
+
+ let initial = reader.ReadAsync().AsTask().GetAwaiter().GetResult()
+ let running = store.Start(at 9)
+ let update = reader.ReadAsync().AsTask().GetAwaiter().GetResult()
+
+ Assert.Equal(RunStatus.Idle, initial.Status)
+ Assert.Equal(running, update)
+
+ [<Fact>]
+ let ``artifact store applies lifecycle events to a run snapshot`` () =
+ let store = ArtifactRunStore(artifactIds, TimeSpan.FromSeconds 15., at 9)
+
+ let start =
+ RunEvent.Start
+ { Ids = artifactIds
+ At = at 9
+ TotalSteps = 3 }
+
+ let checkpoint =
+ RunEvent.Checkpoint
+ { Ids = artifactIds
+ At = at 9
+ StepId = "01-foundation"
+ StepIndex = 0
+ TotalSteps = 3
+ Message = "artifact verified"
+ ArtifactPath = "steps/01-foundation.glb" }
+
+ Assert.True(store.Apply(start) |> Result.isOk)
+ Assert.True(store.Apply(checkpoint) |> Result.isOk)
+
+ let snapshot = store.Snapshot()
+
+ Assert.Equal("running", snapshot.Status)
+ Assert.Equal(artifactIds.BaseId, snapshot.BaseId)
+ Assert.Equal(artifactIds.TargetId, snapshot.TargetId)
+ Assert.Equal(Some "01-foundation", snapshot.CurrentStepId)
+ Assert.Equal(0, snapshot.CurrentStepIndex)
+ Assert.Equal(3, snapshot.TotalSteps)
+ Assert.True(snapshot.ManifestPath.IsNone)
+ Assert.False(snapshot.IsStale)
+
+ [<Fact>]
+ let ``artifact store derives staleness without changing lifecycle status`` () =
+ let store = ArtifactRunStore(artifactIds, TimeSpan.FromSeconds 15., at 9)
+
+ store.Apply(
+ RunEvent.Start
+ { Ids = artifactIds
+ At = at 9
+ TotalSteps = 3 }
+ )
+ |> ignore
+
+ let snapshot = store.Observe(at 10)
+
+ Assert.Equal("running", snapshot.Status)
+ Assert.True(snapshot.IsStale)
+
+ [<Fact>]
+ let ``artifact store rejects lifecycle events after completion`` () =
+ let store = ArtifactRunStore(artifactIds, TimeSpan.FromSeconds 15., at 9)
+
+ store.Apply(
+ RunEvent.Start
+ { Ids = artifactIds
+ At = at 9
+ TotalSteps = 3 }
+ )
+ |> ignore
+
+ for index, stepId in [| 0, "01-foundation"; 1, "02-frame"; 2, "03-cabin" |] do
+ store.Apply(
+ RunEvent.Checkpoint
+ { Ids = artifactIds
+ At = at 9
+ StepId = stepId
+ StepIndex = index
+ TotalSteps = 3
+ Message = "artifact verified"
+ ArtifactPath = $"steps/{stepId}.glb" }
+ )
+ |> ignore
+
+ store.Apply(
+ RunEvent.Complete
+ { Ids = artifactIds
+ At = at 9
+ ManifestPath = "manifest.json" }
+ )
+ |> ignore
+
+ let result =
+ store.Apply(
+ RunEvent.Heartbeat
+ { Ids = artifactIds
+ At = at 9
+ Message = "late heartbeat" }
+ )
+
+ Assert.True(result |> Result.isError)
+
+ [<Fact>]
+ let ``artifact store rejects completion before every checkpoint`` () =
+ let store = ArtifactRunStore(artifactIds, TimeSpan.FromSeconds 15., at 9)
+
+ store.Apply(
+ RunEvent.Start
+ { Ids = artifactIds
+ At = at 9
+ TotalSteps = 3 }
+ )
+ |> ignore
+
+ let result =
+ store.Apply(
+ RunEvent.Complete
+ { Ids = artifactIds
+ At = at 9
+ ManifestPath = "manifest.json" }
+ )
+
+ Assert.True(result |> Result.isError)
+ Assert.Equal("running", store.Snapshot().Status)
+
+ [<Fact>]
+ let ``artifact store records a pipeline failure before start`` () =
+ let store = ArtifactRunStore(artifactIds, TimeSpan.FromSeconds 15., at 9)
+
+ let result =
+ store.Apply(
+ RunEvent.Fail
+ { Ids = artifactIds
+ At = at 9
+ StepId = None
+ Message = "run directory already exists" }
+ )
+
+ Assert.True(result |> Result.isOk)
+ Assert.Equal("failed", store.Snapshot().Status)
+ Assert.Equal(Some "run directory already exists", store.Snapshot().Error)
+
+ [<Fact>]
+ let ``artifact store accepts completion after ordered checkpoints`` () =
+ let store = ArtifactRunStore(artifactIds, TimeSpan.FromSeconds 15., at 9)
+
+ store.Apply(
+ RunEvent.Start
+ { Ids = artifactIds
+ At = at 9
+ TotalSteps = 3 }
+ )
+ |> ignore
+
+ for index, stepId in [| 0, "01-foundation"; 1, "02-frame"; 2, "03-cabin" |] do
+ store.Apply(
+ RunEvent.Checkpoint
+ { Ids = artifactIds
+ At = at 9
+ StepId = stepId
+ StepIndex = index
+ TotalSteps = 3
+ Message = "artifact verified"
+ ArtifactPath = $"steps/{stepId}.glb" }
+ )
+ |> ignore
+
+ let result =
+ store.Apply(
+ RunEvent.Complete
+ { Ids = artifactIds
+ At = at 9
+ ManifestPath = "manifest.json" }
+ )
+
+ Assert.True(result |> Result.isOk)
+ Assert.Equal("complete", store.Snapshot().Status)
+
+ [<Fact>]
+ let ``artifact registry atomically creates only one store for a run key`` () =
+ let registry = ArtifactRunRegistry(TimeSpan.FromSeconds 15., fun () -> at 9)
+
+ let first = registry.TryCreate(artifactIds)
+ let duplicate = registry.TryCreate(artifactIds)
+
+ Assert.True(first.IsSome)
+ Assert.True(duplicate.IsNone)