Simplify D&D scene chunking responses

This commit is contained in:
2026-07-24 00:35:10 +00:00
parent f08ca4ddfa
commit cacf3f24e7
7 changed files with 118 additions and 465 deletions

View File

@@ -35,7 +35,7 @@ func TestLoadResponseSchemaForScenes(t *testing.T) {
}
}
func TestResponseSchemaValidatesSceneResponses(t *testing.T) {
func TestResponseSchemaValidatesMinimalSceneResponses(t *testing.T) {
schema, err := loadResponseSchema()
if err != nil {
t.Fatalf("loadResponseSchema() error = %v, want nil", err)
@@ -55,11 +55,15 @@ func TestResponseSchemaValidatesSceneResponses(t *testing.T) {
mutate func(map[string]any)
}{
{
name: "obsolete segment boundaries",
name: "missing scenes",
mutate: func(response map[string]any) {
scene := response["scenes"].([]any)[0].(map[string]any)
scene["start_segment_id"] = 1
scene["end_segment_id"] = 2
delete(response, "scenes")
},
},
{
name: "empty scenes",
mutate: func(response map[string]any) {
response["scenes"] = []any{}
},
},
{
@@ -75,27 +79,21 @@ func TestResponseSchemaValidatesSceneResponses(t *testing.T) {
},
},
{
name: "invalid primary mode",
name: "non-integer endpoint",
mutate: func(response map[string]any) {
response["scenes"].([]any)[0].(map[string]any)["primary_mode"] = "Unknown"
response["scenes"].([]any)[0].(map[string]any)["start_unit_id"] = 1.5
},
},
{
name: "invalid boundary confidence",
name: "unknown top-level field",
mutate: func(response map[string]any) {
response["scenes"].([]any)[0].(map[string]any)["boundary_confidence"] = "Unknown"
response["boundary_caveats"] = []any{}
},
},
{
name: "empty boundary caveat",
name: "unknown scene field",
mutate: func(response map[string]any) {
response["boundary_caveats"] = []any{""}
},
},
{
name: "unknown property",
mutate: func(response map[string]any) {
response["unexpected"] = true
response["scenes"].([]any)[0].(map[string]any)["short_title"] = "Old contract"
},
},
}
@@ -116,21 +114,7 @@ func TestResponseSchemaValidatesSceneResponses(t *testing.T) {
}
func TestResponseStructAcceptsIntegerBoundaries(t *testing.T) {
raw := []byte(`{
"scenes": [
{
"start_unit_id": 1,
"end_unit_id": 3,
"short_title": "Ambush",
"primary_mode": "Combat",
"main_participants": ["Aria"],
"summary": "The party fights.",
"boundary_note": "Combat starts and resolves.",
"boundary_confidence": "High"
}
],
"boundary_caveats": []
}`)
raw := []byte(`{"scenes":[{"start_unit_id":1,"end_unit_id":3}]}`)
var response chunkResponse
if err := json.Unmarshal(raw, &response); err != nil {
@@ -159,7 +143,7 @@ func TestResponseSchemaJSONIsMutationSafe(t *testing.T) {
t.Fatalf("schema JSON was mutated: %s", second.JSONSchema)
}
if len(second.JSONSchema) > 0 && second.JSONSchema[0] == '[' {
t.Fatalf("schema JSON did not use defensive copy")
t.Fatal("schema JSON did not use defensive copy")
}
}
@@ -167,17 +151,10 @@ func validSceneSchemaResponse() map[string]any {
return map[string]any{
"scenes": []any{
map[string]any{
"start_unit_id": 1,
"end_unit_id": 3,
"short_title": "Ambush",
"primary_mode": "Combat",
"main_participants": []any{"Aria"},
"summary": "The party fights.",
"boundary_note": "Combat starts and resolves.",
"boundary_confidence": "High",
"start_unit_id": 1,
"end_unit_id": 3,
},
},
"boundary_caveats": []any{},
}
}