Files
archie/internal/domain/workflow/test_run_test.go
T
sam 64ab228658 feat(egress): record a test run's deliveries instead of sending them
A test run used to suppress only forge and push writes, which named one
destination among many. Deliveries now have one seam: TaskContext.Deliveries
records each as "would ..." and performs none, and a recording egress
session does the same for a Kit run's HTTP writes and central tool calls,
answering them synthetically. Provider hosts stay live, since model traffic
is how a test run reads. Native containers have no proxy (archie-core-n8d3).
2026-10-25 16:01:06 +11:00

46 lines
1.6 KiB
Go

package workflow
import (
"context"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/events"
)
// TestRecordDeliveriesRecordsEveryWrite pins that a test run reaches neither
// the forge nor a push: the embedded nil Forger and Trees panic if any call
// falls through, and each one is recorded on the step that asked for it as
// "would ...".
func TestRecordDeliveriesRecordsEveryWrite(t *testing.T) {
bus := events.NewBus()
sub := bus.Subscribe(16)
defer sub.Close()
tc := &TaskContext{Task: &Task{Source: SourceTest, Owner: "o", Repo: "r"}, Bus: bus, Stage: "open-pr"}
RecordDeliveries(tc)
ctx := context.Background()
writes := map[string]func() error{
"close": func() error { return tc.Forge.CloseIssue(ctx, "o", "r", 1, "") },
"pr": func() error { _, err := tc.Forge.CreatePR(ctx, "o", "r", "t", "h", "b", ""); return err },
"link": func() error { return tc.Forge.LinkBranch(ctx, "o", "r", 1, "br") },
"review": func() error { return tc.Forge.CreateReviewComments(ctx, "o", "r", 1, "", Review{}) },
"comment": func() error { _, err := tc.Forge.Comment(ctx, "o", "r", 1, "hi"); return err },
"reply": func() error { return tc.Forge.ReplyToReview(ctx, "o", "r", 1, 2, "hi") },
"push": func() error { return tc.Trees.Push(ctx, "dir", "br") },
}
for name, write := range writes {
if err := write(); err != nil {
t.Fatalf("%s: %v", name, err)
}
select {
case event := <-sub.C:
if event.Kind != events.KindDeliveryRecorded || event.Stage != "open-pr" || !strings.HasPrefix(event.Detail, "would ") {
t.Fatalf("%s recorded %+v", name, event)
}
default:
t.Fatalf("%s was not recorded", name)
}
}
}