1
0

M5 AP-002 JSON-Only-Erwartung in KI-Anfrage ergänzt und Tests geschärft

This commit is contained in:
2026-04-07 00:09:25 +02:00
parent cd5b6253df
commit 9ea6c3aaa5
2 changed files with 130 additions and 18 deletions

View File

@@ -192,4 +192,70 @@ class AiRequestComposerTest {
assertThat(result).contains("Prompt\nwith\nnewlines");
assertThat(result).contains("Document\ntext");
}
@Test
void buildCompleteRequestText_shouldIncludeJsonResponseFormat() {
// Given
PromptIdentifier promptId = new PromptIdentifier("prompt.txt");
String promptContent = "Analyze the document.";
String documentText = "Sample document content";
// When
String result = AiRequestComposer.buildCompleteRequestText(promptId, promptContent, documentText);
// Then
// Verify that the actual composed request includes JSON response format specification
assertThat(result).contains("Response Format (JSON-only)");
assertThat(result).contains("\"title\"");
assertThat(result).contains("\"reasoning\"");
assertThat(result).contains("\"date\"");
assertThat(result).contains("mandatory");
assertThat(result).contains("optional");
assertThat(result).contains("No text outside the JSON object");
}
@Test
void buildCompleteRequestText_shouldHaveDeterministicJsonFormatOrder() {
// Given
PromptIdentifier promptId = new PromptIdentifier("prompt.txt");
String promptContent = "Process this.";
String documentText = "Document to process";
// When
String result = AiRequestComposer.buildCompleteRequestText(promptId, promptContent, documentText);
// Then
// Verify deterministic order: document text comes before JSON response format
int documentTextIndex = result.indexOf(documentText);
int jsonFormatIndex = result.indexOf("Response Format (JSON-only)");
assertThat(documentTextIndex).isLessThan(jsonFormatIndex);
// Verify JSON field order: title before reasoning, reasoning before date
int titleIndex = result.indexOf("\"title\"");
int reasoningIndex = result.indexOf("\"reasoning\"");
int dateIndex = result.indexOf("\"date\"");
assertThat(titleIndex).isLessThan(reasoningIndex);
assertThat(reasoningIndex).isLessThan(dateIndex);
}
@Test
void buildCompleteRequestText_shouldProduceCompleteRequest_withAllSections() {
// Given
PromptIdentifier promptId = new PromptIdentifier("prompt_v3.txt");
String promptContent = "Classify the document.";
String documentText = "Content to classify";
// When
String result = AiRequestComposer.buildCompleteRequestText(promptId, promptContent, documentText);
// Then
// Verify all sections are present in the actual composed request
assertThat(result)
.contains("Classify the document.") // prompt
.contains("--- Prompt-ID: prompt_v3.txt ---") // identifier
.contains("--- Document Text ---") // document marker
.contains("Content to classify") // document text
.contains("--- Response Format (JSON-only) ---") // JSON format marker
.contains("Respond with a JSON object containing exactly:"); // JSON instruction
}
}