Bugfixes and documentation cleanup for v1.0 release.
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
This commit is contained in:
@@ -13,22 +13,23 @@ import (
|
||||
const (
|
||||
DefaultInputReader = "json-files"
|
||||
DefaultOutputModules = "json"
|
||||
DefaultOutputSchema = OutputSchemaDefault
|
||||
DefaultOutputSchema = OutputSchemaIntermediate
|
||||
DefaultPreprocessingModules = "validate-raw,normalize-speakers,trim-text"
|
||||
DefaultPostprocessingModules = "detect-overlaps,resolve-overlaps,backchannel,filler,resolve-danglers,coalesce,detect-overlaps,autocorrect,assign-ids,validate-output"
|
||||
DefaultOverlapWordRunGap = 0.75
|
||||
DefaultOverlapWordRunGap = 1.0
|
||||
DefaultWordRunReorderWindow = 1.0
|
||||
DefaultCoalesceGap = 3.0
|
||||
DefaultCoalesceGapValue = "3.0"
|
||||
DefaultBackchannelMaxDuration = 2.0
|
||||
DefaultFillerMaxDuration = 1.25
|
||||
OutputSchemaEnv = "SERIATIM_OUTPUT_SCHEMA"
|
||||
OverlapWordRunGapEnv = "SERIATIM_OVERLAP_WORD_RUN_GAP"
|
||||
WordRunReorderWindowEnv = "SERIATIM_OVERLAP_WORD_RUN_REORDER_WINDOW"
|
||||
BackchannelMaxDurationEnv = "SERIATIM_BACKCHANNEL_MAX_DURATION"
|
||||
FillerMaxDurationEnv = "SERIATIM_FILLER_MAX_DURATION"
|
||||
OutputSchemaDefault = "default"
|
||||
OutputSchemaSeriatim = "seriatim"
|
||||
OutputSchemaMinimal = "minimal"
|
||||
OutputSchemaMinimal = "seriatim-minimal"
|
||||
OutputSchemaIntermediate = "seriatim-intermediate"
|
||||
OutputSchemaFull = "seriatim-full"
|
||||
)
|
||||
|
||||
// MergeOptions captures raw CLI option values before validation.
|
||||
@@ -70,7 +71,7 @@ func NewMergeConfig(opts MergeOptions) (Config, error) {
|
||||
cfg := Config{
|
||||
InputReader: strings.TrimSpace(opts.InputReader),
|
||||
OutputModules: nil,
|
||||
OutputSchema: strings.TrimSpace(opts.OutputSchema),
|
||||
OutputSchema: "",
|
||||
PreprocessingModules: nil,
|
||||
PostprocessingModules: nil,
|
||||
OverlapWordRunGap: DefaultOverlapWordRunGap,
|
||||
@@ -83,14 +84,12 @@ func NewMergeConfig(opts MergeOptions) (Config, error) {
|
||||
if cfg.InputReader == "" {
|
||||
return Config{}, errors.New("--input-reader is required")
|
||||
}
|
||||
if cfg.OutputSchema == "" {
|
||||
cfg.OutputSchema = DefaultOutputSchema
|
||||
}
|
||||
if err := validateOutputSchema(cfg.OutputSchema); err != nil {
|
||||
var err error
|
||||
cfg.OutputSchema, err = resolveOutputSchema(opts.OutputSchema)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
var err error
|
||||
cfg.OutputModules, err = parseModuleList(opts.OutputModules)
|
||||
if err != nil {
|
||||
return Config{}, fmt.Errorf("--output-modules: %w", err)
|
||||
@@ -189,13 +188,27 @@ func parseModuleList(value string) ([]string, error) {
|
||||
|
||||
func validateOutputSchema(value string) error {
|
||||
switch value {
|
||||
case OutputSchemaDefault, OutputSchemaSeriatim, OutputSchemaMinimal:
|
||||
case OutputSchemaMinimal, OutputSchemaIntermediate, OutputSchemaFull:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("--output-schema must be one of %q, %q, or %q", OutputSchemaDefault, OutputSchemaMinimal, OutputSchemaSeriatim)
|
||||
return fmt.Errorf("--output-schema must be one of %q, %q, or %q", OutputSchemaMinimal, OutputSchemaIntermediate, OutputSchemaFull)
|
||||
}
|
||||
}
|
||||
|
||||
func resolveOutputSchema(value string) (string, error) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
value = strings.TrimSpace(os.Getenv(OutputSchemaEnv))
|
||||
}
|
||||
if value == "" {
|
||||
value = DefaultOutputSchema
|
||||
}
|
||||
if err := validateOutputSchema(value); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func normalizeInputFiles(paths []string) ([]string, error) {
|
||||
if len(paths) == 0 {
|
||||
return nil, errors.New("at least one --input-file is required")
|
||||
|
||||
@@ -46,7 +46,8 @@ func TestDuplicateInputFilesFailValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputSchemaDefaultsToDefault(t *testing.T) {
|
||||
func TestOutputSchemaDefaultsToIntermediate(t *testing.T) {
|
||||
t.Setenv(OutputSchemaEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
@@ -67,7 +68,8 @@ func TestOutputSchemaDefaultsToDefault(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputSchemaAcceptsDefault(t *testing.T) {
|
||||
func TestOutputSchemaAcceptsIntermediate(t *testing.T) {
|
||||
t.Setenv(OutputSchemaEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
@@ -77,19 +79,20 @@ func TestOutputSchemaAcceptsDefault(t *testing.T) {
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
OutputSchema: OutputSchemaDefault,
|
||||
OutputSchema: OutputSchemaIntermediate,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("config failed: %v", err)
|
||||
}
|
||||
if cfg.OutputSchema != OutputSchemaDefault {
|
||||
t.Fatalf("output schema = %q, want %q", cfg.OutputSchema, OutputSchemaDefault)
|
||||
if cfg.OutputSchema != OutputSchemaIntermediate {
|
||||
t.Fatalf("output schema = %q, want %q", cfg.OutputSchema, OutputSchemaIntermediate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputSchemaAcceptsMinimal(t *testing.T) {
|
||||
t.Setenv(OutputSchemaEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
@@ -111,7 +114,8 @@ func TestOutputSchemaAcceptsMinimal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputSchemaAcceptsSeriatim(t *testing.T) {
|
||||
func TestOutputSchemaAcceptsFull(t *testing.T) {
|
||||
t.Setenv(OutputSchemaEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
@@ -121,19 +125,87 @@ func TestOutputSchemaAcceptsSeriatim(t *testing.T) {
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
OutputSchema: OutputSchemaSeriatim,
|
||||
OutputSchema: OutputSchemaFull,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("config failed: %v", err)
|
||||
}
|
||||
if cfg.OutputSchema != OutputSchemaSeriatim {
|
||||
t.Fatalf("output schema = %q, want %q", cfg.OutputSchema, OutputSchemaSeriatim)
|
||||
if cfg.OutputSchema != OutputSchemaFull {
|
||||
t.Fatalf("output schema = %q, want %q", cfg.OutputSchema, OutputSchemaFull)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputSchemaUsesEnvWhenFlagOmitted(t *testing.T) {
|
||||
t.Setenv(OutputSchemaEnv, OutputSchemaFull)
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
|
||||
cfg, err := NewMergeConfig(MergeOptions{
|
||||
InputFiles: []string{input},
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("config failed: %v", err)
|
||||
}
|
||||
if cfg.OutputSchema != OutputSchemaFull {
|
||||
t.Fatalf("output schema = %q, want %q", cfg.OutputSchema, OutputSchemaFull)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputSchemaFlagOverridesEnv(t *testing.T) {
|
||||
t.Setenv(OutputSchemaEnv, OutputSchemaFull)
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
|
||||
cfg, err := NewMergeConfig(MergeOptions{
|
||||
InputFiles: []string{input},
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
OutputSchema: OutputSchemaMinimal,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("config failed: %v", err)
|
||||
}
|
||||
if cfg.OutputSchema != OutputSchemaMinimal {
|
||||
t.Fatalf("output schema = %q, want %q", cfg.OutputSchema, OutputSchemaMinimal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputSchemaRejectsInvalidEnvValue(t *testing.T) {
|
||||
t.Setenv(OutputSchemaEnv, "compact")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
|
||||
_, err := NewMergeConfig(MergeOptions{
|
||||
InputFiles: []string{input},
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected output schema error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "--output-schema must be one of") {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputSchemaRejectsUnknownValue(t *testing.T) {
|
||||
t.Setenv(OutputSchemaEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
@@ -155,7 +227,36 @@ func TestOutputSchemaRejectsUnknownValue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverlapWordRunGapDefaultsTo075(t *testing.T) {
|
||||
func TestOutputSchemaRejectsLegacyValues(t *testing.T) {
|
||||
tests := []string{"default", "minimal", "seriatim"}
|
||||
|
||||
for _, legacy := range tests {
|
||||
t.Run(legacy, func(t *testing.T) {
|
||||
t.Setenv(OutputSchemaEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
output := filepath.Join(dir, "merged.json")
|
||||
|
||||
_, err := NewMergeConfig(MergeOptions{
|
||||
InputFiles: []string{input},
|
||||
OutputFile: output,
|
||||
InputReader: DefaultInputReader,
|
||||
OutputModules: DefaultOutputModules,
|
||||
OutputSchema: legacy,
|
||||
PreprocessingModules: DefaultPreprocessingModules,
|
||||
PostprocessingModules: DefaultPostprocessingModules,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected output schema error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "--output-schema must be one of") {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverlapWordRunGapDefaultsTo1(t *testing.T) {
|
||||
t.Setenv(OverlapWordRunGapEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
|
||||
Reference in New Issue
Block a user