Adopt the native CommandKit application boundary
This commit is contained in:
@@ -19,7 +19,7 @@ func TestExecuteRunStageArtifactsUnsupportedStageFails(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute(
|
||||
code := executeForTest(
|
||||
[]string{"run-stage", "extract", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--artifacts", "session_recap"},
|
||||
&stdout,
|
||||
&stderr,
|
||||
@@ -77,7 +77,7 @@ func TestExecuteUnknownArtifactsFailValidation(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute(
|
||||
code := executeForTest(
|
||||
[]string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--artifacts", "unknown_artifact"},
|
||||
&stdout,
|
||||
&stderr,
|
||||
@@ -234,7 +234,7 @@ func TestExecuteAnalyzeUnknownArtifactFailsValidation(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute(
|
||||
code := executeForTest(
|
||||
[]string{"analyze", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--artifacts", "unknown_artifact"},
|
||||
&stdout,
|
||||
&stderr,
|
||||
@@ -260,7 +260,7 @@ func TestExecuteAnalyzeRejectsPositionalArgsAndForceFlag(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute(tc.args, &stdout, &stderr)
|
||||
code := executeForTest(tc.args, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -344,7 +344,7 @@ func TestExecutePublishRejectsUnsupportedArgsAndFlags(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute(tc.args, &stdout, &stderr)
|
||||
code := executeForTest(tc.args, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -361,7 +361,7 @@ func TestExecutePublishUnknownArtifactFailsValidation(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute(
|
||||
code := executeForTest(
|
||||
[]string{"publish", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--artifacts", "unknown_artifact"},
|
||||
&stdout,
|
||||
&stderr,
|
||||
@@ -393,7 +393,7 @@ func TestExecutePublishMissingConfigUsesRunStageLoadingPath(t *testing.T) {
|
||||
func TestExecuteUsageIncludesAnalyzeAndPublish(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute(nil, &stdout, &stderr)
|
||||
code := executeForTest(nil, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ func TestBoundedRunCommandHelp(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
if code := Execute(test.args, &stdout, &stderr); code != 0 {
|
||||
if code := executeForTest(test.args, &stdout, &stderr); code != 0 {
|
||||
t.Fatalf("exit code = %d, stderr = %q", code, stderr.String())
|
||||
}
|
||||
if !strings.Contains(stdout.String(), test.want) || stderr.Len() != 0 {
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestExecuteCleanSessionDeletesWorkAndSpoolButPreservesCache(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func TestExecuteCleanSessionDryRunDeletesNothing(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--dry-run"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--dry-run"}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func TestExecuteCleanMissingSessionPathsSucceeds(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func TestExecuteCleanLocalAudioClearCacheIsNoop(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--clear-cache"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--clear-cache"}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func TestExecuteCleanAllDeletesWorkAndSpoolContentsButPreservesCache(t *testing.
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clean", "--config", pipelinePath, "--all"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clean", "--config", pipelinePath, "--all"}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func TestExecuteCleanAllClearCacheRemovesS3AudioNamespaceOnly(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clean", "--config", pipelinePath, "--all", "--clear-cache"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clean", "--config", pipelinePath, "--all", "--clear-cache"}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func TestExecuteCleanAllRejectsSessionScopedFlags(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--all"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--all"}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -196,7 +196,7 @@ func TestExecuteCleanAllRejectsSessionScopedFlags(t *testing.T) {
|
||||
func TestCleanRequiresSessionID(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clean"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clean"}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -231,7 +231,7 @@ func TestCleanRejectsUnsafeTargets(t *testing.T) {
|
||||
func TestClearIsNotCommandAlias(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clear"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clear"}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
|
||||
49
internal/app/command_outcome.go
Normal file
49
internal/app/command_outcome.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
// inputError identifies an invalid Narratio request independently of native
|
||||
// configuration diagnostics. Operational errors retain their own classification.
|
||||
type inputError struct{ message string }
|
||||
|
||||
func (e *inputError) Error() string { return e.message }
|
||||
|
||||
func operationOutcome(err error) commandkit.Outcome {
|
||||
if err == nil {
|
||||
return commandkit.Success()
|
||||
}
|
||||
if classifyOperationError(err) == commandkit.OutcomeUsage {
|
||||
return commandkit.Usage(err.Error()).WithCause(err)
|
||||
}
|
||||
return commandkit.Failure(err.Error()).WithCause(err)
|
||||
}
|
||||
|
||||
func classifyOperationError(err error) commandkit.OutcomeKind {
|
||||
if _, ok := err.(*inputError); ok {
|
||||
return commandkit.OutcomeUsage
|
||||
}
|
||||
switch wrapped := err.(type) {
|
||||
case interface{ Unwrap() []error }:
|
||||
found := false
|
||||
for _, child := range wrapped.Unwrap() {
|
||||
if child == nil {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if classifyOperationError(child) != commandkit.OutcomeUsage {
|
||||
return commandkit.OutcomeOperational
|
||||
}
|
||||
}
|
||||
if found {
|
||||
return commandkit.OutcomeUsage
|
||||
}
|
||||
case interface{ Unwrap() error }:
|
||||
if child := wrapped.Unwrap(); child != nil {
|
||||
return classifyOperationError(child)
|
||||
}
|
||||
}
|
||||
return ckconfig.ClassifyConfigurationError(err)
|
||||
}
|
||||
44
internal/app/command_selection.go
Normal file
44
internal/app/command_selection.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package app
|
||||
|
||||
import "go.maximumdirect.net/commandkit"
|
||||
|
||||
// configurationSelection distinguishes source selection from identity assertions
|
||||
// and retains explicit empty selections until the operation checks its inputs.
|
||||
type configurationSelection struct {
|
||||
Config commandkit.Supplied[string]
|
||||
Overlay commandkit.Supplied[string]
|
||||
Campaign commandkit.Supplied[string]
|
||||
CampaignFile commandkit.Supplied[string]
|
||||
Session commandkit.Supplied[string]
|
||||
SessionFile commandkit.Supplied[string]
|
||||
PartyFile commandkit.Supplied[string]
|
||||
SecretsDir commandkit.Supplied[string]
|
||||
}
|
||||
|
||||
type configurationFlags[I any] struct {
|
||||
Config, Overlay, Campaign, CampaignFile commandkit.Flag[I]
|
||||
Session, SessionFile, PartyFile, SecretsDir commandkit.Flag[I]
|
||||
}
|
||||
|
||||
func newConfigurationFlags[I any](selection func(*I) *configurationSelection) configurationFlags[I] {
|
||||
return configurationFlags[I]{
|
||||
Config: commandkit.ValueFlag(commandkit.FlagMeta{Name: "config", Usage: "Pipeline configuration file."}, nil, stringValue,
|
||||
func(in *I, v commandkit.Supplied[string]) { selection(in).Config = v }),
|
||||
Overlay: commandkit.ValueFlag(commandkit.FlagMeta{Name: "overlay", Usage: "Pipeline overlay."}, nil, stringValue,
|
||||
func(in *I, v commandkit.Supplied[string]) { selection(in).Overlay = v }),
|
||||
Campaign: commandkit.ValueFlag(commandkit.FlagMeta{Name: "campaign", Usage: "Assert the campaign identity."}, nil, stringValue,
|
||||
func(in *I, v commandkit.Supplied[string]) { selection(in).Campaign = v }),
|
||||
CampaignFile: commandkit.ValueFlag(commandkit.FlagMeta{Name: "campaign-file", Usage: "Campaign configuration file."}, nil, stringValue,
|
||||
func(in *I, v commandkit.Supplied[string]) { selection(in).CampaignFile = v }),
|
||||
Session: commandkit.ValueFlag(commandkit.FlagMeta{Name: "session", Usage: "Assert the session identity for configuration inspection."}, nil, stringValue,
|
||||
func(in *I, v commandkit.Supplied[string]) { selection(in).Session = v }),
|
||||
SessionFile: commandkit.ValueFlag(commandkit.FlagMeta{Name: "session-file", Usage: "Session configuration file."}, nil, stringValue,
|
||||
func(in *I, v commandkit.Supplied[string]) { selection(in).SessionFile = v }),
|
||||
PartyFile: commandkit.ValueFlag(commandkit.FlagMeta{Name: "party-file", Usage: "Party file replacing the campaign default."}, nil, stringValue,
|
||||
func(in *I, v commandkit.Supplied[string]) { selection(in).PartyFile = v }),
|
||||
SecretsDir: commandkit.ValueFlag(commandkit.FlagMeta{Name: "secrets-dir", Usage: "Credential-bootstrap directory."}, nil, stringValue,
|
||||
func(in *I, v commandkit.Supplied[string]) { selection(in).SecretsDir = v }),
|
||||
}
|
||||
}
|
||||
|
||||
func stringValue(value string) (string, error) { return value, nil }
|
||||
24
internal/app/command_test_helpers_test.go
Normal file
24
internal/app/command_test_helpers_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
func executeForTest(args []string, stdout, stderr io.Writer) int {
|
||||
return Execute(context.Background(), args, commandkit.Streams{Out: stdout, Err: stderr}).Status
|
||||
}
|
||||
|
||||
func executeWithPipelineExecutor(args []string, stdout, stderr io.Writer, executor pipelineExecutor) int {
|
||||
return executeWithDependencies(args, stdout, stderr, commandDependencies{}, executor)
|
||||
}
|
||||
|
||||
func executeWithDependencies(args []string, stdout, stderr io.Writer, deps commandDependencies, executor pipelineExecutor) int {
|
||||
application, err := newApplication(deps, executor)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return application.Execute(context.Background(), args, commandkit.Streams{Out: stdout, Err: stderr}).Status
|
||||
}
|
||||
@@ -2,70 +2,31 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/buildinfo"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
var supportedCommands = []string{"version", "run", "regenerate-artifacts", "run-stage", "analyze", "publish", "clean", "session", "config"}
|
||||
|
||||
// Execute dispatches CLI commands and returns a process exit code.
|
||||
func Execute(args []string, stdout, stderr io.Writer) int {
|
||||
return executeWithDependencies(args, stdout, stderr, commandDependencies{}, executePlan)
|
||||
// NewApplication constructs the native command boundary without acquiring configuration
|
||||
// or initializing external services.
|
||||
func NewApplication() (*commandkit.App, error) {
|
||||
return newApplication(commandDependencies{}, executePlan)
|
||||
}
|
||||
|
||||
func executeWithPipelineExecutor(args []string, stdout, stderr io.Writer, executor pipelineExecutor) int {
|
||||
return executeWithDependencies(args, stdout, stderr, commandDependencies{}, executor)
|
||||
func newApplication(deps commandDependencies, executor pipelineExecutor) (*commandkit.App, error) {
|
||||
return commandkit.New(
|
||||
commandkit.Identity{Name: "narratio", Version: buildinfo.Version},
|
||||
commandkit.Group("artifacts", "Inspect and regenerate configured artifacts."),
|
||||
commandkit.Group("session", "Manage and inspect sessions."),
|
||||
)
|
||||
}
|
||||
|
||||
func executeWithDependencies(args []string, stdout, stderr io.Writer, deps commandDependencies, executor pipelineExecutor) int {
|
||||
if deps.diagnostics == nil {
|
||||
deps.diagnostics = stderr
|
||||
}
|
||||
deps = normalizeCommandDependencies(deps)
|
||||
if len(args) == 0 {
|
||||
printUsage(stderr)
|
||||
return 1
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
cmd := args[0]
|
||||
cmdArgs := args[1:]
|
||||
|
||||
var err error
|
||||
switch cmd {
|
||||
case "version":
|
||||
err = Version(cmdArgs, stdout)
|
||||
case "run":
|
||||
err = runWithDependencies(ctx, cmdArgs, stdout, executor, deps)
|
||||
case "regenerate-artifacts":
|
||||
err = regenerateArtifactsWithDependencies(ctx, cmdArgs, stdout, executor, deps)
|
||||
case "run-stage":
|
||||
err = runStageWithDependencies(ctx, cmdArgs, stdout, executor, deps)
|
||||
case "analyze":
|
||||
err = analyzeWithDependencies(ctx, cmdArgs, stdout, executor, deps)
|
||||
case "publish":
|
||||
err = publishWithDependencies(ctx, cmdArgs, stdout, executor, deps)
|
||||
case "session":
|
||||
err = sessionWithDependencies(ctx, cmdArgs, stdout, deps)
|
||||
case "clean":
|
||||
err = cleanWithDependencies(ctx, cmdArgs, stdout, deps)
|
||||
case "config":
|
||||
err = configWithDependencies(ctx, cmdArgs, stdout, deps)
|
||||
default:
|
||||
fmt.Fprintf(stderr, "unknown command: %q\n\n", cmd)
|
||||
printUsage(stderr)
|
||||
return 1
|
||||
}
|
||||
|
||||
// Execute runs an invocation with caller-owned context and streams and returns
|
||||
// its finalized native outcome. The process boundary owns exit handling.
|
||||
func Execute(ctx context.Context, args []string, streams commandkit.Streams) commandkit.Outcome {
|
||||
application, err := NewApplication()
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "%v\n", err)
|
||||
return 1
|
||||
return operationOutcome(err)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func printUsage(w io.Writer) {
|
||||
fmt.Fprintf(w, "Usage: narratio <%s>\n", strings.Join(supportedCommands, "|"))
|
||||
return application.Execute(ctx, args, streams)
|
||||
}
|
||||
|
||||
115
internal/app/commands_boundary_test.go
Normal file
115
internal/app/commands_boundary_test.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestNativeDiscoveryDoesNotAcquireConfiguration(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
t.Chdir(root)
|
||||
if err := os.WriteFile(filepath.Join(root, "pipeline.yml"), []byte("invalid: ["), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
application, err := newApplication(commandDependencies{
|
||||
loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) {
|
||||
t.Fatal("discovery loaded pipeline configuration")
|
||||
return nil, nil
|
||||
},
|
||||
loadSecretsDir: func(string) (*configkit.SecretsReport, error) {
|
||||
t.Fatal("discovery bootstrapped credentials")
|
||||
return nil, nil
|
||||
},
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, args := range [][]string{nil, {"help"}, {"--help"}, {"session"}, {"artifacts"}, {"version"}} {
|
||||
var out, diagnostics bytes.Buffer
|
||||
outcome := application.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostics})
|
||||
if outcome.Status != 0 || out.Len() == 0 || diagnostics.Len() != 0 {
|
||||
t.Fatalf("%v: outcome=%+v stdout=%q stderr=%q", args, outcome, out.String(), diagnostics.String())
|
||||
}
|
||||
}
|
||||
if outcome := application.Execute(context.Background(), []string{"unknown"}, commandkit.Streams{}); outcome.Status != 2 {
|
||||
t.Fatalf("invalid invocation: %+v", outcome)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeSelectionRetainsPresenceAndCallerContext(t *testing.T) {
|
||||
flags := newConfigurationFlags(func(in *configurationSelection) *configurationSelection { return in })
|
||||
type contextKey struct{}
|
||||
ctx := context.WithValue(context.Background(), contextKey{}, "caller")
|
||||
application, err := commandkit.New(commandkit.Identity{Name: "narratio"}, commandkit.NewCommand(commandkit.CommandSpec[configurationSelection]{
|
||||
Name: "inspect",
|
||||
Flags: []commandkit.Flag[configurationSelection]{flags.Config, flags.Overlay, flags.Campaign, flags.CampaignFile, flags.Session, flags.SessionFile, flags.PartyFile, flags.SecretsDir},
|
||||
CheckInput: func(in configurationSelection) error {
|
||||
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)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Run: func(inv commandkit.Invocation, in configurationSelection) commandkit.Outcome {
|
||||
if inv.Context.Value(contextKey{}) != "caller" {
|
||||
t.Fatal("caller context lost")
|
||||
}
|
||||
return commandkit.Success()
|
||||
},
|
||||
}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
outcome := application.Execute(ctx, []string{"inspect", "--config=", "--campaign", "campaign", "--campaign-file", "campaign.yml"}, commandkit.Streams{})
|
||||
if outcome.Status != 0 {
|
||||
t.Fatalf("selection outcome: %+v", outcome)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOperationOutcomePreservesCausesAndOperationalPrecedence(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "pipeline.yml")
|
||||
if err := os.WriteFile(path, []byte("invalid: ["), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, invalid := config.LoadPipeline(path)
|
||||
if invalid == nil {
|
||||
t.Fatal("expected invalid configuration")
|
||||
}
|
||||
input := &inputError{message: "invalid identity selection"}
|
||||
operational := errors.New("storage unavailable")
|
||||
for _, tc := range []struct {
|
||||
err error
|
||||
status int
|
||||
}{
|
||||
{nil, 0}, {input, 2}, {invalid, 2},
|
||||
{fmt.Errorf("request: %w", errors.Join(input, invalid)), 2},
|
||||
{errors.Join(input, operational), 1},
|
||||
{fmt.Errorf("request: %w", errors.Join(invalid, context.Canceled)), 1},
|
||||
} {
|
||||
outcome := operationOutcome(tc.err)
|
||||
if outcome.Status != tc.status || (tc.err != nil && !errors.Is(outcome.Cause, tc.err)) {
|
||||
t.Fatalf("%v: outcome=%+v, want status %d and original cause", tc.err, outcome, tc.status)
|
||||
}
|
||||
}
|
||||
application, err := commandkit.New(commandkit.Identity{Name: "narratio"}, commandkit.NewCommand(commandkit.CommandSpec[struct{}]{
|
||||
Name: "fail", Run: func(commandkit.Invocation, struct{}) commandkit.Outcome { return operationOutcome(operational) },
|
||||
}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var diagnostics bytes.Buffer
|
||||
outcome := application.Execute(context.Background(), []string{"fail", "--quiet"}, commandkit.Streams{Out: io.Discard, Err: &diagnostics})
|
||||
if outcome.Status != 1 || !errors.Is(outcome.Cause, operational) || strings.Count(diagnostics.String(), operational.Error()) != 1 {
|
||||
t.Fatalf("failure delivery: outcome=%+v diagnostics=%q", outcome, diagnostics.String())
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func TestExecuteValidCommands(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
code := Execute(tc.args, &stdout, &stderr)
|
||||
code := executeForTest(tc.args, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0", code)
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func TestExecuteRunStageUnknownFails(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
code := Execute([]string{"run-stage", "unknown", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"run-stage", "unknown", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func TestExecuteRunStageArchiveAliasFails(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
code := Execute([]string{"run-stage", "archive", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"run-stage", "archive", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func TestExecuteRunStageNormalizeIsAccepted(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
code := Execute([]string{"run-stage", "normalize", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"run-stage", "normalize", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -164,14 +164,14 @@ func TestExecuteRunStageTranscribeUsesConfiguredWhisperXServer(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
code := Execute([]string{"run-stage", "prepare", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"run-stage", "prepare", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("prepare exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
stdout.Reset()
|
||||
stderr.Reset()
|
||||
|
||||
code = Execute([]string{"run-stage", "transcribe", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--force"}, &stdout, &stderr)
|
||||
code = executeForTest([]string{"run-stage", "transcribe", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--force"}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("transcribe exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -261,7 +261,7 @@ inputs:
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"run-stage", "polish", sessionID, "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--force", "--secrets-dir", secretsDir}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"run-stage", "polish", sessionID, "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--force", "--secrets-dir", secretsDir}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -351,7 +351,7 @@ inputs:
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--secrets-dir", filepath.Join(configDir, "missing-secrets")}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"run", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--secrets-dir", filepath.Join(configDir, "missing-secrets")}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -374,7 +374,7 @@ func TestExecuteUsesDefaultPipelineConfigPathWhenConfigFlagOmitted(t *testing.T)
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"run", "2026-05-03", "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"run", "2026-05-03", "--session", sessionPath}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -392,7 +392,7 @@ func TestExecuteMissingCampaignConfigReportsRegistryPath(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"run", "2026-05-03", "--config", pipelinePath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"run", "2026-05-03", "--config", pipelinePath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -413,7 +413,7 @@ func TestExecuteUsesPipelineDefaultCampaignID(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"session", "status", "2026-05-03", "--config", pipelinePath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"session", "status", "2026-05-03", "--config", pipelinePath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -442,7 +442,7 @@ inputs:
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"session", "status", "2026-05-03", "--config", pipelinePath, "--campaign", "icewind", "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"session", "status", "2026-05-03", "--config", pipelinePath, "--campaign", "icewind", "--session", sessionPath}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
@@ -457,7 +457,7 @@ func TestExecuteRejectsCampaignIDAndCampaignFile(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"session", "status", "2026-05-03", "--config", pipelinePath, "--campaign", "sample-campaign", "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"session", "status", "2026-05-03", "--config", pipelinePath, "--campaign", "sample-campaign", "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -470,7 +470,7 @@ func TestExecuteInvalidCommand(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
code := Execute([]string{"bogus"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"bogus"}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatalf("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -490,7 +490,7 @@ func TestExecuteMissingCommand(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
code := Execute(nil, &stdout, &stderr)
|
||||
code := executeForTest(nil, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatalf("exit code = 0, want non-zero")
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestConfigCommandHelpAndDispatch(t *testing.T) {
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
code := Execute(test.args, &stdout, &stderr)
|
||||
code := executeForTest(test.args, &stdout, &stderr)
|
||||
if code != test.code {
|
||||
t.Fatalf("exit code = %d, want %d; stdout=%q stderr=%q", code, test.code, stdout.String(), stderr.String())
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestExecuteSessionInitLocalUsesDefaultConfigDiscovery(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{
|
||||
code := executeForTest([]string{
|
||||
"session", "init", "2026-06-07",
|
||||
"--output", outputPath,
|
||||
}, &stdout, &stderr)
|
||||
@@ -154,7 +154,7 @@ func TestExecuteSessionInitRequiresSessionID(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"session", "init", "--remote"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"session", "init", "--remote"}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -223,7 +223,7 @@ inputs:
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{
|
||||
code := executeForTest([]string{
|
||||
"session", "init", "2026-06-07",
|
||||
"--config", pipelinePath,
|
||||
"--campaign-file", campaignPath,
|
||||
@@ -267,7 +267,7 @@ func TestExecuteSessionInitUsesImportedTemplateLocation(t *testing.T) {
|
||||
}
|
||||
output := filepath.Join(t.TempDir(), "session.yml")
|
||||
var stdout, stderr bytes.Buffer
|
||||
if code := Execute([]string{"session", "init", "2026-06-07", "--config", pipeline, "--campaign-file", campaign, "--output", output}, &stdout, &stderr); code != 0 {
|
||||
if code := executeForTest([]string{"session", "init", "2026-06-07", "--config", pipeline, "--campaign-file", campaign, "--output", output}, &stdout, &stderr); code != 0 {
|
||||
t.Fatalf("exit = %d; stderr = %q", code, stderr.String())
|
||||
}
|
||||
data, err := os.ReadFile(output)
|
||||
@@ -328,7 +328,7 @@ inputs:
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{
|
||||
code := executeForTest([]string{
|
||||
"session", "init", "2026-06-07",
|
||||
"--config", pipelinePath,
|
||||
"--campaign-file", campaignPath,
|
||||
@@ -358,7 +358,7 @@ inputs:
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{
|
||||
code := executeForTest([]string{
|
||||
"session", "init", "2026-06-07",
|
||||
"--config", pipelinePath,
|
||||
"--campaign-file", campaignPath,
|
||||
@@ -383,7 +383,7 @@ inputs:
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{
|
||||
code := executeForTest([]string{
|
||||
"session", "init", "2026-06-07",
|
||||
"--config", pipelinePath,
|
||||
"--campaign-file", campaignPath,
|
||||
@@ -410,7 +410,7 @@ inputs:
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{
|
||||
code := executeForTest([]string{
|
||||
"session", "init", "2026-06-07",
|
||||
"--config", pipelinePath,
|
||||
"--campaign-file", campaignPath,
|
||||
@@ -741,7 +741,7 @@ func TestExecuteLocksRequireSessionID(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute(tt.args, &stdout, &stderr)
|
||||
code := executeForTest(tt.args, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -805,7 +805,7 @@ func TestExecuteTopLevelLockAndUnlockAreRemoved(t *testing.T) {
|
||||
t.Run(cmd, func(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{cmd, "narratio.transcript.final_trimmed"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{cmd, "narratio.transcript.final_trimmed"}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ inputs:
|
||||
`)
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
if code := Execute([]string{"config", "show", "--config", configPath, "--secrets-dir", secretsDir}, &stdout, &stderr); code != 0 {
|
||||
if code := executeForTest([]string{"config", "show", "--config", configPath, "--secrets-dir", secretsDir}, &stdout, &stderr); code != 0 {
|
||||
t.Fatalf("config show exit = %d; stderr=%q", code, stderr.String())
|
||||
}
|
||||
if !strings.Contains(stdout.String(), sharedProviderName) || !strings.Contains(stdout.String(), auditaOnlyName) {
|
||||
@@ -107,7 +107,7 @@ inputs:
|
||||
args := []string{"--secrets-dir", secretsDir, "--config", configPath, "--campaign-file", campaignPath, "--session", sessionPath}
|
||||
stdout.Reset()
|
||||
stderr.Reset()
|
||||
if code := Execute(append([]string{"run-stage", "polish", "2026-05-03", "--force"}, args...), &stdout, &stderr); code != 0 {
|
||||
if code := executeForTest(append([]string{"run-stage", "polish", "2026-05-03", "--force"}, args...), &stdout, &stderr); code != 0 {
|
||||
t.Fatalf("polish exit = %d; stderr=%q", code, stderr.String())
|
||||
}
|
||||
assertNoProviderValues(t, stdout.Bytes(), stderr.Bytes())
|
||||
@@ -136,7 +136,7 @@ inputs:
|
||||
}
|
||||
stdout.Reset()
|
||||
stderr.Reset()
|
||||
if code := Execute(append([]string{"run-stage", "extract", "2026-05-03", "--force"}, args...), &stdout, &stderr); code != 0 {
|
||||
if code := executeForTest(append([]string{"run-stage", "extract", "2026-05-03", "--force"}, args...), &stdout, &stderr); code != 0 {
|
||||
t.Fatalf("extract exit = %d; stderr=%q", code, stderr.String())
|
||||
}
|
||||
assertNoProviderValues(t, stdout.Bytes(), stderr.Bytes())
|
||||
@@ -146,7 +146,7 @@ inputs:
|
||||
redactedLogs := 0
|
||||
stdout.Reset()
|
||||
stderr.Reset()
|
||||
if code := Execute(append([]string{"analyze", "2026-05-03"}, args...), &stdout, &stderr); code != 0 {
|
||||
if code := executeForTest(append([]string{"analyze", "2026-05-03"}, args...), &stdout, &stderr); code != 0 {
|
||||
t.Fatalf("analyze exit = %d; stderr=%q", code, stderr.String())
|
||||
}
|
||||
assertNoProviderValues(t, stdout.Bytes(), stderr.Bytes())
|
||||
|
||||
@@ -81,7 +81,7 @@ func TestRegenerateArtifactsHelpDoesNotInvokeRun(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
if code := executeWithPipelineExecutor([]string{"regenerate-artifacts", "--help"}, &stdout, &stderr, executor); code != 0 {
|
||||
t.Fatalf("Execute() code = %d, stderr = %q", code, stderr.String())
|
||||
t.Fatalf("executeForTest() code = %d, stderr = %q", code, stderr.String())
|
||||
}
|
||||
if called {
|
||||
t.Fatal("help invoked canonical run handler")
|
||||
@@ -114,8 +114,8 @@ func TestRegenerateArtifactsOwnedOptionsFailThroughRunParser(t *testing.T) {
|
||||
args := []string{"regenerate-artifacts", "2026-05-03"}
|
||||
args = append(args, test.args...)
|
||||
var stderr bytes.Buffer
|
||||
if code := Execute(args, io.Discard, &stderr); code == 0 {
|
||||
t.Fatalf("Execute(%#v) code = 0", args)
|
||||
if code := executeForTest(args, io.Discard, &stderr); code == 0 {
|
||||
t.Fatalf("executeForTest(%#v) code = 0", args)
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "--"+test.owned+" may be specified only once") {
|
||||
t.Fatalf("stderr = %q, want shared duplicate %s error", stderr.String(), test.owned)
|
||||
@@ -126,8 +126,8 @@ func TestRegenerateArtifactsOwnedOptionsFailThroughRunParser(t *testing.T) {
|
||||
|
||||
func TestRegenerateArtifactsRejectsUnknownOptionsThroughRunParser(t *testing.T) {
|
||||
var stderr bytes.Buffer
|
||||
if code := Execute([]string{"regenerate-artifacts", "2026-05-03", "--regenerate-only"}, io.Discard, &stderr); code == 0 {
|
||||
t.Fatal("Execute() code = 0")
|
||||
if code := executeForTest([]string{"regenerate-artifacts", "2026-05-03", "--regenerate-only"}, io.Discard, &stderr); code == 0 {
|
||||
t.Fatal("executeForTest() code = 0")
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "flag provided but not defined") || !strings.Contains(stderr.String(), "regenerate-only") {
|
||||
t.Fatalf("stderr = %q, want canonical parser unknown-option error", stderr.String())
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestExecuteRestoreHelp(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
code := Execute([]string{"session", "restore", "--help"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"session", "restore", "--help"}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0", code)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func TestExecuteRestoreRejectsUnexpectedPositionalArguments(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"session", "restore", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "extra"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"session", "restore", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "extra"}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func TestExecuteRestoreFailsWhenStorageBackendNotConfigured(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"session", "restore", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"session", "restore", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func TestExecuteRestoreLoadsSecretsBeforeObjectStoreInit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecuteRestoreNonDryRunConflictDoesNotExecute(t *testing.T) {
|
||||
func TestExecuteRestoreNonDryRunConflictDoesNotexecuteForTest(t *testing.T) {
|
||||
deps := restoreCommandDependencies(&storage.FakeBackend{})
|
||||
deps.discoverRemoteCurrentState = func(context.Context, *config.Config, storage.ObjectStore) (*RemoteCurrentState, error) {
|
||||
return &RemoteCurrentState{
|
||||
|
||||
@@ -216,7 +216,7 @@ func TestExecuteConfigShowReportsSuccessfulSecretsBootstrapOnStderr(t *testing.T
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
if code := Execute([]string{"config", "show", "--config", pipelinePath, "--secrets-dir", secretsDir}, &stdout, &stderr); code != 0 {
|
||||
if code := executeForTest([]string{"config", "show", "--config", pipelinePath, "--secrets-dir", secretsDir}, &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+`"`) {
|
||||
@@ -249,7 +249,7 @@ func TestExecuteConfigValidateReportsSkippedEmptyBeforeTypedLoadFailure(t *testi
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
if code := Execute([]string{"config", "validate", "--config", pipelinePath, "--secrets-dir", secretsDir}, &stdout, &stderr); code == 0 {
|
||||
if code := executeForTest([]string{"config", "validate", "--config", pipelinePath, "--secrets-dir", secretsDir}, &stdout, &stderr); code == 0 {
|
||||
t.Fatal("config validate succeeded, want empty-secret failure")
|
||||
}
|
||||
got := stderr.String()
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestExecutePositionalSessionIDMismatchFails(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{
|
||||
code := executeForTest([]string{
|
||||
"run",
|
||||
"2026-05-04",
|
||||
"--config", pipelinePath,
|
||||
@@ -71,7 +71,7 @@ func TestExecutePositionalSessionIDMismatchFails(t *testing.T) {
|
||||
func TestExecuteSessionIDFlagMismatchFails(t *testing.T) {
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"session", "status", "2026-05-03", "--session-id", "2026-05-04"}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"session", "status", "2026-05-03", "--session-id", "2026-05-04"}, &stdout, &stderr)
|
||||
if code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func TestExecuteSessionIDFlagAcceptedWithoutPositional(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{
|
||||
code := executeForTest([]string{
|
||||
"session", "status",
|
||||
"--session-id", "2026-05-03",
|
||||
"--config", pipelinePath,
|
||||
@@ -288,7 +288,7 @@ func TestExecuteSessionInitAcceptsPositionalSessionID(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{
|
||||
code := executeForTest([]string{
|
||||
"session", "init", "2026-06-07",
|
||||
"--config", pipelinePath,
|
||||
"--campaign-file", campaignPath,
|
||||
@@ -360,7 +360,7 @@ func TestExecuteCleanAcceptsPositionalSessionID(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
code := Execute([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
code := executeForTest([]string{"clean", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d, want 0; stderr=%q", code, stderr.String())
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/buildinfo"
|
||||
)
|
||||
|
||||
// Version prints the version embedded in the current Narratio binary.
|
||||
func Version(args []string, out io.Writer) error {
|
||||
if len(args) != 0 {
|
||||
return fmt.Errorf("version: unexpected arguments")
|
||||
}
|
||||
_, err := fmt.Fprintf(out, "narratio %s\n", buildinfo.Version)
|
||||
return err
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -16,11 +17,18 @@ func TestExecuteVersionReportsEmbeddedBuildVersion(t *testing.T) {
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
if code := Execute([]string{"version"}, &stdout, &stderr); code != 0 {
|
||||
t.Fatalf("Execute() code = %d, stderr = %q", code, stderr.String())
|
||||
if code := executeForTest([]string{"version", "--format", "json"}, &stdout, &stderr); code != 0 {
|
||||
t.Fatalf("executeForTest() code = %d, stderr = %q", code, stderr.String())
|
||||
}
|
||||
if got, want := stdout.String(), "narratio v1.5.0-test\n"; got != want {
|
||||
t.Fatalf("stdout = %q, want %q", got, want)
|
||||
var identity struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
if err := json.Unmarshal(stdout.Bytes(), &identity); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if identity.Name != "narratio" || identity.Version != buildinfo.Version {
|
||||
t.Fatalf("version identity = %+v", identity)
|
||||
}
|
||||
if stderr.Len() != 0 {
|
||||
t.Fatalf("stderr = %q, want empty", stderr.String())
|
||||
@@ -29,10 +37,10 @@ func TestExecuteVersionReportsEmbeddedBuildVersion(t *testing.T) {
|
||||
|
||||
func TestExecuteVersionRejectsArguments(t *testing.T) {
|
||||
var stderr bytes.Buffer
|
||||
if code := Execute([]string{"version", "extra"}, io.Discard, &stderr); code == 0 {
|
||||
t.Fatal("Execute() code = 0, want failure")
|
||||
if code := executeForTest([]string{"version", "extra"}, io.Discard, &stderr); code != 2 {
|
||||
t.Fatalf("version argument status = %d, want 2", code)
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "version: unexpected arguments") {
|
||||
if !strings.Contains(stderr.String(), "extra") {
|
||||
t.Fatalf("stderr = %q, want argument error", stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func TestAssetBuilderBuildsNamedAssetsAndChecksEmbeddedVersion(t *testing.T) {
|
||||
if !slicesEqual(got, want) {
|
||||
t.Fatalf("asset names = %#v, want %#v", got, want)
|
||||
}
|
||||
version := exec.Command(filepath.Join(outputDir, "narratio-v0.0.0-test-linux-amd64"), "version")
|
||||
version := exec.Command(filepath.Join(outputDir, "narratio-v0.0.0-test-linux-amd64"), "version", "--format", "text")
|
||||
var versionOutput bytes.Buffer
|
||||
version.Stdout = &versionOutput
|
||||
if err := version.Run(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user