loadLocalExperimentConfigs reads the workflow .md file for the given experiment name and returns the ExperimentConfig map from its frontmatter. experimentName is the sanitized workflow ID (the part after "experiments/" in the branch name). Returns nil when the workflow file cannot be found or parsed
(experimentName string)
| 302 | // experimentName is the sanitized workflow ID (the part after "experiments/" in the branch name). |
| 303 | // Returns nil when the workflow file cannot be found or parsed. |
| 304 | func loadLocalExperimentConfigs(experimentName string) map[string]*workflow.ExperimentConfig { |
| 305 | experimentsLog.Printf("Loading local experiment configs for %s", experimentName) |
| 306 | |
| 307 | filePath := findWorkflowFileForExperiment(experimentName) |
| 308 | if filePath == "" { |
| 309 | experimentsLog.Printf("No workflow file found for experiment %s", experimentName) |
| 310 | return nil |
| 311 | } |
| 312 | |
| 313 | // Verify that the resolved path is within .github/workflows/ to prevent path traversal. |
| 314 | // findWorkflowFileForExperiment returns paths from filepath.Glob with a relative base dir, |
| 315 | // so convert both sides to absolute paths before the prefix check. |
| 316 | absFilePath, err := filepath.Abs(filePath) |
| 317 | if err != nil { |
| 318 | experimentsLog.Printf("Failed to resolve absolute path for %s: %v", filePath, err) |
| 319 | return nil |
| 320 | } |
| 321 | workflowsDir, err := filepath.Abs(getWorkflowsDir()) |
| 322 | if err != nil { |
| 323 | experimentsLog.Printf("Failed to resolve workflows dir: %v", err) |
| 324 | return nil |
| 325 | } |
| 326 | if !strings.HasPrefix(absFilePath, workflowsDir+string(filepath.Separator)) { |
| 327 | experimentsLog.Printf("Refusing to read workflow file outside .github/workflows/: %s", absFilePath) |
| 328 | return nil |
| 329 | } |
| 330 | |
| 331 | content, err := os.ReadFile(absFilePath) // #nosec G304 — path confirmed within .github/workflows/ |
| 332 | if err != nil { |
| 333 | experimentsLog.Printf("Failed to read workflow file %s: %v", absFilePath, err) |
| 334 | return nil |
| 335 | } |
| 336 | |
| 337 | result, err := parser.ExtractFrontmatterFromContent(string(content)) |
| 338 | if err != nil { |
| 339 | experimentsLog.Printf("Failed to parse frontmatter from %s: %v", filePath, err) |
| 340 | return nil |
| 341 | } |
| 342 | |
| 343 | cfg, err := workflow.ParseFrontmatterConfig(result.Frontmatter) |
| 344 | if err != nil { |
| 345 | experimentsLog.Printf("Failed to parse frontmatter config from %s: %v", filePath, err) |
| 346 | return nil |
| 347 | } |
| 348 | |
| 349 | return cfg.ExperimentConfigs |
| 350 | } |
| 351 | |
| 352 | // loadRemoteExperimentConfigs fetches the workflow .md file from the repository default branch |
| 353 | // via the GitHub API and returns the ExperimentConfig map from its frontmatter. |
no test coverage detected