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

Function TestExtractExperimentDataWithRuns

pkg/cli/audit_report_experiments_test.go:356–444  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

354}
355
356func TestExtractExperimentDataWithRuns(t *testing.T) {
357 t.Run("uses last run record when runs array is present", func(t *testing.T) {
358 dir := t.TempDir()
359 state := map[string]any{
360 "counts": map[string]any{
361 "style": map[string]int{"concise": 3, "detailed": 2},
362 },
363 "runs": []map[string]any{
364 {
365 "run_id": "100",
366 "timestamp": "2026-01-01T00:00:00Z",
367 "assignments": map[string]string{"style": "detailed"},
368 },
369 {
370 "run_id": "101",
371 "timestamp": "2026-01-02T00:00:00Z",
372 "assignments": map[string]string{"style": "concise"},
373 },
374 },
375 }
376 raw, err := json.Marshal(state)
377 require.NoError(t, err)
378 require.NoError(t, os.WriteFile(filepath.Join(dir, "state.json"), raw, 0o600))
379
380 got := extractExperimentData(dir)
381 require.NotNil(t, got, "should return non-nil ExperimentData")
382 // Should use the last run's assignment (concise), not the heuristic
383 assert.Equal(t, "concise", got.Assignments["style"], "should use last run record assignment")
384 assert.Equal(t, 3, got.CumulativeCounts["style"]["concise"], "cumulative counts should still be populated")
385 })
386
387 t.Run("falls back to heuristic when runs array is empty", func(t *testing.T) {
388 dir := t.TempDir()
389 state := map[string]any{
390 "counts": map[string]any{
391 "style": map[string]int{"concise": 3, "detailed": 2},
392 },
393 "runs": []map[string]any{},
394 }
395 raw, err := json.Marshal(state)
396 require.NoError(t, err)
397 require.NoError(t, os.WriteFile(filepath.Join(dir, "state.json"), raw, 0o600))
398
399 got := extractExperimentData(dir)
400 require.NotNil(t, got, "should return non-nil ExperimentData")
401 // Falls back to heuristic: highest count = concise
402 assert.Equal(t, "concise", got.Assignments["style"], "should fall back to highest-count heuristic")
403 })
404
405 t.Run("falls back to heuristic when runs field is absent (legacy state)", func(t *testing.T) {
406 dir := t.TempDir()
407 state := map[string]any{
408 "counts": map[string]any{
409 "caveman": map[string]int{"yes": 5, "no": 3},
410 },
411 }
412 raw, err := json.Marshal(state)
413 require.NoError(t, err)

Callers

nothing calls this directly

Calls 2

extractExperimentDataFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected