Files
yidaima/RuoYi-Vue/docs/superpowers/plans/2026-06-18-business-effect-amount-prompt-fix.md

5.1 KiB

Business Effect Amount Prompt Fix Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: Prevent business blueprint generation from repeatedly producing invalid numeric effect amounts by documenting the safe numeric DSL in both generation and correction prompts.

Architecture: Keep validation and runtime behavior unchanged. Add one private prompt helper in AiGenerateServiceImpl and reuse it from both prompt builders so their numeric contracts cannot drift.

Tech Stack: Java 8, Spring Boot, JUnit 4, Mockito, Maven


Task 1: Lock the prompt contract with regression tests

Files:

  • Modify: ruoyi-generator/src/test/java/com/ruoyi/generator/service/front/AiGenerateServiceImplTest.java

  • Step 1: Extend the initial-prompt test

In generateBusinessBlueprintUsesSavedDatabaseAndPersistsActions, assert that the captured prompt includes the numeric DSL contract:

assertTrue(prompt.contains("INCREASE_NUMBER and DECREASE_NUMBER require"));
assertTrue(prompt.contains("numeric literal or ${param.saved_column}"));
assertTrue(prompt.contains("Do not use arithmetic expressions such as stock - 1"));
  • Step 2: Add an invalid-amount correction test

Add a test that returns an invalid blueprint first and a valid blueprint second, then checks the correction prompt:

@Test
public void generateBusinessBlueprintCorrectionPromptExplainsNumericAmountContract()
{
    when(frontProjectMapper.selectFrontProjectByUserAndId(7L, 10L)).thenReturn(project());
    mockSavedLibraryTables();
    when(deepSeekClient.chat(anyString())).thenReturn(
            businessBlueprintWithInvalidAmountResponse(),
            executableBusinessBlueprintResponse());

    service.generateBusinessBlueprint(7L, 10L, businessBlueprintRequest());

    ArgumentCaptor<String> promptCaptor = ArgumentCaptor.forClass(String.class);
    verify(deepSeekClient, times(2)).chat(promptCaptor.capture());
    String correctionPrompt = promptCaptor.getAllValues().get(1);
    assertTrue(correctionPrompt.contains("Business effect amount is invalid"));
    assertTrue(correctionPrompt.contains("INCREASE_NUMBER and DECREASE_NUMBER require"));
    assertTrue(correctionPrompt.contains("numeric literal or ${param.saved_column}"));
    assertTrue(correctionPrompt.contains("Do not use arithmetic expressions such as stock - 1"));
}

Add this fixture beside the other business-blueprint response helpers:

private String businessBlueprintWithInvalidAmountResponse()
{
    return executableBusinessBlueprintResponse().replace(
            "\"amount\": \"1\"", "\"amount\": \"stock - 1\"");
}
  • Step 3: Run the focused tests and verify RED

Run:

mvn -pl ruoyi-generator -Dtest=AiGenerateServiceImplTest test

Expected: the new prompt assertions fail because the numeric contract is absent.

Task 2: Reuse one numeric DSL constraint in both prompts

Files:

  • Modify: ruoyi-generator/src/main/java/com/ruoyi/generator/service/front/AiGenerateServiceImpl.java

  • Test: ruoyi-generator/src/test/java/com/ruoyi/generator/service/front/AiGenerateServiceImplTest.java

  • Step 1: Add the shared prompt helper

Add:

private void appendBusinessBlueprintNumericExpressionConstraints(StringBuilder prompt)
{
    prompt.append("INCREASE_NUMBER and DECREASE_NUMBER require targetTable, targetField, conditionFields, and a non-empty amount.\n");
    prompt.append("NUMBER_GTE.compareValue, effects.amount, and effects.minValue must be a numeric literal or ${param.saved_column}, where saved_column is a real saved database column. DECREASE_NUMBER.minValue may be omitted and defaults to 0.\n");
    prompt.append("Do not use arithmetic expressions such as stock - 1, SQL fragments, units, or descriptive text in numeric expression fields.\n");
}
  • Step 2: Call the helper from the initial prompt

Immediately after the supported effects and value requirements in buildBusinessBlueprintPrompt, call:

appendBusinessBlueprintNumericExpressionConstraints(prompt);
  • Step 3: Call the helper from the correction prompt

After appending the validation error in buildBusinessBlueprintCorrectionPrompt, call:

appendBusinessBlueprintNumericExpressionConstraints(prompt);
  • Step 4: Run the focused test suite and verify GREEN

Run:

mvn -pl ruoyi-generator -Dtest=AiGenerateServiceImplTest test

Expected: all AiGenerateServiceImplTest tests pass.

  • Step 5: Run the generator module regression suite

Run:

mvn -pl ruoyi-generator test

Expected: the module finishes with zero failures and zero errors.

  • Step 6: Inspect the final diff

Run:

git diff --check
git diff -- ruoyi-generator/src/main/java/com/ruoyi/generator/service/front/AiGenerateServiceImpl.java ruoyi-generator/src/test/java/com/ruoyi/generator/service/front/AiGenerateServiceImplTest.java

Expected: no whitespace errors and only the numeric prompt contract plus its regression tests are added.