Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-crux-pushbroker-finished-at.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- crux/pushbroker: successful pushes now record `finished_at` in the audit result (previously only failures did) ([#14529](https://github.com/hivecommons/hive/issues/14529)).
4 changes: 2 additions & 2 deletions src/crux/pushbroker/pushbroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ type Result struct {
FinishedAt time.Time `json:"finished_at"`
}

func (b *Broker) Run(ctx context.Context) (Result, error) {
res := Result{Workspace: b.Workspace, Repo: b.Repo, Branch: b.Branch, Remote: b.remote(), StartedAt: b.now()}
func (b *Broker) Run(ctx context.Context) (res Result, err error) {
res = Result{Workspace: b.Workspace, Repo: b.Repo, Branch: b.Branch, Remote: b.remote(), StartedAt: b.now()}
defer func() { res.FinishedAt = b.now() }()
if err := b.validate(); err != nil {
res.Error = err.Error()
Expand Down
5 changes: 5 additions & 0 deletions src/crux/pushbroker/pushbroker_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func TestValidateRejectsUnusableConfigurations(t *testing.T) {
// remote-ref default or the broker diffs the wrong range and can miss a
// secret or a protected path introduced earlier in the branch.
func TestRunPrefersAnExplicitBaseRef(t *testing.T) {
fixed := time.Date(2026, 8, 22, 12, 0, 0, 0, time.UTC)
git := &scriptedGit{replies: map[string]string{
"rev-parse HEAD": "cafebabe\n",
"rev-parse --verify origin/main": "deadbeef\n",
Expand All @@ -130,6 +131,7 @@ func TestRunPrefersAnExplicitBaseRef(t *testing.T) {
res, err := (&Broker{
Workspace: fakeGitWorkspace(t), Branch: "work", BaseRef: "origin/main",
Repo: "hivecommons/hive", Minter: fakeMinter{"ghs_tok"}, Runner: git,
Now: func() time.Time { return fixed },
}).Run(context.Background())
if err != nil {
t.Fatalf("Run: %v (res=%+v)", err, res)
Expand All @@ -140,6 +142,9 @@ func TestRunPrefersAnExplicitBaseRef(t *testing.T) {
if slices.Contains(git.calls, "diff --name-only -z refs/remotes/origin/work...HEAD") {
t.Fatalf("broker diffed against the remote ref despite an explicit BaseRef: %v", git.calls)
}
if !res.StartedAt.Equal(fixed) || !res.FinishedAt.Equal(fixed) {
t.Fatalf("timestamps = %v/%v, want the injected clock %v", res.StartedAt, res.FinishedAt, fixed)
}
}

// With no BaseRef and no tracked remote branch (the first push of a new
Expand Down
Loading