controllogic: add Graph.StateVars declarations (persisted via store JSON)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -72,6 +72,10 @@ type Graph struct {
|
|||||||
Nodes []Node `json:"nodes"`
|
Nodes []Node `json:"nodes"`
|
||||||
Wires []Wire `json:"wires"`
|
Wires []Wire `json:"wires"`
|
||||||
Groups []NodeGroup `json:"groups,omitempty"`
|
Groups []NodeGroup `json:"groups,omitempty"`
|
||||||
|
// StateVars declares graph-local variables (scalar or array). Live values are
|
||||||
|
// instantiated in memory per generation from these declarations; only the
|
||||||
|
// declarations persist. Mirrors the panel-logic statevars feature.
|
||||||
|
StateVars []StateVar `json:"statevars,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Node) param(key string) string {
|
func (n Node) param(key string) string {
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package controllogic
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestStoreRoundTripStateVars(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
st, err := NewStore(dir) // NewStore takes the storage DIRECTORY
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
g := Graph{
|
||||||
|
ID: "g1",
|
||||||
|
Name: "with-vars",
|
||||||
|
StateVars: []StateVar{
|
||||||
|
{Name: "count", Type: "number", Initial: "0"},
|
||||||
|
{Name: "buf", Type: "array", Initial: "[1,2]", Elem: "number", Sizing: "capped", Capacity: 5},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := st.Save(g); err != nil { // Save returns only error
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
st2, err := NewStore(dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
got, err := st2.Get("g1") // Get returns (Graph, error); ErrNotFound if absent
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(got.StateVars) != 2 || got.StateVars[1].Name != "buf" || got.StateVars[1].Capacity != 5 {
|
||||||
|
t.Fatalf("statevars not round-tripped: %#v", got.StateVars)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user