S2 sdk-process-bus-consumes: a process's bus may name consumes

Builds: design 47 G A-340, §50 (A-343, A-344)

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
2026-11-13 11:36:20 +01:00
parent 4e21bae65a
commit 9ac5ba2364
2 changed files with 26 additions and 1 deletions
+4 -1
View File
@@ -19,6 +19,9 @@ type ProcessBus struct {
// Emits are the events this process emits, named locally, as the module's own Emits names them
// (EmitsAll): a process emits only what its module may emit as a whole.
Emits []string `json:"emits,omitempty"`
// Consumes are the events this process hears, each as its module's `consumes` names it: only an event its module
// consumes (design 47 G A-340, after design 42 zfs-owns-zfs V5 and G1).
Consumes []string `json:"consumes,omitempty"`
// Queues are the module's own work-queue streams (ADR 0436 §6) this process consumes.
Queues []string `json:"queues,omitempty"`
// State is the module's own state, by local name, this process reads and writes.
@@ -97,7 +100,7 @@ func (b *ProcessBus) UnmarshalJSON(raw []byte) error {
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&p); err != nil {
return fmt.Errorf("a process's bus is {emits, queues, state, asks, invokes, keeps}: %w", typedUnknown(err))
return fmt.Errorf("a process's bus is {emits, consumes, queues, state, asks, invokes, keeps}: %w", typedUnknown(err))
}
*b = ProcessBus(p)
return nil
+22
View File
@@ -1,5 +1,10 @@
package catalogue
import (
"encoding/json"
"testing"
)
func strSliceEqual(a, b []string) bool {
if len(a) != len(b) {
return false
@@ -11,3 +16,20 @@ func strSliceEqual(a, b []string) bool {
}
return true
}
// Design 47 G A-340: a process's bus names the events it hears under `consumes`; a bus of today reads as today and an
// unknown key is still refused.
func TestAProcessBusMayNameWhatItConsumes(t *testing.T) {
var heard ProcessBus
if err := json.Unmarshal([]byte(`{"emits":["a"],"consumes":["mesh-conditions.findings-asked"]}`), &heard); err != nil ||
!strSliceEqual(heard.Consumes, []string{"mesh-conditions.findings-asked"}) || !strSliceEqual(heard.Emits, []string{"a"}) {
t.Errorf("a bus's consumes read as %v (%v)", heard.Consumes, err)
}
var today ProcessBus
if err := json.Unmarshal([]byte(`{"emits":["a"],"queues":["q"]}`), &today); err != nil || len(today.Consumes) != 0 {
t.Errorf("a bus of today read as %+v (%v)", today, err)
}
if err := json.Unmarshal([]byte(`{"hears":["x"]}`), &ProcessBus{}); err == nil {
t.Error("an unknown key was accepted")
}
}