2026-11-10 17:12:28 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
commandkit "go.maximumdirect.net/commandkit"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestProcessUsesResolvedReportingMode(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
for name, contents := range map[string]string{
|
|
|
|
|
"config.yml": "version: 3\npipeline:\n stages: []\nreporting:\n enabled: false\n",
|
|
|
|
|
"transcript.json": `[{"speaker":"Alice","start":0,"end":1,"text":"hello"}]`,
|
|
|
|
|
"blocked": "file",
|
|
|
|
|
} {
|
|
|
|
|
if err := os.WriteFile(filepath.Join(dir, name), []byte(contents), 0644); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
app, err := buildApplication()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
|
name string
|
|
|
|
|
flags []string
|
|
|
|
|
status int
|
|
|
|
|
stdout bool
|
|
|
|
|
info bool
|
|
|
|
|
warning bool
|
|
|
|
|
}{
|
|
|
|
|
{"ordinary", nil, 0, true, false, false},
|
|
|
|
|
{"verbose", []string{"--verbose"}, 0, true, true, false},
|
|
|
|
|
{"quiet stdout", []string{"--quiet"}, 2, false, false, false},
|
|
|
|
|
{"quiet file", []string{"--quiet", "--output", filepath.Join(dir, "quiet.json")}, 0, false, false, false},
|
|
|
|
|
{"verbose after quiet", []string{"--quiet", "--verbose"}, 0, true, true, false},
|
|
|
|
|
{"quiet after verbose", []string{"--verbose", "--quiet", "--output", filepath.Join(dir, "ordered.json")}, 0, false, false, false},
|
|
|
|
|
{"debug disabled", []string{"--debug=false", "--work-dir", filepath.Join(dir, "blocked")}, 0, true, false, false},
|
|
|
|
|
{"debug failure", []string{"--debug", "--work-dir", filepath.Join(dir, "blocked")}, 0, true, true, true},
|
|
|
|
|
{"debug quiet", []string{"--debug", "--quiet", "--output", filepath.Join(dir, "debug-quiet.json"), "--work-dir", filepath.Join(dir, "blocked")}, 0, false, false, false},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
|
var out, stderr bytes.Buffer
|
|
|
|
|
args := []string{"process", "--config", filepath.Join(dir, "config.yml")}
|
|
|
|
|
args = append(args, tc.flags...)
|
|
|
|
|
args = append(args, filepath.Join(dir, "transcript.json"))
|
|
|
|
|
result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &stderr})
|
|
|
|
|
if result.Status != tc.status || (out.Len() > 0) != tc.stdout || strings.Contains(stderr.String(), "Completed:") != tc.info || strings.Contains(stderr.String(), "Debug artifact:") != tc.warning {
|
|
|
|
|
t.Fatalf("status=%d out=%q err=%q", result.Status, out.String(), stderr.String())
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-10 17:18:30 +00:00
|
|
|
|
|
|
|
|
func TestProcessCollectionFlags(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
for name, contents := range map[string]string{
|
|
|
|
|
"config.yml": "version: 3\npipeline:\n stages: []\nreporting:\n enabled: false\nglossary_collections:\n party: {entries: []}\n",
|
|
|
|
|
"transcript.json": `[{"speaker":"Alice","start":0,"end":1,"text":"hello"}]`,
|
|
|
|
|
} {
|
|
|
|
|
if err := os.WriteFile(filepath.Join(dir, name), []byte(contents), 0644); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
app, err := buildApplication()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
|
value string
|
|
|
|
|
status int
|
|
|
|
|
}{{`["party"]`, 0}, {`[]`, 0}, {`null`, 0}, {`[1]`, 2}, {`"party"`, 2}} {
|
|
|
|
|
var out, stderr bytes.Buffer
|
|
|
|
|
args := []string{"process", "--config", filepath.Join(dir, "config.yml"), "--glossaries", tc.value, filepath.Join(dir, "transcript.json")}
|
|
|
|
|
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &stderr})
|
|
|
|
|
if outcome.Status != tc.status {
|
|
|
|
|
t.Fatalf("value=%q status=%d out=%q err=%q", tc.value, outcome.Status, out.String(), stderr.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|