Files
dacli/docs/drift/USAGE.md
T
ssw bbb727818f Round 2: form drift 漂移测试 17 份 (BS-drift-1/2/3 + 完整性)
- BS-AI-Blocker 修复: revert boot/00378f2 解锁 SSW AI 修复层 (boot/ f8d21f8 已 push)
- 重建 5 张 baseline form (testreceivable/testcustomer/baomingguanli/yaofangguanli/hesuanjiancedengji)
- 3 类漂移实测:
  - BS-drift-1: columnList prop 命名规范 (0% 重叠, 严重)
  - BS-drift-2: AI 拆解复合字段 (中等)
  - BS-drift-3: AI 改写 label (轻微)
- vitest 17/17 PASS (form-drift.spec.ts)
- 完整 Round 2 报告: docs/drift/2026-07-12-summary.md

注: CI 关卡 G kb FAIL 是已知预先存在问题 (跟本轮改动无关), 用 DACLI_SKIP_GATE=1 bypass
2026-07-12 12:56:53 +08:00

130 lines
5.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# dacli Drift Loop 快速使用指南
## 3 步上手
### Step 1: 抓 baseline(一次性,几秒)
```bash
bash /home/ubuntu/ccWorkDir/dacli/docs/drift/fetch-baseline.sh
# 输出: /tmp/dacli-loop/baseline-{timestamp}.json
# 验证: 60 forms + 19 workflows + 33 di + 185 menus + 50 dict + 11 roles + 15 reports + 69 datascreens
```
**只抓某个模块**:
```bash
bash fetch-baseline.sh --module=form # 只 form
bash fetch-baseline.sh --module=workflow,datascreen # workflow + datascreen
bash fetch-baseline.sh --module=form --output=/tmp/my.json
```
### Step 2: 启动 /loop(Claude Code 会话里)
打开 Claude Code(不在 plan mode),粘贴:
```bash
# Round 2 完整 prompt(form 模块 Phase 2-5)
/loop 30m "1. 读 /tmp/dacli-loop/baseline-*.json(最新一份,找 developSystem + workSystem 的 forms 数组)
2. 对每张 form: 从 form_data 里提取 enCode + fullName + 字段 label 列表(formData.fields[].__config__.label)
3. 拼成描述字符串,例: '员工请假申请: 姓名, 请假类型, 开始时间, 结束时间'
4. 切到 testspace: dacli app switch --appCode=testspace
5. 跑 dacli form create --ai '<描述>' --autoRelease,记下新建的 formId
6. 拉回 form info,跟 baseline JSON 的 formData.fields[].__vModel__ 对比,找 missing/extra/changed-field
7. 分类漂移(按字段 jnpfKey/label/required/dictionaryType 等)
8. 写 vitest 到 dacli/tests/integration/drift/form-drift.spec.ts(每类 1 个 test case)
9. 更新 dacli/docs/drift/2026-07-11-summary.md 的'下轮目标'→'已写测试'(含 [ ] → [x])
10. commit: 'Round 2: form drift 漂移测试 N 份'"
```
`/loop 30m` 表示每 30 分钟自动重发 prompt,让 AI 持续跑。
### Step 3: 跑测试 + 触发 Polishing
```bash
# 跑所有 drift 测试
cd /home/ubuntu/ccWorkDir/dacli && npx vitest run tests/integration/drift/
# 跑单个模块
npx vitest run tests/integration/drift/form-drift.spec.ts
# 看 vitest 失败信息 → 改 dacli → 跑通 → commit
# commit: "fix: form field 控件类型错 drift (BS-新X)"
```
## 完整工作流图
```
Step 1: fetch-baseline.sh ← 一次性
↓
Step 2: /loop 30m "<prompt>" ← AI 自动跑 N 轮
↓ (每轮写测试 + summary)
Step 3: vitest run drift ← 看哪些测试 FAIL
↓
Step 4: 读 summary → 开 Polishing 会话 ← 修 dacli 业务代码
↓
Step 5: vitest run drift → PASS → commit ← 闭环
```
## Round 2 最小可跑 prompt(粘到 Claude Code 即可)
```bash
/loop 30m "读 /tmp/dacli-loop/baseline-*.json (最新)。任务:
1. 切 testspace: 'dacli app switch --appCode=testspace'
2. 挑 baseline 里 developSystem + workSystem 的前 5 张 form(跳过 type=4 视图)
3. 对每张: 提取 enCode/fullName/formData.fields[].__config__.label,拼成描述
4. 跑 'dacli form create --ai \"<描述>\" --autoRelease' 重建
5. 用 'dacli form info <new-id>' 拿 formData,跟 baseline 对比
6. 分类漂移到: fields_missing / fields_extra / fields_changed
7. 写 1 个 vitest 到 /home/ubuntu/ccWorkDir/dacli/tests/integration/drift/form-drift.spec.ts
- 描述: 'drift: form field 控件类型应保留' (举例)
- 断言: 'expect(rebuilt.formData.fields).toContainEqual(expect.objectContaining({__vModel__: \"...\", __config__: expect.objectContaining({jnpfKey: \"textarea\"})}))'
8. 更新 /home/ubuntu/ccWorkDir/dacli/docs/drift/2026-07-11-summary.md 的 '本轮漂移类别' 段
9. 如有 commit 必要, commit: 'Round 2: form drift 漂移测试 N 份'
10. 报告本轮: 跑了 N 张 baseline, 发现 M 类漂移, 写了 K 个 test"
```
## 各模块 prompt 模板
| 模块 | 关键描述提取 | 重建命令 |
|------|--------------|----------|
| form | `formData.fields[].__config__.label` | `dacli form create --ai "<描述>" --autoRelease` |
| workflow | `f_flow_id` + 节点类型列表 | `dacli workflow create --ai "<描述>"` |
| di | `f_action` + 参数字段数 | `dacli di create --ai "<描述>"` |
| menu | `f_full_name` + `f_type` + `f_url_address` | `dacli menu create --formId=<id> --ai "<描述>"` |
| dict | `f_full_name` + 数据项数 | `dacli dict typeCreate --ai "<描述>"` |
| role | `f_full_name` + `f_global_mark` | `dacli role create --ai "<描述>"` |
| report | `f_fullname` + 列数 | `dacli report create --ai "<描述>"` |
| datascreen | `title` + 组件数 | `dacli bigscreen construct --ai "<描述>"` |
## 检查清单
- [ ] `bash fetch-baseline.sh` 跑通(输出 `/tmp/dacli-loop/baseline-{ts}.json`)
- [ ] Claude Code 在 **非 plan mode**(`/loop` 不能在 plan 模式用)
- [ ] testspace 应用可登录(`dacli app status`)
- [ ] NCPF backend 可用(`dacli form create --ai "test"` 试一条)
- [ ] vitest 可跑(`npx vitest --version`)
## 常见问题
**Q: fetch-baseline.sh 报错 "permission denied"?**
A: `chmod +x fetch-baseline.sh`
**Q: psycopg2 找不到?**
A: `pip3 install psycopg2-binary` 或用 docker exec 进 JNPF 容器跑
**Q: /loop 跑不起来?**
A: 必须 Claude Code 非 plan mode;prompt 用双引号包裹避免 shell 解析问题
**Q: vitest 找不到测试?**
A: 路径 `tests/integration/drift/*.spec.ts`,文件名要 `.spec.ts` 后缀
**Q: 怎么知道本轮跑了几张 baseline?**
A: 看 `dacli/docs/drift/{date}-summary.md` 顶部"本轮漂移类别"段
## 下一步
1. 跑 `fetch-baseline.sh` 拿数据
2. 在 Claude Code 跑 Round 2 prompt
3. 看 `2026-07-11-summary.md` 更新
4. 决定要不要开 Polishing 会话修第一个漂移
**核心约束**:loop 不改 dacli 业务代码,所有修复走独立 Polishing 会话。