From ad4325082963818247041d7bd1f2d35e81dbe7be Mon Sep 17 00:00:00 2001 From: R0ck Date: Sun, 25 Oct 2026 01:15:40 +0000 Subject: [PATCH 1/2] firmware: a build declares whether it takes MeshCore's console commands A build's settings gain dialect. A node running one that is not MeshCore's is not provisioned (the script is one comment saying why), and experiment.start refuses an arm that would pin a setting onto it. Settable at import, on firmware.update, and from the build's window. Closes #599. --- CHANGELOG.md | 6 ++ docs/firmware-build-settings.md | 20 ++++ docs/scripting-verbs.md | 6 +- docs/verb-reference.md | 6 +- docs/verbs.json | 13 ++- internal/app/session/dialect.go | 95 +++++++++++++++++++ internal/app/session/dialect_test.go | 65 +++++++++++++ internal/app/session/experiment/control.go | 6 ++ .../app/session/experiment/control.verbs.json | 2 +- .../app/session/firmwarelib/firmwarecache.go | 9 ++ .../firmwarelib/firmwarecache.verbs.json | 5 + .../app/session/firmwarelib/firmwaredetail.go | 25 ++++- .../firmwarelib/firmwaredetail.verbs.json | 6 ++ internal/app/session/provisioning.go | 4 +- internal/firmware/buildsettings.go | 16 ++++ internal/ui/workbench/firmwarewindow.go | 5 + .../ui/workbench/firmwarewindowsettings.go | 25 +++++ pkg/client-go/meshbench/firmware.go | 9 +- pkg/client-go/meshbench/types.go | 7 +- pkg/client-js/lib/firmware.mjs | 3 +- pkg/client-python/meshbench/parts.py | 9 +- pkg/client-python/meshbench/types.py | 3 + 22 files changed, 330 insertions(+), 15 deletions(-) create mode 100644 internal/app/session/dialect.go create mode 100644 internal/app/session/dialect_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index a38e02b4..8774983a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,12 @@ had changed in them - which is the gap this file exists to close. ### Added +- **A build says whether it takes MeshCore's console commands.** A firmware + that is not MeshCore is no longer sent provisioning it refuses line by line, + and an experiment arm that would pin a setting onto one is refused before + the run rather than producing cells that differ by nothing. `dialect` on + `firmware.import`, `firmware.update` and `firmware.details`, and a switch + in the build's window. - **Script input at an instant of simulated time.** `console.type`, `console.cli` and the `companion.*` verbs that write to a node take `at_ms`: the call is held and runs when the run reaches that instant, so a script diff --git a/docs/firmware-build-settings.md b/docs/firmware-build-settings.md index de66706a..eb0bb18c 100644 --- a/docs/firmware-build-settings.md +++ b/docs/firmware-build-settings.md @@ -104,6 +104,26 @@ the card with nothing saying why. **Verbs:** `node.card {node, fitted, file, wipe}`, and `firmware.wipe` for all of them at once. +## Takes MeshCore's console commands + +On by default. Provisioning, and every setting an experiment arm pins, is +MeshCore's command line typed at the node's console: `set name`, `set lat`, +`region put`, and so on. A firmware that is not MeshCore refuses each line, and +the only trace was a line in its console: + +``` +set name Deck Error: unknown config: name Deck +``` + +Off, a node running this build is sent none of it. The Provisioning panel says +so in place of the script, and `experiment.start` refuses an arm that would pin +a setting onto such a node, because a setting that did not apply makes two +cells that differ by nothing. + +The verbs call it `dialect`: `meshcore`, `none`, or another firmware's name. +`firmware.import` takes it too, so a third-party image is never provisioned on +its first run. + ## Notes `notes` diff --git a/docs/scripting-verbs.md b/docs/scripting-verbs.md index 29e6554d..5bca3547 100644 --- a/docs/scripting-verbs.md +++ b/docs/scripting-verbs.md @@ -207,10 +207,10 @@ Two verbs are **not** in this table: | `firmware.build_failed` | — | — | *none* — the build worker telling the store it failed | | `firmware.built` | — | `built` | *none* — the build worker telling the store it finished | | `firmware.delete` | *a bare string*, `path` string | `deleted` | `wb.firmware.delete(build)` | -| `firmware.details` | *a bare string*, `version` string, `role` string, `board` string | `role`, `version`, `board`, `native`, `on_disk`, `path`, `settings_path`, `bytes`, `modified`, `in_use`, `kind`, `bootable`, `flash_mb`, `coproc_at_reset`, `card_required`, `notes` | `wb.firmware.details(build)` | +| `firmware.details` | *a bare string*, `version` string, `role` string, `board` string | `role`, `version`, `board`, `native`, `on_disk`, `path`, `settings_path`, `bytes`, `modified`, `in_use`, `kind`, `bootable`, `flash_mb`, `coproc_at_reset`, `card_required`, `dialect`, `notes` | `wb.firmware.details(build)` | | `firmware.download` | *a bare string*, `role` string, `version` string, `board` string | `downloading`, `role`, `version`, `board`, `job` | `wb.firmware.download(role, version, board=None)` | | `firmware.failed` | *a bare string*, `reason` string | — | *none* — the firmware starter reporting a failure | -| `firmware.import` | *a bare string*, `path` string, `role` string, `board` string, `label` string, `version` string | `version`, `role`, `board`, `path`, `bytes` | `wb.firmware.import_(path, role, board=None, label="")` | +| `firmware.import` | *a bare string*, `path` string, `role` string, `board` string, `label` string, `version` string, `dialect` string | `version`, `role`, `board`, `path`, `bytes` | `wb.firmware.import_(path, role, board=None, label="")` | | `firmware.installed` | — | `cache`, `installed` | `wb.firmware.installed` | | `firmware.library` | — | `builds`, `count` | `wb.firmware.library` | | `firmware.needed` | — | `roles` | `wb.firmware.needed()` | @@ -220,7 +220,7 @@ Two verbs are **not** in this table: | `firmware.start` | — | `starting` | `wb.firmware.start()` | | `firmware.started` | — | `running`, `playing` | *none* — the firmware starter reporting back | | `firmware.state` | — | `running`, `nodes`, `total`, `starting` | `wb.firmware.state() / wb.firmware.wait_started()` | -| `firmware.update` | *a bare string*, `version` string, `role` string, `board` string, `label` string, `new_role` string, `new_board` string, `card_required` bool, `coproc_at_reset` bool, `notes` string | `role`, `version`, `board`, `path`, `renamed`, `repinned`, `settings` | `wb.firmware.update(build, label=\|new_role=\|coproc_at_reset=\|notes=)` | +| `firmware.update` | *a bare string*, `version` string, `role` string, `board` string, `label` string, `new_role` string, `new_board` string, `card_required` bool, `coproc_at_reset` bool, `dialect` string, `notes` string | `role`, `version`, `board`, `path`, `renamed`, `repinned`, `settings` | `wb.firmware.update(build, label=\|new_role=\|coproc_at_reset=\|notes=)` | | `firmware.window` 🪟 | *a bare string*, `version` string, `role` string, `board` string | `role`, `version`, `board` | `wb.firmware.window(build)` | | `firmware.wipe` | — | `wiped`, `root`, `cards` | `wb.firmware.wipe()` | diff --git a/docs/verb-reference.md b/docs/verb-reference.md index 36e84e35..ee92946d 100644 --- a/docs/verb-reference.md +++ b/docs/verb-reference.md @@ -1763,7 +1763,7 @@ Report everything known about one build: where it is, what it is, and what has b | `role` | string | optional | which role, when one label carries more than one | | `board` | string | optional | which board; absent means a build for this machine | -**Answers** `role`, `version`, `board`, `native`, `on_disk`, `path`, `settings_path`, `bytes`, `modified`, `in_use`, `kind`, `bootable`, `flash_mb`, `coproc_at_reset`, `card_required`, `notes`. Answered from the library, so a published build nobody has fetched is described too: `on_disk` is then false and `path` and `bytes` are empty. `in_use` counts the nodes pinned to it, `kind`, `bootable` and `flash_mb` are read from a board image and say nothing about a native build, `settings_path` is where its settings would be written whether any exist or not, and `modified` is absent for a build not on this machine. A label naming more than one build is refused rather than guessed at. +**Answers** `role`, `version`, `board`, `native`, `on_disk`, `path`, `settings_path`, `bytes`, `modified`, `in_use`, `kind`, `bootable`, `flash_mb`, `coproc_at_reset`, `card_required`, `dialect`, `notes`. Answered from the library, so a published build nobody has fetched is described too: `on_disk` is then false and `path` and `bytes` are empty. `in_use` counts the nodes pinned to it, `kind`, `bootable` and `flash_mb` are read from a board image and say nothing about a native build, `settings_path` is where its settings would be written whether any exist or not, and `modified` is absent for a build not on this machine. A label naming more than one build is refused rather than guessed at. **Example** - find out where a build lives and what is running it @@ -1828,6 +1828,7 @@ Put somebody's own build into the library, which is how a change is tested again | `board` | string | optional | the board it is for; absent means a build for this machine | | `label` | string | optional | what the library will know it by and what a node pins; absent, it is stamped with a timestamp so a second import does not replace the first in place | | `version` | string | optional | an older name for `label`, read only when `label` is absent, because scripts written against it are already out in the world | +| `dialect` | string | optional | the console vocabulary the image speaks: meshcore, absent included, for MeshCore's own; none for a firmware with no console; or the name of another. A node running a build that is not MeshCore's is not sent provisioning, which it would refuse line by line | **Answers** `version`, `role`, `board`, `path`, `bytes`. `version` is the label the build was stored under, which is the timestamp when none was given and is what `firmware.set` then has to be handed. @@ -2006,6 +2007,7 @@ Rename a build, move it to another board or role, or change how it is run. | `new_board` | string | optional | move it to this board instead; unchanged when absent | | `card_required` | bool | optional | this firmware will not get far without storage in the board's slot, so every node running it is given a card whatever it would otherwise have had | | `coproc_at_reset` | bool | optional | start this build's coprocessors enabled, which the part does not do - for a firmware that traps inside its own exception vector and cannot be seen past | +| `dialect` | string | optional | the console vocabulary the build speaks: meshcore for MeshCore's own, none for no console, or another name; absent leaves it alone. Anything but meshcore means nodes running this build are not provisioned, and an experiment arm that pins settings onto one is refused | | `notes` | string | optional | what the next person should know about this build | **Answers** `role`, `version`, `board`, `path`, `renamed`, `repinned`, `settings`. The build's identity after the change comes back, with `renamed` saying whether the file actually moved and `repinned` how many nodes were pointed at the new name, which happens on their behalf so none is left naming a build nothing answers to. `settings` holds `coproc_at_reset`, `card_required` and `notes` as they now stand. Refused for a build not on this machine, and refused while a node is running it. @@ -3683,7 +3685,7 @@ Put every arm through every seed on a worker, each cell in its own engine with n **Takes** nothing. -**Answers** `running`, `runs`, `reproducible`, `not_reproducible_why`. `runs` is how many cells were queued. Poll experiment.state until `running` goes false. It refuses where a sweep is already running, where no network is loaded, where no sender has been named, and where the last sweep's cell in flight has not yet let go of the results table. `reproducible` is false where the network carries a node running in an emulator, whose firmware is stepped by the emulator's clock rather than by the run's: the cells then differ for reasons the matrix does not record, so the arms measure nothing against each other, and `not_reproducible_why` says which node, empty when there is none. The sweep still runs - a single arm on emulated firmware is a legitimate thing to watch - but a script comparing arms should stop here. +**Answers** `running`, `runs`, `reproducible`, `not_reproducible_why`. `runs` is how many cells were queued. Poll experiment.state until `running` goes false. It refuses where a sweep is already running, where no network is loaded, where no sender has been named, and where the last sweep's cell in flight has not yet let go of the results table. `reproducible` is false where the network carries a node running in an emulator, whose firmware is stepped by the emulator's clock rather than by the run's: the cells then differ for reasons the matrix does not record, so the arms measure nothing against each other, and `not_reproducible_why` says which node, empty when there is none. The sweep still runs - a single arm on emulated firmware is a legitimate thing to watch - but a script comparing arms should stop here. Refused before anything runs when an arm pins a setting onto a node whose firmware does not take MeshCore's console commands (`firmware.update` `dialect`), naming the arm and the nodes: the setting would not apply, and the cells would differ by nothing. **Example** - start the matrix that is defined diff --git a/docs/verbs.json b/docs/verbs.json index bc16e7ab..44a19eb9 100644 --- a/docs/verbs.json +++ b/docs/verbs.json @@ -1634,7 +1634,7 @@ "reproducible", "not_reproducible_why" ], - "answers": "`runs` is how many cells were queued. Poll experiment.state until `running` goes false. It refuses where a sweep is already running, where no network is loaded, where no sender has been named, and where the last sweep's cell in flight has not yet let go of the results table. `reproducible` is false where the network carries a node running in an emulator, whose firmware is stepped by the emulator's clock rather than by the run's: the cells then differ for reasons the matrix does not record, so the arms measure nothing against each other, and `not_reproducible_why` says which node, empty when there is none. The sweep still runs - a single arm on emulated firmware is a legitimate thing to watch - but a script comparing arms should stop here.", + "answers": "`runs` is how many cells were queued. Poll experiment.state until `running` goes false. It refuses where a sweep is already running, where no network is loaded, where no sender has been named, and where the last sweep's cell in flight has not yet let go of the results table. `reproducible` is false where the network carries a node running in an emulator, whose firmware is stepped by the emulator's clock rather than by the run's: the cells then differ for reasons the matrix does not record, so the arms measure nothing against each other, and `not_reproducible_why` says which node, empty when there is none. The sweep still runs - a single arm on emulated firmware is a legitimate thing to watch - but a script comparing arms should stop here. Refused before anything runs when an arm pins a setting onto a node whose firmware does not take MeshCore's console commands (`firmware.update` `dialect`), naming the arm and the nodes: the setting would not apply, and the cells would differ by nothing.", "example": { "params": {}, "what": "start the matrix that is defined" @@ -1876,6 +1876,7 @@ "flash_mb", "coproc_at_reset", "card_required", + "dialect", "notes" ], "answers": "Answered from the library, so a published build nobody has fetched is described too: `on_disk` is then false and `path` and `bytes` are empty. `in_use` counts the nodes pinned to it, `kind`, `bootable` and `flash_mb` are read from a board image and say nothing about a native build, `settings_path` is where its settings would be written whether any exist or not, and `modified` is absent for a build not on this machine. A label naming more than one build is refused rather than guessed at.", @@ -1966,6 +1967,11 @@ "name": "version", "type": "string", "what": "an older name for `label`, read only when `label` is absent, because scripts written against it are already out in the world" + }, + { + "name": "dialect", + "type": "string", + "what": "the console vocabulary the image speaks: meshcore, absent included, for MeshCore's own; none for a firmware with no console; or the name of another. A node running a build that is not MeshCore's is not sent provisioning, which it would refuse line by line" } ], "returns": [ @@ -2165,6 +2171,11 @@ "type": "bool", "what": "start this build's coprocessors enabled, which the part does not do - for a firmware that traps inside its own exception vector and cannot be seen past" }, + { + "name": "dialect", + "type": "string", + "what": "the console vocabulary the build speaks: meshcore for MeshCore's own, none for no console, or another name; absent leaves it alone. Anything but meshcore means nodes running this build are not provisioned, and an experiment arm that pins settings onto one is refused" + }, { "name": "notes", "type": "string", diff --git a/internal/app/session/dialect.go b/internal/app/session/dialect.go new file mode 100644 index 00000000..399e8d64 --- /dev/null +++ b/internal/app/session/dialect.go @@ -0,0 +1,95 @@ +// Which firmware takes MeshCore's console commands (#599). +// +// Provisioning, and every setting an experiment arm pins, is a run of MeshCore +// CLI lines typed at a node's console. A firmware that is not MeshCore refuses +// each of them, and the only trace was a line in its console somebody had to +// read - "set name Deck Error: unknown config". So a build can say what it +// speaks, a node running one that does not speak MeshCore's is not sent it, +// and an arm that would pin a setting onto one is refused before the run. +package session + +import ( + "fmt" + "sort" + "strings" + + "github.com/MeshBench/meshbench/internal/app/state" + "github.com/MeshBench/meshbench/internal/firmware" + "github.com/MeshBench/meshbench/internal/world/scenario" +) + +// dialectOf is the console vocabulary a node's build speaks, or "" for +// MeshCore's own. +func dialectOf(n scenario.Node, installed []firmware.Installed) string { + if n.Firmware.Version == "" { + return "" + } + for _, in := range installed { + if in.Board == n.Firmware.Board && in.Version == n.Firmware.Version { + if set := firmware.LoadBuildSettings(in.Path); !set.SpeaksMeshCore() { + return set.Dialect + } + return "" + } + } + return "" +} + +// withDialect is a node's provisioning script, or in place of it one line +// saying why there is none. +func withDialect(n scenario.Node, lines []state.ProvisionLine) []state.ProvisionLine { + d := dialectOf(n, firmware.ListInstalled(firmware.DefaultCacheDir())) + if d == "" { + return lines + } + return []state.ProvisionLine{{ + Command: fmt.Sprintf("# %s runs %s, which does not take MeshCore's console commands: "+ + "nothing is sent", n.Name, describeDialect(d)), + Why: "a build declares the console vocabulary it speaks, and this one is not MeshCore's", + Comment: true, + }} +} + +func describeDialect(d string) string { + if d == "none" { + return "a firmware with no console" + } + return d + " firmware" +} + +// PinsSettings reports whether this arm sets anything provisioning carries, as +// opposed to only choosing builds or timing. +func (a ExpArm) PinsSettings() bool { + return a.PathHashMode != nil || a.RepPathHash != nil || + a.LoopDetect != "" || a.CAD != "" || len(a.Set) > 0 +} + +// RefuseUnprovisionable says which arms would pin settings onto nodes whose +// firmware cannot take them, or "" when none would. Each node is judged on the +// build the arm runs it on. +func (s *Sim) RefuseUnprovisionable(arms []ExpArm, nodes []scenario.Node) string { + installed := firmware.ListInstalled(firmware.DefaultCacheDir()) + var bad []string + for _, arm := range arms { + if !arm.PinsSettings() { + continue + } + var names []string + for _, n := range nodes { + n = WithFirmware(n, SweepArm{RepeaterVersion: arm.RepeaterVersion, + CompanionVersion: arm.CompanionVersion}) + if d := dialectOf(n, installed); d != "" { + names = append(names, fmt.Sprintf("%s (%s)", n.Name, d)) + } + } + if len(names) > 0 { + sort.Strings(names) + bad = append(bad, fmt.Sprintf("arm %q pins settings onto %s", arm.Label, strings.Join(names, ", "))) + } + } + if len(bad) == 0 { + return "" + } + return strings.Join(bad, "; ") + ", whose firmware does not take MeshCore's console commands, " + + "so the settings would not apply and the cells would differ by nothing" +} diff --git a/internal/app/session/dialect_test.go b/internal/app/session/dialect_test.go new file mode 100644 index 00000000..71afc548 --- /dev/null +++ b/internal/app/session/dialect_test.go @@ -0,0 +1,65 @@ +package session + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/MeshBench/meshbench/internal/firmware" + "github.com/MeshBench/meshbench/internal/world/scenario" +) + +// deckWith installs a T-Deck build into a fresh cache, speaking dialect. +func deckWith(t *testing.T, version, dialect string) scenario.Node { + t.Helper() + cache := t.TempDir() + t.Setenv("XDG_CACHE_HOME", cache) + t.Setenv("LOCALAPPDATA", cache) + t.Setenv("HOME", cache) + dir := filepath.Join(firmware.DefaultCacheDir(), "board", "LilyGo_TDeck") + if err := os.MkdirAll(dir, 0o755); err != nil { + t.Fatal(err) + } + image := filepath.Join(dir, "companion_radio_usb@"+version+".bin") + if err := os.WriteFile(image, make([]byte, 64), 0o644); err != nil { + t.Fatal(err) + } + if dialect != "" { + if err := firmware.SaveBuildSettings(image, firmware.BuildSettings{Dialect: dialect}); err != nil { + t.Fatal(err) + } + } + return scenario.Node{Name: "Deck", Kind: scenario.Companion, + Firmware: scenario.FirmwareRef{Version: version, Board: "LilyGo_TDeck", Role: "companion_radio_usb"}} +} + +// A node whose build does not speak MeshCore's console is told why it is sent +// nothing, rather than sent lines it refuses (#599). +func TestAFirmwareThatIsNotMeshCoreIsNotProvisioned(t *testing.T) { + n := deckWith(t, "wadamesh", "wadamesh") + got := (&Sim{}).provisionLines(n) + if len(got) != 1 || !got[0].Comment || !strings.Contains(got[0].Command, "wadamesh firmware") { + t.Fatalf("provisioning for a wadamesh build: %+v", got) + } + + plain := deckWith(t, "v1.17.1", "") + if got := (&Sim{}).provisionLines(plain); len(got) < 2 { + t.Errorf("a MeshCore build lost its provisioning: %+v", got) + } +} + +// An arm that pins a setting onto such a node is refused before the run; an +// arm that only chooses builds is not (#599). +func TestAnArmPinningSettingsOntoForeignFirmwareIsRefused(t *testing.T) { + n := deckWith(t, "wadamesh", "none") + s := &Sim{} + mode := 1 + why := s.RefuseUnprovisionable([]ExpArm{{Label: "two-byte", PathHashMode: &mode}}, []scenario.Node{n}) + if !strings.Contains(why, `arm "two-byte"`) || !strings.Contains(why, "Deck (none)") { + t.Errorf("refusal: %q", why) + } + if why := s.RefuseUnprovisionable([]ExpArm{{Label: "builds", RepeaterVersion: "v1.17.1"}}, []scenario.Node{n}); why != "" { + t.Errorf("an arm pinning no settings was refused: %q", why) + } +} diff --git a/internal/app/session/experiment/control.go b/internal/app/session/experiment/control.go index 9847e087..389a2790 100644 --- a/internal/app/session/experiment/control.go +++ b/internal/app/session/experiment/control.go @@ -46,6 +46,12 @@ func registerExperimentControl(st *state.Store, s *session.Sim, e *experiment) { e.mu.Unlock() return nil, fmt.Errorf("experiment.start needs at least one sender") } + // Before the run, not in a log afterwards: a cell whose settings did + // not apply compares two configurations that were the same. + if why := s.RefuseUnprovisionable(e.Arms, s.Nodes()); why != "" { + e.mu.Unlock() + return nil, fmt.Errorf("refused: %s", why) + } // Refused rather than started alongside the last run's tail. Waiting // here is not open to us, and starting anyway is what raced stale cells // into a new run's table. diff --git a/internal/app/session/experiment/control.verbs.json b/internal/app/session/experiment/control.verbs.json index 87d27aee..d66e7453 100644 --- a/internal/app/session/experiment/control.verbs.json +++ b/internal/app/session/experiment/control.verbs.json @@ -7,7 +7,7 @@ "reproducible", "not_reproducible_why" ], - "answers": "`runs` is how many cells were queued. Poll experiment.state until `running` goes false. It refuses where a sweep is already running, where no network is loaded, where no sender has been named, and where the last sweep's cell in flight has not yet let go of the results table. `reproducible` is false where the network carries a node running in an emulator, whose firmware is stepped by the emulator's clock rather than by the run's: the cells then differ for reasons the matrix does not record, so the arms measure nothing against each other, and `not_reproducible_why` says which node, empty when there is none. The sweep still runs - a single arm on emulated firmware is a legitimate thing to watch - but a script comparing arms should stop here.", + "answers": "`runs` is how many cells were queued. Poll experiment.state until `running` goes false. It refuses where a sweep is already running, where no network is loaded, where no sender has been named, and where the last sweep's cell in flight has not yet let go of the results table. `reproducible` is false where the network carries a node running in an emulator, whose firmware is stepped by the emulator's clock rather than by the run's: the cells then differ for reasons the matrix does not record, so the arms measure nothing against each other, and `not_reproducible_why` says which node, empty when there is none. The sweep still runs - a single arm on emulated firmware is a legitimate thing to watch - but a script comparing arms should stop here. Refused before anything runs when an arm pins a setting onto a node whose firmware does not take MeshCore's console commands (`firmware.update` `dialect`), naming the arm and the nodes: the setting would not apply, and the cells would differ by nothing.", "example": { "params": {}, "what": "start the matrix that is defined" diff --git a/internal/app/session/firmwarelib/firmwarecache.go b/internal/app/session/firmwarelib/firmwarecache.go index f74cab94..a20d9c3c 100644 --- a/internal/app/session/firmwarelib/firmwarecache.go +++ b/internal/app/session/firmwarelib/firmwarecache.go @@ -99,6 +99,15 @@ func registerFirmwareCache(st *state.Store, s *session.Sim) { if err != nil { return nil, err } + // What the build speaks travels with it, so a third-party firmware is + // not sent MeshCore's provisioning the first time it is run. + if d, ok := session.NamedField(p, "dialect"); ok && normalDialect(d) != "" { + set := firmware.LoadBuildSettings(img.URL) + set.Dialect = normalDialect(d) + if err := firmware.SaveBuildSettings(img.URL, set); err != nil { + return nil, err + } + } fillLibrary(s, w) w.Say("imported " + img.Version + " as " + role) return map[string]any{ diff --git a/internal/app/session/firmwarelib/firmwarecache.verbs.json b/internal/app/session/firmwarelib/firmwarecache.verbs.json index 5e21093b..81eda4d8 100644 --- a/internal/app/session/firmwarelib/firmwarecache.verbs.json +++ b/internal/app/session/firmwarelib/firmwarecache.verbs.json @@ -89,6 +89,11 @@ "name": "version", "type": "string", "what": "an older name for `label`, read only when `label` is absent, because scripts written against it are already out in the world" + }, + { + "name": "dialect", + "type": "string", + "what": "the console vocabulary the image speaks: meshcore, absent included, for MeshCore's own; none for a firmware with no console; or the name of another. A node running a build that is not MeshCore's is not sent provisioning, which it would refuse line by line" } ], "returns": [ diff --git a/internal/app/session/firmwarelib/firmwaredetail.go b/internal/app/session/firmwarelib/firmwaredetail.go index 1765266c..a0f0defb 100644 --- a/internal/app/session/firmwarelib/firmwaredetail.go +++ b/internal/app/session/firmwarelib/firmwaredetail.go @@ -36,6 +36,7 @@ func registerFirmwareDetails(st *state.Store, s *session.Sim) { "flash_mb": row.Facts.FlashMB, "coproc_at_reset": row.Settings.CoprocAtReset, "card_required": row.Settings.CardRequired, + "dialect": dialectName(row.Settings), "notes": row.Settings.Notes, } if !row.Modified.IsZero() { @@ -103,6 +104,9 @@ func registerFirmwareUpdate(st *state.Store, s *session.Sim) { if on, ok := session.BoolOf(p, "card_required"); ok { set.CardRequired = on } + if d, ok := session.NamedField(p, "dialect"); ok { + set.Dialect = normalDialect(d) + } if err := firmware.SaveBuildSettings(in.Path, set); err != nil { return nil, err } @@ -120,7 +124,7 @@ func registerFirmwareUpdate(st *state.Store, s *session.Sim) { "path": in.Path, "renamed": renamed, "repinned": repinned, "settings": map[string]any{ "coproc_at_reset": set.CoprocAtReset, "notes": set.Notes, - "card_required": set.CardRequired, + "card_required": set.CardRequired, "dialect": dialectName(set), }, }, nil }) @@ -266,3 +270,22 @@ func deleteBuildSettings(path string) { } _ = os.Remove(firmware.SettingsPath(path)) } + +// normalDialect stores MeshCore's own vocabulary as no setting at all, so a +// build that says "meshcore" and one that says nothing are one build. +func normalDialect(d string) string { + d = strings.ToLower(strings.TrimSpace(d)) + if d == firmware.DialectMeshCore { + return "" + } + return d +} + +// dialectName is what a build speaks, said: "meshcore" when nothing else is +// recorded. +func dialectName(set firmware.BuildSettings) string { + if set.Dialect == "" { + return firmware.DialectMeshCore + } + return set.Dialect +} diff --git a/internal/app/session/firmwarelib/firmwaredetail.verbs.json b/internal/app/session/firmwarelib/firmwaredetail.verbs.json index d5bfe782..bd5762c5 100644 --- a/internal/app/session/firmwarelib/firmwaredetail.verbs.json +++ b/internal/app/session/firmwarelib/firmwaredetail.verbs.json @@ -36,6 +36,7 @@ "flash_mb", "coproc_at_reset", "card_required", + "dialect", "notes" ], "answers": "Answered from the library, so a published build nobody has fetched is described too: `on_disk` is then false and `path` and `bytes` are empty. `in_use` counts the nodes pinned to it, `kind`, `bootable` and `flash_mb` are read from a board image and say nothing about a native build, `settings_path` is where its settings would be written whether any exist or not, and `modified` is absent for a build not on this machine. A label naming more than one build is refused rather than guessed at.", @@ -91,6 +92,11 @@ "type": "bool", "what": "start this build's coprocessors enabled, which the part does not do - for a firmware that traps inside its own exception vector and cannot be seen past" }, + { + "name": "dialect", + "type": "string", + "what": "the console vocabulary the build speaks: meshcore for MeshCore's own, none for no console, or another name; absent leaves it alone. Anything but meshcore means nodes running this build are not provisioned, and an experiment arm that pins settings onto one is refused" + }, { "name": "notes", "type": "string", diff --git a/internal/app/session/provisioning.go b/internal/app/session/provisioning.go index f7c163da..fa176283 100644 --- a/internal/app/session/provisioning.go +++ b/internal/app/session/provisioning.go @@ -36,7 +36,7 @@ func ProvisioningFor(n scenario.Node) []state.ProvisionLine { // to anything at all and the nodes were told the same thing regardless - which // is worse than the panel not existing. func (s *Sim) provisionLines(n scenario.Node) []state.ProvisionLine { - return provisioningWith(*s.provisioning(), n) + return withDialect(n, provisioningWith(*s.provisioning(), n)) } // provisionLinesFor is the script for one cell of an experiment: the session's @@ -44,7 +44,7 @@ func (s *Sim) provisionLines(n scenario.Node) []state.ProvisionLine { func (s *Sim) provisionLinesFor(n scenario.Node, arm ExpArm) []state.ProvisionLine { prov := *s.provisioning() arm.ApplyOver(&prov) - return provisioningWith(prov, n) + return withDialect(n, provisioningWith(prov, n)) } // provisioningWith is the script under a stated set of settings. diff --git a/internal/firmware/buildsettings.go b/internal/firmware/buildsettings.go index 90d892b0..d7b91081 100644 --- a/internal/firmware/buildsettings.go +++ b/internal/firmware/buildsettings.go @@ -44,11 +44,27 @@ type BuildSettings struct { // slot fails minutes into a run, somewhere that does not mention cards. CardRequired bool `json:"card_required,omitempty"` + // Dialect is the console vocabulary this firmware speaks: empty or + // "meshcore" for MeshCore's own commands, "none" for a firmware with no + // command line, or the name of another. Provisioning speaks MeshCore's, + // so a node running anything else is not sent it - every line would be + // refused, and a setting an experiment pinned would silently not apply + // (#599). + Dialect string `json:"dialect,omitempty"` + // Notes is whatever the person who imported it wanted the next person to // know: where it came from, what it is for, what is wrong with it. Notes string `json:"notes,omitempty"` } +// SpeaksMeshCore reports whether provisioning can be sent to this build. +func (b BuildSettings) SpeaksMeshCore() bool { + return b.Dialect == "" || b.Dialect == DialectMeshCore +} + +// DialectMeshCore is MeshCore's own console vocabulary. +const DialectMeshCore = "meshcore" + // Zero reports whether anything has been decided at all, which is when the // file is removed rather than written empty. func (b BuildSettings) Zero() bool { return b == BuildSettings{} } diff --git a/internal/ui/workbench/firmwarewindow.go b/internal/ui/workbench/firmwarewindow.go index 94d92d0f..5e209499 100644 --- a/internal/ui/workbench/firmwarewindow.go +++ b/internal/ui/workbench/firmwarewindow.go @@ -45,6 +45,9 @@ type firmwareWindowPanel struct { notes comp.Field coproc comp.Check card comp.Check + // console is whether the build takes MeshCore's console commands, which + // is what provisioning types at it. + console comp.Check // roleWant and boardWant are the draft: what the chips and the board // list say, which is not the same as what the build is until apply. They @@ -82,6 +85,7 @@ func (p *firmwareWindowPanel) build() { p.notes.Hint = "what the next person should know about this build" p.coproc.Label = "coprocessors enabled at reset" p.card.Label = "needs a card in the board's slot" + p.console.Label = "takes MeshCore's console commands" p.apply.Label, p.apply.Kind = "apply", comp.Primary p.revert.Label, p.revert.Kind = "revert", comp.Secondary p.useFor.Label, p.useFor.Kind = "use for this role", comp.Secondary @@ -121,6 +125,7 @@ func (p *firmwareWindowPanel) seed(r state.FirmwareRow) { p.notes.Editor.SetText(r.Settings.Notes) p.coproc.Bool.Value = r.Settings.CoprocAtReset p.card.Bool.Value = r.Settings.CardRequired + p.console.Bool.Value = r.Settings.SpeaksMeshCore() p.roleWant, p.boardWant = r.Role, r.Board } diff --git a/internal/ui/workbench/firmwarewindowsettings.go b/internal/ui/workbench/firmwarewindowsettings.go index 9b54fcbe..bf359622 100644 --- a/internal/ui/workbench/firmwarewindowsettings.go +++ b/internal/ui/workbench/firmwarewindowsettings.go @@ -61,12 +61,35 @@ func (p *firmwareWindowPanel) howItRuns(t *theme.Theme, gtx layout.Context, "failure minutes into a run, in a message that never mentions "+ "cards.")) }), + layout.Rigid(func(gtx layout.Context) layout.Dimensions { + return p.console.LayoutSwitch(t, gtx) + }), + layout.Rigid(func(gtx layout.Context) layout.Dimensions { + return layout.Inset{Top: t.Sp.XS, Bottom: t.Sp.S}.Layout(gtx, + comp.Text(t, t.Sz.Caption, t.P.Faint, + "Provisioning, and any setting an experiment pins, is MeshCore's "+ + "command line typed at the node. Off, a node running this build "+ + "is sent none of it, and an arm that would pin a setting onto it "+ + "is refused before the run rather than applying nothing.")) + }), layout.Rigid(func(gtx layout.Context) layout.Dimensions { return p.notes.Layout(t, gtx) }), ) } +// dialectWanted is what the console switch asks for: MeshCore's own, or +// whatever other vocabulary the build already declared, or "none". +func (p *firmwareWindowPanel) dialectWanted(r state.FirmwareRow) string { + if p.console.Bool.Value { + return firmware.DialectMeshCore + } + if !r.Settings.SpeaksMeshCore() { + return r.Settings.Dialect + } + return "none" +} + // facts is where the build actually is and what it actually contains. func (p *firmwareWindowPanel) facts(t *theme.Theme, gtx layout.Context, r state.FirmwareRow) layout.Dimensions { @@ -164,6 +187,7 @@ func (p *firmwareWindowPanel) changed(r state.FirmwareRow) bool { return p.renaming(r) || p.coproc.Bool.Value != r.Settings.CoprocAtReset || p.card.Bool.Value != r.Settings.CardRequired || + p.console.Bool.Value != r.Settings.SpeaksMeshCore() || comp.FieldText(&p.notes) != r.Settings.Notes } @@ -183,6 +207,7 @@ func (p *firmwareWindowPanel) act(gtx layout.Context, r state.FirmwareRow) { "label": name, "new_role": p.roleWant, "new_board": p.boardWant, "coproc_at_reset": p.coproc.Bool.Value, "card_required": p.card.Bool.Value, + "dialect": p.dialectWanted(r), "notes": comp.FieldText(&p.notes), } // A board of "" is the host build, and an absent new_board means diff --git a/pkg/client-go/meshbench/firmware.go b/pkg/client-go/meshbench/firmware.go index 28dc0fb5..ab156878 100644 --- a/pkg/client-go/meshbench/firmware.go +++ b/pkg/client-go/meshbench/firmware.go @@ -109,7 +109,11 @@ type BuildChange struct { CoprocAtReset *bool CardRequired *bool - Notes *string + // Dialect is the console vocabulary the build speaks: "meshcore", "none", + // or another name. A node running anything but MeshCore's is not sent + // provisioning. + Dialect *string + Notes *string } // Update renames a build, moves it to another board or role, or changes how it @@ -131,6 +135,9 @@ func (f Firmware) Update(ctx context.Context, id BuildID, c BuildChange) (BuildD if c.CardRequired != nil { p["card_required"] = *c.CardRequired } + if c.Dialect != nil { + p["dialect"] = *c.Dialect + } if c.Notes != nil { p["notes"] = *c.Notes } diff --git a/pkg/client-go/meshbench/types.go b/pkg/client-go/meshbench/types.go index 9687ee17..2a7015fb 100644 --- a/pkg/client-go/meshbench/types.go +++ b/pkg/client-go/meshbench/types.go @@ -186,8 +186,11 @@ type BuildDetails struct { // CardRequired says this firmware will not get far without storage in the // board's slot, so every node running it is given a card whatever its own // slot was set to. - CardRequired bool `json:"card_required"` - Notes string `json:"notes"` + CardRequired bool `json:"card_required"` + // Dialect is the console vocabulary the build speaks; "meshcore" unless + // something else was recorded. + Dialect string `json:"dialect"` + Notes string `json:"notes"` } // Describe is how this build is named where a person will read it. diff --git a/pkg/client-js/lib/firmware.mjs b/pkg/client-js/lib/firmware.mjs index 4432b41a..71d6a489 100644 --- a/pkg/client-js/lib/firmware.mjs +++ b/pkg/client-js/lib/firmware.mjs @@ -69,7 +69,7 @@ export class Firmware { * answers. */ async update(build, { board = "", role = "", label, newRole, newBoard, - coprocAtReset, cardRequired, notes, + coprocAtReset, cardRequired, dialect, notes, } = {}) { const p = buildID(build, { board, role }); if (label !== undefined) p.label = label; @@ -77,6 +77,7 @@ export class Firmware { if (newBoard !== undefined) p.new_board = newBoard; if (coprocAtReset !== undefined) p.coproc_at_reset = coprocAtReset; if (cardRequired !== undefined) p.card_required = cardRequired; + if (dialect !== undefined) p.dialect = dialect; if (notes !== undefined) p.notes = notes; const moved = (await this._wb.call("firmware.update", p)) || {}; // Read back under whatever it is called now, which is not what it was diff --git a/pkg/client-python/meshbench/parts.py b/pkg/client-python/meshbench/parts.py index c1394be6..a437784f 100644 --- a/pkg/client-python/meshbench/parts.py +++ b/pkg/client-python/meshbench/parts.py @@ -265,7 +265,9 @@ def download(self, role: str, version: str, board: Board | str = "") -> None: p["board"] = board self._wb.call("firmware.download", p) - def import_(self, path: str, role: str, board: str = "", label: str = "") -> Build: + def import_( + self, path: str, role: str, board: str = "", label: str = "", dialect: str = "" + ) -> Build: """Take a build from a path - the one way a locally built image gets into the library. @@ -279,6 +281,8 @@ def import_(self, path: str, role: str, board: str = "", label: str = "") -> Bui p["board"] = board if label: p["label"] = label + if dialect: + p["dialect"] = dialect return Build.parse(self._wb.call("firmware.import", p) or {}) def delete(self, build: Build) -> str: @@ -318,6 +322,7 @@ def update( new_board: Board | str | None = None, coproc_at_reset: bool | None = None, card_required: bool | None = None, + dialect: str | None = None, notes: str | None = None, ) -> BuildDetails: """Rename a build, move it to another board or role, or change how it @@ -344,6 +349,8 @@ def update( p["coproc_at_reset"] = coproc_at_reset if card_required is not None: p["card_required"] = card_required + if dialect is not None: + p["dialect"] = dialect if notes is not None: p["notes"] = notes got = self._wb.call("firmware.update", p) or {} diff --git a/pkg/client-python/meshbench/types.py b/pkg/client-python/meshbench/types.py index 83771f45..baf3d9d6 100644 --- a/pkg/client-python/meshbench/types.py +++ b/pkg/client-python/meshbench/types.py @@ -268,6 +268,9 @@ class BuildDetails: #: This firmware will not get far without storage in the board's slot, so #: every node running it is given a card whatever its own slot was set to. card_required: bool = False + #: The console vocabulary the build speaks: "meshcore", "none", or another + #: name. Anything but "meshcore" is not sent provisioning. + dialect: str = "meshcore" notes: str = "" def __str__(self) -> str: From b2931548e542b6f9e18cb337a5f47a64d0ad1a37 Mon Sep 17 00:00:00 2001 From: R0ck Date: Fri, 30 Oct 2026 17:08:21 +0000 Subject: [PATCH 2/2] dialect: match a node's build on its role too, as the engine does, so one image's dialect is not read off another's --- internal/app/session/dialect.go | 14 ++++++++++++-- internal/app/session/dialect_test.go | 27 +++++++++++++++++++++++++-- internal/firmware/buildsettings.go | 3 +-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/internal/app/session/dialect.go b/internal/app/session/dialect.go index 399e8d64..0d0c7620 100644 --- a/internal/app/session/dialect.go +++ b/internal/app/session/dialect.go @@ -1,4 +1,4 @@ -// Which firmware takes MeshCore's console commands (#599). +// Which firmware takes MeshCore's console commands. // // Provisioning, and every setting an experiment arm pins, is a run of MeshCore // CLI lines typed at a node's console. A firmware that is not MeshCore refuses @@ -25,7 +25,8 @@ func dialectOf(n scenario.Node, installed []firmware.Installed) string { return "" } for _, in := range installed { - if in.Board == n.Firmware.Board && in.Version == n.Firmware.Version { + if in.Board == n.Firmware.Board && in.Version == n.Firmware.Version && + sameRole(in.Role, string(n.Firmware.Role)) { if set := firmware.LoadBuildSettings(in.Path); !set.SpeaksMeshCore() { return set.Dialect } @@ -35,6 +36,15 @@ func dialectOf(n scenario.Node, installed []firmware.Installed) string { return "" } +// sameRole matches an installed image to the role a node names, as the engine +// does when it boots one: the role itself, or that role plus the transport a +// published companion carries. Matching on board and version alone took a +// repeater and a companion image of one version for each other, and each has +// its own settings. +func sameRole(installed, node string) bool { + return node == "" || installed == node || strings.HasPrefix(installed, node+"_") +} + // withDialect is a node's provisioning script, or in place of it one line // saying why there is none. func withDialect(n scenario.Node, lines []state.ProvisionLine) []state.ProvisionLine { diff --git a/internal/app/session/dialect_test.go b/internal/app/session/dialect_test.go index 71afc548..0e21b5d2 100644 --- a/internal/app/session/dialect_test.go +++ b/internal/app/session/dialect_test.go @@ -35,7 +35,7 @@ func deckWith(t *testing.T, version, dialect string) scenario.Node { } // A node whose build does not speak MeshCore's console is told why it is sent -// nothing, rather than sent lines it refuses (#599). +// nothing, rather than sent lines it refuses. func TestAFirmwareThatIsNotMeshCoreIsNotProvisioned(t *testing.T) { n := deckWith(t, "wadamesh", "wadamesh") got := (&Sim{}).provisionLines(n) @@ -50,7 +50,7 @@ func TestAFirmwareThatIsNotMeshCoreIsNotProvisioned(t *testing.T) { } // An arm that pins a setting onto such a node is refused before the run; an -// arm that only chooses builds is not (#599). +// arm that only chooses builds is not. func TestAnArmPinningSettingsOntoForeignFirmwareIsRefused(t *testing.T) { n := deckWith(t, "wadamesh", "none") s := &Sim{} @@ -63,3 +63,26 @@ func TestAnArmPinningSettingsOntoForeignFirmwareIsRefused(t *testing.T) { t.Errorf("an arm pinning no settings was refused: %q", why) } } + +// Settings belong to one image, so a repeater of the same version on the same +// board is not taken for the companion that declared a dialect. +func TestADialectBelongsToItsOwnRole(t *testing.T) { + deck := deckWith(t, "wadamesh", "wadamesh") + if d := dialectOf(deck, firmware.ListInstalled(firmware.DefaultCacheDir())); d != "wadamesh" { + t.Fatalf("the companion itself: %q", d) + } + dir := filepath.Join(firmware.DefaultCacheDir(), "board", "LilyGo_TDeck") + if err := os.WriteFile(filepath.Join(dir, "simple_repeater@wadamesh.bin"), make([]byte, 64), 0o644); err != nil { + t.Fatal(err) + } + rep := deck + rep.Kind, rep.Firmware.Role = scenario.SimpleRepeater, scenario.RoleSimpleRepeater + if d := dialectOf(rep, firmware.ListInstalled(firmware.DefaultCacheDir())); d != "" { + t.Errorf("a repeater image with no settings of its own was given the companion's: %q", d) + } + generic := deck + generic.Firmware.Role = "companion_radio" + if d := dialectOf(generic, firmware.ListInstalled(firmware.DefaultCacheDir())); d != "wadamesh" { + t.Errorf("a node naming the role without its transport: %q", d) + } +} diff --git a/internal/firmware/buildsettings.go b/internal/firmware/buildsettings.go index d7b91081..bde52858 100644 --- a/internal/firmware/buildsettings.go +++ b/internal/firmware/buildsettings.go @@ -48,8 +48,7 @@ type BuildSettings struct { // "meshcore" for MeshCore's own commands, "none" for a firmware with no // command line, or the name of another. Provisioning speaks MeshCore's, // so a node running anything else is not sent it - every line would be - // refused, and a setting an experiment pinned would silently not apply - // (#599). + // refused, and a setting an experiment pinned would silently not apply. Dialect string `json:"dialect,omitempty"` // Notes is whatever the person who imported it wanted the next person to