Remove the secrets directory flag and update fixtures
This commit is contained in:
@@ -155,6 +155,13 @@ command-side native preparation, and reuse returns before another preparation.
|
|||||||
|
|
||||||
## Stage 4 — Remove the CLI surface and migrate affected fixtures
|
## Stage 4 — Remove the CLI surface and migrate affected fixtures
|
||||||
|
|
||||||
|
**Completed.** Removed the secrets-directory selector and binding from the
|
||||||
|
command tree, and migrated acquisition and credential fixtures to configured
|
||||||
|
bootstrap or disposable environment values. Retired obsolete fallback/guard
|
||||||
|
tests and conventional-directory test setup; representative help and rejection
|
||||||
|
coverage protects the removed flag. Application and process tests pass with Go
|
||||||
|
1.27.4. Native final bootstrap reporting is addressed in Stage 5.
|
||||||
|
|
||||||
Read `internal/app/command_selection.go`, command declarations reached by its
|
Read `internal/app/command_selection.go`, command declarations reached by its
|
||||||
flags, `configuration_commands.go`, and tests identified by graph search for
|
flags, `configuration_commands.go`, and tests identified by graph search for
|
||||||
`SecretsDir`, `secretsBootstrap`, and `loadSecretsDir`.
|
`SecretsDir`, `secretsBootstrap`, and `loadSecretsDir`.
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func artifactCatalogCommand(deps commandDependencies) commandkit.Command {
|
|||||||
common := newConfigurationFlags(func(input *configurationSelection) *configurationSelection { return input })
|
common := newConfigurationFlags(func(input *configurationSelection) *configurationSelection { return input })
|
||||||
return commandkit.NewCommand(commandkit.CommandSpec[configurationSelection]{
|
return commandkit.NewCommand(commandkit.CommandSpec[configurationSelection]{
|
||||||
Name: "list", Summary: "List artifact definitions for the selected pipeline and party.",
|
Name: "list", Summary: "List artifact definitions for the selected pipeline and party.",
|
||||||
Flags: []commandkit.Flag[configurationSelection]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.PartyFile, common.SecretsDir},
|
Flags: []commandkit.Flag[configurationSelection]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.PartyFile},
|
||||||
CheckInput: checkConfigurationSelection,
|
CheckInput: checkConfigurationSelection,
|
||||||
Run: func(invocation commandkit.Invocation, input configurationSelection) commandkit.Outcome {
|
Run: func(invocation commandkit.Invocation, input configurationSelection) commandkit.Outcome {
|
||||||
report, err := loadArtifactCatalogReport(invocation.Context, input, withCommandReporting(deps, invocation))
|
report, err := loadArtifactCatalogReport(invocation.Context, input, withCommandReporting(deps, invocation))
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ scriptorium:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
catalogSelection := []string{"--config", pipelinePath, "--overlay", overlay, "--campaign-file", campaignPath, "--party-file", partyPath, "--secrets-dir", t.TempDir(), "--format", "json"}
|
catalogSelection := []string{"--config", pipelinePath, "--overlay", overlay, "--campaign-file", campaignPath, "--party-file", partyPath, "--format", "json"}
|
||||||
common := append(append([]string{}, catalogSelection...), "--session-file", sessionPath)
|
common := append(append([]string{}, catalogSelection...), "--session-file", sessionPath)
|
||||||
for _, scope := range []string{"app", "session", "party"} {
|
for _, scope := range []string{"app", "session", "party"} {
|
||||||
output := nativeInspectionForTest(t, append([]string{"config", "show", "--scope", scope}, common...))
|
output := nativeInspectionForTest(t, append([]string{"config", "show", "--scope", scope}, common...))
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func checkCleanInput(input *cleanCommandInput) error {
|
|||||||
func cleanCommand(deps commandDependencies) commandkit.Command {
|
func cleanCommand(deps commandDependencies) commandkit.Command {
|
||||||
common := newConfigurationFlags(func(input **cleanCommandInput) *configurationSelection { return &(*input).Selection })
|
common := newConfigurationFlags(func(input **cleanCommandInput) *configurationSelection { return &(*input).Selection })
|
||||||
return commandkit.NewCommand(commandkit.CommandSpec[*cleanCommandInput]{Name: "clean", Summary: "Remove selected local session data, preserving cache unless requested.", NewInput: func() *cleanCommandInput { return &cleanCommandInput{} },
|
return commandkit.NewCommand(commandkit.CommandSpec[*cleanCommandInput]{Name: "clean", Summary: "Remove selected local session data, preserving cache unless requested.", NewInput: func() *cleanCommandInput { return &cleanCommandInput{} },
|
||||||
Flags: []commandkit.Flag[*cleanCommandInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile, common.SecretsDir,
|
Flags: []commandkit.Flag[*cleanCommandInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile,
|
||||||
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **cleanCommandInput, value commandkit.Supplied[string]) { (*input).PreviousSession = value }),
|
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **cleanCommandInput, value commandkit.Supplied[string]) { (*input).PreviousSession = value }),
|
||||||
commandkit.BoolFlag(commandkit.FlagMeta{Name: "all", Usage: "Clean all local session workspace and spool entries."}, false, func(input **cleanCommandInput, value commandkit.Supplied[bool]) { (*input).All = value.Value }),
|
commandkit.BoolFlag(commandkit.FlagMeta{Name: "all", Usage: "Clean all local session workspace and spool entries."}, false, func(input **cleanCommandInput, value commandkit.Supplied[bool]) { (*input).All = value.Value }),
|
||||||
commandkit.BoolFlag(commandkit.FlagMeta{Name: "dry-run", Usage: "Preview exact paths without deleting them."}, false, func(input **cleanCommandInput, value commandkit.Supplied[bool]) { (*input).DryRun = value.Value }),
|
commandkit.BoolFlag(commandkit.FlagMeta{Name: "dry-run", Usage: "Preview exact paths without deleting them."}, false, func(input **cleanCommandInput, value commandkit.Supplied[bool]) { (*input).DryRun = value.Value }),
|
||||||
|
|||||||
@@ -47,11 +47,11 @@ func TestCleanCommandReportsCompletedActionsBeforeLaterFailure(t *testing.T) {
|
|||||||
|
|
||||||
func TestCleanCommandChecksAllSelectionBeforeBootstrap(t *testing.T) {
|
func TestCleanCommandChecksAllSelectionBeforeBootstrap(t *testing.T) {
|
||||||
app, err := newApplication(commandDependencies{
|
app, err := newApplication(commandDependencies{
|
||||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
preparePipelineSource: func(configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
||||||
t.Fatal("invalid cleanup bootstrapped secrets")
|
t.Fatal("invalid cleanup bootstrapped secrets")
|
||||||
return nil, nil
|
return nil, configkit.Source{}, nil
|
||||||
},
|
},
|
||||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
t.Fatal("invalid cleanup loaded configuration")
|
t.Fatal("invalid cleanup loaded configuration")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,12 +12,11 @@ type configurationSelection struct {
|
|||||||
Session commandkit.Supplied[string]
|
Session commandkit.Supplied[string]
|
||||||
SessionFile commandkit.Supplied[string]
|
SessionFile commandkit.Supplied[string]
|
||||||
PartyFile commandkit.Supplied[string]
|
PartyFile commandkit.Supplied[string]
|
||||||
SecretsDir commandkit.Supplied[string]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type configurationFlags[I any] struct {
|
type configurationFlags[I any] struct {
|
||||||
Config, Overlay, Campaign, CampaignFile commandkit.Flag[I]
|
Config, Overlay, Campaign, CampaignFile commandkit.Flag[I]
|
||||||
Session, SessionFile, PartyFile, SecretsDir commandkit.Flag[I]
|
Session, SessionFile, PartyFile commandkit.Flag[I]
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfigurationFlags[I any](selection func(*I) *configurationSelection) configurationFlags[I] {
|
func newConfigurationFlags[I any](selection func(*I) *configurationSelection) configurationFlags[I] {
|
||||||
@@ -36,8 +35,6 @@ func newConfigurationFlags[I any](selection func(*I) *configurationSelection) co
|
|||||||
func(in *I, v commandkit.Supplied[string]) { selection(in).SessionFile = v }),
|
func(in *I, v commandkit.Supplied[string]) { selection(in).SessionFile = v }),
|
||||||
PartyFile: commandkit.ValueFlag(commandkit.FlagMeta{Name: "party-file", Completion: commandkit.CompleteFiles(), Usage: "Party file replacing the campaign default."}, nil, stringValue,
|
PartyFile: commandkit.ValueFlag(commandkit.FlagMeta{Name: "party-file", Completion: commandkit.CompleteFiles(), Usage: "Party file replacing the campaign default."}, nil, stringValue,
|
||||||
func(in *I, v commandkit.Supplied[string]) { selection(in).PartyFile = v }),
|
func(in *I, v commandkit.Supplied[string]) { selection(in).PartyFile = v }),
|
||||||
SecretsDir: commandkit.ValueFlag(commandkit.FlagMeta{Name: "secrets-dir", Completion: commandkit.CompleteDirectories(), Usage: "Credential-bootstrap directory."}, nil, stringValue,
|
|
||||||
func(in *I, v commandkit.Supplied[string]) { selection(in).SecretsDir = v }),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func TestNativeDiscoveryDoesNotAcquireConfiguration(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
application, err := newApplication(commandDependencies{
|
application, err := newApplication(commandDependencies{
|
||||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
t.Fatal("discovery loaded pipeline configuration")
|
t.Fatal("discovery loaded pipeline configuration")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
@@ -32,9 +32,9 @@ func TestNativeDiscoveryDoesNotAcquireConfiguration(t *testing.T) {
|
|||||||
t.Fatal("discovery initialized object storage")
|
t.Fatal("discovery initialized object storage")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
preparePipelineSource: func(configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
||||||
t.Fatal("discovery bootstrapped credentials")
|
t.Fatal("discovery bootstrapped credentials")
|
||||||
return nil, nil
|
return nil, configkit.Source{}, nil
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -51,7 +51,7 @@ func TestNativeDiscoveryDoesNotAcquireConfiguration(t *testing.T) {
|
|||||||
args []string
|
args []string
|
||||||
fragment string
|
fragment string
|
||||||
}{
|
}{
|
||||||
{[]string{"__complete", "run", "--config", "missing.yml", "--secrets-dir", "missing-secrets", "--stage", "tr"}, "transcribe\n"},
|
{[]string{"__complete", "run", "--config", "missing.yml", "--stage", "tr"}, "transcribe\n"},
|
||||||
{[]string{"__complete", "session", "plan", "--from", "an"}, "analyze\n"},
|
{[]string{"__complete", "session", "plan", "--from", "an"}, "analyze\n"},
|
||||||
{[]string{"__complete", "run", "--through", "pub"}, "publish\n"},
|
{[]string{"__complete", "run", "--through", "pub"}, "publish\n"},
|
||||||
{[]string{"__complete", "config", "show", "--scope", ""}, "party\n"},
|
{[]string{"__complete", "config", "show", "--scope", ""}, "party\n"},
|
||||||
@@ -61,7 +61,6 @@ func TestNativeDiscoveryDoesNotAcquireConfiguration(t *testing.T) {
|
|||||||
{[]string{"__complete", "config", "diff", "--scope", "party", "--against-party-file", ""}, ":0\n"},
|
{[]string{"__complete", "config", "diff", "--scope", "party", "--against-party-file", ""}, ":0\n"},
|
||||||
{[]string{"__complete", "session", "init", "--output", ""}, ":0\n"},
|
{[]string{"__complete", "session", "init", "--output", ""}, ":0\n"},
|
||||||
{[]string{"__complete", "session", "init", "--audio-dir", ""}, ":16\n"},
|
{[]string{"__complete", "session", "init", "--audio-dir", ""}, ":16\n"},
|
||||||
{[]string{"__complete", "run", "--secrets-dir", ""}, ":16\n"},
|
|
||||||
} {
|
} {
|
||||||
var out, diagnostics bytes.Buffer
|
var out, diagnostics bytes.Buffer
|
||||||
outcome := application.Execute(context.Background(), query.args, commandkit.Streams{Out: &out, Err: &diagnostics})
|
outcome := application.Execute(context.Background(), query.args, commandkit.Streams{Out: &out, Err: &diagnostics})
|
||||||
@@ -80,7 +79,7 @@ func TestNativeSelectionRetainsPresenceAndCallerContext(t *testing.T) {
|
|||||||
ctx := context.WithValue(context.Background(), contextKey{}, "caller")
|
ctx := context.WithValue(context.Background(), contextKey{}, "caller")
|
||||||
application, err := commandkit.New(commandkit.Identity{Name: "narratio"}, commandkit.NewCommand(commandkit.CommandSpec[configurationSelection]{
|
application, err := commandkit.New(commandkit.Identity{Name: "narratio"}, commandkit.NewCommand(commandkit.CommandSpec[configurationSelection]{
|
||||||
Name: "inspect",
|
Name: "inspect",
|
||||||
Flags: []commandkit.Flag[configurationSelection]{flags.Config, flags.Overlay, flags.Campaign, flags.CampaignFile, flags.Session, flags.SessionFile, flags.PartyFile, flags.SecretsDir},
|
Flags: []commandkit.Flag[configurationSelection]{flags.Config, flags.Overlay, flags.Campaign, flags.CampaignFile, flags.Session, flags.SessionFile, flags.PartyFile},
|
||||||
CheckInput: func(in configurationSelection) error {
|
CheckInput: func(in configurationSelection) error {
|
||||||
if !in.Config.Set || in.Config.Value != "" || !in.Campaign.Set || !in.CampaignFile.Set || in.PartyFile.Set {
|
if !in.Config.Set || in.Config.Value != "" || !in.Campaign.Set || !in.CampaignFile.Set || in.PartyFile.Set {
|
||||||
t.Fatalf("selection lost presence or complementary selectors: %+v", in)
|
t.Fatalf("selection lost presence or complementary selectors: %+v", in)
|
||||||
@@ -153,13 +152,13 @@ func TestOperationOutcomePreservesCausesAndOperationalPrecedence(t *testing.T) {
|
|||||||
|
|
||||||
func TestNativeTreeRejectsRemovedRoutesAndMissingOperandsBeforeAcquisition(t *testing.T) {
|
func TestNativeTreeRejectsRemovedRoutesAndMissingOperandsBeforeAcquisition(t *testing.T) {
|
||||||
application, err := newApplication(commandDependencies{
|
application, err := newApplication(commandDependencies{
|
||||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
t.Fatal("invalid input loaded configuration")
|
t.Fatal("invalid input loaded configuration")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
preparePipelineSource: func(configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
||||||
t.Fatal("invalid input bootstrapped credentials")
|
t.Fatal("invalid input bootstrapped credentials")
|
||||||
return nil, nil
|
return nil, configkit.Source{}, nil
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -233,3 +232,21 @@ func TestNativeDiagnosticsRetainWarningsAndJoinedOperationalCause(t *testing.T)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRemovedSecretsDirectoryFlagIsUnavailable(t *testing.T) {
|
||||||
|
app, err := newApplication(commandDependencies{}, executePlan)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var output, diagnostics bytes.Buffer
|
||||||
|
result := app.Execute(context.Background(), []string{"run", "--help"}, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||||
|
if result.Status != 0 || strings.Contains(output.String(), "--secrets-dir") {
|
||||||
|
t.Fatalf("help exposes removed flag: %s", output.String())
|
||||||
|
}
|
||||||
|
output.Reset()
|
||||||
|
diagnostics.Reset()
|
||||||
|
result = app.Execute(context.Background(), []string{"run", "session", "--secrets-dir", "credentials"}, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||||
|
if result.Status != 2 || !strings.Contains(diagnostics.String(), "--secrets-dir") {
|
||||||
|
t.Fatalf("removed flag: status=%d diagnostics=%s", result.Status, diagnostics.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -178,9 +178,10 @@ inputs:
|
|||||||
|
|
||||||
seedInvocationPrerequisites(t, workspaceRoot, "polish")
|
seedInvocationPrerequisites(t, workspaceRoot, "polish")
|
||||||
|
|
||||||
|
configureTestSecrets(t, pipelinePath, secretsDir)
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
code := executeForTest([]string{"run", sessionID, "--stage", "polish", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--force", "--secrets-dir", secretsDir}, &stdout, &stderr)
|
code := executeForTest([]string{"run", sessionID, "--stage", "polish", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--force"}, &stdout, &stderr)
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||||
}
|
}
|
||||||
@@ -268,13 +269,14 @@ inputs:
|
|||||||
t.Fatalf("write session.yml: %v", err)
|
t.Fatalf("write session.yml: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configureTestSecrets(t, pipelinePath, filepath.Join(configDir, "missing-secrets"))
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
code := executeForTest([]string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--secrets-dir", filepath.Join(configDir, "missing-secrets")}, &stdout, &stderr)
|
code := executeForTest([]string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &stdout, &stderr)
|
||||||
if code == 0 {
|
if code == 0 {
|
||||||
t.Fatal("exit code = 0, want non-zero")
|
t.Fatal("exit code = 0, want non-zero")
|
||||||
}
|
}
|
||||||
if !strings.Contains(stderr.String(), "bootstrap secrets directory") {
|
if !strings.Contains(stderr.String(), "prepare pipeline configuration") {
|
||||||
t.Fatalf("stderr = %q, want secrets validation error context", stderr.String())
|
t.Fatalf("stderr = %q, want secrets validation error context", stderr.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"go.maximumdirect.net/commandkit"
|
"go.maximumdirect.net/commandkit"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func catalogReportForTest(t *testing.T, args []string) *artifactCatalogReport {
|
func catalogReportForTest(t *testing.T, args []string) *artifactCatalogReport {
|
||||||
@@ -97,7 +98,7 @@ func TestArtifactCatalogCommandUsesExplicitRosterAndNativeConfiguration(t *testi
|
|||||||
if err := loaded.ConfigKitResult().WriteEffective(&before); err != nil {
|
if err := loaded.ConfigKitResult().WriteEffective(&before); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
app, err := newApplication(commandDependencies{loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) { return loaded, nil }}, executePlan)
|
app, err := newApplication(commandDependencies{loadPipelineSource: func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error) { return loaded, nil }}, executePlan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExecuteConfigUsesInvocationPipelineLoader(t *testing.T) {
|
func TestExecuteConfigUsesInvocationPipelineLoader(t *testing.T) {
|
||||||
@@ -21,9 +22,9 @@ func TestExecuteConfigUsesInvocationPipelineLoader(t *testing.T) {
|
|||||||
t.Run(subcommand, func(t *testing.T) {
|
t.Run(subcommand, func(t *testing.T) {
|
||||||
calls := 0
|
calls := 0
|
||||||
deps := commandDependencies{
|
deps := commandDependencies{
|
||||||
loadPipelineConfig: func(path string, opts config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(source configkit.Source, opts config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
calls++
|
calls++
|
||||||
return config.LoadPipelineWithOptions(path, opts)
|
return config.LoadPipelineSourceWithOptions(source, opts)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
@@ -134,11 +135,12 @@ func TestNativeBundleInspectionAndExecutionAgree(t *testing.T) {
|
|||||||
}
|
}
|
||||||
secrets := filepath.Join(bundle, "secrets")
|
secrets := filepath.Join(bundle, "secrets")
|
||||||
mustWriteSecretFile(t, filepath.Join(secrets, secretName), secretValue)
|
mustWriteSecretFile(t, filepath.Join(secrets, secretName), secretValue)
|
||||||
|
configureTestSecrets(t, pipeline, secrets)
|
||||||
t.Chdir(root)
|
t.Chdir(root)
|
||||||
campaign := filepath.Join(bundle, "campaigns", "sample-campaign", "campaign.yml")
|
campaign := filepath.Join(bundle, "campaigns", "sample-campaign", "campaign.yml")
|
||||||
common := []string{"--campaign-file", campaign, "--secrets-dir", secrets}
|
common := []string{"--campaign-file", campaign}
|
||||||
for _, operation := range []string{"validate", "show", "sources"} {
|
for _, operation := range []string{"validate", "show", "sources"} {
|
||||||
args := []string{"config", operation, "--secrets-dir", secrets}
|
args := []string{"config", operation}
|
||||||
out := nativeInspectionForTest(t, args)
|
out := nativeInspectionForTest(t, args)
|
||||||
if strings.Contains(out, secretValue) {
|
if strings.Contains(out, secretValue) {
|
||||||
t.Fatalf("%s exposed credential value", operation)
|
t.Fatalf("%s exposed credential value", operation)
|
||||||
@@ -151,7 +153,7 @@ func TestNativeBundleInspectionAndExecutionAgree(t *testing.T) {
|
|||||||
if !strings.Contains(catalog, "character_meta_arannis") {
|
if !strings.Contains(catalog, "character_meta_arannis") {
|
||||||
t.Fatal("domain catalog omitted concrete family member")
|
t.Fatal("domain catalog omitted concrete family member")
|
||||||
}
|
}
|
||||||
diff := nativeInspectionForTest(t, []string{"config", "diff", "--details", "--against-overlay", "testing", "--secrets-dir", secrets, "--format", "json"})
|
diff := nativeInspectionForTest(t, []string{"config", "diff", "--details", "--against-overlay", "testing", "--format", "json"})
|
||||||
if !strings.Contains(diff, "/audita/proposal_profile") || strings.Contains(diff, secretValue) {
|
if !strings.Contains(diff, "/audita/proposal_profile") || strings.Contains(diff, secretValue) {
|
||||||
t.Fatalf("unexpected diff: %s", diff)
|
t.Fatalf("unexpected diff: %s", diff)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadCommandConfigRetainsInitiallyLoadedPipeline(t *testing.T) {
|
func TestLoadCommandConfigRetainsInitiallyLoadedPipeline(t *testing.T) {
|
||||||
@@ -15,20 +16,20 @@ func TestLoadCommandConfigRetainsInitiallyLoadedPipeline(t *testing.T) {
|
|||||||
|
|
||||||
loadCalls := 0
|
loadCalls := 0
|
||||||
deps := commandDependencies{
|
deps := commandDependencies{
|
||||||
loadPipelineConfig: func(path string, opts config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(source configkit.Source, opts config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
loaded, err := config.LoadPipelineWithOptions(path, opts)
|
loaded, err := config.LoadPipelineSourceWithOptions(source, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
loadCalls++
|
loadCalls++
|
||||||
|
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(pipelinePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
changedRoot := workspaceRoot + "-changed"
|
changedRoot := workspaceRoot + "-changed"
|
||||||
updated := strings.ReplaceAll(string(data), workspaceRoot, changedRoot)
|
updated := strings.ReplaceAll(string(data), workspaceRoot, changedRoot)
|
||||||
if err := os.WriteFile(path, []byte(updated), 0o644); err != nil {
|
if err := os.WriteFile(pipelinePath, []byte(updated), 0o644); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return loaded, nil
|
return loaded, nil
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ func checkConfigurationSelection(selection configurationSelection) error {
|
|||||||
{"config", selection.Config}, {"campaign", selection.Campaign},
|
{"config", selection.Config}, {"campaign", selection.Campaign},
|
||||||
{"campaign-file", selection.CampaignFile}, {"session", selection.Session},
|
{"campaign-file", selection.CampaignFile}, {"session", selection.Session},
|
||||||
{"session-file", selection.SessionFile}, {"party-file", selection.PartyFile},
|
{"session-file", selection.SessionFile}, {"party-file", selection.PartyFile},
|
||||||
{"secrets-dir", selection.SecretsDir},
|
|
||||||
} {
|
} {
|
||||||
if field.value.Set && strings.TrimSpace(field.value.Value) == "" {
|
if field.value.Set && strings.TrimSpace(field.value.Value) == "" {
|
||||||
return &inputError{message: fmt.Sprintf("--%s requires a non-empty value", field.name)}
|
return &inputError{message: fmt.Sprintf("--%s requires a non-empty value", field.name)}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ func TestConfigurationAcquisitionLoadsOnlyReachedDocuments(t *testing.T) {
|
|||||||
selection := configurationSelection{
|
selection := configurationSelection{
|
||||||
CampaignFile: suppliedSelection(campaignPath),
|
CampaignFile: suppliedSelection(campaignPath),
|
||||||
Campaign: suppliedSelection("sample-campaign"),
|
Campaign: suppliedSelection("sample-campaign"),
|
||||||
SecretsDir: suppliedSelection(t.TempDir()),
|
|
||||||
}
|
}
|
||||||
acquired := newConfigurationAcquisition(selection, deps)
|
acquired := newConfigurationAcquisition(selection, deps)
|
||||||
campaign, err := acquired.Campaign(context.Background())
|
campaign, err := acquired.Campaign(context.Background())
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ func configurationCommand(deps commandDependencies) commandkit.Command {
|
|||||||
{Binding: flags.Session, AgainstName: "against-session", Scopes: []string{"session"}},
|
{Binding: flags.Session, AgainstName: "against-session", Scopes: []string{"session"}},
|
||||||
{Binding: flags.SessionFile, AgainstName: "against-session-file", Scopes: []string{"session"}},
|
{Binding: flags.SessionFile, AgainstName: "against-session-file", Scopes: []string{"session"}},
|
||||||
{Binding: flags.PartyFile, AgainstName: "against-party-file", Scopes: []string{"party"}},
|
{Binding: flags.PartyFile, AgainstName: "against-party-file", Scopes: []string{"party"}},
|
||||||
{Binding: flags.SecretsDir, Scopes: []string{"app", "campaign", "session", "party"}},
|
|
||||||
},
|
},
|
||||||
Scopes: scopes,
|
Scopes: scopes,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ import (
|
|||||||
|
|
||||||
func TestConfigurationCommandsExposeNativeScopesLazily(t *testing.T) {
|
func TestConfigurationCommandsExposeNativeScopesLazily(t *testing.T) {
|
||||||
app, err := newApplication(commandDependencies{
|
app, err := newApplication(commandDependencies{
|
||||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
t.Fatal("discovery loaded config")
|
t.Fatal("discovery loaded config")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
preparePipelineSource: func(configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
||||||
t.Fatal("discovery bootstrapped secrets")
|
t.Fatal("discovery bootstrapped secrets")
|
||||||
return nil, nil
|
return nil, configkit.Source{}, nil
|
||||||
},
|
},
|
||||||
}, executePlan)
|
}, executePlan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -20,18 +20,21 @@ func TestConfigurationComparisonUsesIndependentRootDefaults(t *testing.T) {
|
|||||||
loads, bootstrap := 0, 0
|
loads, bootstrap := 0, 0
|
||||||
app, err := newApplication(commandDependencies{
|
app, err := newApplication(commandDependencies{
|
||||||
pipelineSearch: &search,
|
pipelineSearch: &search,
|
||||||
loadPipelineConfig: func(path string, options config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(source configkit.Source, options config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
loads++
|
loads++
|
||||||
return config.LoadPipelineWithOptions(path, options)
|
return config.LoadPipelineSourceWithOptions(source, options)
|
||||||
|
},
|
||||||
|
preparePipelineSource: func(source configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
||||||
|
bootstrap++
|
||||||
|
return configkit.LoadSecretsIntoEnvironmentFromConfig(source)
|
||||||
},
|
},
|
||||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) { bootstrap++; return nil, nil },
|
|
||||||
}, executePlan)
|
}, executePlan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
var out, diagnostic bytes.Buffer
|
var out, diagnostic bytes.Buffer
|
||||||
outcome := app.Execute(context.Background(), []string{"config", "diff", "--details", "--config", left, "--check", "--format", "json", "--secrets-dir", t.TempDir()}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
outcome := app.Execute(context.Background(), []string{"config", "diff", "--details", "--config", left, "--check", "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
if outcome.Status != 3 || loads != 2 || bootstrap != 1 || !strings.Contains(out.String(), "/workspace/root") {
|
if outcome.Status != 3 || loads != 2 || bootstrap != 2 || !strings.Contains(out.String(), "/workspace/root") {
|
||||||
t.Fatalf("status=%d loads=%d bootstrap=%d output=%s diagnostics=%s", outcome.Status, loads, bootstrap, out.String(), diagnostic.String())
|
t.Fatalf("status=%d loads=%d bootstrap=%d output=%s diagnostics=%s", outcome.Status, loads, bootstrap, out.String(), diagnostic.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func executionCommand(name, summary string, regenerate bool, deps commandDepende
|
|||||||
|
|
||||||
func executionCommandSpec(name, summary string, regenerate bool) commandkit.CommandSpec[*executionInput] {
|
func executionCommandSpec(name, summary string, regenerate bool) commandkit.CommandSpec[*executionInput] {
|
||||||
common := newConfigurationFlags(func(input **executionInput) *configurationSelection { return &(*input).Selection })
|
common := newConfigurationFlags(func(input **executionInput) *configurationSelection { return &(*input).Selection })
|
||||||
flags := []commandkit.Flag[*executionInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile, common.SecretsDir,
|
flags := []commandkit.Flag[*executionInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile,
|
||||||
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **executionInput, value commandkit.Supplied[string]) { (*input).PreviousSession = value }),
|
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **executionInput, value commandkit.Supplied[string]) { (*input).PreviousSession = value }),
|
||||||
commandkit.RepeatFlag(commandkit.FlagMeta{Name: "artifacts", Usage: "Analysis artifact or family targets (repeatable or comma-separated)."}, []string(nil), stringValue, func(input **executionInput, value commandkit.Supplied[[]string]) { (*input).Artifacts = value }),
|
commandkit.RepeatFlag(commandkit.FlagMeta{Name: "artifacts", Usage: "Analysis artifact or family targets (repeatable or comma-separated)."}, []string(nil), stringValue, func(input **executionInput, value commandkit.Supplied[[]string]) { (*input).Artifacts = value }),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,11 +69,11 @@ func TestExecutionCommandsUseTypedBoundedPlans(t *testing.T) {
|
|||||||
|
|
||||||
func TestExecutionCommandsRejectInvalidSelectionBeforeBootstrap(t *testing.T) {
|
func TestExecutionCommandsRejectInvalidSelectionBeforeBootstrap(t *testing.T) {
|
||||||
app, err := newApplication(commandDependencies{
|
app, err := newApplication(commandDependencies{
|
||||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
preparePipelineSource: func(configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
||||||
t.Fatal("invalid input bootstrapped secrets")
|
t.Fatal("invalid input bootstrapped secrets")
|
||||||
return nil, nil
|
return nil, configkit.Source{}, nil
|
||||||
},
|
},
|
||||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
t.Fatal("invalid input loaded config")
|
t.Fatal("invalid input loaded config")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ type lockListEntry struct {
|
|||||||
|
|
||||||
func lockCommand(operation string, deps commandDependencies) commandkit.Command {
|
func lockCommand(operation string, deps commandDependencies) commandkit.Command {
|
||||||
common := newConfigurationFlags(func(input **lockCommandInput) *configurationSelection { return &(*input).Selection })
|
common := newConfigurationFlags(func(input **lockCommandInput) *configurationSelection { return &(*input).Selection })
|
||||||
flags := []commandkit.Flag[*lockCommandInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile, common.SecretsDir,
|
flags := []commandkit.Flag[*lockCommandInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile,
|
||||||
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **lockCommandInput, value commandkit.Supplied[string]) { (*input).PreviousSession = value }),
|
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **lockCommandInput, value commandkit.Supplied[string]) { (*input).PreviousSession = value }),
|
||||||
}
|
}
|
||||||
if operation == "add" {
|
if operation == "add" {
|
||||||
|
|||||||
@@ -73,11 +73,11 @@ func TestLockCommandsPreserveConditionalMutationAndIdempotentRemoval(t *testing.
|
|||||||
|
|
||||||
func TestLockCommandsCheckOperandsBeforeAcquisitionAndKeepGroupLazy(t *testing.T) {
|
func TestLockCommandsCheckOperandsBeforeAcquisitionAndKeepGroupLazy(t *testing.T) {
|
||||||
app, err := newApplication(commandDependencies{
|
app, err := newApplication(commandDependencies{
|
||||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
preparePipelineSource: func(configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
||||||
t.Fatal("help or invalid operands bootstrapped secrets")
|
t.Fatal("help or invalid operands bootstrapped secrets")
|
||||||
return nil, nil
|
return nil, configkit.Source{}, nil
|
||||||
},
|
},
|
||||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
t.Fatal("help or invalid operands loaded config")
|
t.Fatal("help or invalid operands loaded config")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -183,7 +183,6 @@ func TestExecuteSessionInitMissingDefaultConfigReportsSearchedPaths(t *testing.T
|
|||||||
func TestExecuteSessionInitRemoteLoadsSecretsBeforeObjectStoreInit(t *testing.T) {
|
func TestExecuteSessionInitRemoteLoadsSecretsBeforeObjectStoreInit(t *testing.T) {
|
||||||
workspaceRoot := t.TempDir()
|
workspaceRoot := t.TempDir()
|
||||||
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
|
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||||
withDefaultPipelineCampaignConfigs(t, pipelinePath, campaignPath)
|
|
||||||
accessKeyEnv := "NARRATIO_TEST_SESSION_INIT_OBJECT_KEY_ID"
|
accessKeyEnv := "NARRATIO_TEST_SESSION_INIT_OBJECT_KEY_ID"
|
||||||
secretKeyEnv := "NARRATIO_TEST_SESSION_INIT_OBJECT_SECRET"
|
secretKeyEnv := "NARRATIO_TEST_SESSION_INIT_OBJECT_SECRET"
|
||||||
restoreEnvAfterTest(t, accessKeyEnv, secretKeyEnv)
|
restoreEnvAfterTest(t, accessKeyEnv, secretKeyEnv)
|
||||||
@@ -202,7 +201,7 @@ func TestExecuteSessionInitRemoteLoadsSecretsBeforeObjectStoreInit(t *testing.T)
|
|||||||
|
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
code := executeWithDependencies([]string{"session", "init", "2026-06-07", "--remote", "--secrets-dir", secretsDir}, &stdout, &stderr, deps, executePlan)
|
code := executeWithDependencies([]string{"session", "init", "2026-06-07", "--remote", "--config", pipelinePath, "--campaign-file", campaignPath}, &stdout, &stderr, deps, executePlan)
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||||
}
|
}
|
||||||
@@ -454,7 +453,7 @@ inputs:
|
|||||||
|
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
code := executeWithDependencies([]string{"session", "validate", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath, "--secrets-dir", secretsDir}, &stdout, &stderr, deps, executePlan)
|
code := executeWithDependencies([]string{"session", "validate", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &stdout, &stderr, deps, executePlan)
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
t.Fatalf("exit code = %d, want 0; stdout=%q stderr=%q", code, stdout.String(), stderr.String())
|
t.Fatalf("exit code = %d, want 0; stdout=%q stderr=%q", code, stdout.String(), stderr.String())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,9 @@ inputs:
|
|||||||
glossary_file: ./glossary.yml
|
glossary_file: ./glossary.yml
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
configureTestSecrets(t, configPath, secretsDir)
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
if code := executeForTest([]string{"config", "show", "--config", configPath, "--secrets-dir", secretsDir}, &stdout, &stderr); code != 0 {
|
if code := executeForTest([]string{"config", "show", "--config", configPath}, &stdout, &stderr); code != 0 {
|
||||||
t.Fatalf("config show exit = %d; stderr=%q", code, stderr.String())
|
t.Fatalf("config show exit = %d; stderr=%q", code, stderr.String())
|
||||||
}
|
}
|
||||||
if !strings.Contains(stdout.String(), sharedProviderName) || !strings.Contains(stdout.String(), auditaOnlyName) {
|
if !strings.Contains(stdout.String(), sharedProviderName) || !strings.Contains(stdout.String(), auditaOnlyName) {
|
||||||
@@ -105,7 +106,7 @@ inputs:
|
|||||||
seedCurrentBuiltInEvidence(t, manifestPath, "2026-05-03", "sample-campaign", "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, basePath)
|
seedCurrentBuiltInEvidence(t, manifestPath, "2026-05-03", "sample-campaign", "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, basePath)
|
||||||
mustWriteTestFile(t, filepath.Join(workRoot, "inputs", "glossary.yml"), "[]\n")
|
mustWriteTestFile(t, filepath.Join(workRoot, "inputs", "glossary.yml"), "[]\n")
|
||||||
seedInvocationPrerequisites(t, workspace, "polish")
|
seedInvocationPrerequisites(t, workspace, "polish")
|
||||||
args := []string{"--secrets-dir", secretsDir, "--config", configPath, "--campaign-file", campaignPath, "--session-file", sessionPath}
|
args := []string{"--config", configPath, "--campaign-file", campaignPath, "--session-file", sessionPath}
|
||||||
stdout.Reset()
|
stdout.Reset()
|
||||||
stderr.Reset()
|
stderr.Reset()
|
||||||
if code := executeForTest(append([]string{"run", "2026-05-03", "--stage", "polish", "--force"}, args...), &stdout, &stderr); code != 0 {
|
if code := executeForTest(append([]string{"run", "2026-05-03", "--stage", "polish", "--force"}, args...), &stdout, &stderr); code != 0 {
|
||||||
|
|||||||
@@ -259,9 +259,9 @@ inputs:
|
|||||||
setSessionConfigSearchPaths(t, []string{filepath.Join(t.TempDir(), "session.yml")})
|
setSessionConfigSearchPaths(t, []string{filepath.Join(t.TempDir(), "session.yml")})
|
||||||
bootstrapCalls := 0
|
bootstrapCalls := 0
|
||||||
deps := commandDependencies{
|
deps := commandDependencies{
|
||||||
loadSecretsDir: func(directory string) (*configkit.SecretsReport, error) {
|
preparePipelineSource: func(source configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
||||||
bootstrapCalls++
|
bootstrapCalls++
|
||||||
return configkit.LoadSecretsIntoEnvironment(directory)
|
return configkit.LoadSecretsIntoEnvironmentFromConfig(source)
|
||||||
},
|
},
|
||||||
newObjectStore: func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
newObjectStore: func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
||||||
if os.Getenv(accessKeyEnv) != "remote-session-key-id" || os.Getenv(secretKeyEnv) != "remote-session-secret" {
|
if os.Getenv(accessKeyEnv) != "remote-session-key-id" || os.Getenv(secretKeyEnv) != "remote-session-secret" {
|
||||||
@@ -272,7 +272,7 @@ inputs:
|
|||||||
|
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
code := executeWithDependencies([]string{"session", "plan", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--secrets-dir", secretsDir}, &stdout, &stderr, deps, executePlan)
|
code := executeWithDependencies([]string{"session", "plan", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath}, &stdout, &stderr, deps, executePlan)
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
t.Fatalf("exit code = %d, want 0; stdout=%q stderr=%q", code, stdout.String(), stderr.String())
|
t.Fatalf("exit code = %d, want 0; stdout=%q stderr=%q", code, stdout.String(), stderr.String())
|
||||||
}
|
}
|
||||||
@@ -489,10 +489,9 @@ func addSecretsToPipelineConfig(t *testing.T, pipelinePath, secretsDir, accessKe
|
|||||||
"storage:\n backend: s3\n s3:\n bucket: test-bucket\n access_key_id: "+accessKeyEnv+"\n secret_access_key: "+secretKeyEnv+"\n",
|
"storage:\n backend: s3\n s3:\n bucket: test-bucket\n access_key_id: "+accessKeyEnv+"\n secret_access_key: "+secretKeyEnv+"\n",
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := os.WriteFile(pipelinePath, []byte(pipelineYAML), 0o644); err != nil {
|
if err := os.WriteFile(pipelinePath, []byte(pipelineYAML), 0o644); err != nil {
|
||||||
t.Fatalf("write pipeline: %v", err)
|
t.Fatalf("write pipeline: %v", err)
|
||||||
}
|
}
|
||||||
if err := os.Symlink(secretsDir, filepath.Join(filepath.Dir(pipelinePath), "secrets")); err != nil {
|
configureTestSecrets(t, pipelinePath, secretsDir)
|
||||||
t.Fatalf("link conventional secrets directory: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ func restoreSessionState(ctx context.Context, cfg *config.Config, opts RestorePl
|
|||||||
func restoreCommand(deps commandDependencies) commandkit.Command {
|
func restoreCommand(deps commandDependencies) commandkit.Command {
|
||||||
common := newConfigurationFlags(func(input **restoreCommandInput) *configurationSelection { return &(*input).Selection })
|
common := newConfigurationFlags(func(input **restoreCommandInput) *configurationSelection { return &(*input).Selection })
|
||||||
return commandkit.NewCommand(commandkit.CommandSpec[*restoreCommandInput]{Name: "restore", Summary: "Restore the committed remote session snapshot.", NewInput: func() *restoreCommandInput { return &restoreCommandInput{} },
|
return commandkit.NewCommand(commandkit.CommandSpec[*restoreCommandInput]{Name: "restore", Summary: "Restore the committed remote session snapshot.", NewInput: func() *restoreCommandInput { return &restoreCommandInput{} },
|
||||||
Flags: []commandkit.Flag[*restoreCommandInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile, common.SecretsDir,
|
Flags: []commandkit.Flag[*restoreCommandInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile,
|
||||||
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **restoreCommandInput, value commandkit.Supplied[string]) {
|
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **restoreCommandInput, value commandkit.Supplied[string]) {
|
||||||
(*input).PreviousSession = value.Value
|
(*input).PreviousSession = value.Value
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ func TestExecuteRestoreLoadsSecretsBeforeObjectStoreInit(t *testing.T) {
|
|||||||
mustWriteSecretFile(t, filepath.Join(secretsDir, accessKeyEnv), "test-access-key-id\n")
|
mustWriteSecretFile(t, filepath.Join(secretsDir, accessKeyEnv), "test-access-key-id\n")
|
||||||
mustWriteSecretFile(t, filepath.Join(secretsDir, secretKeyEnv), "test-secret-key\n")
|
mustWriteSecretFile(t, filepath.Join(secretsDir, secretKeyEnv), "test-secret-key\n")
|
||||||
|
|
||||||
|
configureTestSecrets(t, pipelinePath, secretsDir)
|
||||||
storeInitCalled := false
|
storeInitCalled := false
|
||||||
deps := commandDependencies{newObjectStore: func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
deps := commandDependencies{newObjectStore: func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
||||||
storeInitCalled = true
|
storeInitCalled = true
|
||||||
@@ -215,7 +216,6 @@ func TestExecuteRestoreLoadsSecretsBeforeObjectStoreInit(t *testing.T) {
|
|||||||
"--campaign-file", campaignPath,
|
"--campaign-file", campaignPath,
|
||||||
"--session-file", sessionPath,
|
"--session-file", sessionPath,
|
||||||
"--dry-run",
|
"--dry-run",
|
||||||
"--secrets-dir", secretsDir,
|
|
||||||
},
|
},
|
||||||
&stdout,
|
&stdout,
|
||||||
&stderr,
|
&stderr,
|
||||||
|
|||||||
@@ -1,267 +1,28 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
||||||
configkit "go.maximumdirect.net/configkit"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPipelineLoadSkipsAbsentConventionalSecretsDirectory(t *testing.T) {
|
func TestNotariusCredentialLoadsFromConfiguredBootstrap(t *testing.T) {
|
||||||
pipelinePath := filepath.Join(t.TempDir(), "pipeline.yml")
|
const name = "NARRATIO_NOTARIUS_CONFIGURED_BOOTSTRAP"
|
||||||
if err := os.WriteFile(pipelinePath, []byte("version: 1\n"), 0o644); err != nil {
|
restoreEnvAfterTest(t, name)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
secretCalls := 0
|
|
||||||
pipelineCalls := 0
|
|
||||||
deps := commandDependencies{
|
|
||||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
|
||||||
secretCalls++
|
|
||||||
return nil, nil
|
|
||||||
},
|
|
||||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
|
||||||
pipelineCalls++
|
|
||||||
return &config.PipelineConfig{}, nil
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, _, err := loadPipelineConfigWithDependencies(pipelinePath, config.PipelineLoadOptions{}, nil, deps); err != nil {
|
|
||||||
t.Fatalf("load pipeline: %v", err)
|
|
||||||
}
|
|
||||||
if secretCalls != 0 || pipelineCalls != 1 {
|
|
||||||
t.Fatalf("calls = secrets %d, pipeline %d; want 0, 1", secretCalls, pipelineCalls)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPipelineLoadUsesIndependentConventionalSecretsDirectory(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
previous := conventionalSecretsDirectory
|
mustWriteSecretFile(t, filepath.Join(dir, "secrets", name), "synthetic-value\n")
|
||||||
conventionalSecretsDirectory = dir
|
pipeline := filepath.Join(dir, "pipeline.yml")
|
||||||
t.Cleanup(func() { conventionalSecretsDirectory = previous })
|
mustWriteTestFile(t, pipeline, "config: {secrets_dir: secrets}\nwhisperx: {transcribe_url: https://example.test/transcribe}\nnotarius: {enabled: false, credentials: ["+name+"]}\n")
|
||||||
const name = "NARRATIO_TEST_CONVENTIONAL_SECRET"
|
acquisition := newConfigurationAcquisition(configurationSelection{Config: suppliedSelection(pipeline)}, commandDependencies{})
|
||||||
restoreEnvAfterTest(t, name)
|
loaded, err := acquisition.Pipeline(context.Background())
|
||||||
mustWriteSecretFile(t, filepath.Join(dir, name), "synthetic-value\n")
|
|
||||||
pipelinePath := filepath.Join(t.TempDir(), "pipeline.yml")
|
|
||||||
if err := os.WriteFile(pipelinePath, []byte("whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+name+"]\n"), 0o644); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, pipeline, err := loadPipelineConfigWithDependencies(pipelinePath, config.PipelineLoadOptions{}, nil, commandDependencies{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if got := pipeline.Notarius.Credentials[0].Value(); got != "synthetic-value" {
|
if len(loaded.Notarius.Credentials) != 1 || loaded.Notarius.Credentials[0].Value() != "synthetic-value" {
|
||||||
t.Fatal("conventional directory credential was not resolved")
|
t.Fatal("credential was not resolved")
|
||||||
|
}
|
||||||
|
if os.Getenv(name) != "synthetic-value" || acquisition.bootstrapReport == nil {
|
||||||
|
t.Fatal("configured bootstrap did not retain its report")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExplicitSecretsDirectoryIsResolvedFromCallerWorkingDirectory(t *testing.T) {
|
|
||||||
callerDir := t.TempDir()
|
|
||||||
selected := filepath.Join(callerDir, "credentials")
|
|
||||||
if err := os.Mkdir(selected, 0o700); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
original, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := os.Chdir(callerDir); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
t.Cleanup(func() { _ = os.Chdir(original) })
|
|
||||||
|
|
||||||
got, required, err := selectedSecretsDirectory(stringPointer("credentials"))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("select secrets: %v", err)
|
|
||||||
}
|
|
||||||
if !required || got != selected {
|
|
||||||
t.Fatalf("selection = %q, required=%t; want %q, true", got, required, selected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExplicitSecretsFailurePrecedesPipelineLoad(t *testing.T) {
|
|
||||||
pipelinePath := filepath.Join(t.TempDir(), "pipeline.yml")
|
|
||||||
if err := os.WriteFile(pipelinePath, []byte("version: 1\n"), 0o644); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
for name, selection := range map[string]string{"empty": "", "missing": filepath.Join(t.TempDir(), "missing")} {
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
pipelineCalls := 0
|
|
||||||
deps := commandDependencies{loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
|
||||||
pipelineCalls++
|
|
||||||
return &config.PipelineConfig{}, nil
|
|
||||||
}}
|
|
||||||
if _, _, err := loadPipelineConfigWithDependencies(pipelinePath, config.PipelineLoadOptions{}, &selection, deps); err == nil {
|
|
||||||
t.Fatal("load succeeded, want bootstrap error")
|
|
||||||
}
|
|
||||||
if pipelineCalls != 0 {
|
|
||||||
t.Fatalf("pipeline load calls = %d, want 0", pipelineCalls)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSecretsBootstrapPreservesExistingEnvironmentValues(t *testing.T) {
|
|
||||||
directory := t.TempDir()
|
|
||||||
const emptyName = "NARRATIO_BOOTSTRAP_EXISTING_EMPTY"
|
|
||||||
const valueName = "NARRATIO_BOOTSTRAP_EXISTING_VALUE"
|
|
||||||
const loadedName = "NARRATIO_BOOTSTRAP_NEW_VALUE"
|
|
||||||
t.Setenv(emptyName, "")
|
|
||||||
t.Setenv(valueName, "from-environment")
|
|
||||||
restoreEnvAfterTest(t, loadedName)
|
|
||||||
for name, value := range map[string]string{
|
|
||||||
emptyName: "from-file-empty\n",
|
|
||||||
valueName: "from-file-value\n",
|
|
||||||
loadedName: "new-value\n",
|
|
||||||
} {
|
|
||||||
mustWriteSecretFile(t, filepath.Join(directory, name), value)
|
|
||||||
}
|
|
||||||
|
|
||||||
bootstrap := &secretsBootstrap{selection: &directory, selectionSet: true}
|
|
||||||
var diagnostics bytes.Buffer
|
|
||||||
if err := bootstrap.load(configkit.LoadSecretsIntoEnvironment, &diagnostics); err != nil {
|
|
||||||
t.Fatalf("bootstrap: %v", err)
|
|
||||||
}
|
|
||||||
if got := diagnostics.String(); !strings.Contains(got, `status="skipped_existing"`) || !strings.Contains(got, `existing_empty=true`) {
|
|
||||||
t.Fatalf("diagnostics lack explicit skipped-empty result: %q", got)
|
|
||||||
}
|
|
||||||
if got := os.Getenv(emptyName); got != "" {
|
|
||||||
t.Fatalf("existing empty value = %q, want empty", got)
|
|
||||||
}
|
|
||||||
if got := os.Getenv(valueName); got != "from-environment" {
|
|
||||||
t.Fatalf("existing value = %q, want environment value", got)
|
|
||||||
}
|
|
||||||
if got := os.Getenv(loadedName); got != "new-value" {
|
|
||||||
t.Fatalf("new value = %q, want file value", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNotariusCredentialLoadsFromCommandSecretBootstrap(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
explicit bool
|
|
||||||
environment string
|
|
||||||
fileValue string
|
|
||||||
wantValue string
|
|
||||||
}{
|
|
||||||
{name: "explicit", explicit: true, fileValue: "explicit-value", wantValue: "explicit-value"},
|
|
||||||
{name: "environment precedence", explicit: true, environment: "environment-value", fileValue: "file-value", wantValue: "environment-value"},
|
|
||||||
}
|
|
||||||
for index, test := range tests {
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
|
||||||
envName := fmt.Sprintf("NARRATIO_NOTARIUS_BOOTSTRAP_%d", index)
|
|
||||||
restoreEnvAfterTest(t, envName)
|
|
||||||
root := t.TempDir()
|
|
||||||
pipelinePath := filepath.Join(root, "pipeline.yml")
|
|
||||||
if err := os.WriteFile(pipelinePath, []byte("whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+envName+"]\n"), 0o644); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
secretsDir := filepath.Join(root, "secrets")
|
|
||||||
var selection *string
|
|
||||||
if test.explicit {
|
|
||||||
secretsDir = filepath.Join(t.TempDir(), "selected-secrets")
|
|
||||||
selection = &secretsDir
|
|
||||||
}
|
|
||||||
mustWriteSecretFile(t, filepath.Join(secretsDir, envName), test.fileValue+"\n")
|
|
||||||
if test.environment != "" {
|
|
||||||
if err := os.Setenv(envName, test.environment); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, pipeline, err := loadPipelineConfigWithDependencies(pipelinePath, config.PipelineLoadOptions{}, selection, commandDependencies{diagnostics: io.Discard})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("load pipeline: %v", err)
|
|
||||||
}
|
|
||||||
if pipeline.Notarius == nil || len(pipeline.Notarius.Credentials) != 1 || !pipeline.Notarius.Credentials[0].IsResolved() ||
|
|
||||||
pipeline.Notarius.Credentials[0].EnvName() != envName || pipeline.Notarius.Credentials[0].Value() != test.wantValue {
|
|
||||||
t.Fatal("Notarius credential did not resolve from the selected command bootstrap source")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSecretsBootstrapPreservesSafePartialReportOnFailure(t *testing.T) {
|
|
||||||
directory := t.TempDir()
|
|
||||||
mustWriteSecretFile(t, filepath.Join(directory, "INVALID-NAME"), "must-not-appear\n")
|
|
||||||
bootstrap := &secretsBootstrap{selection: &directory, selectionSet: true}
|
|
||||||
err := bootstrap.load(configkit.LoadSecretsIntoEnvironment, io.Discard)
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("bootstrap succeeded, want error")
|
|
||||||
}
|
|
||||||
if !strings.Contains(err.Error(), `status="failed"`) || !strings.Contains(err.Error(), `name="INVALID-NAME"`) {
|
|
||||||
t.Fatalf("error lacks partial report: %v", err)
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "must-not-appear") {
|
|
||||||
t.Fatalf("error exposed secret value: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExecuteConfigShowReportsSuccessfulSecretsBootstrapOnStderr(t *testing.T) {
|
|
||||||
workspaceRoot := t.TempDir()
|
|
||||||
pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot)
|
|
||||||
secretsDir := t.TempDir()
|
|
||||||
const name = "NARRATIO_BOOTSTRAP_REPORT_SECRET"
|
|
||||||
const canary = "synthetic-secret-must-not-appear"
|
|
||||||
restoreEnvAfterTest(t, name)
|
|
||||||
if err := os.Unsetenv(name); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
mustWriteSecretFile(t, filepath.Join(secretsDir, name), canary+"\n")
|
|
||||||
|
|
||||||
var stdout bytes.Buffer
|
|
||||||
var stderr bytes.Buffer
|
|
||||||
if code := executeForTest([]string{"config", "show", "--config", pipelinePath, "--secrets-dir", secretsDir, "--verbose"}, &stdout, &stderr); code != 0 {
|
|
||||||
t.Fatalf("config show exit = %d, stderr = %q", code, stderr.String())
|
|
||||||
}
|
|
||||||
if got := stderr.String(); !strings.Contains(got, `status="loaded"`) || !strings.Contains(got, `name="`+name+`"`) {
|
|
||||||
t.Fatalf("stderr lacks safe bootstrap report: %q", got)
|
|
||||||
}
|
|
||||||
if strings.Contains(stderr.String(), canary) || strings.Contains(stdout.String(), canary) {
|
|
||||||
t.Fatal("command output exposed secret value")
|
|
||||||
}
|
|
||||||
if strings.Contains(stdout.String(), `status="loaded"`) || strings.Contains(stdout.String(), name) {
|
|
||||||
t.Fatalf("show stdout was polluted by bootstrap report: %q", stdout.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExecuteConfigValidateReportsSkippedEmptyBeforeTypedLoadFailure(t *testing.T) {
|
|
||||||
workspaceRoot := t.TempDir()
|
|
||||||
pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot)
|
|
||||||
const name = "NARRATIO_REVIEW_KEY"
|
|
||||||
const canary = "synthetic-skipped-secret-must-not-appear"
|
|
||||||
t.Setenv(name, "")
|
|
||||||
pipelineYAML, err := os.ReadFile(pipelinePath)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
pipelineYAML = append(pipelineYAML, []byte("notarius:\n enabled: false\n credentials: ["+name+"]\n")...)
|
|
||||||
if err := os.WriteFile(pipelinePath, pipelineYAML, 0o644); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
secretsDir := t.TempDir()
|
|
||||||
mustWriteSecretFile(t, filepath.Join(secretsDir, name), canary+"\n")
|
|
||||||
|
|
||||||
var stdout bytes.Buffer
|
|
||||||
var stderr bytes.Buffer
|
|
||||||
if code := executeForTest([]string{"config", "validate", "--config", pipelinePath, "--secrets-dir", secretsDir, "--verbose"}, &stdout, &stderr); code == 0 {
|
|
||||||
t.Fatal("config validate succeeded, want empty-secret failure")
|
|
||||||
}
|
|
||||||
got := stderr.String()
|
|
||||||
if !strings.Contains(got, `status="skipped_existing"`) || !strings.Contains(got, `existing_empty=true`) {
|
|
||||||
t.Fatalf("stderr lacks useful skipped-empty diagnostic: %q", got)
|
|
||||||
}
|
|
||||||
if !strings.Contains(got, "secret.empty") {
|
|
||||||
t.Fatalf("stderr lacks typed load failure: %q", got)
|
|
||||||
}
|
|
||||||
if strings.Contains(got, canary) || strings.Contains(stdout.String(), canary) {
|
|
||||||
t.Fatal("command output exposed skipped secret value")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func stringPointer(value string) *string { return &value }
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func checkSessionInitializationInput(input *sessionInitializationInput) error {
|
|||||||
func sessionInitializationCommand(deps commandDependencies) commandkit.Command {
|
func sessionInitializationCommand(deps commandDependencies) commandkit.Command {
|
||||||
common := newConfigurationFlags(func(input **sessionInitializationInput) *configurationSelection { return &(*input).Selection })
|
common := newConfigurationFlags(func(input **sessionInitializationInput) *configurationSelection { return &(*input).Selection })
|
||||||
return commandkit.NewCommand(commandkit.CommandSpec[*sessionInitializationInput]{Name: "init", Summary: "Create standalone local or remote session configuration.", NewInput: func() *sessionInitializationInput { return &sessionInitializationInput{} },
|
return commandkit.NewCommand(commandkit.CommandSpec[*sessionInitializationInput]{Name: "init", Summary: "Create standalone local or remote session configuration.", NewInput: func() *sessionInitializationInput { return &sessionInitializationInput{} },
|
||||||
Flags: []commandkit.Flag[*sessionInitializationInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SecretsDir,
|
Flags: []commandkit.Flag[*sessionInitializationInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile,
|
||||||
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Previous session identity."}, nil, stringValue, func(input **sessionInitializationInput, value commandkit.Supplied[string]) {
|
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Previous session identity."}, nil, stringValue, func(input **sessionInitializationInput, value commandkit.Supplied[string]) {
|
||||||
(*input).PreviousSessionID = value.Value
|
(*input).PreviousSessionID = value.Value
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -81,11 +81,11 @@ func TestSessionInitializationCommandRemoteRoundTrips(t *testing.T) {
|
|||||||
|
|
||||||
func TestSessionInitializationCommandChecksTargetsBeforeAcquisition(t *testing.T) {
|
func TestSessionInitializationCommandChecksTargetsBeforeAcquisition(t *testing.T) {
|
||||||
app, err := newApplication(commandDependencies{
|
app, err := newApplication(commandDependencies{
|
||||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
preparePipelineSource: func(configkit.Source) (*configkit.SecretsReport, configkit.Source, error) {
|
||||||
t.Fatal("invalid initialization bootstrapped secrets")
|
t.Fatal("invalid initialization bootstrapped secrets")
|
||||||
return nil, nil
|
return nil, configkit.Source{}, nil
|
||||||
},
|
},
|
||||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
loadPipelineSource: func(configkit.Source, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||||
t.Fatal("invalid initialization loaded config")
|
t.Fatal("invalid initialization loaded config")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type sessionValidationReport struct {
|
|||||||
|
|
||||||
func sessionInspectionSpec(name, summary string, remoteOption bool) commandkit.CommandSpec[*sessionInspectionInput] {
|
func sessionInspectionSpec(name, summary string, remoteOption bool) commandkit.CommandSpec[*sessionInspectionInput] {
|
||||||
common := newConfigurationFlags(func(input **sessionInspectionInput) *configurationSelection { return &(*input).Selection })
|
common := newConfigurationFlags(func(input **sessionInspectionInput) *configurationSelection { return &(*input).Selection })
|
||||||
flags := []commandkit.Flag[*sessionInspectionInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile, common.SecretsDir,
|
flags := []commandkit.Flag[*sessionInspectionInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile,
|
||||||
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **sessionInspectionInput, value commandkit.Supplied[string]) {
|
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **sessionInspectionInput, value commandkit.Supplied[string]) {
|
||||||
(*input).PreviousSession = value
|
(*input).PreviousSession = value
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -4,23 +4,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
dir, err := os.MkdirTemp("", "narratio-app-test-*")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
conventionalSecretsDirectory = filepath.Join(dir, "secrets")
|
|
||||||
code := m.Run()
|
|
||||||
_ = os.RemoveAll(dir)
|
|
||||||
os.Exit(code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// restoreEnvAfterTest clears names for a test and restores both their prior
|
// restoreEnvAfterTest clears names for a test and restores both their prior
|
||||||
// values and their set/unset state during cleanup.
|
// values and their set/unset state during cleanup.
|
||||||
func restoreEnvAfterTest(t *testing.T, names ...string) {
|
func restoreEnvAfterTest(t *testing.T, names ...string) {
|
||||||
@@ -76,3 +66,38 @@ func guardedMissingPipelineDiscovery(t *testing.T) (commandDependencies, string,
|
|||||||
}
|
}
|
||||||
return deps, candidate, executor
|
return deps, candidate, executor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func configureTestSecrets(t *testing.T, pipeline, directory string) {
|
||||||
|
t.Helper()
|
||||||
|
destination := filepath.Join(filepath.Dir(pipeline), "test-secrets")
|
||||||
|
entries, err := os.ReadDir(directory)
|
||||||
|
if err == nil {
|
||||||
|
if err := os.MkdirAll(destination, 0700); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, entry := range entries {
|
||||||
|
data, err := os.ReadFile(filepath.Join(directory, entry.Name()))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(filepath.Join(destination, entry.Name()), data, 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if !os.IsNotExist(err) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
data, err := os.ReadFile(pipeline)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
body := string(data)
|
||||||
|
if strings.Contains(body, "\nconfig:\n") || strings.HasPrefix(body, "config:\n") {
|
||||||
|
body = strings.Replace(body, "config:\n", "config:\n secrets_dir: test-secrets\n", 1)
|
||||||
|
} else {
|
||||||
|
body = "config: {secrets_dir: test-secrets}\n" + body
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(pipeline, []byte(body), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user