Compose native application commands and shared configuration scopes
This commit is contained in:
76
internal/cli/application_test.go
Normal file
76
internal/cli/application_test.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
func TestNativeApplicationBuiltinsNeedNoConfiguration(t *testing.T) {
|
||||
t.Parallel()
|
||||
app, err := NewApplication("v1.2.3", Options{LookupEnv: func(string) (string, bool) { t.Fatal("builtin attempted configuration discovery"); return "", false }})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, args := range [][]string{{"--help"}, {"help"}, {"version"}, {"completion", "bash"}, {"completion", "zsh"}, {"completion", "fish"}, {"config", "--help"}} {
|
||||
var out, diagnostics bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostics})
|
||||
if outcome.Status != 0 || out.Len() == 0 {
|
||||
t.Fatalf("%v: %#v, %s", args, outcome, diagnostics.String())
|
||||
}
|
||||
if args[0] == "version" && !strings.Contains(out.String(), "v1.2.3") {
|
||||
t.Fatalf("release identity missing: %s", out.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeConfigurationScopesAndDiffUseSelectedLoadEvidence(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
left, right := filepath.Join(dir, "left.yml"), filepath.Join(dir, "right.yml")
|
||||
writeConfigKitFile(t, left, "version: 6\nconcurrency: {workers: 1}\n")
|
||||
writeConfigKitFile(t, right, "version: 6\nconcurrency: {workers: 3}\n")
|
||||
app, err := NewApplication("development", Options{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
args []string
|
||||
status int
|
||||
fragment string
|
||||
}{
|
||||
{"application explanation", []string{"config", "explain", "--path", "/concurrency/workers", "--config", left}, 0, "workers"},
|
||||
{"focused settings", []string{"config", "show", "--scope", "promptkit", "--config", left, "--format", "json"}, 0, "notarius"},
|
||||
{"sources", []string{"config", "sources", "--config", left}, 0, "left.yml"},
|
||||
{"validation", []string{"config", "validate", "--scope", "all", "--config", left}, 0, ""},
|
||||
{"differences", []string{"config", "diff", "--config", left, "--against-config", right, "--check"}, 3, "workers"},
|
||||
{"identical", []string{"config", "diff", "--config", left, "--against-config", left, "--check"}, 0, ""},
|
||||
{"empty", []string{"config", "show", "--config", ""}, 2, ""},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var out, diagnostics bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), test.args, commandkit.Streams{Out: &out, Err: &diagnostics})
|
||||
if outcome.Status != test.status {
|
||||
t.Fatalf("outcome = %#v, output %s, diagnostics %s", outcome, out.String(), diagnostics.String())
|
||||
}
|
||||
if test.fragment != "" && !strings.Contains(out.String(), test.fragment) {
|
||||
t.Fatalf("missing %q: %s", test.fragment, out.String())
|
||||
}
|
||||
if test.name == "focused settings" {
|
||||
var report map[string]any
|
||||
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, found := report["pipelines"]; found {
|
||||
t.Fatal("focused PromptKit report exposed application-root value")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user