Verify configured pipeline secrets startup
This commit is contained in:
@@ -248,6 +248,14 @@ do not snapshot incidental wording or require old buffers/wrapper choreography.
|
||||
|
||||
## Stage 6 — Verify configured startup behavior at stable boundaries
|
||||
|
||||
**Completed.** Added real configured-startup checks for explicit and discovered
|
||||
sources, relative context, provenance, acquisition reuse, environment-only
|
||||
operation, preservation/overwrite and existing-empty values, missing startup
|
||||
input, and absence of implicit adjacent-directory selection. Existing fixtures
|
||||
cover native errors/reports, retained effects, and adapter credential forwarding.
|
||||
Configuration, application and process suites and focused race checks pass with
|
||||
Go 1.27.4.
|
||||
|
||||
Read the migrated `secrets_bootstrap_test.go`,
|
||||
`configuration_acquisition_test.go`, `configuration_commands_test.go`, and
|
||||
existing environment helpers. Consolidate into focused behavioral fixtures.
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestNotariusCredentialLoadsFromConfiguredBootstrap(t *testing.T) {
|
||||
@@ -26,3 +32,103 @@ func TestNotariusCredentialLoadsFromConfiguredBootstrap(t *testing.T) {
|
||||
t.Fatal("configured bootstrap did not retain its report")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfiguredPipelineAcquisitionDiscoveryAndReuse(t *testing.T) {
|
||||
const name = "NARRATIO_DISCOVERED_TEST_KEY"
|
||||
restoreEnvAfterTest(t, name)
|
||||
root := t.TempDir()
|
||||
pipeline := filepath.Join(root, "narratio.yml")
|
||||
mustWriteSecretFile(t, filepath.Join(root, "secrets", name), "discovered-value")
|
||||
mustWriteTestFile(t, pipeline, "config: {secrets_dir: secrets}\nwhisperx: {transcribe_url: https://example.test}\nnotarius: {enabled: false, credentials: ["+name+"]}\n")
|
||||
search := configkit.SearchPaths(pipeline)
|
||||
t.Chdir(t.TempDir())
|
||||
acquisition := newConfigurationAcquisition(configurationSelection{}, commandDependencies{pipelineSearch: &search})
|
||||
first, err := acquisition.Pipeline(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if first.Notarius.Credentials[0].Value() != "discovered-value" || config.EffectivePipelineRootPath(first) != pipeline || first.ConfigKitResult() == nil {
|
||||
t.Fatal("discovered configuration lost credential or provenance")
|
||||
}
|
||||
if err := os.Remove(pipeline); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second, err := acquisition.Pipeline(context.Background())
|
||||
if err != nil || first != second {
|
||||
t.Fatalf("acquisition did not reuse result: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfiguredBootstrapEnvironmentSelection(t *testing.T) {
|
||||
const name = "NARRATIO_ENV_SELECTION_TEST"
|
||||
root := t.TempDir()
|
||||
pipeline := filepath.Join(root, "pipeline.yml")
|
||||
mustWriteSecretFile(t, filepath.Join(root, "secrets", name), "file-value")
|
||||
for _, test := range []struct{ name, control, initial, want string }{
|
||||
{"environment only", "", "environment-value", "environment-value"},
|
||||
{"preserve", "config: {secrets_dir: secrets}\n", "environment-value", "environment-value"},
|
||||
{"overwrite", "config: {secrets_dir: secrets, secrets_overwrite: true}\n", "environment-value", "file-value"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Setenv(name, test.initial)
|
||||
mustWriteTestFile(t, pipeline, test.control+"whisperx: {transcribe_url: https://example.test}\nnotarius: {enabled: false, credentials: ["+name+"]}\n")
|
||||
acquired := newConfigurationAcquisition(configurationSelection{Config: suppliedSelection(pipeline)}, commandDependencies{})
|
||||
cfg, err := acquired.Pipeline(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.Notarius.Credentials[0].Value() != test.want {
|
||||
t.Fatal("wrong resolved credential")
|
||||
}
|
||||
})
|
||||
}
|
||||
t.Setenv(name, "")
|
||||
mustWriteTestFile(t, pipeline, "config: {secrets_dir: secrets}\nwhisperx: {transcribe_url: https://example.test}\n")
|
||||
acquired := newConfigurationAcquisition(configurationSelection{Config: suppliedSelection(pipeline)}, commandDependencies{})
|
||||
if _, err := acquired.Pipeline(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if os.Getenv(name) != "" || !acquired.bootstrapReport.Entries()[0].ExistingEmpty {
|
||||
t.Fatal("existing empty environment value was not preserved")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfiguredStartupFailureStopsBeforeExecution(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
pipeline := filepath.Join(root, "pipeline.yml")
|
||||
mustWriteTestFile(t, pipeline, "config: {secrets_dir: absent}\nwhisperx: {transcribe_url: https://example.test}\n")
|
||||
called := false
|
||||
application, err := newApplication(commandDependencies{}, func(context.Context, *config.Config, BoundedPlan, RunOptions) (*RunSummary, error) {
|
||||
called = true
|
||||
return nil, nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var output, diagnostics bytes.Buffer
|
||||
result := application.Execute(context.Background(), []string{"run", "session", "--config", pipeline}, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||
var native *configkit.SecretsError
|
||||
if called || !errors.As(result.Cause, &native) || result.Status != 1 {
|
||||
t.Fatalf("result=%#v executed=%t diagnostics=%s", result, called, diagnostics.String())
|
||||
}
|
||||
acquired := newConfigurationAcquisition(configurationSelection{Config: suppliedSelection(pipeline)}, commandDependencies{})
|
||||
if _, err := acquired.Pipeline(context.Background()); !errors.As(err, &native) || acquired.bootstrapReport == nil {
|
||||
t.Fatalf("lost report or cause: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdjacentSecretsAreNotSelectedImplicitly(t *testing.T) {
|
||||
const name = "NARRATIO_ADJACENT_UNUSED_TEST"
|
||||
restoreEnvAfterTest(t, name)
|
||||
root := t.TempDir()
|
||||
mustWriteSecretFile(t, filepath.Join(root, "secrets", name), "unexpected")
|
||||
pipeline := filepath.Join(root, "pipeline.yml")
|
||||
mustWriteTestFile(t, pipeline, "whisperx: {transcribe_url: https://example.test}\n")
|
||||
acquired := newConfigurationAcquisition(configurationSelection{Config: suppliedSelection(pipeline)}, commandDependencies{})
|
||||
if _, err := acquired.Pipeline(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := os.LookupEnv(name); ok {
|
||||
t.Fatal("adjacent secrets were loaded without configuration")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user