@buaa_smat/hometrans 26.0.6 → 26.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/agents/a2h-executor.md +37 -0
- package/dist/cli/editors.json +13 -0
- package/dist/platform/compose.js +4 -0
- package/dist/platform/registry.js +3 -1
- package/dist/platform/transform.js +37 -3
- package/env-requirements.json +15 -1
- package/i18n/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
- package/i18n/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
- package/i18n/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
- package/i18n/skills/a2h-app-migrate/SKILL.md +2 -2
- package/i18n/skills/a2h-app-migrate/references/workflow.yaml +27 -4
- package/i18n/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
- package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
- package/i18n/skills/a2h-batch-ui-align/SKILL.md +7 -7
- package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
- package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
- package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
- package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
- package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
- package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
- package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
- package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
- package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
- package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
- package/i18n/skills/a2h-page-specgen/SKILL.md +1 -1
- package/i18n/skills/a2h-page-specgen/references/gates.md +3 -1
- package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +11 -11
- package/i18n/skills/a2h-page-specgen/references/spec-template.md +3 -3
- package/i18n/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
- package/i18n/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
- package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +144 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +132 -3
- package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
- package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
- package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
- package/i18n/skills/a2h-utg-static/SKILL.md +2 -0
- package/package.json +1 -1
- package/platforms/atomcode/agents/a2h-executor.frontmatter.md +6 -0
- package/platforms/codebuddy/agents/a2h-executor.frontmatter.md +5 -0
- package/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
- package/platforms/deveco/agents/a2h-executor.frontmatter.md +7 -0
- package/platforms/deveco/agents/build-fixer.frontmatter.md +0 -2
- package/platforms/deveco/agents/code-reviewer.frontmatter.md +0 -2
- package/platforms/deveco/agents/model-render-worker.frontmatter.md +0 -2
- package/platforms/deveco/agents/model-worker.frontmatter.md +0 -2
- package/platforms/deveco/agents/specgen-worker.frontmatter.md +0 -2
- package/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
- package/platforms/opencode/agents/a2h-executor.frontmatter.md +7 -0
- package/platforms/opencode/agents/build-fixer.frontmatter.md +0 -2
- package/platforms/opencode/agents/code-reviewer.frontmatter.md +0 -2
- package/platforms/opencode/agents/model-render-worker.frontmatter.md +0 -2
- package/platforms/opencode/agents/model-worker.frontmatter.md +0 -2
- package/platforms/opencode/agents/specgen-worker.frontmatter.md +0 -2
- package/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
- package/skills/a2h-app-migrate/SKILL.md +29 -3
- package/skills/a2h-app-migrate/references/host-rules.md +33 -0
- package/skills/a2h-app-migrate/references/workflow.yaml +24 -4
- package/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
- package/skills/a2h-app-migrate/test/test_executor_header_sync.mjs +78 -0
- package/skills/a2h-app-migrate/test/test_opencode_depth.mjs +312 -0
- package/skills/a2h-app-migrate/tools/dag.mjs +267 -0
- package/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
- package/skills/a2h-batch-ui-align/SKILL.md +7 -7
- package/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
- package/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
- package/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
- package/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
- package/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
- package/skills/a2h-batch-ui-align/references/host-dispatch.md +5 -5
- package/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
- package/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
- package/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
- package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
- package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
- package/skills/a2h-batch-ui-align/scripts/group_pass.mjs +3 -2
- package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +139 -23
- package/skills/a2h-batch-ui-align/scripts/host_env.mjs +32 -8
- package/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
- package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +82 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
- package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +184 -2
- package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +33 -0
- package/skills/a2h-batch-ui-align/scripts/tests/interactions.test.mjs +258 -0
- package/skills/a2h-page-specgen/SKILL.md +1 -1
- package/skills/a2h-page-specgen/references/evidence.md +15 -0
- package/skills/a2h-page-specgen/references/gates.md +3 -1
- package/skills/a2h-page-specgen/references/scenario-authoring.md +10 -10
- package/skills/a2h-page-specgen/references/spec-template.md +2 -2
- package/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
- package/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
- package/skills/a2h-page-specgen/scripts/gate.mjs +141 -0
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
- package/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
- package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +104 -3
- package/skills/a2h-resource-convert/references/conversion-rules.md +2 -0
- package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
- package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +42 -0
- package/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
- package/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
- package/skills/a2h-spec-design-pipeline/references/execution-model.md +2 -2
- package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +5 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +5 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +4 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +2 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +3 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-cn.md +105 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-en.md +122 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +4 -4
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIV2ObservationCheck.js +1862 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +2 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +1 -1
- package/skills/a2h-spec-design-pipeline/scripts/dispatch/wait.mjs +15 -2
- package/skills/a2h-spec-design-pipeline/scripts/dispatch.mjs +20 -4
- package/skills/a2h-spec-design-pipeline/scripts/test_arkui_v2_observation.ts +284 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_commands.mjs +32 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_wait.mjs +22 -1
- package/skills/a2h-utg-static/SKILL.md +2 -0
- package/skills/a2h-utg-static/references/extractors.md +16 -0
- package/skills/a2h-utg-static/scripts/run_pipeline.mjs +22 -1
- package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +4 -0
- package/skills/a2h-utg-static/scripts/tests/test_pr169_review_fixes.mjs +15 -0
- package/skills/a2h-utg-static/scripts/tests/test_view_attachments.mjs +330 -0
- package/skills/a2h-utg-static/scripts/view_attachments.mjs +465 -0
- package/platforms/codebuddy/agents/build-fixer.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/code-reviewer.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/model-render-worker.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/model-worker.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/specgen-worker.frontmatter.md +0 -5
|
@@ -187,18 +187,18 @@ lifecycle-signal 候选逐个复核后三选一:有用户可感知行为 →
|
|
|
187
187
|
|
|
188
188
|
时点措辞照源码:当场生效写“立即刷新”;下次可见才重读写“返回时重新读取”“下次进入时重新读取”,不得混用。轴场景的触发序列从对应时点事件写起,最后一步落在可断言的可观察结果上。
|
|
189
189
|
|
|
190
|
-
##
|
|
190
|
+
## 网络请求的请求参数与响应结构
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
场景涉及网络请求时,请求参数(`query` 与 `body`)写成**发起请求那一步里的一张树状字段表**;路径参数与请求头用 `in` 逐项列出;返回结果写到键一级。
|
|
193
193
|
|
|
194
194
|
表固定为四段,每段用自己的标签开头、顺序固定,写成顶格的围栏代码块,保证任何渲染器都保留换行:
|
|
195
195
|
|
|
196
196
|
```text
|
|
197
|
-
|
|
197
|
+
<请求参数名>
|
|
198
198
|
├─ 字段名:<路径> 类型/编码方式:<类型> 默认值:<缺省值> 是否传:<发送规则>
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
-
-
|
|
201
|
+
- **字段必须写全**:以源码构造请求(`query` 或 `body`)处的键为准逐个列出,包括**恒为默认值**、**始终发送**、**本页不发**的键;漏一个即失败,不得按场景挑字段写。**字段存在默认值不代表它一定会发送**,是否出现在报文里必须按源码的序列化或请求构造位置确认。
|
|
202
202
|
- `字段名:` 顶层写字段名;嵌套叶子写 `a.b`;数组元素写 `a[].b`;数组本身写 `a[]`(类型段写 `array<T>`)。父对象默认随子字段出现,只有父对象自身另有发送规则时才单列一行 `object`。
|
|
203
203
|
- `类型/编码方式:` 只用闭合词表 `string`、`int`、`int64`、`float`、`double`、`bool`、`object`、`array<T>`;时间格式、字节、进制等编码写进括号,如 `string(yyyy-MM-dd HH:mm)`、`string(Base64)`、`int(>=1)`。不写“文本”“数值”“布尔”这类散文泛称,并与契约 `type` 逐字一致。
|
|
204
204
|
- `默认值:` `—` 表示没有缺省值;字符串带引号;只写取值,不写是否发送。
|
|
@@ -206,22 +206,22 @@ lifecycle-signal 候选逐个复核后三选一:有用户可感知行为 →
|
|
|
206
206
|
- `必传`:键一定出现。源值缺失就算缺陷时到此为止;缺失时用缺省值补上时写“,缺失时取默认值”,需要点名来源或失败原因时写全,如“,读取不到时取默认值 unknown”;
|
|
207
207
|
- `非必传`:键不一定出现,必须紧跟一个可判定的条件,写成“,<条件>时不发送”或“,只在<条件>时发送”,例如“,无值时不发送”“,空数组时不发送”“,等于默认值 0 时不发送”“,来源无法判断时不发送”“,用户未指定插入位置时不发送”;
|
|
208
208
|
- `不传`:永不出现,字段只保留在数据模型里,序列化时跳过。
|
|
209
|
-
-
|
|
209
|
+
- 是否传以源码的序列化或请求构造位置为准:字段可空、有默认值、模型里标必填,都不等于线上必传;`"nullable": false` 也只说明值不能为空。**这些都不等价于 `必传`**——有默认值的字段可能等于默认值时被省略,也可能始终发送。
|
|
210
210
|
- 发送条件必须能直接写成一次判断:用“无值”“空数组”“等于默认值”“开关关闭”“未选中”“读取不到”“来源无法判断”这类具体条件,不写“按需”“视情况”“酌情”“一般”“可能”;一个字段有多个条件时逐个列出,不合并成“特殊情况除外”。
|
|
211
211
|
- `必传` 与 `非必传` 只差键是否一定出现;`默认值:` 只说值缺失时填什么,不说键出不出现,两段不要互相替代。布尔字段用 `false` 表示“用户没设置”时,`是否传:` 写“等于默认值 false 时不发送”,不写“无值时不发送”。
|
|
212
212
|
- 写条件时“无值”指未赋值或 `null`;字符串与数组另外把长度 0 算无值;`0` 与 `false` 算有值。
|
|
213
|
-
-
|
|
213
|
+
- 表前写一句可执行动作,不写“结构如下”这类说明句,例如:“请求参数按下列字段表逐字段序列化后发送,键顺序与表内行序一致,键是否出现按 `是否传:` 的条件执行。”
|
|
214
214
|
- 各段之间至少留一个空格:`字段名:` 后面的路径不能直接接下一段,免得路径与 `默认值:` 粘成 `file:line` 的样子;默认值写 `默认值:false`,不写 `默认值=false`;表里不写行首 `#`。
|
|
215
|
-
-
|
|
215
|
+
- 表根写业务名(如“同步请求体”“天气查询参数”),不写源码里的请求类型名。
|
|
216
216
|
- 字段的取值来源不是本页界面输入时(本地存储、上一次响应、固定值、计算值),在表后补一行逐字段写明,例如:“来源:`userId` 为本地存储的当前登录用户编号,`deviceId` 为本地存储的设备标识,`payload` 为本地待同步队列的条数。”界面输入的字段不必列。
|
|
217
217
|
|
|
218
|
-
**与契约的关系**:表里每个字段同时写进该场景的 `contracts.endpoints[].params`(`in` 为 `body`),两处逐字一致。契约是校验底稿,G2
|
|
218
|
+
**与契约的关系**:表里每个字段同时写进该场景的 `contracts.endpoints[].params`(`in` 为 `query` 或 `body`),两处逐字一致。契约是校验底稿,G2 逐个参数名、默认值与取值来源比对步骤文本,缺一个即失败;表是读者和下游实现看到的形态。路径参数和请求头同样用 `in` 标明归属并逐项列出(不强制表格);键名、默认值和固定值以源码为准,SPEC 未写明时读源码中构造请求与解析响应的位置补齐,不得猜测,也不得省略有默认值的键。
|
|
219
219
|
|
|
220
220
|
**响应**:`response_fields[]` 逐个列出字段路径(如 `current_temperature`、`hourly.temperatures[]`),只写字段名或路径;外层封装(如 code/data/message)、类型、可空性以及字段缺失或为缺省值时的处理写进该接口的 `note` 并合入步骤,不要塞进 `response_fields` 的元素里——G2 要求元素与步骤逐字一致。
|
|
221
221
|
|
|
222
222
|
**G2 逐字校验**方法、URL、参数名、参数默认值、取值来源和响应字段:契约里写了而步骤没出现会直接失败。外层封装、类型、可空性与缺失处理不在校验范围内,同样必须写进步骤,不能只留在 `contracts` 里。
|
|
223
223
|
|
|
224
|
-
同一个请求出现在多个场景时,每个场景各自写全表,不得写“同上”“见场景一”。发送条件只写在表的 `是否传:`
|
|
224
|
+
同一个请求出现在多个场景时,每个场景各自写全表,不得写“同上”“见场景一”。发送条件只写在表的 `是否传:` 段;步骤只写条件成立后的服务端行为或用户可见结果。请求体(或嵌套查询对象)为对象或数组时写清层级与每个子键,不得写“其他字段”“等”或只给一个示例值。
|
|
225
225
|
|
|
226
226
|
## 正文平台中立
|
|
227
227
|
|
|
@@ -315,7 +315,7 @@ SPEC 是供再实现的契约:无法落成代码或测试断言的表述都是
|
|
|
315
315
|
- 数值输入已写明整数还是小数、是否允许负数,没有用“只接受数字”代替类型;源码实现的小数位、上下限、空白与非法字符处理已逐项写明,未实现的约束没有写成已有行为。
|
|
316
316
|
- 每个数据边界都点名了在场侧(来源与落点)与缺席侧(不带、不写、不发的项,及为空/缺失/取默认时的走向);同一数据集合的多个入口逐项对齐,缺席项显式写出,没有写成 -1/0/空串这类占位值。
|
|
317
317
|
- 每条数据都答了「从哪来(含字段在消费代码里的出处)、怎么处理(含会改变结果的输入及变化后的差异)、用在哪」,缺一即不完整。
|
|
318
|
-
- 每个分支都写了判定依据与两个走向;每个步骤都能指到源码位置或 evidence
|
|
318
|
+
- 每个分支都写了判定依据与两个走向;每个步骤都能指到源码位置或 evidence 条目;是否传按源码序列化判定,没有用可空性(如 `"nullable": false`)、默认值或模型必填去推断。
|
|
319
319
|
- 涉及增删改查、状态同步或数据同步的场景,已逐项列出所有受影响的数据及其变化,没有“相关数据同步变化”之类的笼统表述。
|
|
320
320
|
- 涉及网络请求的场景已在发起请求的那一步写成字段表,每行的四段分别以 `字段名:`、`类型/编码方式:`、`默认值:`、`是否传:` 开头,并在 `contracts.endpoints[].params` 逐条声明同一批字段;非界面输入的取值来源已逐字段列出;每个字段的 `是否传:` 都以必传/非必传/不传开头并给出可判定的条件,没有按需/视情况这类含糊措辞;并写清返回结果的结构,且这些事实已在同一步里。
|
|
321
321
|
- 没有用“其他错误统一处理”之类的含糊措辞替代具体分支。
|
|
@@ -105,14 +105,14 @@ Percent encoding is **reversible** (`%` itself becomes `%25`, and the encoded re
|
|
|
105
105
|
|
|
106
106
|
| kind | Contents | Written into the steps as |
|
|
107
107
|
|---|---|---|
|
|
108
|
-
| `endpoints` | `operation_id` / `branch` / `state_version` (audit-only) / `name` / `method` / `url` / `params[]` (`in`∈`query`\|`path`\|`header`\|`body`, `name` / `type` / `required` / `default` / `source` / `note`) / `response_fields[]` / `timeouts[]` / `note` | The request step: method, complete URL, request headers and timeouts; the body as a field table whose rows carry four labels (`字段名:` / `类型/编码方式:` / `默认值:` / `是否传:`) plus a value-source line for fields not fed by this page's input; every response field. `operation_id`, `branch`, and `state_version` are not rendered |
|
|
108
|
+
| `endpoints` | `operation_id` / `branch` / `state_version` (audit-only) / `name` / `method` / `url` / `params[]` (`in`∈`query`\|`path`\|`header`\|`body`, `name` / `type` / `required` / `default` / `source` / `note`) / `response_fields[]` / `timeouts[]` / `note` | The request step: method, complete URL, request headers and timeouts; the query and body parameters as a field table whose rows carry four labels (`字段名:` / `类型/编码方式:` / `默认值:` / `是否传:`) plus a value-source line for fields not fed by this page's input; every response field. `operation_id`, `branch`, and `state_version` are not rendered |
|
|
109
109
|
| `stores` | `name` / `key` / `type` / `default` / `values[]` (strings or `{value, label}`) / `note` | The persistence step: key name, type, default, and every enum value — never "等" |
|
|
110
110
|
| `entities` | `name` / `fields[]` (`name` / `type` / `nullable` / `unit` / `note`) / `note` | The display or computation step: the entity's business name and every field with its type, nullability, and unit |
|
|
111
111
|
| `rules` | `name` / `statement` | The step that performs the conversion or applies the boundary: an instruction that can be followed verbatim, carrying every numeric value the rule can be wrong about (a coefficient, an offset, a threshold, an enum value) |
|
|
112
112
|
|
|
113
113
|
**Request and response keys are written key by key.** A parameter's default and value source belong in its `default` and `source` fields (`default: 0`, `source: 本地存储`) and are merged into the request step; a nested key keeps its path in `name` (`data.list[].id`); a non-required parameter also states in its `note` when it is absent from the wire (e.g. “equals its default, so the request body omits it”) or that it is always sent with its default (“always sent, uses the default value”), and the request step carries that rule too so the coder does not turn a default value into a sent key; `response_fields[]` lists one field path per string (`current_temperature`, `hourly.temperatures[]`), while the envelope (code/data/message), types, nullability and missing-value handling go into the entry's `note` and the step text. An endpoint or parameter field outside the lists above, or a non-string `response_fields[]` item, is rejected by G2 because the fact base cannot carry it.
|
|
114
114
|
|
|
115
|
-
**The request body
|
|
115
|
+
**The request parameters (query and body) are a field table inside the request step.** Every row carries four labelled segments in a fixed order — `field:`, `type/encoding:`, `default:`, `send:` — and the table is a top-level fenced block whose row order is the serialization key order. The send segment starts with `必传` (always present), `非必传` (may be absent) or `不传` (never present), followed by a decidable condition such as “,等于默认值 0 时不发送”; a plain `必传` means a missing source value is a defect, while “,缺失时取默认值” means the default fills it. A value-source line follows the table for every field not fed by this page's input. Each row must also be declared in `params[]` with the same `in` (`query` or `body`): the path goes after `字段名:` (`a.b` nested, `a[].b` for an array element), the type matches the table token verbatim, and the default/source hold the same values. A `params[]` entry missing from the table is reported by G2 as a missing field row. See `scenario-authoring.md`, “网络请求的请求参数与响应结构”, for the complete rule.
|
|
116
116
|
|
|
117
117
|
**The body language rules apply to the merged steps.** Contract-only syntax is no longer legal anywhere: no `dp`/`sp`/`px`/`dip` (with or without a number), no `#hex`, no `key=value` (write `字段 code 为 1001`), no framework type names, no `file:line`. Visual values are rewritten as business descriptions ("档位为大号"). Data values keep their source spelling (`maxRows`, `countryName`, `temperaturePrefs`, `kmh`) because the coder must use the same names. A value the body rules forbid verbatim (`600dp`, `#FF5733`, `timezone=auto`, a framework type) is therefore rewritten, and G2 does not require it token by token.
|
|
118
118
|
|
|
@@ -26,7 +26,7 @@ import path from "node:path";
|
|
|
26
26
|
import { canonicalSourcePath, stableDigest } from "./behavior-model.mjs";
|
|
27
27
|
import { stripJsComments, stripSourceComments } from "./lib/source-text.mjs";
|
|
28
28
|
|
|
29
|
-
export const CONTRACT_CALLS_SCHEMA_VERSION =
|
|
29
|
+
export const CONTRACT_CALLS_SCHEMA_VERSION = 3; // v3: `targets` is projected per (file, symbol); each target carries `target_symbols`.
|
|
30
30
|
export const DEFAULT_MAX_CONTRACT_TARGETS = 128;
|
|
31
31
|
const MAX_SOURCE_BYTES = 1_000_000;
|
|
32
32
|
|
|
@@ -277,7 +277,7 @@ function emptyResult(pageId) {
|
|
|
277
277
|
omitted: [],
|
|
278
278
|
source_contracts: sourceContracts,
|
|
279
279
|
counts: {
|
|
280
|
-
calls: 0, kept: 0, deferred: 0, not_contract: 0,
|
|
280
|
+
calls: 0, targets: 0, kept: 0, deferred: 0, not_contract: 0,
|
|
281
281
|
reviewed_scope: 0, contract_path: 0, omitted: 0,
|
|
282
282
|
},
|
|
283
283
|
};
|
|
@@ -373,6 +373,33 @@ function callSortKey(call) {
|
|
|
373
373
|
].join("\u0000");
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
+
/**
|
|
377
|
+
* One evidence record per (file, symbol). A service file often exposes several transport
|
|
378
|
+
* functions; the file-level target kept only the first symbol, so the projection expands it back.
|
|
379
|
+
*
|
|
380
|
+
* `kinds` and `signals` stay file-level summaries (the transport classification runs on the file);
|
|
381
|
+
* `call_sites` are narrowed to the symbol so each record still points at its own calls. A call site
|
|
382
|
+
* with a null `target_symbol` cannot be attributed to one symbol, so it is copied into every
|
|
383
|
+
* expanded record (the payload may show that site more than once).
|
|
384
|
+
*/
|
|
385
|
+
function expandTargetSymbols(targets) {
|
|
386
|
+
const out = [];
|
|
387
|
+
for (const target of targets) {
|
|
388
|
+
const symbols = Array.isArray(target.target_symbols) && target.target_symbols.length > 0
|
|
389
|
+
? [...new Set(target.target_symbols)]
|
|
390
|
+
: [target.target_symbol];
|
|
391
|
+
for (const symbol of symbols) {
|
|
392
|
+
out.push({
|
|
393
|
+
...target,
|
|
394
|
+
target_symbol: symbol,
|
|
395
|
+
call_sites: (target.call_sites ?? []).filter(site =>
|
|
396
|
+
site.target_symbol === undefined || site.target_symbol === null || site.target_symbol === symbol),
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return out;
|
|
401
|
+
}
|
|
402
|
+
|
|
376
403
|
/**
|
|
377
404
|
* Collect contract-only calls for one page.
|
|
378
405
|
*
|
|
@@ -573,6 +600,7 @@ export function collectContractCalls({
|
|
|
573
600
|
targets.set(target, {
|
|
574
601
|
locator: target,
|
|
575
602
|
target_symbol: targetSymbol,
|
|
603
|
+
target_symbols: [],
|
|
576
604
|
platform: classification.platform,
|
|
577
605
|
kinds: [...classification.kinds],
|
|
578
606
|
signals: [...classification.signals],
|
|
@@ -580,11 +608,15 @@ export function collectContractCalls({
|
|
|
580
608
|
});
|
|
581
609
|
}
|
|
582
610
|
const targetRecord = targets.get(target);
|
|
611
|
+
if (targetSymbol !== null && !targetRecord.target_symbols.includes(targetSymbol)) {
|
|
612
|
+
targetRecord.target_symbols.push(targetSymbol);
|
|
613
|
+
}
|
|
583
614
|
targetRecord.kinds = [...new Set([...targetRecord.kinds, ...classification.kinds])].sort(cmp);
|
|
584
615
|
targetRecord.signals = [...new Set([...targetRecord.signals, ...classification.signals])].sort(cmp);
|
|
585
616
|
targetRecord.call_sites.push({
|
|
586
617
|
from,
|
|
587
618
|
kind,
|
|
619
|
+
target_symbol: targetSymbol,
|
|
588
620
|
line: Number.isInteger(row.line) ? row.line : null,
|
|
589
621
|
col: Number.isInteger(row.col) ? row.col : null,
|
|
590
622
|
});
|
|
@@ -616,6 +648,7 @@ export function collectContractCalls({
|
|
|
616
648
|
for (const target of kept) {
|
|
617
649
|
dispose(target.locator, "kept", "contract-signal", {
|
|
618
650
|
target_symbol: target.target_symbol,
|
|
651
|
+
target_symbols: target.target_symbols,
|
|
619
652
|
kinds: target.kinds,
|
|
620
653
|
signals: target.signals,
|
|
621
654
|
});
|
|
@@ -623,6 +656,7 @@ export function collectContractCalls({
|
|
|
623
656
|
for (const target of omitted) {
|
|
624
657
|
dispose(target.locator, "omitted", "contract-evidence-limit", {
|
|
625
658
|
target_symbol: target.target_symbol,
|
|
659
|
+
target_symbols: target.target_symbols,
|
|
626
660
|
kinds: target.kinds,
|
|
627
661
|
signals: target.signals,
|
|
628
662
|
});
|
|
@@ -691,18 +725,21 @@ export function collectContractCalls({
|
|
|
691
725
|
const sourceContracts = extractSourceContracts(contracts);
|
|
692
726
|
|
|
693
727
|
const dispositionList = [...dispositions.values()].sort((a, b) => cmp(a.locator, b.locator));
|
|
728
|
+
const expandedKept = expandTargetSymbols(kept);
|
|
694
729
|
const payload = {
|
|
695
730
|
schema_version: CONTRACT_CALLS_SCHEMA_VERSION,
|
|
696
731
|
page_id: pageId,
|
|
697
732
|
calls: keptCalls,
|
|
698
|
-
targets:
|
|
733
|
+
targets: expandedKept,
|
|
699
734
|
dispositions: dispositionList,
|
|
700
735
|
deferred: deferredCalls,
|
|
701
736
|
omitted,
|
|
702
737
|
source_contracts: sourceContracts,
|
|
703
738
|
counts: {
|
|
704
739
|
calls: callCount,
|
|
740
|
+
// kept/omitted describe the file-level budget; targets counts the expanded (file, symbol) evidence.
|
|
705
741
|
kept: kept.length,
|
|
742
|
+
targets: expandedKept.length,
|
|
706
743
|
deferred: dispositionList.filter(item => item.disposition === "deferred").length,
|
|
707
744
|
not_contract: dispositionList.filter(item => item.disposition === "not-contract").length,
|
|
708
745
|
reviewed_scope: dispositionList.filter(item => item.disposition === "reviewed-scope").length,
|
|
@@ -832,6 +832,63 @@ function dbImplementations(db, targetPage, targetOrigin) {
|
|
|
832
832
|
return implementations;
|
|
833
833
|
}
|
|
834
834
|
|
|
835
|
+
/** File part of a `path:line` locator. */
|
|
836
|
+
function locatorFile(locator) {
|
|
837
|
+
const value = normalizeLocator(locator);
|
|
838
|
+
if (value === null) return null;
|
|
839
|
+
const match = /^(.*):\d+$/.exec(value);
|
|
840
|
+
return match === null ? value : match[1];
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/** The name part of a `kind:name` node id. */
|
|
844
|
+
function pageIdName(pageId) {
|
|
845
|
+
const value = firstString(pageId);
|
|
846
|
+
return value === null ? null : value.replace(/^[^:]*:/, "");
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Implementation identities recoverable from `declared_at` and the page-body source unit when the
|
|
851
|
+
* page/origin registers no `fqn` (e.g. UTG nodes for sheets/overlays carry only `declared_at`).
|
|
852
|
+
* The node is looked up by file + the origin/page label, so the same exact `qualified_name` +
|
|
853
|
+
* `file_path` contract as `explicitImplementations` still governs the match.
|
|
854
|
+
*/
|
|
855
|
+
function derivedImplementations({ targetPage, targetOrigin, db }) {
|
|
856
|
+
if (!db || typeof db.prepare !== "function") return [];
|
|
857
|
+
const pageBody = targetPage?.behavior && Array.isArray(targetPage.behavior.source_units)
|
|
858
|
+
? targetPage.behavior.source_units.filter(unit => unit?.role === "page-body").map(unit => unit?.locator)
|
|
859
|
+
: [];
|
|
860
|
+
const files = uniqueStrings([
|
|
861
|
+
locatorFile(targetOrigin?.declared_at),
|
|
862
|
+
locatorFile(targetPage?.declared_at),
|
|
863
|
+
...pageBody.map(locatorFile),
|
|
864
|
+
]);
|
|
865
|
+
const names = new Set(uniqueStrings([
|
|
866
|
+
targetOrigin?.label, targetPage?.label,
|
|
867
|
+
pageIdName(targetOrigin?.page_id), pageIdName(targetPage?.page_id),
|
|
868
|
+
]).map(name => String(name).trim()).filter(name => name !== ""));
|
|
869
|
+
if (files.length === 0 || names.size === 0) return [];
|
|
870
|
+
let statement;
|
|
871
|
+
try {
|
|
872
|
+
statement = db.prepare("SELECT name, qualified_name, file_path FROM nodes WHERE file_path = ?");
|
|
873
|
+
} catch {
|
|
874
|
+
return [];
|
|
875
|
+
}
|
|
876
|
+
const out = [];
|
|
877
|
+
for (const file of files) {
|
|
878
|
+
let rows = [];
|
|
879
|
+
try { rows = statement.all(file); } catch { continue; }
|
|
880
|
+
for (const row of rows) {
|
|
881
|
+
const name = firstString(row?.name);
|
|
882
|
+
const qualifiedName = firstString(row?.qualified_name);
|
|
883
|
+
const filePath = normalizeLocator(row?.file_path);
|
|
884
|
+
if (name !== null && names.has(name) && qualifiedName !== null && filePath !== null) {
|
|
885
|
+
out.push({ qualified_name: qualifiedName, file_path: filePath });
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
return out;
|
|
890
|
+
}
|
|
891
|
+
|
|
835
892
|
function readableCurrentSource(sourceProject, locator) {
|
|
836
893
|
if (typeof sourceProject !== "string" || sourceProject === "" || locator === null) return false;
|
|
837
894
|
try {
|
|
@@ -843,15 +900,15 @@ function readableCurrentSource(sourceProject, locator) {
|
|
|
843
900
|
}
|
|
844
901
|
|
|
845
902
|
/** Resolve only a qualified callee independently backed by the target implementation. */
|
|
846
|
-
function implementationMatch({ item, targetPage, targetOrigin, db, sourceProject }) {
|
|
903
|
+
function implementationMatch({ item, targetPage, targetOrigin, db, sourceProject, implementations = null }) {
|
|
847
904
|
if (dynamicDispatch(item)) return null;
|
|
848
905
|
const identity = calleeIdentity(item);
|
|
849
906
|
if (identity === null || !readableCurrentSource(sourceProject, identity.file_path)) return null;
|
|
850
|
-
const
|
|
907
|
+
const pool = implementations ?? [
|
|
851
908
|
...explicitImplementations(targetPage, targetOrigin),
|
|
852
909
|
...dbImplementations(db, targetPage, targetOrigin),
|
|
853
910
|
];
|
|
854
|
-
return
|
|
911
|
+
return pool.some(implementation =>
|
|
855
912
|
implementation.qualified_name === identity.qualified_name
|
|
856
913
|
&& implementation.file_path === identity.file_path)
|
|
857
914
|
? identity
|
|
@@ -896,9 +953,18 @@ function outboundFor({ pages, pageById, db, query, sourceProject }) {
|
|
|
896
953
|
const fromDb = dbCallees(db, edge);
|
|
897
954
|
const items = [...(fromQuery?.items ?? []), ...(fromDb?.items ?? [])];
|
|
898
955
|
const partial = [fromQuery, fromDb].find(result => result?.status === "partial") ?? null;
|
|
956
|
+
const implementations = [
|
|
957
|
+
...explicitImplementations(targetPage, targetOrigin),
|
|
958
|
+
...dbImplementations(db, targetPage, targetOrigin),
|
|
959
|
+
];
|
|
960
|
+
// The derived fallback exists only for origins that register no FQN. With an FQN present,
|
|
961
|
+
// a same-named node in the declared_at file must not weaken the exact identity check.
|
|
962
|
+
if (targetQualifiedNames(targetPage, targetOrigin).length === 0) {
|
|
963
|
+
implementations.push(...derivedImplementations({ targetPage, targetOrigin, db }));
|
|
964
|
+
}
|
|
899
965
|
const matches = items.map(item => ({
|
|
900
966
|
item,
|
|
901
|
-
implementation: implementationMatch({ item, targetPage, targetOrigin, db, sourceProject }),
|
|
967
|
+
implementation: implementationMatch({ item, targetPage, targetOrigin, db, sourceProject, implementations }),
|
|
902
968
|
}));
|
|
903
969
|
const validated = matches.find(match => match.implementation !== null) ?? null;
|
|
904
970
|
const dynamic = items.some(dynamicDispatch);
|
|
@@ -906,7 +972,9 @@ function outboundFor({ pages, pageById, db, query, sourceProject }) {
|
|
|
906
972
|
const status = resolved ? "resolved" : "partial";
|
|
907
973
|
const reason = status === "resolved" ? null
|
|
908
974
|
: partial?.reason ?? (items.length === 0 ? "outbound-callees-missing"
|
|
909
|
-
: dynamic && validated === null ? "outbound-dynamic-dispatch-unresolved"
|
|
975
|
+
: dynamic && validated === null ? "outbound-dynamic-dispatch-unresolved"
|
|
976
|
+
: implementations.length === 0 ? "outbound-implementation-unavailable"
|
|
977
|
+
: "outbound-target-unresolved");
|
|
910
978
|
const record = {
|
|
911
979
|
source: page.page_id,
|
|
912
980
|
target: edge.target,
|
|
@@ -107,6 +107,79 @@ function factPattern(token) {
|
|
|
107
107
|
return null;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
/** The field name of one field-table row, or "" when the line is not a row. */
|
|
111
|
+
function fieldTableRowName(line) {
|
|
112
|
+
const match = /字段名\s*[::]\s*([^\s ]+)/.exec(line);
|
|
113
|
+
return match === null ? "" : match[1];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const BODY_TABLE_LABELS = ["字段名:", "类型/编码方式:", "默认值:", "是否传:"];
|
|
117
|
+
// Accept both half-width and full-width colons, the same way row parsing does.
|
|
118
|
+
const BODY_TABLE_LABEL_RES = BODY_TABLE_LABELS.map(
|
|
119
|
+
(label) => new RegExp(`${escapeRe(label.slice(0, -1))}\\s*[::]`),
|
|
120
|
+
);
|
|
121
|
+
const BODY_TABLE_ROW_RE = /字段名\s*[::]/;
|
|
122
|
+
const BODY_TABLE_SEND_RE = /是否传\s*[::]/;
|
|
123
|
+
const BODY_SEND_VALUES = ["必传", "非必传", "不传"];
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Parameters that must appear in the four-label field table: `query` and `body`.
|
|
127
|
+
* A path/header-only endpoint stays prose (its values are positional or metadata, not selectable fields).
|
|
128
|
+
*
|
|
129
|
+
* @param {object|null|undefined} contracts
|
|
130
|
+
* @returns {object[]}
|
|
131
|
+
*/
|
|
132
|
+
function endpointTableParams(contracts) {
|
|
133
|
+
if (contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) return [];
|
|
134
|
+
const endpoints = Array.isArray(contracts.endpoints) ? contracts.endpoints : [];
|
|
135
|
+
const out = [];
|
|
136
|
+
for (const endpoint of endpoints) {
|
|
137
|
+
if (endpoint === null || typeof endpoint !== "object" || Array.isArray(endpoint)) continue;
|
|
138
|
+
const params = Array.isArray(endpoint.params) ? endpoint.params : [];
|
|
139
|
+
for (const param of params) {
|
|
140
|
+
if (param === null || typeof param !== "object" || Array.isArray(param)) continue;
|
|
141
|
+
if ((param.in === "query" || param.in === "body") && typeof param.name === "string" && param.name.trim() !== "") out.push(param);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A declared request (`query` / `body`) must be written as the four-label field table
|
|
149
|
+
* (`字段名:` / `类型/编码方式:` / `默认值:` / `是否传:`).
|
|
150
|
+
*
|
|
151
|
+
* Checked only for scenarios that declare at least one `in: "query"` or `in: "body"` parameter,
|
|
152
|
+
* so a path/header-only endpoint is never required to carry a table.
|
|
153
|
+
*
|
|
154
|
+
* @param {object|null|undefined} contracts
|
|
155
|
+
* @param {unknown} steps
|
|
156
|
+
* @returns {string[]} one entry per missing label, row, or send rule
|
|
157
|
+
*/
|
|
158
|
+
function missingFieldTable(contracts, steps) {
|
|
159
|
+
const params = endpointTableParams(contracts);
|
|
160
|
+
if (params.length === 0) return [];
|
|
161
|
+
const text = (Array.isArray(steps) ? steps : []).map((step) => String(step ?? "")).join("\n");
|
|
162
|
+
const missing = [];
|
|
163
|
+
for (let i = 0; i < BODY_TABLE_LABELS.length; i++) {
|
|
164
|
+
if (!BODY_TABLE_LABEL_RES[i].test(text)) missing.push(`缺少「${BODY_TABLE_LABELS[i]}」`);
|
|
165
|
+
}
|
|
166
|
+
if (missing.length > 0) return missing;
|
|
167
|
+
const rows = text.split(/\r?\n/).filter((line) => BODY_TABLE_ROW_RE.test(line) && BODY_TABLE_SEND_RE.test(line));
|
|
168
|
+
const rowNames = new Set(rows.map(fieldTableRowName).filter((name) => name !== ""));
|
|
169
|
+
for (const param of params) {
|
|
170
|
+
const name = param.name.trim();
|
|
171
|
+
if (!rowNames.has(name)) missing.push(`缺少字段行「${name}」`);
|
|
172
|
+
}
|
|
173
|
+
for (const line of rows) {
|
|
174
|
+
const name = fieldTableRowName(line);
|
|
175
|
+
const send = /是否传\s*[::]\s*([^\s ]+)/.exec(line);
|
|
176
|
+
if (send === null || !BODY_SEND_VALUES.some((value) => send[1].startsWith(value))) {
|
|
177
|
+
missing.push(`「${name === "" ? "?" : name}」的 是否传 未以 ${BODY_SEND_VALUES.join("/")} 开头`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return missing;
|
|
181
|
+
}
|
|
182
|
+
|
|
110
183
|
/**
|
|
111
184
|
* Fact tokens from a scenario's `contracts` that never made it into the merged steps.
|
|
112
185
|
*
|
|
@@ -129,6 +202,49 @@ function missingFactsInSteps(contracts, steps) {
|
|
|
129
202
|
.map((token) => `${token.kind}/${token.label}: ${token.value}`);
|
|
130
203
|
}
|
|
131
204
|
|
|
205
|
+
const BODY_REQUEST_VERB_RE = /\b(?:POST|PUT|PATCH)\b/i;
|
|
206
|
+
const BODY_REQUEST_URL_RE = /https?:\/\//i;
|
|
207
|
+
const BODY_REQUEST_LANGUAGE_RE = /(请求体|请求参数|\bbody\b|表单)/i;
|
|
208
|
+
const BODY_REQUEST_NO_BODY_RE = /(不携带[^。;;,,\n]{0,12}请求体|无请求体|不带请求体|没有请求体|不携带[^。;;,,\n]{0,12}请求参数|无请求参数|不带请求参数|没有请求参数)/;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Warnings for a body-shaped request described in steps without a declared body contract.
|
|
212
|
+
*
|
|
213
|
+
* The hard check (`missingFieldTable`) owns scenarios that declare `in: "query"`/`in: "body"`
|
|
214
|
+
* params. This warning targets the case where no body contract is projected at all (e.g. operations
|
|
215
|
+
* owned by `external`, which the ledger does not project): the steps still describe a request body
|
|
216
|
+
* (or carry a request-parameter field table) that no `contracts.endpoints[]` backs. Warn-only
|
|
217
|
+
* because prose detection is a heuristic; an explicit "不携带请求体" statement closes it.
|
|
218
|
+
*
|
|
219
|
+
* @param {object|null|undefined} contracts
|
|
220
|
+
* @param {unknown} steps
|
|
221
|
+
* @returns {string[]}
|
|
222
|
+
*/
|
|
223
|
+
function bodyRequestWarnings(contracts, steps) {
|
|
224
|
+
if (endpointTableParams(contracts).length > 0) return [];
|
|
225
|
+
const endpoints = contracts !== null && typeof contracts === "object" && !Array.isArray(contracts)
|
|
226
|
+
&& Array.isArray(contracts.endpoints) ? contracts.endpoints : [];
|
|
227
|
+
const hasEndpoints = endpoints.length > 0;
|
|
228
|
+
const out = [];
|
|
229
|
+
for (const raw of Array.isArray(steps) ? steps : []) {
|
|
230
|
+
const step = String(raw ?? "");
|
|
231
|
+
if (BODY_REQUEST_NO_BODY_RE.test(step)) continue;
|
|
232
|
+
const hasTable = step.split(/\r?\n/).some((line) => BODY_TABLE_ROW_RE.test(line) && BODY_TABLE_SEND_RE.test(line));
|
|
233
|
+
if (hasTable) {
|
|
234
|
+
out.push(hasEndpoints
|
|
235
|
+
? "步骤里有请求参数字段表,但 contracts.endpoints[].params 未声明对应的 query/body 参数"
|
|
236
|
+
: "步骤里有请求参数字段表,但未声明 scenarios[].contracts.endpoints");
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (BODY_REQUEST_VERB_RE.test(step) && BODY_REQUEST_URL_RE.test(step) && BODY_REQUEST_LANGUAGE_RE.test(step)) {
|
|
240
|
+
out.push(hasEndpoints
|
|
241
|
+
? "步骤描述了请求体,但 contracts.endpoints[].params 缺少对应的 body 参数"
|
|
242
|
+
: "步骤描述了请求体,但未声明 scenarios[].contracts.endpoints");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return Array.from(new Set(out));
|
|
246
|
+
}
|
|
247
|
+
|
|
132
248
|
/**
|
|
133
249
|
* Split deterministic renderer output into the scanned prose, the scenario headings, and any
|
|
134
250
|
* leftover contract headings.
|
|
@@ -421,6 +537,31 @@ function runGates(opts, { partial }) {
|
|
|
421
537
|
hint: "把每条事实自然写进消费它的步骤,保持既有步骤数量与顺序",
|
|
422
538
|
});
|
|
423
539
|
}
|
|
540
|
+
|
|
541
|
+
// A declared request (`query` / `body`) must be a four-label field table
|
|
542
|
+
// (spec-template.md). Only scenarios that declare those parameters are checked; a
|
|
543
|
+
// path/header-only endpoint is not required to carry a table.
|
|
544
|
+
const missingFieldTableIssues = missingFieldTable(scenarioDraft?.contracts, scenarioDraft?.steps);
|
|
545
|
+
if (missingFieldTableIssues.length > 0) {
|
|
546
|
+
failures.push({
|
|
547
|
+
gate: "G2",
|
|
548
|
+
spec_id,
|
|
549
|
+
message: `scenario ${scenarioNumber} 声明了查询/请求体参数,但步骤缺少四段字段表:${missingFieldTableIssues.join("、")}`,
|
|
550
|
+
hint: "查询参数与请求体都写成四段表(字段名:/类型/编码方式:/默认值:/是否传:),一行一个字段,是否传以 必传/非必传/不传 开头并带条件",
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// A body-shaped request described in steps without any body contract (e.g. an `external`
|
|
555
|
+
// operation that the ledger does not project) is a warning, not a failure: prose detection
|
|
556
|
+
// is a heuristic and "不携带请求体" closes it.
|
|
557
|
+
for (const alert of bodyRequestWarnings(scenarioDraft?.contracts, scenarioDraft?.steps)) {
|
|
558
|
+
warnings.push({
|
|
559
|
+
gate: "G2",
|
|
560
|
+
spec_id,
|
|
561
|
+
message: `scenario ${scenarioNumber}:${alert}`,
|
|
562
|
+
hint: "若该请求确实无 body,在步骤中写明「不携带请求体」;否则补 endpoint/body 参数,或说明未投影原因",
|
|
563
|
+
});
|
|
564
|
+
}
|
|
424
565
|
}
|
|
425
566
|
for (let i = draftScenarios.length; i < zones.scenarios.length; i++) {
|
|
426
567
|
failures.push({
|
package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md
CHANGED
|
@@ -283,18 +283,18 @@ lifecycle-signal 候选逐个复核后三选一:有用户可感知行为 →
|
|
|
283
283
|
|
|
284
284
|
时点措辞照源码:当场生效写“立即刷新”;下次可见才重读写“返回时重新读取”“下次进入时重新读取”,不得混用。轴场景的触发序列从对应时点事件写起,最后一步落在可断言的可观察结果上。
|
|
285
285
|
|
|
286
|
-
###
|
|
286
|
+
### 网络请求的请求参数与响应结构
|
|
287
287
|
|
|
288
|
-
|
|
288
|
+
场景涉及网络请求时,请求参数(`query` 与 `body`)写成**发起请求那一步里的一张树状字段表**;路径参数与请求头用 `in` 逐项列出;返回结果写到键一级。
|
|
289
289
|
|
|
290
290
|
表固定为四段,每段用自己的标签开头、顺序固定,写成顶格的围栏代码块,保证任何渲染器都保留换行:
|
|
291
291
|
|
|
292
292
|
```text
|
|
293
|
-
|
|
293
|
+
<请求参数名>
|
|
294
294
|
├─ 字段名:<路径> 类型/编码方式:<类型> 默认值:<缺省值> 是否传:<发送规则>
|
|
295
295
|
```
|
|
296
296
|
|
|
297
|
-
-
|
|
297
|
+
- **字段必须写全**:以源码构造请求(`query` 或 `body`)处的键为准逐个列出,包括**恒为默认值**、**始终发送**、**本页不发**的键;漏一个即失败,不得按场景挑字段写。**字段存在默认值不代表它一定会发送**,是否出现在报文里必须按源码的序列化或请求构造位置确认。
|
|
298
298
|
- `字段名:` 顶层写字段名;嵌套叶子写 `a.b`;数组元素写 `a[].b`;数组本身写 `a[]`(类型段写 `array<T>`)。父对象默认随子字段出现,只有父对象自身另有发送规则时才单列一行 `object`。
|
|
299
299
|
- `类型/编码方式:` 只用闭合词表 `string`、`int`、`int64`、`float`、`double`、`bool`、`object`、`array<T>`;时间格式、字节、进制等编码写进括号,如 `string(yyyy-MM-dd HH:mm)`、`string(Base64)`、`int(>=1)`。不写“文本”“数值”“布尔”这类散文泛称,并与契约 `type` 逐字一致。
|
|
300
300
|
- `默认值:` `—` 表示没有缺省值;字符串带引号;只写取值,不写是否发送。
|
|
@@ -302,22 +302,22 @@ lifecycle-signal 候选逐个复核后三选一:有用户可感知行为 →
|
|
|
302
302
|
- `必传`:键一定出现。源值缺失就算缺陷时到此为止;缺失时用缺省值补上时写“,缺失时取默认值”,需要点名来源或失败原因时写全,如“,读取不到时取默认值 unknown”;
|
|
303
303
|
- `非必传`:键不一定出现,必须紧跟一个可判定的条件,写成“,<条件>时不发送”或“,只在<条件>时发送”,例如“,无值时不发送”“,空数组时不发送”“,等于默认值 0 时不发送”“,来源无法判断时不发送”“,用户未指定插入位置时不发送”;
|
|
304
304
|
- `不传`:永不出现,字段只保留在数据模型里,序列化时跳过。
|
|
305
|
-
-
|
|
305
|
+
- 是否传以源码的序列化或请求构造位置为准:字段可空、有默认值、模型里标必填,都不等于线上必传;`"nullable": false` 也只说明值不能为空。**这些都不等价于 `必传`**——有默认值的字段可能等于默认值时被省略,也可能始终发送。
|
|
306
306
|
- 发送条件必须能直接写成一次判断:用“无值”“空数组”“等于默认值”“开关关闭”“未选中”“读取不到”“来源无法判断”这类具体条件,不写“按需”“视情况”“酌情”“一般”“可能”;一个字段有多个条件时逐个列出,不合并成“特殊情况除外”。
|
|
307
307
|
- `必传` 与 `非必传` 只差键是否一定出现;`默认值:` 只说值缺失时填什么,不说键出不出现,两段不要互相替代。布尔字段用 `false` 表示“用户没设置”时,`是否传:` 写“等于默认值 false 时不发送”,不写“无值时不发送”。
|
|
308
308
|
- 写条件时“无值”指未赋值或 `null`;字符串与数组另外把长度 0 算无值;`0` 与 `false` 算有值。
|
|
309
|
-
-
|
|
309
|
+
- 表前写一句可执行动作,不写“结构如下”这类说明句,例如:“请求参数按下列字段表逐字段序列化后发送,键顺序与表内行序一致,键是否出现按 `是否传:` 的条件执行。”
|
|
310
310
|
- 各段之间至少留一个空格:`字段名:` 后面的路径不能直接接下一段,免得路径与 `默认值:` 粘成 `file:line` 的样子;默认值写 `默认值:false`,不写 `默认值=false`;表里不写行首 `#`。
|
|
311
|
-
-
|
|
311
|
+
- 表根写业务名(如“同步请求体”“天气查询参数”),不写源码里的请求类型名。
|
|
312
312
|
- 字段的取值来源不是本页界面输入时(本地存储、上一次响应、固定值、计算值),在表后补一行逐字段写明,例如:“来源:`userId` 为本地存储的当前登录用户编号,`deviceId` 为本地存储的设备标识,`payload` 为本地待同步队列的条数。”界面输入的字段不必列。
|
|
313
313
|
|
|
314
|
-
**与契约的关系**:表里每个字段同时写进该场景的 `contracts.endpoints[].params`(`in` 为 `body`),两处逐字一致。契约是校验底稿,G2
|
|
314
|
+
**与契约的关系**:表里每个字段同时写进该场景的 `contracts.endpoints[].params`(`in` 为 `query` 或 `body`),两处逐字一致。契约是校验底稿,G2 逐个参数名、默认值与取值来源比对步骤文本,缺一个即失败;表是读者和下游实现看到的形态。路径参数和请求头同样用 `in` 标明归属并逐项列出(不强制表格);键名、默认值和固定值以源码为准,SPEC 未写明时读源码中构造请求与解析响应的位置补齐,不得猜测,也不得省略有默认值的键。
|
|
315
315
|
|
|
316
316
|
**响应**:`response_fields[]` 逐个列出字段路径(如 `current_temperature`、`hourly.temperatures[]`),只写字段名或路径;外层封装(如 code/data/message)、类型、可空性以及字段缺失或为缺省值时的处理写进该接口的 `note` 并合入步骤,不要塞进 `response_fields` 的元素里——G2 要求元素与步骤逐字一致。
|
|
317
317
|
|
|
318
318
|
**G2 逐字校验**方法、URL、参数名、参数默认值、取值来源和响应字段:契约里写了而步骤没出现会直接失败。外层封装、类型、可空性与缺失处理不在校验范围内,同样必须写进步骤,不能只留在 `contracts` 里。
|
|
319
319
|
|
|
320
|
-
同一个请求出现在多个场景时,每个场景各自写全表,不得写“同上”“见场景一”。发送条件只写在表的 `是否传:`
|
|
320
|
+
同一个请求出现在多个场景时,每个场景各自写全表,不得写“同上”“见场景一”。发送条件只写在表的 `是否传:` 段;步骤只写条件成立后的服务端行为或用户可见结果。请求体(或嵌套查询对象)为对象或数组时写清层级与每个子键,不得写“其他字段”“等”或只给一个示例值。
|
|
321
321
|
|
|
322
322
|
### 正文平台中立
|
|
323
323
|
|
|
@@ -411,7 +411,7 @@ SPEC 是供再实现的契约:无法落成代码或测试断言的表述都是
|
|
|
411
411
|
- 数值输入已写明整数还是小数、是否允许负数,没有用“只接受数字”代替类型;源码实现的小数位、上下限、空白与非法字符处理已逐项写明,未实现的约束没有写成已有行为。
|
|
412
412
|
- 每个数据边界都点名了在场侧(来源与落点)与缺席侧(不带、不写、不发的项,及为空/缺失/取默认时的走向);同一数据集合的多个入口逐项对齐,缺席项显式写出,没有写成 -1/0/空串这类占位值。
|
|
413
413
|
- 每条数据都答了「从哪来(含字段在消费代码里的出处)、怎么处理(含会改变结果的输入及变化后的差异)、用在哪」,缺一即不完整。
|
|
414
|
-
- 每个分支都写了判定依据与两个走向;每个步骤都能指到源码位置或 evidence
|
|
414
|
+
- 每个分支都写了判定依据与两个走向;每个步骤都能指到源码位置或 evidence 条目;是否传按源码序列化判定,没有用可空性(如 `"nullable": false`)、默认值或模型必填去推断。
|
|
415
415
|
- 涉及增删改查、状态同步或数据同步的场景,已逐项列出所有受影响的数据及其变化,没有“相关数据同步变化”之类的笼统表述。
|
|
416
416
|
- 涉及网络请求的场景已在发起请求的那一步写成字段表,每行的四段分别以 `字段名:`、`类型/编码方式:`、`默认值:`、`是否传:` 开头,并在 `contracts.endpoints[].params` 逐条声明同一批字段;非界面输入的取值来源已逐字段列出;每个字段的 `是否传:` 都以必传/非必传/不传开头并给出可判定的条件,没有按需/视情况这类含糊措辞;并写清返回结果的结构,且这些事实已在同一步里。
|
|
417
417
|
- 没有用“其他错误统一处理”之类的含糊措辞替代具体分支。
|
package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md
CHANGED
|
@@ -241,18 +241,18 @@ lifecycle-signal 候选逐个复核后三选一:有用户可感知行为 →
|
|
|
241
241
|
|
|
242
242
|
时点措辞照源码:当场生效写“立即刷新”;下次可见才重读写“返回时重新读取”“下次进入时重新读取”,不得混用。轴场景的触发序列从对应时点事件写起,最后一步落在可断言的可观察结果上。
|
|
243
243
|
|
|
244
|
-
###
|
|
244
|
+
### 网络请求的请求参数与响应结构
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
场景涉及网络请求时,请求参数(`query` 与 `body`)写成**发起请求那一步里的一张树状字段表**;路径参数与请求头用 `in` 逐项列出;返回结果写到键一级。
|
|
247
247
|
|
|
248
248
|
表固定为四段,每段用自己的标签开头、顺序固定,写成顶格的围栏代码块,保证任何渲染器都保留换行:
|
|
249
249
|
|
|
250
250
|
```text
|
|
251
|
-
|
|
251
|
+
<请求参数名>
|
|
252
252
|
├─ 字段名:<路径> 类型/编码方式:<类型> 默认值:<缺省值> 是否传:<发送规则>
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
-
-
|
|
255
|
+
- **字段必须写全**:以源码构造请求(`query` 或 `body`)处的键为准逐个列出,包括**恒为默认值**、**始终发送**、**本页不发**的键;漏一个即失败,不得按场景挑字段写。**字段存在默认值不代表它一定会发送**,是否出现在报文里必须按源码的序列化或请求构造位置确认。
|
|
256
256
|
- `字段名:` 顶层写字段名;嵌套叶子写 `a.b`;数组元素写 `a[].b`;数组本身写 `a[]`(类型段写 `array<T>`)。父对象默认随子字段出现,只有父对象自身另有发送规则时才单列一行 `object`。
|
|
257
257
|
- `类型/编码方式:` 只用闭合词表 `string`、`int`、`int64`、`float`、`double`、`bool`、`object`、`array<T>`;时间格式、字节、进制等编码写进括号,如 `string(yyyy-MM-dd HH:mm)`、`string(Base64)`、`int(>=1)`。不写“文本”“数值”“布尔”这类散文泛称,并与契约 `type` 逐字一致。
|
|
258
258
|
- `默认值:` `—` 表示没有缺省值;字符串带引号;只写取值,不写是否发送。
|
|
@@ -260,22 +260,22 @@ lifecycle-signal 候选逐个复核后三选一:有用户可感知行为 →
|
|
|
260
260
|
- `必传`:键一定出现。源值缺失就算缺陷时到此为止;缺失时用缺省值补上时写“,缺失时取默认值”,需要点名来源或失败原因时写全,如“,读取不到时取默认值 unknown”;
|
|
261
261
|
- `非必传`:键不一定出现,必须紧跟一个可判定的条件,写成“,<条件>时不发送”或“,只在<条件>时发送”,例如“,无值时不发送”“,空数组时不发送”“,等于默认值 0 时不发送”“,来源无法判断时不发送”“,用户未指定插入位置时不发送”;
|
|
262
262
|
- `不传`:永不出现,字段只保留在数据模型里,序列化时跳过。
|
|
263
|
-
-
|
|
263
|
+
- 是否传以源码的序列化或请求构造位置为准:字段可空、有默认值、模型里标必填,都不等于线上必传;`"nullable": false` 也只说明值不能为空。**这些都不等价于 `必传`**——有默认值的字段可能等于默认值时被省略,也可能始终发送。
|
|
264
264
|
- 发送条件必须能直接写成一次判断:用“无值”“空数组”“等于默认值”“开关关闭”“未选中”“读取不到”“来源无法判断”这类具体条件,不写“按需”“视情况”“酌情”“一般”“可能”;一个字段有多个条件时逐个列出,不合并成“特殊情况除外”。
|
|
265
265
|
- `必传` 与 `非必传` 只差键是否一定出现;`默认值:` 只说值缺失时填什么,不说键出不出现,两段不要互相替代。布尔字段用 `false` 表示“用户没设置”时,`是否传:` 写“等于默认值 false 时不发送”,不写“无值时不发送”。
|
|
266
266
|
- 写条件时“无值”指未赋值或 `null`;字符串与数组另外把长度 0 算无值;`0` 与 `false` 算有值。
|
|
267
|
-
-
|
|
267
|
+
- 表前写一句可执行动作,不写“结构如下”这类说明句,例如:“请求参数按下列字段表逐字段序列化后发送,键顺序与表内行序一致,键是否出现按 `是否传:` 的条件执行。”
|
|
268
268
|
- 各段之间至少留一个空格:`字段名:` 后面的路径不能直接接下一段,免得路径与 `默认值:` 粘成 `file:line` 的样子;默认值写 `默认值:false`,不写 `默认值=false`;表里不写行首 `#`。
|
|
269
|
-
-
|
|
269
|
+
- 表根写业务名(如“同步请求体”“天气查询参数”),不写源码里的请求类型名。
|
|
270
270
|
- 字段的取值来源不是本页界面输入时(本地存储、上一次响应、固定值、计算值),在表后补一行逐字段写明,例如:“来源:`userId` 为本地存储的当前登录用户编号,`deviceId` 为本地存储的设备标识,`payload` 为本地待同步队列的条数。”界面输入的字段不必列。
|
|
271
271
|
|
|
272
|
-
**与契约的关系**:表里每个字段同时写进该场景的 `contracts.endpoints[].params`(`in` 为 `body`),两处逐字一致。契约是校验底稿,G2
|
|
272
|
+
**与契约的关系**:表里每个字段同时写进该场景的 `contracts.endpoints[].params`(`in` 为 `query` 或 `body`),两处逐字一致。契约是校验底稿,G2 逐个参数名、默认值与取值来源比对步骤文本,缺一个即失败;表是读者和下游实现看到的形态。路径参数和请求头同样用 `in` 标明归属并逐项列出(不强制表格);键名、默认值和固定值以源码为准,SPEC 未写明时读源码中构造请求与解析响应的位置补齐,不得猜测,也不得省略有默认值的键。
|
|
273
273
|
|
|
274
274
|
**响应**:`response_fields[]` 逐个列出字段路径(如 `current_temperature`、`hourly.temperatures[]`),只写字段名或路径;外层封装(如 code/data/message)、类型、可空性以及字段缺失或为缺省值时的处理写进该接口的 `note` 并合入步骤,不要塞进 `response_fields` 的元素里——G2 要求元素与步骤逐字一致。
|
|
275
275
|
|
|
276
276
|
**G2 逐字校验**方法、URL、参数名、参数默认值、取值来源和响应字段:契约里写了而步骤没出现会直接失败。外层封装、类型、可空性与缺失处理不在校验范围内,同样必须写进步骤,不能只留在 `contracts` 里。
|
|
277
277
|
|
|
278
|
-
同一个请求出现在多个场景时,每个场景各自写全表,不得写“同上”“见场景一”。发送条件只写在表的 `是否传:`
|
|
278
|
+
同一个请求出现在多个场景时,每个场景各自写全表,不得写“同上”“见场景一”。发送条件只写在表的 `是否传:` 段;步骤只写条件成立后的服务端行为或用户可见结果。请求体(或嵌套查询对象)为对象或数组时写清层级与每个子键,不得写“其他字段”“等”或只给一个示例值。
|
|
279
279
|
|
|
280
280
|
### 正文平台中立
|
|
281
281
|
|
|
@@ -369,7 +369,7 @@ SPEC 是供再实现的契约:无法落成代码或测试断言的表述都是
|
|
|
369
369
|
- 数值输入已写明整数还是小数、是否允许负数,没有用“只接受数字”代替类型;源码实现的小数位、上下限、空白与非法字符处理已逐项写明,未实现的约束没有写成已有行为。
|
|
370
370
|
- 每个数据边界都点名了在场侧(来源与落点)与缺席侧(不带、不写、不发的项,及为空/缺失/取默认时的走向);同一数据集合的多个入口逐项对齐,缺席项显式写出,没有写成 -1/0/空串这类占位值。
|
|
371
371
|
- 每条数据都答了「从哪来(含字段在消费代码里的出处)、怎么处理(含会改变结果的输入及变化后的差异)、用在哪」,缺一即不完整。
|
|
372
|
-
- 每个分支都写了判定依据与两个走向;每个步骤都能指到源码位置或 evidence
|
|
372
|
+
- 每个分支都写了判定依据与两个走向;每个步骤都能指到源码位置或 evidence 条目;是否传按源码序列化判定,没有用可空性(如 `"nullable": false`)、默认值或模型必填去推断。
|
|
373
373
|
- 涉及增删改查、状态同步或数据同步的场景,已逐项列出所有受影响的数据及其变化,没有“相关数据同步变化”之类的笼统表述。
|
|
374
374
|
- 涉及网络请求的场景已在发起请求的那一步写成字段表,每行的四段分别以 `字段名:`、`类型/编码方式:`、`默认值:`、`是否传:` 开头,并在 `contracts.endpoints[].params` 逐条声明同一批字段;非界面输入的取值来源已逐字段列出;每个字段的 `是否传:` 都以必传/非必传/不传开头并给出可判定的条件,没有按需/视情况这类含糊措辞;并写清返回结果的结构,且这些事实已在同一步里。
|
|
375
375
|
- 没有用“其他错误统一处理”之类的含糊措辞替代具体分支。
|