fix(page-schema): scope typed-recipe gate to AI drafts, not designer overlay saves
putOverlay hard-rejected (400) any overlay using components/actions outside the ~35-component AI recipe whitelist. Existing converted pages use 13 unregistered component types (search-box/dialog/mapping/tabs/each/tree-select/input-date-range/…) plus 6 onEvent action types that are structurally actionType-without-type (ACTION_WITHOUT_COMPONENT), so editing+saving virtually any existing list page in the designer returned 400. Split path: putOverlay (designer write path) now validates-and-warns instead of blocking; the strict typed gate stays on POST /api/page/schema/validate and the AI draft pipeline. Clears the only existing-page regression blocking the ai-agent merge to main. TDD: PageSchemaControllerTest#20 rewritten RED->GREEN; 37 schema tests green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -181,9 +181,17 @@ public class PageSchemaController {
|
||||
if (schemaJsonRaw == null || schemaJsonRaw.isBlank()) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "请求体不能为空");
|
||||
}
|
||||
// 分流(2026-06-19):typed-recipe 校验是 AI 草稿作用域,不是设计器作用域。
|
||||
// 人工设计器编辑存量转换页用 amis 全量组件(search-box/dialog/each/tabs/mapping 等)
|
||||
// 与 onEvent 动作(actionType 无 type),这些本是合法 amis,但不在 AI 的 ~35 组件
|
||||
// recipe 白名单内。若此处硬拒,几乎所有存量列表页一保存就 400(实测 13 类组件 +
|
||||
// 6 类 onEvent 动作会触雷)。故设计器写路径只观测告警、不阻断保存;严格 typed 闸
|
||||
// 保留在 /api/page/schema/validate 端点 + AI 草稿 pipeline 的 validateDraft 三闸。
|
||||
// 以后若把 AI 写路径收口到本端点,再按来源加 strict 分流参数。
|
||||
TypedPageSchemaReport validation = typedSchemaValidator.validate(schemaJsonRaw);
|
||||
if (!validation.valid()) {
|
||||
return ResponseEntity.badRequest().body(fail("typed schema 校验失败", validationData(validation)));
|
||||
log.warn("[F4-L1][putOverlay] typed-recipe 校验 {} 项告警(设计器路径不阻断)templateId={}: {}",
|
||||
validation.issues().size(), templateId, validation.issues());
|
||||
}
|
||||
|
||||
// 计算 overlay etag
|
||||
|
||||
@@ -7,7 +7,6 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -416,17 +415,29 @@ class PageSchemaControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("20. PUT overlay 先做 typed schema 校验,失败时不写库")
|
||||
void putOverlayRejectsUnsupportedComponentBeforeWrite() {
|
||||
@DisplayName("20. PUT overlay 分流:设计器编辑存量页(search-box 未注册组件 + onEvent 动作 actionType 无 type)放行保存,typed-recipe 校验只告警不阻断")
|
||||
void putOverlayAllowsLegacyComponentsAndOnEventActions() {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
// 查标准层 etag(base_etag)
|
||||
when(jdbc.queryForList(anyString(), eq(TID))).thenReturn(oneStdRow());
|
||||
// UPSERT 成功
|
||||
when(jdbc.update(anyString(), any(), any(), any(), any(), any(), any())).thenReturn(1);
|
||||
PageSchemaController c = new PageSchemaController(jdbc);
|
||||
setAdminSession();
|
||||
|
||||
var resp = c.putOverlay(TID, "{\"type\":\"page\",\"body\":{\"type\":\"evil-widget\"}}");
|
||||
// 存量转换页典型形态:search-box(不在 AI recipe 白名单)+ onEvent setValue 动作(actionType 无 type)
|
||||
String legacyPage = "{\"type\":\"page\",\"body\":{\"type\":\"crud\","
|
||||
+ "\"headerToolbar\":[{\"type\":\"button\",\"label\":\"查询\","
|
||||
+ "\"onEvent\":{\"click\":{\"actions\":[{\"actionType\":\"setValue\"}]}}}],"
|
||||
+ "\"filter\":{\"type\":\"form\",\"body\":[{\"type\":\"search-box\"}]}}}";
|
||||
|
||||
assertEquals(HttpStatus.BAD_REQUEST, resp.getStatusCode());
|
||||
assertTrue(resp.getBody().toString().contains("UNSUPPORTED_COMPONENT"));
|
||||
verify(jdbc, never()).update(anyString(), any(), any(), any(), any(), any(), any());
|
||||
var resp = c.putOverlay(TID, legacyPage);
|
||||
|
||||
assertEquals(HttpStatus.OK, resp.getStatusCode(),
|
||||
"设计器编辑存量页应放行保存,不被 AI 作用域的 typed-recipe 白名单阻断");
|
||||
assertEquals(0, resp.getBody().get("status"));
|
||||
// 确实写了库
|
||||
verify(jdbc).update(anyString(), any(), any(), any(), any(), any(), any());
|
||||
clearSession();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user