From 4e520bffe413fca431ea6147b9d5441ea6eaa403 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 17:11:40 +0100 Subject: [PATCH] H6 fingerprint-for-daemons: only a daemon whose want names a fingerprint is handed MESH_FINGERPRINT Builds: design 47 H2 H-A-710 (1) (hq 27369077) --- internal/compositions/compare_test.go | 30 ++++++++++++++--- internal/compositions/composed.go | 46 +++++++++++++++++++++------ 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/internal/compositions/compare_test.go b/internal/compositions/compare_test.go index 434deff4..aedf8596 100644 --- a/internal/compositions/compare_test.go +++ b/internal/compositions/compare_test.go @@ -167,12 +167,12 @@ func TestComparingCompositions(t *testing.T) { t.Errorf("a composition not run is added: %+v", c) } - // Design 47, *The fingerprint handover* (the composed resources are split here): a daemon or a container of a module + // Design 47, *The fingerprint handover* (the composed resources are split here), H2 H-A-710 (1): a daemon of a module // is started with MESH_FINGERPRINT, the fingerprint of the want it applies, over any value its module declared of that - // name; a file, or a resource of no module, carries none. + // name; a container, a file, or a resource of no module, carries none. split, err := Split("novox", []json.RawMessage{ json.RawMessage(`{"id":"d","type":"process","module":"nats","run":["x"],"env":{"A":"1","MESH_FINGERPRINT":"stale"}}`), - json.RawMessage(`{"id":"c","type":"container","module":"nats","image":"i"}`), + json.RawMessage(`{"id":"c","type":"container","module":"nats","image":"i","env":{"MESH_FINGERPRINT":"stale","B":"2"}}`), file("conf", "a"), json.RawMessage(`{"id":"own","type":"process","run":["x"]}`), }, map[string]string{"nats": fp}, nil, NodeOwn{}) @@ -192,10 +192,10 @@ func TestComparingCompositions(t *testing.T) { } _ = json.Unmarshal(raw, &r) want := fp - if r.ID == "conf" { + if r.ID == "conf" || r.ID == "c" { want = "" } - if r.Env[FingerprintVar] != want || (r.ID == "d" && r.Env["A"] != "1") { + if r.Env[FingerprintVar] != want || (r.ID == "d" && r.Env["A"] != "1") || (r.ID == "c" && r.Env["B"] != "2") { t.Errorf("%s starts with %v, want %s=%q and its own words kept", r.ID, r.Env, FingerprintVar, want) } } @@ -205,6 +205,26 @@ func TestComparingCompositions(t *testing.T) { } } + // H-A-710 (1): a daemon whose want names no fingerprint composes none, its declared value taken out and said once per + // module and node-engine process; a container's declared value likewise, and an env left empty goes. + var said []string + wasJournal := journal + t.Cleanup(func() { journal = wasJournal }) + journal = func(line string) { said = append(said, line) } + takenOutSaid.Clear() + for range 2 { + for kind, in := range map[string]string{"process": `{"id":"d","type":"process","module":"nats","run":["x"],"env":{"A":"1","MESH_FINGERPRINT":"stale"}}`, + "container": `{"id":"c","type":"container","module":"nats","image":"i","env":{"MESH_FINGERPRINT":"stale"}}`} { + got, err := withFingerprint(json.RawMessage(in), kind, "nats", "") + if err != nil || strings.Contains(string(got), FingerprintVar) || (kind == "container" && strings.Contains(string(got), "env")) { + t.Errorf("a %s with no fingerprint composed %s, %v", kind, got, err) + } + } + } + if len(said) != 1 || !strings.Contains(said[0], "nats") { + t.Errorf("said %q, want one line for the module", said) + } + // §519, §618: the tool runner's process hands each bundle's module its own want's fingerprint in the words of its // bundles, a module with bundles and no words included, and the runner's own fingerprint reaches no other module's. fpLamp, fpBare := "src2:"+strings.Repeat("1", 64), "src2:"+strings.Repeat("2", 64) diff --git a/internal/compositions/composed.go b/internal/compositions/composed.go index 5d1d730b..a02a2f2a 100644 --- a/internal/compositions/composed.go +++ b/internal/compositions/composed.go @@ -3,8 +3,10 @@ package compositions import ( "encoding/json" "fmt" + "os" "regexp" "strings" + "sync" "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" @@ -239,7 +241,7 @@ func Split(node string, resources []json.RawMessage, fps map[string]string, fill pathOf[head.Path] = key } if head.Module != "" { - if raw, err = withFingerprint(raw, head.Type, fps[head.Module]); err != nil { + if raw, err = withFingerprint(raw, head.Type, head.Module, fps[head.Module]); err != nil { return nil, err } if raw, err = withBundleFingerprints(raw, head.Type, fps); err != nil { @@ -262,16 +264,24 @@ func Split(node string, resources []json.RawMessage, fps map[string]string, fill return out, nil } -// FingerprintVar is the environment value every process the node-engine starts, a daemon or a container, holds: the -// fingerprint of the want it applies. mesh-sdk's runtime reads it once at the process's start as the process's own build -// (novox/hq ADR 0656 §1, design 47 *The fingerprint handover*). +// FingerprintVar is the environment value every daemon the node-engine starts holds: the fingerprint of the want it +// applies. mesh-sdk's runtime reads it once at the process's start as the process's own build (novox/hq ADR 0656 §1, +// design 47 *The fingerprint handover*). A container is handed none (H-A-710). const FingerprintVar = "MESH_FINGERPRINT" -// withFingerprint is raw, when it is a daemon or a container, with FingerprintVar in its env set to fp. The value is -// the node-engine's to say, so one a module declared of that name is replaced. Another resource, or no fingerprint, is -// returned as it is. -func withFingerprint(raw json.RawMessage, kind, fp string) (json.RawMessage, error) { - if fp == "" || (kind != string(declaration.TypeProcess) && kind != string(declaration.TypeContainer)) { +// journal says one line in the node-engine's journal (its standard error); a variable so a test reads what was said. +var journal = func(line string) { fmt.Fprintf(os.Stderr, "mesh-host: %s\n", line) } + +// takenOutSaid is each module a value of FingerprintVar taken out of an env was said for, once per node-engine process. +var takenOutSaid sync.Map + +// withFingerprint is raw with FingerprintVar in its env set to fp when it is a daemon and the want names a fingerprint +// (design 47 H2, H-A-710 (1)). The value is the node-engine's to say, so one a module declared of that name is replaced. +// A container is handed none, and a daemon whose want names none no more, so no process reports a build it was never +// handed: a value of that name in such an env is taken out, said once per module and node-engine process. Another +// resource is returned as it is. +func withFingerprint(raw json.RawMessage, kind, module, fp string) (json.RawMessage, error) { + if kind != string(declaration.TypeProcess) && kind != string(declaration.TypeContainer) { return raw, nil } var fields map[string]json.RawMessage @@ -284,7 +294,23 @@ func withFingerprint(raw json.RawMessage, kind, fp string) (json.RawMessage, err return nil, fmt.Errorf("compositions: the env of a %s resource is not words by name: %w", kind, err) } } - env[FingerprintVar] = fp + if kind == string(declaration.TypeProcess) && fp != "" { + env[FingerprintVar] = fp + } else { + declared, has := env[FingerprintVar] + if !has { + return raw, nil + } + delete(env, FingerprintVar) + if _, said := takenOutSaid.LoadOrStore(module, true); !said { + journal(fmt.Sprintf("%s: %s is taken out of the env of a %s it declares (%q): the node-engine hands it to a daemon whose want names a fingerprint, and to nothing else (H-A-710)", + module, FingerprintVar, kind, declared)) + } + } + if len(env) == 0 { + delete(fields, "env") + return json.Marshal(fields) + } body, err := json.Marshal(env) if err != nil { return nil, err