summaryrefslogtreecommitdiff
path: root/tests/SomhairlesDream.Shared.Tests/RunStateTests.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.Shared.Tests/RunStateTests.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.Shared.Tests/RunStateTests.fs')
-rw-r--r--tests/SomhairlesDream.Shared.Tests/RunStateTests.fs62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/SomhairlesDream.Shared.Tests/RunStateTests.fs b/tests/SomhairlesDream.Shared.Tests/RunStateTests.fs
new file mode 100644
index 0000000..08e4e89
--- /dev/null
+++ b/tests/SomhairlesDream.Shared.Tests/RunStateTests.fs
@@ -0,0 +1,62 @@
+namespace SomhairlesDream.Shared.Tests
+
+open System
+open Xunit
+open SomhairlesDream.Shared
+
+module RunStateTests =
+ let private at hour = DateTimeOffset(2026, 9, 20, hour, 0, 0, 0, TimeSpan.Zero)
+
+ [<Fact>]
+ let ``a new run is idle with no design work scheduled`` () =
+ let snapshot = RunState.initial "heritage-001" "run-001" (at 8)
+
+ Assert.Equal("heritage-001", snapshot.ProjectId)
+ Assert.Equal("run-001", snapshot.RunId)
+ Assert.Equal(RunStatus.Idle, snapshot.Status)
+ Assert.Equal(0, snapshot.CurrentVersion)
+ Assert.Equal(0, snapshot.TargetVersion)
+ Assert.False(snapshot.NextDesignRunScheduled)
+ Assert.Equal("等待设计运行", snapshot.Message)
+
+ [<Fact>]
+ let ``starting a run increments the target version and heartbeat keeps it running`` () =
+ let started =
+ RunState.initial "heritage-001" "run-001" (at 8)
+ |> RunState.start (at 9)
+
+ let alive = RunState.heartbeat (at 9) started
+
+ Assert.Equal(RunStatus.Running, alive.Status)
+ Assert.Equal(1, alive.TargetVersion)
+ Assert.Equal(Some(at 9), alive.HeartbeatAt)
+
+ [<Fact>]
+ let ``a running run becomes stale after the heartbeat window`` () =
+ let started =
+ RunState.initial "heritage-001" "run-001" (at 8)
+ |> RunState.start (at 9)
+
+ let stale = RunState.statusAt (TimeSpan.FromMinutes 2.) (at 10) started
+
+ Assert.Equal(RunStatus.Stale, stale.Status)
+ Assert.Equal("心跳超时,等待重连", stale.Message)
+
+ [<Fact>]
+ let ``publishing a mesh records the current version and makes the run successful`` () =
+ let started =
+ RunState.initial "heritage-001" "run-001" (at 8)
+ |> RunState.start (at 9)
+
+ let mesh =
+ { Version = 1
+ Label = "基础结构"
+ Vertices = [| { X = 0.; Y = 0.; Z = 0. } |]
+ Faces = [||] }
+
+ let published = RunState.publish (at 9) mesh started
+
+ Assert.Equal(RunStatus.Succeeded, published.Status)
+ Assert.Equal(1, published.CurrentVersion)
+ Assert.Equal(Some mesh, published.Mesh)
+ Assert.Equal("已发布基础结构", published.Message)