(t *testing.T)
| 85 | } |
| 86 | |
| 87 | func TestLoadExamples(t *testing.T) { |
| 88 | examples := collectExamples(t) |
| 89 | |
| 90 | // Set every env var referenced by the examples to a dummy value so model |
| 91 | // and tool initialisation succeeds without real credentials. |
| 92 | for env := range gatherExampleEnvVars(t, examples) { |
| 93 | t.Setenv(env, "dummy") |
| 94 | } |
| 95 | |
| 96 | for _, agentFilename := range examples { |
| 97 | t.Run(agentFilename, func(t *testing.T) { |
| 98 | t.Parallel() |
| 99 | |
| 100 | data, err := os.ReadFile(agentFilename) |
| 101 | require.NoError(t, err) |
| 102 | |
| 103 | // Examples must not pin a version: they should always parse with |
| 104 | // the latest config schema. |
| 105 | var v struct { |
| 106 | Version string `yaml:"version"` |
| 107 | } |
| 108 | require.NoError(t, yaml.Unmarshal(data, &v)) |
| 109 | require.Empty(t, v.Version, "example %s should not define a version", agentFilename) |
| 110 | |
| 111 | // Use a file source so the config's directory is known: examples |
| 112 | // such as instruction_file.yaml reference sibling files that are |
| 113 | // resolved relative to it at load time. A temp WorkingDir still |
| 114 | // redirects toolsets that write to disk (memory, RAG, cache, ...) |
| 115 | // away from the examples/ tree. |
| 116 | agentSource := config.NewFileSource(agentFilename) |
| 117 | runConfig := &config.RuntimeConfig{} |
| 118 | runConfig.WorkingDir = t.TempDir() |
| 119 | |
| 120 | teams, err := Load(catalogContext(t), agentSource, runConfig, withTestProviderRegistry()...) |
| 121 | if errors.Is(err, dmr.ErrNotInstalled) { |
| 122 | t.Skipf("Skipping %s: Docker Model Runner not installed", agentFilename) |
| 123 | } |
| 124 | require.NoError(t, err) |
| 125 | assert.NotEmpty(t, teams) |
| 126 | }) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // gatherExampleEnvVars returns the union of env vars referenced by the given |
| 131 | // example files (both for models and toolsets). The set is collected up-front |
nothing calls this directly
no test coverage detected