feat: API skeleton, SSE, staffing and tests

This commit is contained in:
Noel Sabia committed 2026-11-14 04:23:43 +01:00
1 parent 907164f972
commit f284969a4b
14 files changed
+1355 -54

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
package scenario
import (
"sync"
"testing"
"pulsecast/api/internal/model"
)
func TestNewAndSet(t *testing.T) {
state := New()
initial := state.Get()
if initial.Version != 1 || initial.Scenario.Scenario != "base" {
t.Fatalf("initial state=%+v", initial)
}
if initial.At.IsZero() {
t.Fatal("initial timestamp is zero")
}
next := state.Set(model.ScenarioInput{
Scenario: "sunny-saturday-market",
Weather: model.WeatherInput{TempDeltaC: 4, PrecipMM: 0},
Event: model.EventInput{Type: "market", Uplift: 0.2},
})
if next.Version != 2 || next.Scenario.Scenario != "sunny-saturday-market" {
t.Fatalf("next state=%+v", next)
}
if got := state.Get(); got.Version != 2 || got.Scenario.Weather.TempDeltaC != 4 {
t.Fatalf("Get after Set=%+v", got)
}
}
func TestConcurrentSetProducesUniqueVersions(t *testing.T) {
state := New()
const writers = 50
var wg sync.WaitGroup
wg.Add(writers)
for i := 0; i < writers; i++ {
go func() {
defer wg.Done()
state.Set(model.ScenarioInput{Scenario: "base"})
}()
}
wg.Wait()
if got := state.Get().Version; got != writers+1 {
t.Fatalf("version=%d, want %d", got, writers+1)
}
}