diff --git a/cmd/lk/simulate.go b/cmd/lk/simulate.go index 2c085a13..8900c2c2 100644 --- a/cmd/lk/simulate.go +++ b/cmd/lk/simulate.go @@ -24,6 +24,7 @@ import ( "math/rand" "os" "path/filepath" + "slices" "sort" "strings" "time" @@ -416,14 +417,23 @@ func scenarioGroupToYAML(group *livekit.ScenarioGroup) ([]byte, error) { // scenariosFile mirrors a scenarios.yaml; `userdata` is a nested mapping here // and JSON-encoded into the proto's string field. Each `nodes` entry is a -// SimulatorNode in protojson form (see simulate_flow.go). +// SimulatorNode in protojson form (see simulate_flow.go). `include` names files +// whose nodes join this file's (see simulate_include.go). type scenariosFile struct { ID string `yaml:"id"` Name string `yaml:"name"` + Include []string `yaml:"include,omitempty"` Nodes map[string]yaml.Node `yaml:"nodes,omitempty"` Scenarios []yamlScenario `yaml:"scenarios"` } +func (f *scenariosFile) usesFlows() bool { + if len(f.Nodes) > 0 || len(f.Include) > 0 { + return true + } + return slices.ContainsFunc(f.Scenarios, func(s yamlScenario) bool { return s.Start != "" }) +} + type yamlScenario struct { ID string `yaml:"id"` Label string `yaml:"label"` @@ -497,16 +507,38 @@ func loadScenarioGroup(path string) (*livekit.ScenarioGroup, error) { if err := yaml.Unmarshal(data, &f); err != nil { return nil, fmt.Errorf("failed to parse scenarios file: %w", err) } + // only in a file with flows, where a misspelled `include` or `nodes` loses + // nodes; other files may carry keys of their own + if f.usesFlows() { + if err := onlyKeys(data, "a scenarios file", "id", "name", "include", "nodes", "scenarios"); err != nil { + return nil, err + } + } if f.ID == "" { return nil, fmt.Errorf("scenarios file has no id") } group := &livekit.ScenarioGroup{Id: f.ID, Name: f.Name} - nodes, err := decodeNodes(f.Nodes) + nodes, err := resolveNodes(path, f.Nodes, f.Include) if err != nil { return nil, err } - group.Nodes = nodes + names := make([]string, 0, len(nodes)) + for name := range nodes { + names = append(names, name) + } + sort.Strings(names) + for _, name := range names { + value := nodes[name].value + node, err := decodeNode(name, &value) + if err != nil { + return nil, fmt.Errorf("%s: %w", nodes[name].file, err) + } + if group.Nodes == nil { + group.Nodes = map[string]*livekit.SimulatorNode{} + } + group.Nodes[name] = node + } seen := map[string]bool{} for _, s := range f.Scenarios { if s.ID == "" { diff --git a/cmd/lk/simulate_flow.go b/cmd/lk/simulate_flow.go index 322dc4b9..0232aa89 100644 --- a/cmd/lk/simulate_flow.go +++ b/cmd/lk/simulate_flow.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "regexp" - "sort" "strings" "time" @@ -39,28 +38,6 @@ const builtinNodePrefix = "livekit/" // maxNodeTimeout is the documented limit of SimulatorNode.Timeout.after. const maxNodeTimeout = 20 * time.Second -// decodeNodes reads the `nodes` of a scenarios.yaml. -func decodeNodes(nodes map[string]yaml.Node) (map[string]*livekit.SimulatorNode, error) { - if len(nodes) == 0 { - return nil, nil - } - names := make([]string, 0, len(nodes)) - for name := range nodes { - names = append(names, name) - } - sort.Strings(names) - out := make(map[string]*livekit.SimulatorNode, len(nodes)) - for _, name := range names { - value := nodes[name] - node, err := decodeNode(name, &value) - if err != nil { - return nil, err - } - out[name] = node - } - return out, nil -} - // decodeNode reads one entry of a scenarios.yaml's `nodes`. func decodeNode(name string, value *yaml.Node) (*livekit.SimulatorNode, error) { if strings.HasPrefix(name, builtinNodePrefix) { diff --git a/cmd/lk/simulate_include.go b/cmd/lk/simulate_include.go new file mode 100644 index 00000000..ad7aa2ca --- /dev/null +++ b/cmd/lk/simulate_include.go @@ -0,0 +1,222 @@ +// Copyright 2026 LiveKit, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "fmt" + "os" + "path/filepath" + "slices" + "strings" + + "gopkg.in/yaml.v3" +) + +// includedFile is a scenarios.yaml `include` target: it only contributes +// nodes, so running one file never runs scenarios it did not list itself. +type includedFile struct { + Include []string `yaml:"include"` + Nodes map[string]yaml.Node `yaml:"nodes"` +} + +// sourcedNode is a node in YAML form and the file that defines it, named as +// errors name it. +type sourcedNode struct { + value yaml.Node + file string +} + +// nodeResolver merges the nodes of a scenarios file and everything it +// includes. A file's relative includes resolve beside the path it was named +// by, with every directory on that path resolved physically, so `link/..` is +// the parent of where link points. The file itself is identified by +// os.SameFile, so a file reached through two includes, a symlink, two path +// spellings, or two letter cases loads once, beside the name it was first +// reached by. +type nodeResolver struct { + root string // directory errors name files relative to + loaded []os.FileInfo + chain []os.FileInfo // files from the root file to the one loading now + named []string // the same files, as named + nodes map[string]sourcedNode +} + +func resolveNodes(path string, nodes map[string]yaml.Node, include []string) (map[string]sourcedNode, error) { + named, err := physicalDir(path) + if err != nil { + return nil, err + } + info, err := os.Stat(named) + if err != nil { + return nil, err + } + r := &nodeResolver{ + root: filepath.Dir(named), + loaded: []os.FileInfo{info}, + chain: []os.FileInfo{info}, + named: []string{named}, + nodes: map[string]sourcedNode{}, + } + if err := r.add(named, nodes); err != nil { + return nil, err + } + if err := r.includeAll(named, include); err != nil { + return nil, err + } + return r.nodes, nil +} + +// physicalDir makes path absolute and resolves every directory on it through +// symlinks before any `..` is applied, keeping the file's own name. Cleaning +// first, as filepath.Abs and filepath.Join do, would make `link/../x.yaml` the +// x.yaml beside link rather than the one in link's target's parent. +func physicalDir(path string) (string, error) { + if !filepath.IsAbs(path) { + wd, err := os.Getwd() + if err != nil { + return "", err + } + path = wd + string(filepath.Separator) + path + } + i := strings.LastIndexAny(path, "/"+string(filepath.Separator)) + dir, err := filepath.EvalSymlinks(path[:i+1]) + if err != nil { + return "", err + } + return filepath.Join(dir, path[i+1:]), nil +} + +func (r *nodeResolver) includeAll(from string, include []string) error { + for _, rel := range include { + if rel == "" { + return fmt.Errorf("%s: include has an empty entry", r.name(from)) + } + path := rel + if !filepath.IsAbs(path) { + path = filepath.Dir(from) + string(filepath.Separator) + rel + } + named, err := physicalDir(path) + if err != nil { + return fmt.Errorf("%s: include %q: %w", r.name(from), rel, err) + } + info, err := os.Stat(named) + if err != nil { + return fmt.Errorf("%s: include %q: %w", r.name(from), rel, err) + } + if sameFileIn(r.chain, info) { + return fmt.Errorf("include cycle: %s", r.chainNames(append(slices.Clone(r.named), named))) + } + if sameFileIn(r.loaded, info) { + continue + } + if info.IsDir() { + return fmt.Errorf("%s: include %q is a directory, not a file", r.name(from), rel) + } + r.loaded = append(r.loaded, info) + if err := r.load(named, info); err != nil { + return err + } + } + return nil +} + +func sameFileIn(files []os.FileInfo, info os.FileInfo) bool { + return slices.ContainsFunc(files, func(f os.FileInfo) bool { return os.SameFile(f, info) }) +} + +func (r *nodeResolver) load(named string, info os.FileInfo) error { + data, err := os.ReadFile(named) + if err != nil { + return fmt.Errorf("%s: %w", r.name(named), err) + } + if err := onlyKeys(data, "an included file", "nodes", "include"); err != nil { + return fmt.Errorf("%s: %w", r.name(named), err) + } + var f includedFile + if err := yaml.Unmarshal(data, &f); err != nil { + return fmt.Errorf("%s: %w", r.name(named), err) + } + if err := r.add(named, f.Nodes); err != nil { + return err + } + r.chain = append(r.chain, info) + r.named = append(r.named, named) + defer func() { + r.chain = r.chain[:len(r.chain)-1] + r.named = r.named[:len(r.named)-1] + }() + return r.includeAll(named, f.Include) +} + +func (r *nodeResolver) add(file string, nodes map[string]yaml.Node) error { + for name, value := range nodes { + if prev, ok := r.nodes[name]; ok { + return fmt.Errorf("node %q is defined in both %s and %s", name, prev.file, r.name(file)) + } + r.nodes[name] = sourcedNode{value: value, file: r.name(file)} + } + return nil +} + +// anchorKeyPrefix marks a top-level key that only holds YAML anchors, as in +// Docker Compose files: `x-defaults: &machine {speaker: MACHINE}`. +const anchorKeyPrefix = "x-" + +// onlyKeys rejects a top-level key other than allowed or an anchor key, so a +// misspelled key fails instead of being ignored. +func onlyKeys(data []byte, what string, allowed ...string) error { + var keys map[string]yaml.Node // keys only: values are read against the schema later + if err := yaml.Unmarshal(data, &keys); err != nil { + return err + } + var unknown []string + for key := range keys { + if !slices.Contains(allowed, key) && !strings.HasPrefix(key, anchorKeyPrefix) { + unknown = append(unknown, key) + } + } + if len(unknown) == 0 { + return nil + } + slices.Sort(unknown) + quoted := make([]string, len(allowed)) + for i, key := range allowed { + quoted[i] = "`" + key + "`" + } + list := quoted[len(quoted)-1] + if len(quoted) == 2 { + list = quoted[0] + " and " + list + } else if len(quoted) > 2 { + list = strings.Join(quoted[:len(quoted)-1], ", ") + ", and " + list + } + return fmt.Errorf("%s holds only %s, and keys that start with %q for anchors, not %q", what, list, anchorKeyPrefix, unknown[0]) +} + +// name is how errors refer to a file: relative to the root file's directory, +// with forward slashes as in `include`. +func (r *nodeResolver) name(named string) string { + if rel, err := filepath.Rel(r.root, named); err == nil { + return filepath.ToSlash(rel) + } + return named +} + +func (r *nodeResolver) chainNames(chain []string) string { + names := make([]string, len(chain)) + for i, p := range chain { + names[i] = r.name(p) + } + return strings.Join(names, " -> ") +} diff --git a/cmd/lk/simulate_include_test.go b/cmd/lk/simulate_include_test.go new file mode 100644 index 00000000..d87a1f3d --- /dev/null +++ b/cmd/lk/simulate_include_test.go @@ -0,0 +1,297 @@ +// Copyright 2026 LiveKit, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "os" + "path/filepath" + "slices" + "testing" + + "github.com/stretchr/testify/require" + "github.com/urfave/cli/v3" +) + +// writeFiles writes each name -> content under one temp dir and returns it. +func writeFiles(t *testing.T, files map[string]string) string { + t.Helper() + dir := t.TempDir() + for name, content := range files { + path := filepath.Join(dir, name) + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + require.NoError(t, os.WriteFile(path, []byte(content), 0o644)) + } + return dir +} + +const includingScenarios = ` +id: SCNG_dental +include: [nodes/menus.yaml, nodes/people.yaml] +nodes: + greeting: { say: "Hi, you've reached Sam.", then: livekit/voicemail } +scenarios: + - id: SCN_a + label: menu-to-sam + start: menu + agent_expectations: Presses 1, then confirms with Sam. +` + +func TestIncludedNodesJoinTheGroup(t *testing.T) { + dir := writeFiles(t, map[string]string{ + "dental.yaml": includingScenarios, + // nested, with a path relative to the including file + "nodes/menus.yaml": ` +include: [common.yaml] +nodes: + menu: + say: "For Sam, press 1." + routes: [{ match: "1", to: sam }] + timeout: { after: 8s, to: goodbye } +`, + // includes common.yaml too, so dental.yaml reaches it twice + "nodes/people.yaml": ` +include: [common.yaml] +nodes: + sam: { instructions: You are Sam. } +`, + "nodes/common.yaml": ` +nodes: + goodbye: { say: Goodbye., then: livekit/hangup } +`, + }) + + group, err := loadScenarioGroup(filepath.Join(dir, "dental.yaml")) + require.NoError(t, err) + + names := make([]string, 0, len(group.Nodes)) + for name := range group.Nodes { + names = append(names, name) + } + slices.Sort(names) + require.Equal(t, []string{"goodbye", "greeting", "menu", "sam"}, names) + require.Equal(t, "sam", group.Nodes["menu"].Routes[0].To) + require.Equal(t, "menu", group.Scenarios[0].Start) +} + +func TestIncludeErrors(t *testing.T) { + cases := []struct { + name string + files map[string]string + want string + }{ + { + name: "a cycle prints the include chain", + files: map[string]string{ + "dental.yaml": includingScenarios, + "nodes/menus.yaml": "include: [common.yaml]\nnodes: { menu: { say: hi, then: livekit/hangup } }\n", + "nodes/common.yaml": "include: [menus.yaml]\n", + "nodes/people.yaml": "nodes: { sam: { instructions: x } }\n", + }, + want: "include cycle: dental.yaml -> nodes/menus.yaml -> nodes/common.yaml -> nodes/menus.yaml", + }, + { + name: "a node defined in two files names both", + files: map[string]string{ + "dental.yaml": includingScenarios, + "nodes/menus.yaml": "nodes: { menu: { say: hi, then: livekit/hangup } }\n", + "nodes/people.yaml": "nodes: { menu: { say: hello, then: livekit/hangup } }\n", + }, + want: `node "menu" is defined in both nodes/menus.yaml and nodes/people.yaml`, + }, + { + name: "an included file cannot set scenarios", + files: map[string]string{ + "dental.yaml": includingScenarios, + "nodes/menus.yaml": "nodes: { menu: { say: hi, then: livekit/hangup } }\nscenarios: []\n", + "nodes/people.yaml": "nodes: { sam: { instructions: x } }\n", + }, + want: "nodes/menus.yaml: an included file holds only `nodes` and `include`, and keys that start with \"x-\" for anchors, not \"scenarios\"", + }, + { + name: "a missing include path", + files: map[string]string{ + "dental.yaml": includingScenarios, + "nodes/menus.yaml": "nodes: { menu: { say: hi, then: livekit/hangup } }\n", + }, + want: `dental.yaml: include "nodes/people.yaml"`, + }, + { + name: "a cycle back to the root file", + files: map[string]string{ + "dental.yaml": includingScenarios, + "nodes/menus.yaml": "include: [../dental.yaml]\n", + "nodes/people.yaml": "nodes: { sam: { instructions: x } }\n", + }, + want: "include cycle: dental.yaml -> nodes/menus.yaml -> dental.yaml", + }, + { + name: "a root node defined again in an included file", + files: map[string]string{ + "dental.yaml": includingScenarios, + "nodes/menus.yaml": "nodes: { greeting: { say: hi, then: livekit/hangup } }\n", + "nodes/people.yaml": "nodes: { sam: { instructions: x } }\n", + }, + want: `node "greeting" is defined in both dental.yaml and nodes/menus.yaml`, + }, + { + name: "a misspelled include key in the root file", + files: map[string]string{ + "dental.yaml": "id: g\nincludes: [nodes.yaml]\nscenarios: [{ id: s, label: l, start: menu }]\n", + }, + want: "a scenarios file holds only `id`, `name`, `include`, `nodes`, and `scenarios`, and keys that start with \"x-\" for anchors, not \"includes\"", + }, + { + name: "an empty include entry", + files: map[string]string{ + "dental.yaml": "id: g\ninclude: [\x27\x27]\nscenarios: [{ id: s, label: l, start: livekit/hangup }]\n", + }, + want: "dental.yaml: include has an empty entry", + }, + { + name: "a directory include", + files: map[string]string{ + "dental.yaml": "id: g\ninclude: [nodes]\nscenarios: [{ id: s, label: l, start: livekit/hangup }]\n", + "nodes/x.yaml": "nodes: {}\n", + }, + want: `dental.yaml: include "nodes" is a directory, not a file`, + }, + { + name: "two included files with the same name", + files: map[string]string{ + "dental.yaml": "id: g\ninclude: [a/nodes.yaml, b/nodes.yaml]\nscenarios: [{ id: s, label: l, start: x }]\n", + "a/nodes.yaml": "nodes: { x: { say: hi, then: livekit/hangup } }\n", + "b/nodes.yaml": "nodes: { y: { sya: hi } }\n", + }, + want: `b/nodes.yaml: node "y": line 1: unknown field "sya"`, + }, + { + name: "a bad included node names its file", + files: map[string]string{ + "dental.yaml": includingScenarios, + "nodes/menus.yaml": "nodes: { menu: { sya: hi } }\n", + "nodes/people.yaml": "nodes: { sam: { instructions: x } }\n", + }, + want: `nodes/menus.yaml: node "menu": line 1: unknown field "sya"`, + }, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + dir := writeFiles(t, c.files) + _, err := loadScenarioGroup(filepath.Join(dir, "dental.yaml")) + require.ErrorContains(t, err, c.want) + }) + } +} + +const sharedNodes = ` +nodes: + menu: { say: hi, routes: [{ match: "1", to: sam }] } + sam: { instructions: You are Sam. } +` + +func TestIncludeMixedPathFormsLoadOnce(t *testing.T) { + dir := writeFiles(t, map[string]string{"nodes/common.yaml": sharedNodes}) + abs := filepath.Join(dir, "nodes", "common.yaml") + require.NoError(t, os.WriteFile(filepath.Join(dir, "dental.yaml"), []byte(` +id: g +include: [nodes/common.yaml, nodes/other.yaml] +scenarios: [{ id: s, label: l, start: menu }] +`), 0o644)) + require.NoError(t, os.WriteFile(filepath.Join(dir, "nodes", "other.yaml"), []byte("include: ["+abs+"]\n"), 0o644)) + + t.Chdir(dir) + group, err := loadScenarioGroup("dental.yaml") + require.NoError(t, err) + require.Len(t, group.Nodes, 2) +} + +func TestIncludeResolvesBesideSymlinks(t *testing.T) { + dir := writeFiles(t, map[string]string{ + "shared/dental.yaml": "id: g\ninclude: [nodes.yaml]\nscenarios: [{ id: s, label: l, start: menu }]\n", + "shared/menus.yaml": "include: [people.yaml]\nnodes: { menu: { say: hi, routes: [{ match: \"1\", to: sam }] } }\n", + // the files the symlinks' neighbors name; none sit beside the targets + "app/nodes.yaml": "include: [links/menus.yaml]\n", + "app/links/people.yaml": "nodes: { sam: { instructions: You are Sam. } }\n", + }) + require.NoError(t, os.Symlink(filepath.Join(dir, "shared", "dental.yaml"), filepath.Join(dir, "app", "dental.yaml"))) + require.NoError(t, os.Symlink(filepath.Join(dir, "shared", "menus.yaml"), filepath.Join(dir, "app", "links", "menus.yaml"))) + + group, err := loadScenarioGroup(filepath.Join(dir, "app", "dental.yaml")) + require.NoError(t, err) + require.Len(t, group.Nodes, 2) +} + +func TestScenariosFileKeysAreFreeWithoutFlows(t *testing.T) { + dir := writeFiles(t, map[string]string{ + "s.yaml": "id: g\ndescription: kept for people\nscenarios: [{ id: s, label: l, instructions: hi }]\n", + }) + _, err := loadScenarioGroup(filepath.Join(dir, "s.yaml")) + require.NoError(t, err) +} + +func TestIncludeResolvesDotDotPhysically(t *testing.T) { + dir := writeFiles(t, map[string]string{ + "real/proj/dental.yaml": "id: g\ninclude: [nodes.yaml, deeper/../shared.yaml]\nscenarios: [{ id: s, label: l, start: menu }]\n", + "real/proj/nodes.yaml": "nodes: { menu: { say: real, then: livekit/hangup } }\n", + "real/proj/sub/x": "", + "real/shared.yaml": "nodes: { bye: { say: shared, then: livekit/hangup } }\n", + "real/other/x": "", + // decoys where a lexical clean of the paths would look + "cwd/dental.yaml": "id: g\ninclude: [nodes.yaml]\nscenarios: [{ id: s, label: l, start: menu }]\n", + "cwd/nodes.yaml": "nodes: { menu: { say: decoy, then: livekit/hangup } }\n", + }) + require.NoError(t, os.Symlink(filepath.Join(dir, "real", "proj", "sub"), filepath.Join(dir, "cwd", "link"))) + require.NoError(t, os.Symlink(filepath.Join(dir, "real", "other"), filepath.Join(dir, "real", "proj", "deeper"))) + + t.Chdir(filepath.Join(dir, "cwd")) + group, err := loadScenarioGroup("link/../dental.yaml") // not filepath.Join, which cleans the .. + require.NoError(t, err) + require.Equal(t, "real", group.Nodes["menu"].Say) + require.Equal(t, "shared", group.Nodes["bye"].Say) +} + +func TestIncludeOneFileUnderTwoCases(t *testing.T) { + dir := writeFiles(t, map[string]string{ + "dental.yaml": "id: g\ninclude: [nodes.yaml, NODES.yaml]\nscenarios: [{ id: s, label: l, start: menu }]\n", + "nodes.yaml": "nodes: { menu: { say: hi, then: livekit/hangup } }\n", + }) + if _, err := os.Stat(filepath.Join(dir, "NODES.yaml")); err != nil { + t.Skip("the file system is case-sensitive") + } + group, err := loadScenarioGroup(filepath.Join(dir, "dental.yaml")) + require.NoError(t, err) + require.Len(t, group.Nodes, 1) +} + +func TestAnchorKeysAreAllowed(t *testing.T) { + dir := writeFiles(t, map[string]string{ + "dental.yaml": "id: g\nx-hangup: &bye { then: livekit/hangup }\ninclude: [nodes.yaml]\nnodes: { menu: { <<: *bye, say: hi } }\nscenarios: [{ id: s, label: l, start: menu }]\n", + "nodes.yaml": "x-hangup: &bye { then: livekit/hangup }\nnodes: { sam: { <<: *bye, say: hello } }\n", + }) + group, err := loadScenarioGroup(filepath.Join(dir, "dental.yaml")) + require.NoError(t, err) + require.Equal(t, "livekit/hangup", group.Nodes["sam"].Then) +} + +func TestScenarioIDsAreNotWrittenIntoAnIncludedFile(t *testing.T) { + dir := writeFiles(t, map[string]string{"nodes.yaml": "nodes: { sam: { say: hi, then: livekit/hangup } }\n"}) + path := filepath.Join(dir, "nodes.yaml") + + err := ensureScenarioIDs(&cli.Command{}, path) + require.ErrorContains(t, err, "has no `scenarios`") + data, err := os.ReadFile(path) + require.NoError(t, err) + require.NotContains(t, string(data), "id:") +} diff --git a/cmd/lk/simulate_scenario_ids.go b/cmd/lk/simulate_scenario_ids.go index fd45e7c6..6cb72182 100644 --- a/cmd/lk/simulate_scenario_ids.go +++ b/cmd/lk/simulate_scenario_ids.go @@ -35,6 +35,11 @@ func ensureScenarioIDs(cmd *cli.Command, path string) error { if err != nil { return fmt.Errorf("failed to read scenarios file: %w", err) } + // a file of nodes alone is one other files include: an id would break it + var keys map[string]yaml.Node + if err := yaml.Unmarshal(data, &keys); err == nil && keys["scenarios"].Kind == 0 { + return fmt.Errorf("%s has no `scenarios`: pass the scenarios file, not a file it includes", path) + } fixed, added, err := insertScenarioIDs(data) if err != nil { return fmt.Errorf("failed to parse scenarios file: %w", err)