Minor updates to overlap detection and segment coalescing logic
This commit is contained in:
@@ -206,6 +206,102 @@ func TestWordRunReorderWindowRejectsInvalidEnvOverride(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackchannelMaxDurationDefaultsTo2(t *testing.T) {
|
||||
t.Setenv(BackchannelMaxDurationEnv, "")
|
||||
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.BackchannelMaxDuration != DefaultBackchannelMaxDuration {
|
||||
t.Fatalf("backchannel max duration = %f, want %f", cfg.BackchannelMaxDuration, DefaultBackchannelMaxDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackchannelMaxDurationUsesValidEnvOverride(t *testing.T) {
|
||||
t.Setenv(BackchannelMaxDurationEnv, "1.5")
|
||||
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.BackchannelMaxDuration != 1.5 {
|
||||
t.Fatalf("backchannel max duration = %f, want 1.5", cfg.BackchannelMaxDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackchannelMaxDurationRejectsInvalidEnvOverride(t *testing.T) {
|
||||
assertPositiveFloatEnvValidation(t, BackchannelMaxDurationEnv)
|
||||
}
|
||||
|
||||
func TestFillerMaxDurationDefaultsTo125(t *testing.T) {
|
||||
t.Setenv(FillerMaxDurationEnv, "")
|
||||
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.FillerMaxDuration != DefaultFillerMaxDuration {
|
||||
t.Fatalf("filler max duration = %f, want %f", cfg.FillerMaxDuration, DefaultFillerMaxDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillerMaxDurationUsesValidEnvOverride(t *testing.T) {
|
||||
t.Setenv(FillerMaxDurationEnv, "1.75")
|
||||
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.FillerMaxDuration != 1.75 {
|
||||
t.Fatalf("filler max duration = %f, want 1.75", cfg.FillerMaxDuration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillerMaxDurationRejectsInvalidEnvOverride(t *testing.T) {
|
||||
assertPositiveFloatEnvValidation(t, FillerMaxDurationEnv)
|
||||
}
|
||||
|
||||
func TestCoalesceGapDefaultsTo3(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
input := writeTempFile(t, dir, "input.json")
|
||||
@@ -306,6 +402,44 @@ func TestCoalesceGapRejectsInvalidOverride(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func assertPositiveFloatEnvValidation(t *testing.T, envName string) {
|
||||
t.Helper()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
value string
|
||||
want string
|
||||
}{
|
||||
{name: "non-numeric", value: "fast", want: "must be a positive number"},
|
||||
{name: "zero", value: "0", want: "must be positive"},
|
||||
{name: "negative", value: "-0.1", want: "must be positive"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Setenv(envName, test.value)
|
||||
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 error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), test.want) {
|
||||
t.Fatalf("expected error to contain %q, got %v", test.want, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func writeTempFile(t *testing.T, dir string, name string) string {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user