Files
yidaima/RuoYi-Vue/docs/superpowers/plans/2026-06-18-business-blueprint-schema-repair.md

3.9 KiB

Business Blueprint Schema Repair 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 fixed prompt examples from generating invalid target-table condition fields and allow one schema-guided correction attempt.

Architecture: AiGenerateServiceImpl will build its example from the saved database schema and route both initial and corrected AI responses through one parse-normalize-validate helper. Strict validation remains the authority; correction is bounded to one extra model call.

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


Task 1: Add prompt and correction regression tests

Files:

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

  • Add a valid response fixture whose rule targets book_info with conditionFields: ["id"].

  • Add a test using mockSavedTablesWithGenericBookPrimaryKey() that captures the initial prompt and asserts the JSON example contains "conditionFields":["id"] and does not contain a book_info rule conditioned by book_id.

  • Add a test returning the invalid book_id response first and the valid id response second; assert two calls, a correction prompt containing the original validation error, and persisted id.

  • Add a test returning invalid responses twice; assert the strict error is propagated and the AI client is called exactly twice.

  • Run:

mvn -pl ruoyi-generator -Dtest=AiGenerateServiceImplTest test

Expected: the new tests fail because the prompt is fixed and there is no correction call.

Task 2: Generate a schema-valid example

Files:

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

  • Add a helper that selects the first saved table with columns.

  • Add a helper that selects that table's primary key, falling back to its first column.

  • Serialize a minimal action example using that table and field:

{"businessActions":[{"code":"example_workflow","name":"示例流程","ownerTable":"<table>","method":"POST","path":"/workflow/example","transaction":true,"requestFields":["<field>"],"rules":["目标记录必须存在"],"ruleChecks":[{"type":"EXISTS","targetTable":"<table>","conditionFields":["<field>"],"message":"目标记录不存在"}],"effects":[]}]}
  • Replace the fixed book_info.book_id example in buildBusinessBlueprintPrompt.
  • Run the targeted test and confirm the prompt test passes.

Task 3: Add one strict correction attempt

Files:

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

  • Extract a helper that parses, normalizes, and validates one AI response.

  • In generateBusinessBlueprint, call the helper for the first response.

  • Catch only ServiceException from that helper and build a correction prompt containing:

Correct the business blueprint JSON below.
Return JSON only.
Validation error: <message>
Use only the saved target-table columns listed below.
<saved schema>
Original response:
<response>
  • Call the AI client once more and run the corrected response through the same helper without another retry.
  • Persist and record only the final validated response.
  • Run the targeted test and confirm all correction tests pass.

Task 4: Verify the module

Files:

  • Verify only.

  • Run:

mvn -pl ruoyi-generator -Dtest=AiGenerateServiceImplTest,AiGenerationTaskWorkerTest,GenProjectServiceImplTest,QingTemplateSupportTest test
  • Run:
mvn -pl ruoyi-generator test
  • Inspect git diff for the implementation and tests, preserving all unrelated user changes.