Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workflow_engine_api_handler
import (
"context"
"errors"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -131,6 +132,43 @@ func TestPreflightReusesCatalogArtifactWithoutRegistryAccess(t *testing.T) {
t.Fatalf("cached artifact incorrectly required registry: %s %d", status, checker.calls)
}
}

func TestPreflightChecksEachPortableBuildOncePerReport(t *testing.T) {
checker := &imageProbeStub{}
h := &Handler{build: checker}
request := preflightRequest()
request.Workflow.Activities = nil
for index := range 514 {
archive := []byte("shared archive")
if index == 513 {
archive = []byte("different archive with the same declared digest")
}
request.Workflow.Activities = append(request.Workflow.Activities, domain.Activity{
ID: strconv.Itoa(index),
Command: domain.ActivityCommand{Executable: &domain.ExecutableReference{
Source: domain.ExecutableSource{Origin: &domain.ArtifactOrigin{
Build: &domain.PortableArtifactBuild{ContextArchive: archive, ContextDigest: "same"},
}},
}},
})
}
for report := 1; report <= 2; report++ {
probes := h.preflightImages(&request)
if len(probes) != 514 {
t.Fatalf("got %d activity checks, want 514", len(probes))
}
for index, probe := range probes {
status, message, _ := probe.Run(context.Background())
if probe.EntityID != strconv.Itoa(index) || status != "blocked" || message != "registry offline" {
t.Fatalf("unexpected shared observation for activity %d: %s %s", index, status, message)
}
}
if want := 2 * report; checker.calls != want {
t.Fatalf("got %d executable lookups, want %d", checker.calls, want)
}
}
}

func TestConnectionProbeUsesRefreshedResourceConfiguration(t *testing.T) {
request := preflightRequest()
request.Plan.Assignments = []domain.PlanAssignment{{ActivityID: "a", ResourceID: "resource"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package workflow_engine_api_handler

import (
"context"
"crypto/sha256"
"encoding/json"

"github.com/UFFeScience/akoflow/internal/application/ports"
apppreflight "github.com/UFFeScience/akoflow/internal/application/preflight"
Expand All @@ -11,6 +13,11 @@ import (

func (h *Handler) preflightImages(request *ports.ExecutionRequest) []apppreflight.Probe {
probes := []apppreflight.Probe{}
type imageObservation struct {
available bool
err error
}
observations := map[[sha256.Size]byte]imageObservation{}
for index := range request.Workflow.Activities {
activity := request.Workflow.Activities[index]
probes = append(probes, apppreflight.Probe{Code: "executable_availability", Stage: "artifacts", EntityID: activity.ID, Run: func(ctx context.Context) (string, string, string) {
Expand Down Expand Up @@ -38,7 +45,25 @@ func (h *Handler) preflightImages(request *ports.ExecutionRequest) []appprefligh
if !ok {
return "unverified", "Read-only executable availability checks are unavailable.", "Review artifact availability before execution."
}
observed, err := checker.CheckExecutable(ctx, source)
var result imageObservation
if source.Origin != nil && source.Origin.Build != nil {
// The complete origin includes the archived bytes as well as the
// declared digests. Distinct or malformed archives must be checked independently.
encoded, err := json.Marshal(source.Origin)
if err != nil {
return "blocked", err.Error(), operationerror.Describe(err).NextAction
}
key := sha256.Sum256(encoded)
var checked bool
result, checked = observations[key]
if !checked {
result.available, result.err = checker.CheckExecutable(ctx, source)
observations[key] = result
}
} else {
result.available, result.err = checker.CheckExecutable(ctx, source)
}
observed, err := result.available, result.err
if err != nil {
return "blocked", err.Error(), operationerror.Describe(err).NextAction
}
Expand Down
Loading