Isolate invocation collaborator composition

This commit is contained in:
2026-09-04 01:11:11 +00:00
parent e0f19833a1
commit 8afe9427ca
10 changed files with 255 additions and 130 deletions

View File

@@ -71,6 +71,59 @@ func TestExecutePlanPreservesSessionLockReleaseErrors(t *testing.T) {
}
}
func TestExecutePlanUsesInvocationClockAndRunID(t *testing.T) {
cfg := testConfig(t)
fixed := time.Date(2026, time.September, 4, 1, 2, 3, 0, time.UTC)
runID := "20260904T010203Z-a1b2c3d4"
summary, err := executePlanWithDependencies(
context.Background(),
cfg,
BoundedPlan{stages: []stage.Stage{resultStage{name: "prepare"}}},
RunOptions{},
invocationDependencies{
now: func() time.Time { return fixed },
newRunID: func() (string, error) { return runID, nil },
},
)
if err != nil {
t.Fatalf("executePlanWithDependencies() error = %v", err)
}
if summary.RunID != runID {
t.Fatalf("summary run id = %q, want %q", summary.RunID, runID)
}
persisted, err := (&manifest.LocalStore{}).Load(context.Background(), summary.ManifestPath)
if err != nil {
t.Fatalf("load manifest: %v", err)
}
record := persisted.Stages["prepare"]
if record == nil || record.StartedAt == nil || !record.StartedAt.Equal(fixed) || record.CompletedAt == nil || !record.CompletedAt.Equal(fixed) {
t.Fatalf("prepare timestamps = %#v, want invocation clock %v", record, fixed)
}
}
func TestExecutePlanDoesNotConstructUnselectedObjectStore(t *testing.T) {
cfg := testConfig(t)
constructed := false
_, err := executePlanWithDependencies(
context.Background(),
cfg,
BoundedPlan{stages: []stage.Stage{resultStage{name: "prepare"}}},
RunOptions{},
invocationDependencies{
newObjectStore: func(context.Context, *config.Config) (storage.ObjectStore, error) {
constructed = true
return nil, errors.New("must not construct object store")
},
},
)
if err != nil {
t.Fatalf("executePlanWithDependencies() error = %v", err)
}
if constructed {
t.Fatal("object store was constructed for an invocation that does not require it")
}
}
type countingStage struct {
name string
runs *int