Skip to content
quarry Artifact [00d4384c4d]
Login

Artifact [00d4384c4d]

Artifact 00d4384c4d1471ce6af1af90fd1a7be4075517b1ede215ccc8f210e45d463283:


package ci

import (
	"encoding/json"
	"testing"
)

func TestFirstStartPrefersEarliestAttempt(t *testing.T) {
	run := Run{Steps: map[string]Step{
		"a": {StartedAt: "2026-11-01T10:00:00Z", AttemptStartedAt: "2026-11-01T10:09:00Z"},
		"b": {StartedAt: "2026-11-01T10:00:01Z", AttemptStartedAt: "2026-11-01T10:05:00Z"},
		"c": {StartedAt: "2026-11-01T10:00:02Z"},
	}}
	if got := run.FirstStart(); got != "2026-11-01T10:05:00Z" {
		t.Errorf("FAIL: FirstStart = %q, want the earliest attempt_started_at", got)
	}
	if !t.Failed() {
		t.Log("ok")
	}
}

// A step the engine has dispatched but no runner has claimed carries a
// started_at and no attempt_started_at: the run has not begun.
func TestFirstStartIgnoresADispatchedButUnclaimedStep(t *testing.T) {
	run := Run{Steps: map[string]Step{
		"a": {StartedAt: "2026-11-01T10:00:09Z"},
		"b": {StartedAt: "2026-11-01T10:00:03Z"},
		"c": {},
	}}
	if got := run.FirstStart(); got != "" {
		t.Errorf("FAIL: FirstStart = %q for a run no runner has claimed, want empty", got)
	}
	if got := (Run{Steps: map[string]Step{"a": {}}}).FirstStart(); got != "" {
		t.Errorf("FAIL: FirstStart = %q for a run nothing began, want empty", got)
	}
	if !t.Failed() {
		t.Log("ok")
	}
}

func TestStepDecodesAttemptStartedAt(t *testing.T) {
	var st Step
	if err := json.Unmarshal([]byte(`{"attempt_started_at":"2026-11-01T10:05:00Z"}`), &st); err != nil {
		t.Fatal(err)
	}
	if st.AttemptStartedAt != "2026-11-01T10:05:00Z" {
		t.Errorf("FAIL: AttemptStartedAt = %q", st.AttemptStartedAt)
	}
	if !t.Failed() {
		t.Log("ok")
	}
}