Run ordered processing with independent settings
This commit is contained in:
@@ -24,8 +24,8 @@ type LLMSummary struct {
|
||||
}
|
||||
|
||||
type BackendUtilization struct {
|
||||
Concurrency int `json:"concurrency"`
|
||||
QueueCapacity int `json:"queue_capacity"`
|
||||
Concurrency *int `json:"concurrency,omitempty"`
|
||||
QueueCapacity *int `json:"queue_capacity,omitempty"`
|
||||
LLMSummary
|
||||
CapacityWaitMS int64 `json:"capacity_wait_ms"`
|
||||
GenerationMS int64 `json:"generation_ms"`
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type GlossaryEntry struct {
|
||||
Name string `yaml:"name"`
|
||||
Aliases []string `yaml:"aliases,omitempty"`
|
||||
Plural string `yaml:"plural,omitempty"`
|
||||
Category string `yaml:"category"`
|
||||
Summary string `yaml:"summary"`
|
||||
}
|
||||
|
||||
type Glossary struct {
|
||||
Entries []GlossaryEntry `yaml:"glossary"`
|
||||
}
|
||||
|
||||
func ParseGlossaryYAML(raw []byte) (*Glossary, error) {
|
||||
var top map[string]any
|
||||
if err := yaml.Unmarshal(raw, &top); err != nil {
|
||||
return nil, &ParseError{Message: fmt.Sprintf("glossary is not valid YAML: %v", err)}
|
||||
}
|
||||
|
||||
var g Glossary
|
||||
if err := yaml.Unmarshal(raw, &g); err != nil {
|
||||
return nil, &ParseError{Message: fmt.Sprintf("failed to parse glossary: %v", err)}
|
||||
}
|
||||
|
||||
if err := validateGlossary(&g); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &g, nil
|
||||
}
|
||||
|
||||
func validateGlossary(g *Glossary) error {
|
||||
if len(g.Entries) == 0 {
|
||||
return &ValidationError{Field: "glossary", Message: "must contain at least one entry"}
|
||||
}
|
||||
|
||||
for i, e := range g.Entries {
|
||||
entryLabel := fmt.Sprintf("glossary[%d]", i)
|
||||
|
||||
if e.Name == "" {
|
||||
return &ValidationError{Field: fmt.Sprintf("%s.name", entryLabel), Message: "must not be empty"}
|
||||
}
|
||||
|
||||
if e.Category == "" {
|
||||
return &ValidationError{Field: fmt.Sprintf("%s.category", entryLabel), Message: "must not be empty"}
|
||||
}
|
||||
|
||||
if e.Summary == "" {
|
||||
return &ValidationError{Field: fmt.Sprintf("%s.summary", entryLabel), Message: "must not be empty"}
|
||||
}
|
||||
|
||||
for j, alias := range e.Aliases {
|
||||
if alias == "" {
|
||||
return &ValidationError{
|
||||
Field: fmt.Sprintf("%s.aliases[%d]", entryLabel, j),
|
||||
Message: "must not be empty",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if e.Plural != "" && len(e.Plural) == 0 {
|
||||
return &ValidationError{Field: fmt.Sprintf("%s.plural", entryLabel), Message: "must not be empty if present"}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseGlossaryYAML_Valid(t *testing.T) {
|
||||
raw, err := os.ReadFile("testdata/glossary_valid.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read test fixture: %v", err)
|
||||
}
|
||||
|
||||
glossary, err := ParseGlossaryYAML(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseGlossaryYAML failed: %v", err)
|
||||
}
|
||||
|
||||
if len(glossary.Entries) != 2 {
|
||||
t.Fatalf("expected 2 entries, got %d", len(glossary.Entries))
|
||||
}
|
||||
|
||||
e1 := glossary.Entries[0]
|
||||
if e1.Name != "Jesters" {
|
||||
t.Errorf("expected entries[0].name = Jesters, got %q", e1.Name)
|
||||
}
|
||||
if e1.Category != "faction" {
|
||||
t.Errorf("expected entries[0].category = faction, got %q", e1.Category)
|
||||
}
|
||||
if e1.Summary != "A faction name." {
|
||||
t.Errorf("expected entries[0].summary = A faction name., got %q", e1.Summary)
|
||||
}
|
||||
if len(e1.Aliases) != 0 {
|
||||
t.Errorf("expected entries[0].aliases = [], got %v", e1.Aliases)
|
||||
}
|
||||
|
||||
e2 := glossary.Entries[1]
|
||||
if e2.Name != "Popov" {
|
||||
t.Errorf("expected entries[1].name = Popov, got %q", e2.Name)
|
||||
}
|
||||
if len(e2.Aliases) != 1 || e2.Aliases[0] != "Hrank" {
|
||||
t.Errorf("expected entries[1].aliases = [Hrank], got %v", e2.Aliases)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseGlossaryYAML_MalformedYAML(t *testing.T) {
|
||||
raw, err := os.ReadFile("testdata/glossary_malformed.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read test fixture: %v", err)
|
||||
}
|
||||
|
||||
_, err = ParseGlossaryYAML(raw)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for malformed YAML, got nil")
|
||||
}
|
||||
|
||||
parseErr, ok := err.(*ParseError)
|
||||
if !ok {
|
||||
t.Errorf("expected *ParseError, got %T", err)
|
||||
} else if parseErr.Message == "" {
|
||||
t.Error("expected non-empty parse error message")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseGlossaryYAML_MissingRequiredFields(t *testing.T) {
|
||||
raw, err := os.ReadFile("testdata/glossary_missing_fields.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read test fixture: %v", err)
|
||||
}
|
||||
|
||||
_, err = ParseGlossaryYAML(raw)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for missing required fields, got nil")
|
||||
}
|
||||
|
||||
valErr, ok := err.(*ValidationError)
|
||||
if !ok {
|
||||
t.Errorf("expected *ValidationError, got %T", err)
|
||||
} else if valErr.Field == "" {
|
||||
t.Error("expected non-empty validation error field")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseGlossaryYAML_EmptyGlossary(t *testing.T) {
|
||||
raw := []byte(`glossary: []`)
|
||||
|
||||
_, err := ParseGlossaryYAML(raw)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for empty glossary, got nil")
|
||||
}
|
||||
|
||||
valErr, ok := err.(*ValidationError)
|
||||
if !ok {
|
||||
t.Errorf("expected *ValidationError, got %T", err)
|
||||
} else if valErr.Message != "must contain at least one entry" {
|
||||
t.Errorf("expected 'must contain at least one entry', got %q", valErr.Message)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseGlossaryYAML_EmptyName(t *testing.T) {
|
||||
raw := []byte(`
|
||||
glossary:
|
||||
- name: ""
|
||||
category: faction
|
||||
summary: A faction.
|
||||
`)
|
||||
|
||||
_, err := ParseGlossaryYAML(raw)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for empty name, got nil")
|
||||
}
|
||||
|
||||
valErr, ok := err.(*ValidationError)
|
||||
if !ok {
|
||||
t.Errorf("expected *ValidationError, got %T", err)
|
||||
} else if valErr.Message != "must not be empty" {
|
||||
t.Errorf("expected 'must not be empty', got %q", valErr.Message)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseGlossaryYAML_EmptyAlias(t *testing.T) {
|
||||
raw := []byte(`
|
||||
glossary:
|
||||
- name: Test
|
||||
aliases:
|
||||
- ""
|
||||
category: faction
|
||||
summary: A test entry.
|
||||
`)
|
||||
|
||||
_, err := ParseGlossaryYAML(raw)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for empty alias, got nil")
|
||||
}
|
||||
|
||||
valErr, ok := err.(*ValidationError)
|
||||
if !ok {
|
||||
t.Errorf("expected *ValidationError, got %T", err)
|
||||
} else if valErr.Message != "must not be empty" {
|
||||
t.Errorf("expected 'must not be empty', got %q", valErr.Message)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user