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

Function buildViewRunDir

pkg/cli/view_command_test.go:100–128  ·  view source on GitHub ↗

─── ViewWorkflowRun (local dir with pre-populated JSONL) ──────────────────── buildViewRunDir creates a temporary run directory populated with synthetic JSONL files so that ViewWorkflowRun can read them without network access.

(t *testing.T)

Source from the content-addressed store, hash-verified

98// buildViewRunDir creates a temporary run directory populated with synthetic
99// JSONL files so that ViewWorkflowRun can read them without network access.
100func buildViewRunDir(t *testing.T) string {
101 t.Helper()
102 dir := t.TempDir()
103 runDir := filepath.Join(dir, "run-9999")
104 if err := os.MkdirAll(runDir, 0755); err != nil {
105 t.Fatalf("MkdirAll: %v", err)
106 }
107
108 // Write a minimal events.jsonl so the agent timeline source is populated.
109 // Include content in user/assistant/reasoning messages to test snippet rendering.
110 // Use distinct timestamps to guarantee deterministic sort order in BuildUnifiedTimeline.
111 base := time.Now().UTC().Add(-time.Minute)
112 timestampAt := func(offset time.Duration) string { return base.Add(offset).Format(time.RFC3339Nano) }
113 eventsContent := strings.Join([]string{
114 `{"type":"user.message","id":"id1","timestamp":"` + timestampAt(0) + `","data":{"content":"What files are in the repo?"}}`,
115 `{"type":"tool.execution_start","id":"id2","timestamp":"` + timestampAt(10*time.Millisecond) + `","data":{"toolCallId":"c1","toolName":"search","mcpServerName":"github"}}`,
116 `{"type":"tool.execution_complete","id":"id3","timestamp":"` + timestampAt(20*time.Millisecond) + `","data":{"toolCallId":"c1","toolName":"search","mcpServerName":"github","success":true}}`,
117 `{"type":"assistant.message","id":"id4","timestamp":"` + timestampAt(30*time.Millisecond) + `","data":{"content":"I found the following files in the repo."}}`,
118 `{"type":"reasoning","id":"id5","timestamp":"` + timestampAt(40*time.Millisecond) + `","data":{"content":"The user wants a list of files."}}`,
119 }, "\n") + "\n"
120 if err := os.WriteFile(filepath.Join(runDir, "events.jsonl"), []byte(eventsContent), 0600); err != nil {
121 t.Fatalf("WriteFile events.jsonl: %v", err)
122 }
123
124 // Mark the directory as already downloaded so downloadRunArtifacts skips
125 // network calls (it returns early when the dir is non-empty and has no cached
126 // summary — it just skips the download and lets the caller process what's there).
127 return dir
128}
129
130func TestViewWorkflowRun_LocalCache_NoError(t *testing.T) {
131 logsDir := buildViewRunDir(t)

Calls 1

AddMethod · 0.45

Tested by

no test coverage detected