Files
mesh-sdk/go/process/keeps_test.go
T
jschoubben 57d2f31f05 Let a module's code announce the states it keeps, in Go and TypeScript (issue 1790, S10, ADR 0495 §2 §5)
process.Conn.Keeps, stdio.Keeps and the TypeScript keeps publish the announcement on
the module's own subject; afterwards a state the code did not announce is refused at
the call, so announcement and code cannot drift. The package goes to 0.1.15 for keeps.
2026-10-22 17:42:24 +02:00

29 lines
1.1 KiB
Go

package process
import (
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/announce"
)
// After Keeps a process binds only the states it announced (novox/hq ADR 0495 clause 5): any other of its module's
// states is refused at the call, naming it, before the bus is asked; before Keeps nothing is refused.
func TestAProcessBindsOnlyTheStatesItAnnounced(t *testing.T) {
c := &Conn{account: Account{Module: "mesh-mail", Node: "novox"}}
if err := c.remember([]announce.State{{Name: "accounts", Readable: true}}); err != nil {
t.Fatal(err)
}
_, err := c.State("drafts").Get("k")
if err == nil || !strings.Contains(err.Error(), `"drafts"`) || !strings.Contains(err.Error(), "Keeps") {
t.Fatalf("an unannounced state was bound: %v", err)
}
if err := c.remember([]announce.State{{Name: "a_b"}}); err == nil {
t.Fatal("an announcement no bucket could be named by was accepted")
}
got, err := announce.Decode(c.announced)
if err != nil || got.Module != "mesh-mail" || got.Node != "novox" || !got.Readable("accounts") {
t.Fatalf("the announcement is %s (%v)", c.announced, err)
}
}