add black-box debug harness
This commit is contained in:
47
cmd/patterm/debug_harness.go
Normal file
47
cmd/patterm/debug_harness.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/hjbdev/patterm/internal/harness"
|
||||
)
|
||||
|
||||
func runDebugHarness() {
|
||||
var (
|
||||
scenarioPath = flag.String("scenario", "", "JSON scenario path")
|
||||
pattermBin = flag.String("patterm-bin", "", "patterm binary under test (default: this executable)")
|
||||
)
|
||||
flag.Parse()
|
||||
if *scenarioPath == "" {
|
||||
die("debug-harness: --scenario is required")
|
||||
}
|
||||
if *pattermBin == "" {
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
die("debug-harness: os.Executable: %v", err)
|
||||
}
|
||||
*pattermBin = exe
|
||||
}
|
||||
sc, err := harness.LoadScenario(*scenarioPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stdout, "{\"ok\":false,\"error\":%q}\n", err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
res, err := harness.RunScenario(harness.Options{
|
||||
Scenario: sc,
|
||||
PattermBin: *pattermBin,
|
||||
}, func(ev harness.Event) {
|
||||
_ = enc.Encode(ev)
|
||||
})
|
||||
_ = enc.Encode(res)
|
||||
if err != nil {
|
||||
if res.Steps == 0 {
|
||||
os.Exit(2)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
// patterm mcp-stdio --socket S --identity I
|
||||
// internal: stdio MCP proxy spawned for
|
||||
// children, forwards JSON-RPC over S
|
||||
// patterm debug-harness --scenario S
|
||||
// internal: run a black-box harness scenario
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -30,6 +32,11 @@ func main() {
|
||||
runMCPProxy()
|
||||
return
|
||||
}
|
||||
if len(os.Args) >= 2 && os.Args[1] == "debug-harness" {
|
||||
os.Args = append(os.Args[:1], os.Args[2:]...)
|
||||
runDebugHarness()
|
||||
return
|
||||
}
|
||||
|
||||
var projectDir = flag.String("project", "", "project directory (default $PWD)")
|
||||
flag.Parse()
|
||||
|
||||
Reference in New Issue
Block a user