fix(debugger): extract MarteController into an importable controller package
Client/debugger was entirely package main, which Go forbids importing from
another module ("is a program, not an importable package") -- discovered
while wiring the new debugclient E2E tool against NewHeadlessMarteController.
Move martecontrol.go and its test into a new marte2debugger/controller
subpackage (package controller) and update Client/debugger/main.go to call
controller.NewMarteController/controller.DangerousCommandsEnabled. No
behavioral change to the browser-facing server.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package controller
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -1,4 +1,9 @@
|
||||
package main
|
||||
// Package controller implements MarteController, the shared TCP/UDP client
|
||||
// logic that drives a running MARTe2 DebugService+TCPLogger instance. It is
|
||||
// consumed both by the Client/debugger browser-facing WebSocket server
|
||||
// (package main, via NewMarteController) and headlessly by the
|
||||
// Test/E2E/suite/debugclient E2E test tool (via NewHeadlessMarteController).
|
||||
package controller
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@@ -21,9 +26,9 @@ import (
|
||||
// Command safety gate (CR-4)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// dangerousCommandsEnabled gates commands that mutate the RT application state
|
||||
// DangerousCommandsEnabled gates commands that mutate the RT application state
|
||||
// (FORCE, PAUSE, RESUME, STEP, BREAK, MSG). Set via --enable-dangerous-commands.
|
||||
var dangerousCommandsEnabled = false
|
||||
var DangerousCommandsEnabled = false
|
||||
|
||||
// dangerousCommands is the set of MARTe2 commands that can change signal values
|
||||
// or alter execution flow. Without --enable-dangerous-commands these are blocked
|
||||
@@ -319,7 +324,7 @@ func (m *MarteController) HandleBrowserCommand(msg []byte) {
|
||||
// (DISCOVER, TREE, INFO, LS, VALUE, TRACE, UNTRACE, STEP_STATUS) are
|
||||
// forwarded to the MARTe2 TCP control connection.
|
||||
if isDangerousCommand(cmd) {
|
||||
if !dangerousCommandsEnabled {
|
||||
if !DangerousCommandsEnabled {
|
||||
m.sink(map[string]any{
|
||||
"type": "log", "time": time.Now().Format("15:04:05.000"),
|
||||
"level": "WARNING",
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"marte2debugger/controller"
|
||||
|
||||
"marte2/common/wshub"
|
||||
)
|
||||
|
||||
@@ -21,7 +23,7 @@ var staticFiles embed.FS
|
||||
func main() {
|
||||
addr := flag.String("addr", ":7777", "HTTP listen address")
|
||||
sourcesFile := flag.String("sources-file", "", "JSON file for persistent source list")
|
||||
flag.BoolVar(&dangerousCommandsEnabled, "enable-dangerous-commands", false,
|
||||
flag.BoolVar(&controller.DangerousCommandsEnabled, "enable-dangerous-commands", false,
|
||||
"Allow FORCE/PAUSE/RESUME/STEP/BREAK/MSG commands from the browser (CR-4 safety gate)")
|
||||
flag.Parse()
|
||||
|
||||
@@ -29,7 +31,7 @@ func main() {
|
||||
sm := wshub.NewSourceManager(hub, *sourcesFile)
|
||||
hub.SetSourceManager(sm)
|
||||
|
||||
ctrl := NewMarteController(hub)
|
||||
ctrl := controller.NewMarteController(hub)
|
||||
|
||||
go hub.Run()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user