The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(sandbox): reject unknown scenario fields before dispatch (#979)
Divyam Talwar121030c6d15d
diff --git a/beacon-sandbox/scenario/scenario.go b/beacon-sandbox/scenario/scenario.goindex ccd9e9ab..3a5cc365 100644--- a/beacon-sandbox/scenario/scenario.go+++ b/beacon-sandbox/scenario/scenario.go@@ -8,7 +8,10 @@package scenarioimport (+ "bytes"+ "errors""fmt"+ "io""os""path""path/filepath"@@ -334,7 +337,9 @@ func Load(path string) (Scenario, error) {if err != nil {return s, err}- if err := yaml.Unmarshal(b, &s); err != nil {+ decoder := yaml.NewDecoder(bytes.NewReader(b))+ decoder.KnownFields(true)+ if err := decoder.Decode(&s); err != nil && !errors.Is(err, io.EOF) {return s, fmt.Errorf("%s: %w", filepath.Base(path), err)}if err := s.Validate(); err != nil {diff --git a/beacon-sandbox/scenario/scenario_test.go b/beacon-sandbox/scenario/scenario_test.goindex 78fe800e..0d3e6723 100644--- a/beacon-sandbox/scenario/scenario_test.go+++ b/beacon-sandbox/scenario/scenario_test.go@@ -1,6 +1,7 @@package scenarioimport (+ "fmt""os""path/filepath""strings"@@ -132,6 +133,41 @@ func TestLoadValidatesOnRead(t *testing.T) {}}+func TestLoadRejectsUnknownFields(t *testing.T) {+ const body = `id: strict+prompt: run echo {{canary}}+install:+ mode: user+ verify_uninstall: true+expect:+ - action: command.executed+ fields: [command.command]+ min_count: 2+`+ for _, tc := range []struct {+ name, old, replacement, key string+ line int+ }{+ {"scenario", "id: strict\n", "id: strict\npromtp: ignored\n", "promtp", 2},+ {"expectation fields", "fields:", "feilds:", "feilds", 8},+ } {+ t.Run(tc.name, func(t *testing.T) {+ dir := t.TempDir()+ const name = "misspelled.yaml"+ writeScenario(t, dir, name, strings.Replace(body, tc.old, tc.replacement, 1))+ _, err := Load(filepath.Join(dir, name))+ if err == nil {+ t.Fatalf("Load accepted unknown key %q; the intended check may be omitted", tc.key)+ }+ for _, detail := range []string{name, tc.key, fmt.Sprintf("line %d", tc.line)} {+ if !strings.Contains(err.Error(), detail) {+ t.Errorf("Load error %q must identify %q", err, detail)+ }+ }+ })+ }+}+func TestLoadSuiteIsDeterministicallyOrdered(t *testing.T) {dir := t.TempDir()body := "id: %s\nprompt: p {{canary}}\nexpect:\n - action: prompt.submitted\n"