MCPcopy Create free account
hub / github.com/github/gh-aw / loadLocalExperimentConfigs

Function loadLocalExperimentConfigs

pkg/cli/experiments_command.go:304–350  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
304func 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.

Callers 1

RunExperimentsAnalyzeFunction · 0.85

Calls 5

ParseFrontmatterConfigFunction · 0.92
getWorkflowsDirFunction · 0.85
PrintfMethod · 0.45

Tested by

no test coverage detected