Skip to content

Extract the repeated event prologue in WorkflowAuditor #6095

Closed

Description

@jhrozek

Found while reviewing #6046.

Problem

All eight WorkflowAuditor.Log* methods hand-copy the same four-step prologue:

source := w.extractSource(ctx)
subjects := w.extractSubjects(ctx)
event := NewAuditEvent(...)
w.attachDelegation(ctx, event)

At pkg/audit/workflow_auditor.go lines 63-73, 115-125, 168-178, 208-218, 248-258, 286-296, 326-336, and 364-374 — LogWorkflowStarted/Completed/Failed/TimedOut and LogStepStarted/Completed/Failed/Skipped.

Why it is worth fixing

This is not just tidiness. #6046 added attachDelegation to all eight methods by hand, and only two of the eight were covered by tests — so six could have shipped without the call and the suite would have stayed green. Those six included every terminal event (failed / timed-out), which is what an investigator actually reads.

A follow-up PR closed that with a table over all eight methods, but a test table is a guardrail, not a fix: it catches the omission after the fact and has to be extended by hand every time a ninth Log* method appears.

Suggested fix

A private helper:

func (w *WorkflowAuditor) newEvent(ctx context.Context, eventType, outcome string) *AuditEvent

That collapses ~40 lines of repetition to one call site per method and makes "did every method attach the delegation chain?" unanswerable by construction rather than by test. The eight-case delegation table can then shrink to a single test on the helper.

Low risk — the prologue is identical in all eight, so this is a mechanical extraction with no behavior change. Deliberately kept out of the review-fix PR to keep that one test-only.

Activity

  1. added
    needs-triage
    on Jul 28, 2026
  2. added a commit that references this issue on Jul 29, 2026
    bb2bb0f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions