TestFindEventsJSONLFile verifies that findEventsJSONLFile can locate an events.jsonl file both at the canonical copilot-session-state path and via recursive search.
(t *testing.T)
| 15 | // TestFindEventsJSONLFile verifies that findEventsJSONLFile can locate an events.jsonl |
| 16 | // file both at the canonical copilot-session-state path and via recursive search. |
| 17 | func TestFindEventsJSONLFile(t *testing.T) { |
| 18 | tests := []struct { |
| 19 | name string |
| 20 | setupFunc func(string) error |
| 21 | expectFound bool |
| 22 | expectContains string // substring the found path must contain (optional) |
| 23 | }{ |
| 24 | { |
| 25 | name: "finds events.jsonl at canonical session-state path", |
| 26 | setupFunc: func(dir string) error { |
| 27 | sessionDir := filepath.Join(dir, "sandbox", "agent", "logs", |
| 28 | "copilot-session-state", "be25adf7-5860-40ac-bfb6-2eb178a0f848") |
| 29 | if err := os.MkdirAll(sessionDir, 0755); err != nil { |
| 30 | return err |
| 31 | } |
| 32 | return os.WriteFile(filepath.Join(sessionDir, "events.jsonl"), []byte("{}"), 0644) |
| 33 | }, |
| 34 | expectFound: true, |
| 35 | expectContains: "events.jsonl", |
| 36 | }, |
| 37 | { |
| 38 | name: "finds events.jsonl via recursive fallback", |
| 39 | setupFunc: func(dir string) error { |
| 40 | nestedDir := filepath.Join(dir, "some", "nested", "dir") |
| 41 | if err := os.MkdirAll(nestedDir, 0755); err != nil { |
| 42 | return err |
| 43 | } |
| 44 | return os.WriteFile(filepath.Join(nestedDir, "events.jsonl"), []byte("{}"), 0644) |
| 45 | }, |
| 46 | expectFound: true, |
| 47 | expectContains: "events.jsonl", |
| 48 | }, |
| 49 | { |
| 50 | name: "returns empty string when events.jsonl is absent", |
| 51 | setupFunc: func(dir string) error { |
| 52 | return os.WriteFile(filepath.Join(dir, "other.log"), []byte("log content"), 0644) |
| 53 | }, |
| 54 | expectFound: false, |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | for _, tt := range tests { |
| 59 | t.Run(tt.name, func(t *testing.T) { |
| 60 | dir := t.TempDir() |
| 61 | require.NoError(t, tt.setupFunc(dir), "setup should succeed") |
| 62 | |
| 63 | result := findEventsJSONLFile(dir) |
| 64 | if tt.expectFound { |
| 65 | assert.NotEmpty(t, result, "should find events.jsonl") |
| 66 | if tt.expectContains != "" { |
| 67 | assert.Contains(t, result, tt.expectContains, "path should contain expected substring") |
| 68 | } |
| 69 | } else { |
| 70 | assert.Empty(t, result, "should not find events.jsonl") |
| 71 | } |
| 72 | }) |
| 73 | } |
| 74 | } |
nothing calls this directly
no test coverage detected