S6 settings: read a setting by its key in a process and a bundle

The node-engine composes each config value as MESH_CONFIG_<KEY>, 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
This commit is contained in:
2026-11-21 23:23:15 +01:00
parent ab05031e9a
commit 6d290eb46b
2 changed files with 49 additions and 0 deletions
+16
View File
@@ -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)
}
+33
View File
@@ -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_<KEY>, 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
}