2026-10-04 00:45:23 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func writeRuntimeErrorConfig(t *testing.T, operatorDocument string) string {
|
|
|
|
|
t.Helper()
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
main := filepath.Join(dir, "config.yml")
|
2026-11-10 18:13:12 +00:00
|
|
|
for name, body := range map[string]string{"config.yml": "version: 3\n", "prompts.yml": operatorDocument} {
|
|
|
|
|
if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0600); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-10-04 00:45:23 +00:00
|
|
|
}
|
|
|
|
|
return main
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-10 18:13:12 +00:00
|
|
|
func TestResourceCommandsClassifyOperatorPromptErrorsAsInputErrors(t *testing.T) {
|
2026-10-04 00:45:23 +00:00
|
|
|
t.Setenv("AUDITA_TEST_PROVIDER_KEY", "synthetic-cli-redaction-secret")
|
|
|
|
|
definitions := map[string]string{
|
2026-11-10 18:13:12 +00:00
|
|
|
"malformed operator YAML": "profiles: [\n",
|
|
|
|
|
"invalid operator template": "collections:\n audita:\n prompts:\n - id: modules.grammar.proposal\n messages:\n - role: user\n content: '{{'\n output:\n format: text\n validation_mode: none\n",
|
|
|
|
|
"missing operator message resource": "collections:\n audita:\n prompts:\n - id: modules.grammar.proposal\n messages:\n - role: user\n content_file: missing-instruction.md\n output:\n format: text\n validation_mode: none\n",
|
|
|
|
|
}
|
|
|
|
|
for name, document := range definitions {
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
main := writeRuntimeErrorConfig(t, document)
|
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
|
|
if code := Run(context.Background(), []string{"promptkit", "list", "prompts", "--config", main}, &stdout, &stderr); code == 0 {
|
|
|
|
|
t.Fatalf("invalid resource accepted: stdout=%q stderr=%q", stdout.String(), stderr.String())
|
|
|
|
|
}
|
|
|
|
|
if strings.Contains(stderr.String(), "synthetic-cli-redaction-secret") {
|
|
|
|
|
t.Fatal("configured secret leaked")
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-10-04 00:45:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-10 18:13:12 +00:00
|
|
|
func TestResourceCommandKeepsCallerCancellationAsFailure(t *testing.T) {
|
|
|
|
|
main := writeRuntimeErrorConfig(t, "profiles:\n - id: proposal\n model: local-model\n")
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
cancel()
|
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
|
|
|
if code := Run(ctx, []string{"promptkit", "list", "prompts", "--config", main}, &stdout, &stderr); code == 0 {
|
|
|
|
|
t.Fatalf("cancellation succeeded: stdout=%q stderr=%q", stdout.String(), stderr.String())
|
2026-10-04 00:45:23 +00:00
|
|
|
}
|
|
|
|
|
}
|