F2-3:运行时动词闭包子指令机制 + staging 晋级(FULL_AUTO 507/HARD 74)
ScriptFacade:addFieldButton 扩第3参闭包(onClick 子指令数组)+ showConfirm 新动词,服务端急切求值闭包,子指令收进子缓冲,输出嵌套指令 JSON。 前端 scriptCommands.ts/registerReplayAction.ts:处理 addButton onClick/ confirmDialog onOk 嵌套重放,onClickActions/onOkActions 透传给 amis。 ScriptFacadeTest 补 7 个正反例(24/24 全绿)。 staging 晋级:FULL_AUTO 507(+10)/HARD 74(-12)/自动化率 82.7%, 双库各更新 801 条,e2e 30/30 全绿。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
179
docs/P1/F2-3脚本运行时报告.md
Normal file
179
docs/P1/F2-3脚本运行时报告.md
Normal file
@@ -0,0 +1,179 @@
|
||||
# F2-3 脚本运行时报告
|
||||
|
||||
生成时间:2026-06-11
|
||||
作者:P4 脚本迁移线
|
||||
|
||||
---
|
||||
|
||||
## 一、F2-1b 默认导入补全
|
||||
|
||||
### 问题根因
|
||||
|
||||
视图脚本执行路径(`ScriptExecuteController` → `com.dsasp.server.dataDic.binding.ScriptingEnginesManager`)使用裸 `GroovyScriptEngineFactory`,缺少服务端默认导入注入,导致:
|
||||
|
||||
- `GetServicesFunction.loadPOJO(...)` 报「No such property: GetServicesFunction」
|
||||
- `new DateTime[2]` 报「unable to resolve class DateTime」
|
||||
|
||||
服务流路径(`com.dsasp.server.core.service.script.ScriptingEnginesManager`)已正确使用 `SecureGroovyScriptEngineFactory`(含 DEFAULTIMPORTSLIST 8 条 + org.joda.time 星号导入)。
|
||||
|
||||
### 修法
|
||||
|
||||
`com.dsasp.server.dataDic.binding.ScriptingEnginesManager` 换用 `SecureGroovyScriptEngineFactory`。最小改动:删除 `GroovyScriptEngineFactory` 引入,添加 `SecureGroovyScriptEngineFactory` 引入,ArchUnit 保真层纪律不受影响。
|
||||
|
||||
### 默认导入串对照(SecureGroovyScriptEngineFactory.DEFAULTIMPORTSLIST)
|
||||
|
||||
| 类 | 来源 | 用途 |
|
||||
|---|---|---|
|
||||
| `com.dsasp.server.common.dataDic.bean.GeneralPOJO` | platform-legacy-core | 数据实体 |
|
||||
| `com.dsasp.server.common.dataDic.bean.CustomSearchConditional` | platform-legacy-core | 查询条件 |
|
||||
| `com.dsasp.server.common.dataDic.service.POJOCRUDService` | platform-legacy-core | CRUD 服务 |
|
||||
| `com.dsasp.server.common.util.StringUtil` | platform-legacy-core | 字符串工具 |
|
||||
| `com.dsasp.server.common.function.GetServicesFunction` | platform-legacy-core | 服务调用函数库 |
|
||||
| `com.dsasp.server.common.function.GetDefaultValueFunction` | platform-legacy-core | 默认值函数库 |
|
||||
| `com.dsasp.server.common.function.GetValueFunction` | platform-legacy-core | 字段取值函数库 |
|
||||
| `com.dsasp.client.viewframework.template.util.Console` | platform-legacy-core | 脚本调试日志 |
|
||||
|
||||
星号导入:`org.joda.time`(DateTime/DateTimeFormatter 等,joda-time 2.12.7 已在 legacy-core pom)
|
||||
|
||||
---
|
||||
|
||||
## 二、F2-3 嵌套指令协议
|
||||
|
||||
### 规格
|
||||
|
||||
改写器(tools/s3_rewriter F2-3 规则族)产出两个新动词形态,服务端 `ScriptFacade` 急切求值闭包,收集子指令入子缓冲,输出含嵌套数组的指令 JSON。
|
||||
|
||||
#### addFieldButton 四参形态
|
||||
|
||||
**脚本**:
|
||||
```groovy
|
||||
addFieldButton("FIELD", "文案", {
|
||||
// 闭包体动词
|
||||
setFieldVisible("X", true)
|
||||
showToast("完成")
|
||||
}, 1)
|
||||
```
|
||||
|
||||
**服务端输出**:
|
||||
```json
|
||||
{
|
||||
"actionType": "addButton",
|
||||
"componentId": "FIELD",
|
||||
"args": {
|
||||
"label": "文案",
|
||||
"index": 1,
|
||||
"onClick": [
|
||||
{ "actionType": "show", "componentId": "X" },
|
||||
{ "actionType": "toast", "args": { "msgType": "info", "msg": "完成" } }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### showConfirm 形态
|
||||
|
||||
**脚本**:
|
||||
```groovy
|
||||
showConfirm("确认操作?", {
|
||||
setFieldEnabled("BTN", false)
|
||||
})
|
||||
```
|
||||
|
||||
**服务端输出**:
|
||||
```json
|
||||
{
|
||||
"actionType": "confirmDialog",
|
||||
"args": {
|
||||
"msg": "确认操作?",
|
||||
"onOk": [
|
||||
{ "actionType": "disabled", "componentId": "BTN" }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 前端重放协议(registerReplayAction.ts)
|
||||
|
||||
- `addButton` + `onClick` 数组:翻译子指令为 amis 动作数组,挂 `args.onClickActions`,透传给 amis `addButton` 动作;amis 侧按钮点击后 runActions 重放。
|
||||
- `confirmDialog` + `onOk` 数组:翻译子指令为 amis 动作数组,挂 `args.onOkActions`,透传给 amis `confirmDialog` 动作;用户确认后 runActions 重放。
|
||||
- 无嵌套数组的 `addButton` 走常规路径(向后兼容旧三参形态)。
|
||||
|
||||
---
|
||||
|
||||
## 三、staging 晋级前后分布
|
||||
|
||||
| 标签 | 晋级前(基线) | 晋级后(staging) | 变化 |
|
||||
|------|--------------|-----------------|------|
|
||||
| FULL_AUTO | 497 | **507** | +10 |
|
||||
| PARTIAL | 30 | **32** | +2 |
|
||||
| HARD | 86 | **74** | -12 |
|
||||
| NO_S3 | 815 | 815 | 0 |
|
||||
| **自动化率** | **81.1%** | **82.7%** | **+1.6pp** |
|
||||
| 人工作业单 | 116 | **106** | -10 |
|
||||
| templates_with_scripts | 721 | 721 | 0 |
|
||||
|
||||
**双库核数**(load_page_schema.py):
|
||||
- `eip4dev.eip3`:更新 801 条,幂等跳过 688 条
|
||||
- `eip4m0.public`:更新 801 条,幂等跳过 688 条
|
||||
|
||||
**BatchConvertCli**:总量 1516,闸一通过 1489(98.2%),onEvent 钩子挂载 380 个模板
|
||||
|
||||
---
|
||||
|
||||
## 四、4 样本验证结果
|
||||
|
||||
| 样本 | templateId | seq | 脚本标签 | 结果 | 分类 |
|
||||
|------|-----------|-----|---------|------|------|
|
||||
| getConfigValue+page绑定 | 021e3ba7-e03a-412a-9f0e-c20ef440a885 | 2 | NO_S3 | `page` MissingProperty | **预期**:page 是 Vaadin 视图对象,服务端不绑定 |
|
||||
| GetServicesFunction.loadPOJO | 0670aaf9-a045-450d-9ebc-06f3ac36ca19 | 1 | NO_S3 | `PM_BIDRELATIONSHIP_ID` MissingProperty | **预期**:类名已解析,缺行数据 item 字段(无 ID 注入) |
|
||||
| new DateTime[2] | 087739c4-3dee-4bac-b031-772497addc6b | 1 | NO_S3 | **passed: True** | F2-1b 修复验证通过 |
|
||||
| GetValueFunction | 1cc15e59-460e-4949-8a2f-41ea39bad097 | 1 | FULL_AUTO | **passed: True** | F2-1b 修复验证通过 |
|
||||
|
||||
**补充类名解析验证**(/api/script/execute 直接测试):
|
||||
|
||||
| 验证项 | 结果 |
|
||||
|-------|------|
|
||||
| `GetServicesFunction.class.simpleName` → `"GetServicesFunction"` | passed: True |
|
||||
| `GetValueFunction.class.simpleName` → `"GetValueFunction"` | passed: True |
|
||||
| `new DateTime[2]; arr.length` → `2` | passed: True |
|
||||
|
||||
---
|
||||
|
||||
## 五、单测覆盖
|
||||
|
||||
### Java(ScriptFacadeTest,platform-metadata)
|
||||
|
||||
新增 7 个 F2-3 测试用例(总计 24,全绿):
|
||||
|
||||
| 用例 | 验证点 |
|
||||
|-----|-------|
|
||||
| `addFieldButton_withClosure_emitsOnClickSubCommands` | 闭包内动词产生 onClick 子指令数组(2 条) |
|
||||
| `addFieldButton_emptyClosure_emitsEmptyOnClick` | 空闭包产生空 onClick 数组(非 null) |
|
||||
| `addFieldButton_nullHandler_noOnClick` | null handler 不含 onClick 字段(向后兼容) |
|
||||
| `showConfirm_withClosure_emitsOnOkSubCommands` | 闭包内动词产生 onOk 子指令数组(2 条) |
|
||||
| `showConfirm_emptyClosure_emitsEmptyOnOk` | 空闭包产生空 onOk 数组 |
|
||||
| `showConfirm_nullHandler_noOnOk` | null handler 不含 onOk 字段 |
|
||||
| `addFieldButton_nestedClosure_closureBodyExceptionStillReturnsPartialSubCommands` | 闭包内异常前已产生的子指令仍收集(容错) |
|
||||
|
||||
### TypeScript(vitest,eip4-web)
|
||||
|
||||
新增 7 个单测用例(总计 23,全绿):
|
||||
|
||||
**scriptCommands.test.ts(+4)**:
|
||||
- addButton 无 onClick 时透传 args
|
||||
- addButton 含 onClick 子指令数组时原样透传 onClick
|
||||
- confirmDialog 含 onOk 子指令数组时原样透传 onOk
|
||||
- confirmDialog 空 onOk 不含 onOk 字段
|
||||
|
||||
**registerReplayAction.test.ts(+3)**:
|
||||
- addButton 含 onClick 时翻译并挂 onClickActions
|
||||
- confirmDialog 含 onOk 时翻译并挂 onOkActions
|
||||
- addButton 空 onClick 时不挂 onClickActions(直接派发)
|
||||
|
||||
---
|
||||
|
||||
## 六、e2e 验证
|
||||
|
||||
晋级后 `npx playwright test`:**30/30 全绿**(eip4-web)
|
||||
|
||||
8093 状态:RUNNING(PID 55015,Java 17,/tmp/eip4-8093.log)
|
||||
Reference in New Issue
Block a user