2026-11-20 03:35:49 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"go.maximumdirect.net/commandkit"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestNativeMetadataWithoutConfiguration(t *testing.T) {
|
|
|
|
|
t.Chdir(t.TempDir())
|
|
|
|
|
for _, args := range [][]string{
|
|
|
|
|
{"--help"}, {"version"}, {"run", "--help"}, {"serve", "--help"},
|
|
|
|
|
{"config", "scopes"}, {"config", "show", "--help"},
|
|
|
|
|
{"promptkit", "--help"}, {"promptkit", "list", "prompts", "--help"},
|
|
|
|
|
{"completion", "bash"}, {"completion", "zsh"}, {"completion", "fish"},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(strings.Join(args, " "), func(t *testing.T) {
|
|
|
|
|
var out, diagnostics bytes.Buffer
|
|
|
|
|
outcome := Execute(context.Background(), commandkit.Identity{Name: "scriptorium", Version: "test-version", Revision: "test-revision"}, args, &out, &diagnostics)
|
|
|
|
|
if outcome.Status != 0 || out.Len() == 0 {
|
|
|
|
|
t.Fatalf("outcome=%#v stdout=%q stderr=%q", outcome, out.String(), diagnostics.String())
|
|
|
|
|
}
|
|
|
|
|
if args[0] == "version" && !strings.Contains(out.String(), "test-version") {
|
|
|
|
|
t.Fatalf("version identity missing: %q", out.String())
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-20 04:26:17 +00:00
|
|
|
|
|
|
|
|
func TestRemovedSourceAndSchemaFlagsAreRejected(t *testing.T) {
|
|
|
|
|
for _, command := range [][]string{{"run"}, {"serve"}, {"config", "show"}, {"promptkit", "list", "prompts"}} {
|
|
|
|
|
for _, flag := range []string{"--promptkit-source=missing.yml", "--schema-dir=schemas"} {
|
|
|
|
|
args := append(append([]string{}, command...), flag)
|
|
|
|
|
var output, diagnostics bytes.Buffer
|
|
|
|
|
outcome := Execute(context.Background(), commandkit.Identity{Name: "scriptorium"}, args, &output, &diagnostics)
|
|
|
|
|
if outcome.Kind != commandkit.OutcomeUsage || outcome.Status != 2 {
|
|
|
|
|
t.Fatalf("%v: %+v", args, outcome)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|