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:
@@ -57,12 +57,12 @@ func FromMerged(cfg config.Config, merged model.MergedTranscript) schema.Transcr
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultFromMerged converts the internal merged transcript model into the
|
||||
// compact default public serialized output contract.
|
||||
func DefaultFromMerged(cfg config.Config, merged model.MergedTranscript) schema.DefaultTranscript {
|
||||
segments := make([]schema.DefaultSegment, len(merged.Segments))
|
||||
// IntermediateFromMerged converts the internal merged transcript model into the
|
||||
// compact intermediate public serialized output contract.
|
||||
func IntermediateFromMerged(cfg config.Config, merged model.MergedTranscript) schema.IntermediateTranscript {
|
||||
segments := make([]schema.IntermediateSegment, len(merged.Segments))
|
||||
for index, segment := range merged.Segments {
|
||||
segments[index] = schema.DefaultSegment{
|
||||
segments[index] = schema.IntermediateSegment{
|
||||
ID: segment.ID,
|
||||
Start: segment.Start,
|
||||
End: segment.End,
|
||||
@@ -72,11 +72,11 @@ func DefaultFromMerged(cfg config.Config, merged model.MergedTranscript) schema.
|
||||
}
|
||||
}
|
||||
|
||||
return schema.DefaultTranscript{
|
||||
Metadata: schema.DefaultMetadata{
|
||||
return schema.IntermediateTranscript{
|
||||
Metadata: schema.IntermediateMetadata{
|
||||
Application: ApplicationName,
|
||||
Version: buildinfo.Version,
|
||||
OutputSchema: config.OutputSchemaDefault,
|
||||
OutputSchema: config.OutputSchemaIntermediate,
|
||||
},
|
||||
Segments: segments,
|
||||
}
|
||||
@@ -110,14 +110,14 @@ func MinimalFromMerged(cfg config.Config, merged model.MergedTranscript) schema.
|
||||
// runtime-selected public output contract.
|
||||
func SelectedFromMerged(cfg config.Config, merged model.MergedTranscript) any {
|
||||
switch cfg.OutputSchema {
|
||||
case config.OutputSchemaDefault:
|
||||
return DefaultFromMerged(cfg, merged)
|
||||
case config.OutputSchemaMinimal:
|
||||
return MinimalFromMerged(cfg, merged)
|
||||
case config.OutputSchemaSeriatim:
|
||||
case config.OutputSchemaFull:
|
||||
return FromMerged(cfg, merged)
|
||||
case config.OutputSchemaIntermediate:
|
||||
return IntermediateFromMerged(cfg, merged)
|
||||
default:
|
||||
return FromMerged(cfg, merged)
|
||||
return IntermediateFromMerged(cfg, merged)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,28 +23,28 @@ func TestFromMergedUsesBuildVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedFromMergedDefaultsToSeriatimTranscript(t *testing.T) {
|
||||
func TestSelectedFromMergedDefaultsToIntermediateTranscript(t *testing.T) {
|
||||
got := SelectedFromMerged(config.Config{}, model.MergedTranscript{})
|
||||
if _, ok := got.(schema.IntermediateTranscript); !ok {
|
||||
t.Fatalf("selected artifact type = %T, want schema.IntermediateTranscript", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedFromMergedUsesIntermediateWhenConfigured(t *testing.T) {
|
||||
got := SelectedFromMerged(config.Config{OutputSchema: config.OutputSchemaIntermediate}, model.MergedTranscript{})
|
||||
if _, ok := got.(schema.IntermediateTranscript); !ok {
|
||||
t.Fatalf("selected artifact type = %T, want schema.IntermediateTranscript", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedFromMergedUsesFullWhenConfigured(t *testing.T) {
|
||||
got := SelectedFromMerged(config.Config{OutputSchema: config.OutputSchemaFull}, model.MergedTranscript{})
|
||||
if _, ok := got.(schema.Transcript); !ok {
|
||||
t.Fatalf("selected artifact type = %T, want schema.Transcript", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedFromMergedUsesDefaultWhenConfigured(t *testing.T) {
|
||||
got := SelectedFromMerged(config.Config{OutputSchema: config.OutputSchemaDefault}, model.MergedTranscript{})
|
||||
if _, ok := got.(schema.DefaultTranscript); !ok {
|
||||
t.Fatalf("selected artifact type = %T, want schema.DefaultTranscript", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedFromMergedUsesSeriatimWhenConfigured(t *testing.T) {
|
||||
got := SelectedFromMerged(config.Config{OutputSchema: config.OutputSchemaSeriatim}, model.MergedTranscript{})
|
||||
if _, ok := got.(schema.Transcript); !ok {
|
||||
t.Fatalf("selected artifact type = %T, want schema.Transcript", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultFromMergedEmitsOnlyDefaultShape(t *testing.T) {
|
||||
func TestIntermediateFromMergedEmitsOnlyIntermediateShape(t *testing.T) {
|
||||
merged := model.MergedTranscript{
|
||||
Segments: []model.Segment{
|
||||
{
|
||||
@@ -65,19 +65,19 @@ func TestDefaultFromMergedEmitsOnlyDefaultShape(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
got := DefaultFromMerged(config.Config{OutputSchema: config.OutputSchemaDefault}, merged)
|
||||
want := schema.DefaultTranscript{
|
||||
Metadata: schema.DefaultMetadata{
|
||||
got := IntermediateFromMerged(config.Config{OutputSchema: config.OutputSchemaIntermediate}, merged)
|
||||
want := schema.IntermediateTranscript{
|
||||
Metadata: schema.IntermediateMetadata{
|
||||
Application: ApplicationName,
|
||||
Version: buildinfo.Version,
|
||||
OutputSchema: config.OutputSchemaDefault,
|
||||
OutputSchema: config.OutputSchemaIntermediate,
|
||||
},
|
||||
Segments: []schema.DefaultSegment{
|
||||
Segments: []schema.IntermediateSegment{
|
||||
{ID: 1, Start: 1, End: 2, Speaker: "Alice", Text: "hello", Categories: []string{"backchannel"}},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("default transcript = %#v, want %#v", got, want)
|
||||
t.Fatalf("intermediate transcript = %#v, want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ func (validateOutput) Process(ctx context.Context, in model.MergedTranscript, cf
|
||||
selected := artifact.SelectedFromMerged(cfg, in)
|
||||
var err error
|
||||
switch transcript := selected.(type) {
|
||||
case schema.DefaultTranscript:
|
||||
err = schema.ValidateDefaultTranscript(transcript)
|
||||
case schema.IntermediateTranscript:
|
||||
err = schema.ValidateIntermediateTranscript(transcript)
|
||||
case schema.MinimalTranscript:
|
||||
err = schema.ValidateMinimalTranscript(transcript)
|
||||
case schema.Transcript:
|
||||
|
||||
@@ -81,7 +81,7 @@ func TestValidateOutputUsesMinimalSchemaWhenConfigured(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateOutputUsesSeriatimSchemaWhenConfigured(t *testing.T) {
|
||||
func TestValidateOutputUsesFullSchemaWhenConfigured(t *testing.T) {
|
||||
merged := model.MergedTranscript{
|
||||
Segments: []model.Segment{
|
||||
{
|
||||
@@ -100,7 +100,7 @@ func TestValidateOutputUsesSeriatimSchemaWhenConfigured(t *testing.T) {
|
||||
}
|
||||
|
||||
cfg := testConfig()
|
||||
cfg.OutputSchema = config.OutputSchemaSeriatim
|
||||
cfg.OutputSchema = config.OutputSchemaFull
|
||||
got, events, err := validateOutput{}.Process(context.Background(), merged, cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("validate output: %v", err)
|
||||
|
||||
@@ -15,7 +15,12 @@ func newMergeCommand() *cobra.Command {
|
||||
Use: "merge",
|
||||
Short: "Run the transcript merge pipeline",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg, err := config.NewMergeConfig(opts)
|
||||
mergeOpts := opts
|
||||
if !cmd.Flags().Changed("output-schema") {
|
||||
mergeOpts.OutputSchema = ""
|
||||
}
|
||||
|
||||
cfg, err := config.NewMergeConfig(mergeOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -32,7 +37,7 @@ func newMergeCommand() *cobra.Command {
|
||||
flags.StringVar(&opts.AutocorrectFile, "autocorrect", "", "autocorrect rules file")
|
||||
flags.StringVar(&opts.InputReader, "input-reader", config.DefaultInputReader, "input reader module")
|
||||
flags.StringVar(&opts.OutputModules, "output-modules", config.DefaultOutputModules, "comma-separated output modules")
|
||||
flags.StringVar(&opts.OutputSchema, "output-schema", config.DefaultOutputSchema, "output JSON schema: default, minimal, or seriatim")
|
||||
flags.StringVar(&opts.OutputSchema, "output-schema", config.DefaultOutputSchema, "output JSON schema: seriatim-minimal, seriatim-intermediate (default), or seriatim-full")
|
||||
flags.StringVar(&opts.PreprocessingModules, "preprocessing-modules", config.DefaultPreprocessingModules, "comma-separated preprocessing modules")
|
||||
flags.StringVar(&opts.PostprocessingModules, "postprocessing-modules", config.DefaultPostprocessingModules, "comma-separated postprocessing modules")
|
||||
flags.StringVar(&opts.CoalesceGap, "coalesce-gap", config.DefaultCoalesceGapValue, "maximum same-speaker gap in seconds for coalesce")
|
||||
|
||||
@@ -114,7 +114,8 @@ func TestMergeWritesMergedOutputAndReport(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeWritesDefaultOutputSchema(t *testing.T) {
|
||||
func TestMergeWritesIntermediateOutputSchema(t *testing.T) {
|
||||
t.Setenv(config.OutputSchemaEnv, "")
|
||||
dir := t.TempDir()
|
||||
input := writeJSONFile(t, dir, "input.json", `{
|
||||
"segments": [
|
||||
@@ -131,10 +132,10 @@ func TestMergeWritesDefaultOutputSchema(t *testing.T) {
|
||||
t.Fatalf("merge failed: %v", err)
|
||||
}
|
||||
|
||||
var transcript schema.DefaultTranscript
|
||||
var transcript schema.IntermediateTranscript
|
||||
readJSON(t, output, &transcript)
|
||||
if transcript.Metadata.OutputSchema != config.OutputSchemaDefault {
|
||||
t.Fatalf("output_schema = %q, want default", transcript.Metadata.OutputSchema)
|
||||
if transcript.Metadata.OutputSchema != config.OutputSchemaIntermediate {
|
||||
t.Fatalf("output_schema = %q, want %q", transcript.Metadata.OutputSchema, config.OutputSchemaIntermediate)
|
||||
}
|
||||
if len(transcript.Segments) != 1 {
|
||||
t.Fatalf("segment count = %d, want 1", len(transcript.Segments))
|
||||
@@ -149,12 +150,12 @@ func TestMergeWritesDefaultOutputSchema(t *testing.T) {
|
||||
}
|
||||
for _, forbidden := range []string{"overlap_groups", "source", "derived_from", "words"} {
|
||||
if strings.Contains(string(outputBytes), forbidden) {
|
||||
t.Fatalf("default output contains %q:\n%s", forbidden, outputBytes)
|
||||
t.Fatalf("intermediate output contains %q:\n%s", forbidden, outputBytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeWritesSeriatimOutputSchema(t *testing.T) {
|
||||
func TestMergeWritesFullOutputSchema(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
input := writeJSONFile(t, dir, "input.json", `{
|
||||
"segments": [
|
||||
@@ -166,7 +167,7 @@ func TestMergeWritesSeriatimOutputSchema(t *testing.T) {
|
||||
err := executeMergeRaw(
|
||||
"--input-file", input,
|
||||
"--output-file", output,
|
||||
"--output-schema", "seriatim",
|
||||
"--output-schema", config.OutputSchemaFull,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("merge failed: %v", err)
|
||||
@@ -203,7 +204,7 @@ func TestMergeWritesMinimalOutputSchema(t *testing.T) {
|
||||
err := executeMerge(
|
||||
"--input-file", input,
|
||||
"--output-file", output,
|
||||
"--output-schema", "minimal",
|
||||
"--output-schema", config.OutputSchemaMinimal,
|
||||
"--report-file", reportPath,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -215,8 +216,8 @@ func TestMergeWritesMinimalOutputSchema(t *testing.T) {
|
||||
if transcript.Metadata.Application != "seriatim" {
|
||||
t.Fatalf("application = %q, want seriatim", transcript.Metadata.Application)
|
||||
}
|
||||
if transcript.Metadata.OutputSchema != "minimal" {
|
||||
t.Fatalf("output_schema = %q, want minimal", transcript.Metadata.OutputSchema)
|
||||
if transcript.Metadata.OutputSchema != config.OutputSchemaMinimal {
|
||||
t.Fatalf("output_schema = %q, want %q", transcript.Metadata.OutputSchema, config.OutputSchemaMinimal)
|
||||
}
|
||||
if got, want := len(transcript.Segments), 2; got != want {
|
||||
t.Fatalf("segment count = %d, want %d", got, want)
|
||||
@@ -330,7 +331,7 @@ func TestMergeValidateMinimalOutputBeforeAssignIDsFails(t *testing.T) {
|
||||
err := executeMerge(
|
||||
"--input-file", input,
|
||||
"--output-file", output,
|
||||
"--output-schema", "minimal",
|
||||
"--output-schema", config.OutputSchemaMinimal,
|
||||
"--postprocessing-modules", "validate-output,assign-ids",
|
||||
)
|
||||
if err == nil {
|
||||
@@ -472,16 +473,16 @@ func TestMergeResolvesOverlapGroupsWithWordRuns(t *testing.T) {
|
||||
|
||||
var transcript model.FinalTranscript
|
||||
readJSON(t, output, &transcript)
|
||||
if len(transcript.OverlapGroups) != 0 {
|
||||
t.Fatalf("overlap groups = %#v, want none", transcript.OverlapGroups)
|
||||
if got, want := len(transcript.OverlapGroups), 1; got != want {
|
||||
t.Fatalf("overlap group count = %d, want %d (%#v)", got, want, transcript.OverlapGroups)
|
||||
}
|
||||
if got, want := len(transcript.Segments), 3; got != want {
|
||||
if got, want := len(transcript.Segments), 2; got != want {
|
||||
t.Fatalf("segment count = %d, want %d", got, want)
|
||||
}
|
||||
|
||||
wantTexts := []string{"outside hello there", "bob reply", "later"}
|
||||
wantSpeakers := []string{"Alice", "Bob", "Alice"}
|
||||
wantRefs := []string{"word-run:1:1:1", "word-run:1:2:1", "word-run:1:1:2"}
|
||||
wantTexts := []string{"outside hello there later", "bob reply"}
|
||||
wantSpeakers := []string{"Alice", "Bob"}
|
||||
wantRefs := []string{"word-run:1:1:1", "word-run:1:2:1"}
|
||||
for index, segment := range transcript.Segments {
|
||||
if segment.ID != index+1 {
|
||||
t.Fatalf("segment %d id = %d, want %d", index, segment.ID, index+1)
|
||||
@@ -498,8 +499,8 @@ func TestMergeResolvesOverlapGroupsWithWordRuns(t *testing.T) {
|
||||
if segment.SourceSegmentIndex != nil {
|
||||
t.Fatalf("segment %d source_segment_index = %d, want nil", index, *segment.SourceSegmentIndex)
|
||||
}
|
||||
if segment.OverlapGroupID != 0 {
|
||||
t.Fatalf("segment %d overlap_group_id = %d, want 0", index, segment.OverlapGroupID)
|
||||
if segment.OverlapGroupID != 1 {
|
||||
t.Fatalf("segment %d overlap_group_id = %d, want 1", index, segment.OverlapGroupID)
|
||||
}
|
||||
}
|
||||
if !equalStrings(transcript.Segments[0].DerivedFrom, []string{inputA + "#0"}) {
|
||||
@@ -516,7 +517,7 @@ func TestMergeResolvesOverlapGroupsWithWordRuns(t *testing.T) {
|
||||
|
||||
var rpt report.Report
|
||||
readJSON(t, reportPath, &rpt)
|
||||
if !hasReportEvent(rpt, "postprocessing", "resolve-overlaps", "processed 1 overlap group(s); changed 1; removed 2 original segment(s); created 3 replacement segment(s)") {
|
||||
if !hasReportEvent(rpt, "postprocessing", "resolve-overlaps", "processed 1 overlap group(s); changed 1; removed 2 original segment(s); created 2 replacement segment(s)") {
|
||||
t.Fatal("expected resolve-overlaps summary report event")
|
||||
}
|
||||
}
|
||||
@@ -1927,7 +1928,7 @@ func TestMergeResolveOverlapsPreservesAbsorbedContextPrefix(t *testing.T) {
|
||||
"--input-file", inputA,
|
||||
"--input-file", inputB,
|
||||
"--speakers", speakers,
|
||||
"--output-schema", "minimal",
|
||||
"--output-schema", config.OutputSchemaMinimal,
|
||||
"--output-file", output,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -1994,7 +1995,7 @@ func executeMerge(args ...string) error {
|
||||
if !hasOutputSchemaFlag(args) {
|
||||
// Most integration tests were written against the full envelope; keep
|
||||
// that behavior unless the caller explicitly asks for another schema.
|
||||
args = append(args, "--output-schema", config.OutputSchemaSeriatim)
|
||||
args = append(args, "--output-schema", config.OutputSchemaFull)
|
||||
}
|
||||
return executeMergeRaw(args...)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -184,7 +184,7 @@ func nearestPriorMatch(segments []model.Segment, consumed []bool, index int) int
|
||||
if consumed[candidate] {
|
||||
continue
|
||||
}
|
||||
if sharesDerivedFrom(segments[index], segments[candidate]) {
|
||||
if segments[index].Speaker == segments[candidate].Speaker && sharesDerivedFrom(segments[index], segments[candidate]) {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ func nearestSubsequentMatch(segments []model.Segment, consumed []bool, index int
|
||||
if consumed[candidate] {
|
||||
continue
|
||||
}
|
||||
if sharesDerivedFrom(segments[index], segments[candidate]) {
|
||||
if segments[index].Speaker == segments[candidate].Speaker && sharesDerivedFrom(segments[index], segments[candidate]) {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,30 @@ func TestApplyUsesAnyDerivedFromIntersection(t *testing.T) {
|
||||
assertSegment(t, got.Segments[0], "resolve-danglers:1", "target end.", 1, 4, []string{"source#1", "source#2", "source#3"})
|
||||
}
|
||||
|
||||
func TestApplyDoesNotMergeDanglersAcrossSpeakersBackward(t *testing.T) {
|
||||
in := transcript(
|
||||
segment("a", "Alice", 1, 2, "target", []string{"source#1"}),
|
||||
segment("b", "Bob", 3, 4, "end.", []string{"source#1"}),
|
||||
)
|
||||
|
||||
got, summary := Apply(in)
|
||||
if summary.DanglersMerged != 0 || !reflect.DeepEqual(got, in) {
|
||||
t.Fatalf("unexpected merge:\ngot %#v\nwant %#v", got, in)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDoesNotMergeDanglersAcrossSpeakersForward(t *testing.T) {
|
||||
in := transcript(
|
||||
segment("a", "Alice", 1, 2, "start", []string{"source#1"}),
|
||||
segment("b", "Bob", 3, 4, "target", []string{"source#1"}),
|
||||
)
|
||||
|
||||
got, summary := Apply(in)
|
||||
if summary.DanglersMerged != 0 || !reflect.DeepEqual(got, in) {
|
||||
t.Fatalf("unexpected merge:\ngot %#v\nwant %#v", got, in)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDoesNotMergeWithoutSharedProvenance(t *testing.T) {
|
||||
in := transcript(
|
||||
segment("a", "Alice", 1, 2, "target", []string{"source#1"}),
|
||||
|
||||
Reference in New Issue
Block a user