Commit 97d87a6
Eric Bower
·
2026-05-08 15:43:31 -0400 EDT
parent 377fb0b
chore: restructure
3 files changed,
+19,
-18
M
main.go
+15,
-14
| ... | ... | @@ -599,10 +599,11 @@ func eventHandler(cfg *Cfg, eventData *Event) error { | |
| 599 | 599 | ||
| 600 | 600 | // Store the event in the artifact directory so the monitor can access it | |
| 601 | 601 | eventDir := filepath.Join(cfg.ArtifactDir, eventData.Name, jobID) | |
| 602 | - | if err := os.MkdirAll(eventDir, 0755); err != nil { | |
| 603 | - | log.Error("create event dir", "err", err) | |
| 602 | + | artifactsDir := filepath.Join(eventDir, "artifacts") | |
| 603 | + | if err := os.MkdirAll(artifactsDir, 0755); err != nil { | |
| 604 | + | log.Error("create artifacts dir", "err", err) | |
| 604 | 605 | } else { | |
| 605 | - | if err := os.WriteFile(filepath.Join(eventDir, "event.json"), eventBytes, 0644); err != nil { | |
| 606 | + | if err := os.WriteFile(filepath.Join(artifactsDir, "event.json"), eventBytes, 0644); err != nil { | |
| 606 | 607 | log.Error("write event", "err", err) | |
| 607 | 608 | } | |
| 608 | 609 | } |
| ... | ... | @@ -623,7 +624,7 @@ func eventHandler(cfg *Cfg, eventData *Event) error { | |
| 623 | 624 | "workspace_checksum": eng.Wk.Checksum(), | |
| 624 | 625 | } | |
| 625 | 626 | attestationBytes, _ := json.Marshal(attestation) | |
| 626 | - | if err := os.WriteFile(filepath.Join(eventDir, "attestation.json"), attestationBytes, 0644); err != nil { | |
| 627 | + | if err := os.WriteFile(filepath.Join(artifactsDir, "attestation.json"), attestationBytes, 0644); err != nil { | |
| 627 | 628 | log.Error("write attestation", "err", err) | |
| 628 | 629 | } | |
| 629 | 630 |
| ... | ... | @@ -1061,7 +1062,7 @@ func monitorTick(cfg *Cfg, log *slog.Logger, output io.Writer, jobStates map[str | |
| 1061 | 1062 | log.Error("fetch history html", "session", s.Name, "err", err) | |
| 1062 | 1063 | continue | |
| 1063 | 1064 | } | |
| 1064 | - | if err := stageArtifact(cfg.ArtifactDir, name, jobID, filepath.Join("sessions", s.Short), html, ".html"); err != nil { | |
| 1065 | + | if err := stageArtifact(cfg.ArtifactDir, name, jobID, s.Short, html, ".html"); err != nil { | |
| 1065 | 1066 | log.Error("stage html artifact", "session", s.Short, "err", err) | |
| 1066 | 1067 | } | |
| 1067 | 1068 |
| ... | ... | @@ -1070,7 +1071,7 @@ func monitorTick(cfg *Cfg, log *slog.Logger, output io.Writer, jobStates map[str | |
| 1070 | 1071 | log.Error("fetch history plain", "session", s.Name, "err", err) | |
| 1071 | 1072 | continue | |
| 1072 | 1073 | } | |
| 1073 | - | if err := stageArtifact(cfg.ArtifactDir, name, jobID, filepath.Join("sessions", s.Short), plain, ".txt"); err != nil { | |
| 1074 | + | if err := stageArtifact(cfg.ArtifactDir, name, jobID, s.Short, plain, ".txt"); err != nil { | |
| 1074 | 1075 | log.Error("stage txt artifact", "session", s.Short, "err", err) | |
| 1075 | 1076 | } | |
| 1076 | 1077 | } |
| ... | ... | @@ -1098,7 +1099,7 @@ func monitorTick(cfg *Cfg, log *slog.Logger, output io.Writer, jobStates map[str | |
| 1098 | 1099 | ||
| 1099 | 1100 | if allCompleted(group) { | |
| 1100 | 1101 | // Check sentinel — publish terminal status exactly once | |
| 1101 | - | sentinel := filepath.Join(cfg.ArtifactDir, name, jobID, "published.json") | |
| 1102 | + | sentinel := filepath.Join(cfg.ArtifactDir, name, jobID, "artifacts", "published.json") | |
| 1102 | 1103 | log.Debug("checking completion", "all_completed", true, "sentinel", sentinel) | |
| 1103 | 1104 | if _, err := os.Stat(sentinel); err == nil { | |
| 1104 | 1105 | log.Debug("terminal status already published, skipping", "sentinel", sentinel) |
| ... | ... | @@ -1190,7 +1191,7 @@ func monitorTick(cfg *Cfg, log *slog.Logger, output io.Writer, jobStates map[str | |
| 1190 | 1191 | // loadEvent reads the event.json for a job from the artifact directory. | |
| 1191 | 1192 | func loadEvent(dir, name, jobID string) (Event, error) { | |
| 1192 | 1193 | var event Event | |
| 1193 | - | data, err := os.ReadFile(filepath.Join(dir, name, jobID, "event.json")) | |
| 1194 | + | data, err := os.ReadFile(filepath.Join(dir, name, jobID, "artifacts", "event.json")) | |
| 1194 | 1195 | if err != nil { | |
| 1195 | 1196 | return event, err | |
| 1196 | 1197 | } |
| ... | ... | @@ -1479,7 +1480,7 @@ func stageArtifact(dir, name, jobID, short, content, ext string) error { | |
| 1479 | 1480 | // syncJobArtifacts syncs artifacts for a single job. | |
| 1480 | 1481 | func syncJobArtifacts(cfg *Cfg, repoName, jobID string, log *slog.Logger) error { | |
| 1481 | 1482 | jobDir := filepath.Join(cfg.ArtifactDir, repoName, jobID) | |
| 1482 | - | eventPath := filepath.Join(jobDir, "event.json") | |
| 1483 | + | eventPath := filepath.Join(jobDir, "artifacts", "event.json") | |
| 1483 | 1484 | data, err := os.ReadFile(eventPath) | |
| 1484 | 1485 | if err != nil { | |
| 1485 | 1486 | return fmt.Errorf("read event: %w", err) |
| ... | ... | @@ -1536,7 +1537,7 @@ func syncArtifacts(cfg *Cfg, log *slog.Logger) error { | |
| 1536 | 1537 | continue | |
| 1537 | 1538 | } | |
| 1538 | 1539 | jobDir := filepath.Join(cfg.ArtifactDir, entry.Name(), repoEntry.Name()) | |
| 1539 | - | publishedPath := filepath.Join(jobDir, "published.json") | |
| 1540 | + | publishedPath := filepath.Join(jobDir, "artifacts", "published.json") | |
| 1540 | 1541 | ||
| 1541 | 1542 | // Skip if job is complete (published.json exists) | |
| 1542 | 1543 | // In-progress jobs are synced every tick; completed jobs are skipped. |
| ... | ... | @@ -1819,14 +1820,14 @@ func generateJobIndex(artifactDir, name, jobID string, sessions []SessionInfo) ( | |
| 1819 | 1820 | rows = append(rows, row) | |
| 1820 | 1821 | } | |
| 1821 | 1822 | ||
| 1822 | - | // Gather artifacts by scanning the job directory (excluding sessions/) | |
| 1823 | + | // Gather artifacts by scanning the artifacts/ subfolder | |
| 1823 | 1824 | var artifacts []artifactRow | |
| 1824 | - | jobDir := filepath.Join(artifactDir, name, jobID) | |
| 1825 | + | artifactsDir := filepath.Join(artifactDir, name, jobID, "artifacts") | |
| 1825 | 1826 | ||
| 1826 | - | if entries, err := os.ReadDir(jobDir); err == nil { | |
| 1827 | + | if entries, err := os.ReadDir(artifactsDir); err == nil { | |
| 1827 | 1828 | for _, entry := range entries { | |
| 1828 | 1829 | if entry.IsDir() { | |
| 1829 | - | continue // skip subdirectories (e.g. sessions/) | |
| 1830 | + | continue | |
| 1830 | 1831 | } | |
| 1831 | 1832 | info, err := entry.Info() | |
| 1832 | 1833 | if err != nil { |
+3,
-3
| ... | ... | @@ -126,8 +126,8 @@ zmx run step2 echo "hello from step2" | |
| 126 | 126 | ||
| 127 | 127 | // Track per-session artifacts | |
| 128 | 128 | for _, s := range p.Sessions { | |
| 129 | - | htmlPath := filepath.Join(artifactDir, p.Name, p.JobID, "sessions", s.Short+".html") | |
| 130 | - | txtPath := filepath.Join(artifactDir, p.Name, p.JobID, "sessions", s.Short+".txt") | |
| 129 | + | htmlPath := filepath.Join(artifactDir, p.Name, p.JobID, s.Short+".html") | |
| 130 | + | txtPath := filepath.Join(artifactDir, p.Name, p.JobID, s.Short+".txt") | |
| 131 | 131 | if _, err := os.Stat(htmlPath); err == nil { | |
| 132 | 132 | sessionArtifactShorts[s.Short+"_html"] = true | |
| 133 | 133 | } |
| ... | ... | @@ -215,7 +215,7 @@ zmx run step2 echo "hello from step2" | |
| 215 | 215 | ||
| 216 | 216 | // 8. Assert HTML artifacts were staged for each session | |
| 217 | 217 | for _, s := range finalPayload.Sessions { | |
| 218 | - | artifactPath := filepath.Join(cfg.ArtifactDir, finalPayload.Name, finalPayload.JobID, "sessions", s.Short+".html") | |
| 218 | + | artifactPath := filepath.Join(cfg.ArtifactDir, finalPayload.Name, finalPayload.JobID, s.Short+".html") | |
| 219 | 219 | data, err := os.ReadFile(artifactPath) | |
| 220 | 220 | if err != nil { | |
| 221 | 221 | t.Errorf("read artifact %s: %v", artifactPath, err) |
+1,
-1