From 6d290eb46b71ef96bba5c17acdebedde815499e9 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 23:23:15 +0100 Subject: [PATCH] S6 settings: read a setting by its key in a process and a bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The node-engine composes each config value as MESH_CONFIG_, in a process's environment and the module's tool-runner slice alike; stdio.Setting and SettingDuration read it, the one reader both sides use. Builds: design 47 H2 §781; H-A-350 DMC-13, H-A-370 --- go/caller_test.go | 16 ++++++++++++++++ go/settings.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 go/settings.go diff --git a/go/caller_test.go b/go/caller_test.go index 81c7a9f6..81ec0f1c 100644 --- a/go/caller_test.go +++ b/go/caller_test.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/json" "io" + "strings" "testing" "time" @@ -105,6 +106,21 @@ func TestAToolReadsTheCallerTheRuntimeNamed(t *testing.T) { if CallIDOf(map[string]any{"x": 1}) != "" || CallIDOf(nil) != "" { t.Error("arguments no call was handed have a call id") } + // Design 47 H2 §781, H-A-370: a process and a bundle read a setting by its key from the word the node-engine composes. + t.Setenv("MESH_CONFIG_ASK_UNANSWERED_BOUND", "10m") + t.Setenv("MESH_CONFIG_KEPT_CALL_PACE_FIRST", "soon") + if v, ok := Setting("ask-unanswered-bound"); !ok || v != "10m" { + t.Errorf("the setting read %q, %v", v, ok) + } + if d, err := SettingDuration("ask-unanswered-bound", time.Minute); err != nil || d != 10*time.Minute { + t.Errorf("the duration read %s, %v", d, err) + } + if d, err := SettingDuration("compose-ask-bound", 10*time.Second); err != nil || d != 10*time.Second { + t.Errorf("an absent setting read %s, %v, not its default", d, err) + } + if _, err := SettingDuration("kept-call-pace-first", time.Second); err == nil || !strings.Contains(err.Error(), "kept-call-pace-first") { + t.Errorf("a value that is no duration read as %v", err) + } if MetaCall != buscalls.MetaCall { t.Errorf("the call id's place is %q here and %q in buscalls", MetaCall, buscalls.MetaCall) } diff --git a/go/settings.go b/go/settings.go new file mode 100644 index 00000000..fad54cc3 --- /dev/null +++ b/go/settings.go @@ -0,0 +1,33 @@ +package stdio + +import ( + "fmt" + "os" + "strings" + "time" +) + +// SettingWord is the environment word the node-engine composes a module's config value key into, in a process's +// environment and in the module's slice of the tool runner's MESH_TOOL_ENV alike (design 47 H2 §781; H-A-370): +// MESH_CONFIG_, the key upper-cased with '-' and '.' written '_', holding the value as text. +func SettingWord(key string) string { + return "MESH_CONFIG_" + strings.ToUpper(strings.NewReplacer("-", "_", ".", "_").Replace(key)) +} + +// Setting is the module's config value key as the node-engine composed it, and whether it composed one: the one +// settings reader of a process and a bundle (§781). +func Setting(key string) (string, bool) { return os.LookupEnv(SettingWord(key)) } + +// SettingDuration is the config value key read as a Go duration ("10m"): def when none is composed or it is empty, an +// error naming the key for a value that is no duration above zero. +func SettingDuration(key string, def time.Duration) (time.Duration, error) { + v, ok := Setting(key) + if v = strings.TrimSpace(v); !ok || v == "" { + return def, nil + } + d, err := time.ParseDuration(v) + if err != nil || d <= 0 { + return 0, fmt.Errorf("the setting %s (%s) holds %q, which is not a duration above zero", key, SettingWord(key), v) + } + return d, nil +}