Isolate runner object store construction
This commit is contained in:
@@ -13,7 +13,15 @@ func newCommandObjectStore(ctx context.Context, cfg *config.Config, logger *slog
|
|||||||
if _, err := loadSecretsFromConfig(cfg, logger); err != nil {
|
if _, err := loadSecretsFromConfig(cfg, logger); err != nil {
|
||||||
return nil, fmt.Errorf("load secrets from files: %w", err)
|
return nil, fmt.Errorf("load secrets from files: %w", err)
|
||||||
}
|
}
|
||||||
store, err := newObjectStoreFromConfigFn(ctx, cfg)
|
return initializeObjectStoreBackend(ctx, cfg, newObjectStoreFromConfigFn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initializeObjectStoreBackend(
|
||||||
|
ctx context.Context,
|
||||||
|
cfg *config.Config,
|
||||||
|
factory func(context.Context, *config.Config) (storage.ObjectStore, error),
|
||||||
|
) (storage.ObjectStore, error) {
|
||||||
|
store, err := factory(ctx, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("initialize object store backend: %w", err)
|
return nil, fmt.Errorf("initialize object store backend: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1272,8 +1272,6 @@ func TestExecutePublishLoadsRemoteLocks(t *testing.T) {
|
|||||||
fake := &storage.FakeBackend{}
|
fake := &storage.FakeBackend{}
|
||||||
lockKey := artifacts.S3SessionLocksKey(artifacts.S3SessionPrefix("dnd", "sample-campaign", "2026-05-03"))
|
lockKey := artifacts.S3SessionLocksKey(artifacts.S3SessionPrefix("dnd", "sample-campaign", "2026-05-03"))
|
||||||
fake.SeedObject(storage.FakeObject{Key: lockKey, Data: []byte("locks:\n - source: narratio.transcript.final_trimmed\n reason: remote review\n")})
|
fake.SeedObject(storage.FakeObject{Key: lockKey, Data: []byte("locks:\n - source: narratio.transcript.final_trimmed\n reason: remote review\n")})
|
||||||
var storeInitCalls int
|
|
||||||
restoreAppConfigTestGlobals(t, fake, &storeInitCalls, []string{sessionPath})
|
|
||||||
|
|
||||||
workRoot := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03")
|
workRoot := filepath.Join(workspaceRoot, "work", "sample-campaign", "2026-05-03")
|
||||||
mustWriteTestFile(t, filepath.Join(workRoot, "transcripts", "final.trimmed.json"), `{"segments":[]}`)
|
mustWriteTestFile(t, filepath.Join(workRoot, "transcripts", "final.trimmed.json"), `{"segments":[]}`)
|
||||||
@@ -1304,10 +1302,25 @@ func TestExecutePublishLoadsRemoteLocks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var storeInitCalls int
|
||||||
code := Execute([]string{"run-stage", "publish", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--force"}, &stdout, &stderr)
|
err = runStageWithPipelineExecutor(
|
||||||
if code != 0 {
|
context.Background(),
|
||||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
[]string{"publish", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--force"},
|
||||||
|
&stdout,
|
||||||
|
func(ctx context.Context, cfg *config.Config, plan BoundedPlan, opts RunOptions) (*RunSummary, error) {
|
||||||
|
return executePlanWithDependencies(ctx, cfg, plan, opts, invocationDependencies{
|
||||||
|
newObjectStore: func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
||||||
|
storeInitCalls++
|
||||||
|
return fake, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("runStageWithPipelineExecutor() error = %v", err)
|
||||||
|
}
|
||||||
|
if storeInitCalls != 1 {
|
||||||
|
t.Fatalf("object store initialization calls = %d, want 1", storeInitCalls)
|
||||||
}
|
}
|
||||||
publishedKey := artifacts.S3PublishedOutputKey(artifacts.S3SessionPrefix("dnd", "sample-campaign", "2026-05-03"), "transcripts/final.trimmed.json")
|
publishedKey := artifacts.S3PublishedOutputKey(artifacts.S3SessionPrefix("dnd", "sample-campaign", "2026-05-03"), "transcripts/final.trimmed.json")
|
||||||
if _, ok := fake.Objects[publishedKey]; ok {
|
if _, ok := fake.Objects[publishedKey]; ok {
|
||||||
|
|||||||
@@ -206,21 +206,18 @@ previous_session_id: 2026-04-26
|
|||||||
mustReadEquals(t, filepath.Join(sessionRoot, "previous", "artifacts", "session_recap.md"), "# previous recap\n")
|
mustReadEquals(t, filepath.Join(sessionRoot, "previous", "artifacts", "session_recap.md"), "# previous recap\n")
|
||||||
|
|
||||||
scriptoriumFake := &scriptorium.FakeRunner{}
|
scriptoriumFake := &scriptorium.FakeRunner{}
|
||||||
origObjectStoreFn := newObjectStoreFromConfigFn
|
|
||||||
objectStoreConstructed := false
|
objectStoreConstructed := false
|
||||||
t.Cleanup(func() {
|
|
||||||
newObjectStoreFromConfigFn = origObjectStoreFn
|
|
||||||
})
|
|
||||||
executor := func(ctx context.Context, cfg *config.Config, plan BoundedPlan, opts RunOptions) (*RunSummary, error) {
|
executor := func(ctx context.Context, cfg *config.Config, plan BoundedPlan, opts RunOptions) (*RunSummary, error) {
|
||||||
if opts.Env == nil {
|
if opts.Env == nil {
|
||||||
opts.Env = &Env{}
|
opts.Env = &Env{}
|
||||||
}
|
}
|
||||||
opts.Env.Scriptorium = scriptoriumFake
|
opts.Env.Scriptorium = scriptoriumFake
|
||||||
return executePlan(ctx, cfg, plan, opts)
|
return executePlanWithDependencies(ctx, cfg, plan, opts, invocationDependencies{
|
||||||
}
|
newObjectStore: func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
||||||
newObjectStoreFromConfigFn = func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
|
||||||
objectStoreConstructed = true
|
objectStoreConstructed = true
|
||||||
return nil, context.Canceled
|
return nil, context.Canceled
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.Reset()
|
stdout.Reset()
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func (dependencies invocationDependencies) normalized() invocationDependencies {
|
|||||||
}
|
}
|
||||||
if dependencies.newObjectStore == nil {
|
if dependencies.newObjectStore == nil {
|
||||||
dependencies.newObjectStore = func(ctx context.Context, cfg *config.Config) (storage.ObjectStore, error) {
|
dependencies.newObjectStore = func(ctx context.Context, cfg *config.Config) (storage.ObjectStore, error) {
|
||||||
return newCommandObjectStore(ctx, cfg, nil)
|
return initializeObjectStoreBackend(ctx, cfg, storage.NewObjectStoreFromConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if dependencies.loadEffectiveLocks == nil {
|
if dependencies.loadEffectiveLocks == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user