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) {
|
2026-11-25 17:31:38 +00:00
|
|
|
nativePromptFixture(t, "http://127.0.0.1:1/v1")
|
2026-11-25 17:38:26 +00:00
|
|
|
for _, command := range [][]string{deliveryArgs(), {"serve", "--config=app.yml"}, {"config", "show", "--config=app.yml"}, {"promptkit", "list", "prompts", "--config=app.yml"}} {
|
2026-11-20 04:26:17 +00:00
|
|
|
for _, flag := range []string{"--promptkit-source=missing.yml", "--schema-dir=schemas"} {
|
2026-11-25 17:38:26 +00:00
|
|
|
args := append(append([]string{}, command...), flag)
|
2026-11-20 04:26:17 +00:00
|
|
|
var output, diagnostics bytes.Buffer
|
|
|
|
|
outcome := Execute(context.Background(), commandkit.Identity{Name: "scriptorium"}, args, &output, &diagnostics)
|
2026-11-25 17:31:38 +00:00
|
|
|
flagName := strings.SplitN(flag, "=", 2)[0]
|
|
|
|
|
if outcome.Kind != commandkit.OutcomeUsage || outcome.Status != 2 || !strings.Contains(diagnostics.String(), flagName) {
|
|
|
|
|
t.Fatalf("%v: %+v diagnostics=%q", args, outcome, diagnostics.String())
|
2026-11-20 04:26:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|