From 332884f88742da3401d0fee83f38051b01c4dc0f Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sun, 24 May 2026 14:49:18 +0000 Subject: [PATCH] Centralize output schema names in schema package --- internal/config/config.go | 16 +++++++++------- internal/trim/artifact.go | 6 +++--- schema/output.go | 23 +++++++++++++++++++++++ schema/output_test.go | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 9152917..3e6cf7d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -8,6 +8,8 @@ import ( "sort" "strconv" "strings" + + "gitea.maximumdirect.net/eric/seriatim/schema" ) const ( @@ -27,9 +29,9 @@ const ( WordRunReorderWindowEnv = "SERIATIM_OVERLAP_WORD_RUN_REORDER_WINDOW" BackchannelMaxDurationEnv = "SERIATIM_BACKCHANNEL_MAX_DURATION" FillerMaxDurationEnv = "SERIATIM_FILLER_MAX_DURATION" - OutputSchemaMinimal = "seriatim-minimal" - OutputSchemaIntermediate = "seriatim-intermediate" - OutputSchemaFull = "seriatim-full" + OutputSchemaMinimal = schema.OutputSchemaMinimal + OutputSchemaIntermediate = schema.OutputSchemaIntermediate + OutputSchemaFull = schema.OutputSchemaFull ) // MergeOptions captures raw CLI option values before validation. @@ -332,12 +334,12 @@ func parseModuleList(value string) ([]string, error) { } func validateOutputSchema(value string) error { - switch value { - case OutputSchemaMinimal, OutputSchemaIntermediate, OutputSchemaFull: + if schema.ValidOutputSchemaName(value) { return nil - default: - return fmt.Errorf("--output-schema must be one of %q, %q, or %q", OutputSchemaMinimal, OutputSchemaIntermediate, OutputSchemaFull) } + + names := schema.OutputSchemaNames() + return fmt.Errorf("--output-schema must be one of %q, %q, or %q", names[0], names[1], names[2]) } func resolveOutputSchema(value string) (string, error) { diff --git a/internal/trim/artifact.go b/internal/trim/artifact.go index cfe1e0d..cc39290 100644 --- a/internal/trim/artifact.go +++ b/internal/trim/artifact.go @@ -8,9 +8,9 @@ import ( ) const ( - SchemaMinimal = "seriatim-minimal" - SchemaIntermediate = "seriatim-intermediate" - SchemaFull = "seriatim-full" + SchemaMinimal = schema.OutputSchemaMinimal + SchemaIntermediate = schema.OutputSchemaIntermediate + SchemaFull = schema.OutputSchemaFull ) // Artifact stores a parsed seriatim output artifact of one supported schema. diff --git a/schema/output.go b/schema/output.go index 8b30e66..2715d50 100644 --- a/schema/output.go +++ b/schema/output.go @@ -14,6 +14,10 @@ import ( var schemaFS embed.FS const ( + OutputSchemaMinimal = "seriatim-minimal" + OutputSchemaIntermediate = "seriatim-intermediate" + OutputSchemaFull = "seriatim-full" + fullOutputSchemaPath = "full-output.schema.json" intermediateOutputSchemaPath = "intermediate-output.schema.json" minimalOutputSchemaPath = "minimal-output.schema.json" @@ -115,6 +119,25 @@ type OverlapGroup struct { Resolution string `json:"resolution"` } +// ValidOutputSchemaName reports whether value is a supported output schema name. +func ValidOutputSchemaName(value string) bool { + switch value { + case OutputSchemaMinimal, OutputSchemaIntermediate, OutputSchemaFull: + return true + default: + return false + } +} + +// OutputSchemaNames returns supported output schema names in validation order. +func OutputSchemaNames() []string { + return []string{ + OutputSchemaMinimal, + OutputSchemaIntermediate, + OutputSchemaFull, + } +} + // ValidateTranscript validates a full transcript against the public JSON // schema and seriatim-specific semantic rules. func ValidateTranscript(transcript Transcript) error { diff --git a/schema/output_test.go b/schema/output_test.go index 9293456..27285e7 100644 --- a/schema/output_test.go +++ b/schema/output_test.go @@ -5,6 +5,43 @@ import ( "testing" ) +func TestValidOutputSchemaName(t *testing.T) { + valid := []string{ + OutputSchemaMinimal, + OutputSchemaIntermediate, + OutputSchemaFull, + } + for _, name := range valid { + if !ValidOutputSchemaName(name) { + t.Fatalf("expected %q to be valid", name) + } + } + + invalid := []string{"", "compact", "minimal", "seriatim"} + for _, name := range invalid { + if ValidOutputSchemaName(name) { + t.Fatalf("expected %q to be invalid", name) + } + } +} + +func TestOutputSchemaNames(t *testing.T) { + names := OutputSchemaNames() + want := []string{ + OutputSchemaMinimal, + OutputSchemaIntermediate, + OutputSchemaFull, + } + if len(names) != len(want) { + t.Fatalf("len(names) = %d, want %d", len(names), len(want)) + } + for index := range want { + if names[index] != want[index] { + t.Fatalf("names[%d] = %q, want %q", index, names[index], want[index]) + } + } +} + func TestValidateTranscriptAcceptsValidTranscript(t *testing.T) { transcript := validTranscript()