Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f2b9301fa1 | |||
| a8ba8d4b4a | |||
| 1477dbdd18 | |||
| 6d0a5284e7 | |||
| b193aaf8f7 | |||
| a4ab3ef27e | |||
| db0a73dda7 | |||
| f0fb098451 | |||
| 6e67975eca | |||
| 85358bbe4a | |||
| df8ac61c9e | |||
| ace49338b2 | |||
| 076fb25eda | |||
| feac10618d |
+15
-1
@@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"permissionMode": "bypass"
|
"permissionMode": "bypass",
|
||||||
|
"permissions": {
|
||||||
|
"allow": [
|
||||||
|
"Bash(git *)",
|
||||||
|
"Bash(python scripts/agent_poller.py *)",
|
||||||
|
"Bash(python scripts/run_pipeline.py *)",
|
||||||
|
"Bash(python scripts/create_failure_issue.py *)",
|
||||||
|
"Bash(python -m pytest *)",
|
||||||
|
"Bash(python -c *)",
|
||||||
|
"Bash(curl *)"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+17
-2
@@ -63,8 +63,11 @@ description: AI 开发专家,负责 document_analyzer 项目的功能开发、
|
|||||||
4. 轮询内容(多轮递进):
|
4. 轮询内容(多轮递进):
|
||||||
a. `--action list --labels product-code` — 先捡带 `product-code` 标签的 Issue
|
a. `--action list --labels product-code` — 先捡带 `product-code` 标签的 Issue
|
||||||
b. `--action list` 无过滤,筛选 title 带 `[product]` 前缀的无标签 Issue
|
b. `--action list` 无过滤,筛选 title 带 `[product]` 前缀的无标签 Issue
|
||||||
c. 都无则分析无标签、无标识的 Issue,判断是否在 Dev 域内
|
c. `--action blocked-check` — 检查 blocked Issue,若阻塞已解除则自动移除 blocked 标签
|
||||||
5. 有 issue → 走完整闭环处理(分析 → 开发 → push → PR → CI → merge → 自行验证 → 关闭)
|
d. 都无则分析无标签、无标识的 Issue,判断是否在 Dev 域内
|
||||||
|
5. 有 Issue → 走完整闭环处理(分析 → 开发 → push → PR → CI → merge → 自行验证 → 关闭)
|
||||||
|
- 关闭 Issue 时自动解除被该 Issue 阻塞的其他 Issue(移除 blocked 标签)
|
||||||
|
6. 无 Issue → 报告 "main healthy,无待处理 Issue",等待下次轮询
|
||||||
6. 无 issue → 报告 "main healthy,无待处理 Issue",等待下次轮询
|
6. 无 issue → 报告 "main healthy,无待处理 Issue",等待下次轮询
|
||||||
7. 同时保持对话开放,随时响应用户指令
|
7. 同时保持对话开放,随时响应用户指令
|
||||||
|
|
||||||
@@ -86,6 +89,13 @@ python scripts/agent_poller.py --action list
|
|||||||
**第三轮:分析无标识 Issue**
|
**第三轮:分析无标识 Issue**
|
||||||
如果以上两轮都无结果,分析所有无标签、无 title 标识的 Issue,判断是否属于 Dev 域。
|
如果以上两轮都无结果,分析所有无标签、无 title 标识的 Issue,判断是否属于 Dev 域。
|
||||||
|
|
||||||
|
**blocked Issue 处理**:
|
||||||
|
- 不要直接跳过 `blocked` 标签的 Issue
|
||||||
|
- 运行 `--action blocked-check` 检查阻塞状态是否已解除
|
||||||
|
- 如果所有阻塞 Issue 已关闭 → blocked 标签自动移除 → 正常处理
|
||||||
|
- 如果仍有未解决的阻塞 → 跳过,等待阻塞解除
|
||||||
|
- 关闭 Issue 时会自动检查并解除被其阻塞的 Issue(auto-unblock)
|
||||||
|
|
||||||
**处理范围**:Dev-Agent 负责处理**所有非纯测试开发**相关的 Issue。具体来说:
|
**处理范围**:Dev-Agent 负责处理**所有非纯测试开发**相关的 Issue。具体来说:
|
||||||
|
|
||||||
| 处理 | 跳过 |
|
| 处理 | 跳过 |
|
||||||
@@ -215,6 +225,10 @@ QE-Agent 开 Issue (qe-feedback / bug / ci-failure)
|
|||||||
验证不通过 → 重新分析根因 → 回到开发
|
验证不通过 → 重新分析根因 → 回到开发
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 关键约束
|
||||||
|
|
||||||
|
1. **任何对 git 管理内容的修改必须走完整流程**:开 Issue → 改动 → 提交 PR → CI 通过 → merge → close Issue。无论是自主轮询还是与用户互动触发的改动,一律遵守此规则。绝不直接改文件而不走 Issue 流程。
|
||||||
|
|
||||||
## 提交规范
|
## 提交规范
|
||||||
|
|
||||||
- **格式**:`fix: <简短描述> - Closes #N` 或 `feat: <描述> - Closes #N`
|
- **格式**:`fix: <简短描述> - Closes #N` 或 `feat: <描述> - Closes #N`
|
||||||
@@ -252,6 +266,7 @@ QE-Agent 开 Issue (qe-feedback / bug / ci-failure)
|
|||||||
| `--action pr-status --pr N` | 查看 PR + CI 状态 | 5. 等 CI |
|
| `--action pr-status --pr N` | 查看 PR + CI 状态 | 5. 等 CI |
|
||||||
| `--action merge-pr --pr N` | Merge PR(自动检查 CI) | 6. Merge |
|
| `--action merge-pr --pr N` | Merge PR(自动检查 CI) | 6. Merge |
|
||||||
| `--action close-issue --issue N --body "..."` | 手动关闭 Issue | 6. 关闭 |
|
| `--action close-issue --issue N --body "..."` | 手动关闭 Issue | 6. 关闭 |
|
||||||
|
| `--action blocked-check` | 检查并清理已解除阻塞的 Issue | 4-6. 轮询 |
|
||||||
| `--action lifecycle --issue N` | 查看 Issue 完整生命周期 | 随时 |
|
| `--action lifecycle --issue N` | 查看 Issue 完整生命周期 | 随时 |
|
||||||
|
|
||||||
## 闭环完成检查清单
|
## 闭环完成检查清单
|
||||||
|
|||||||
+20
-10
@@ -19,10 +19,12 @@ description: QE Agent — 自动化验收测试开发与质量门禁。轮询 Gi
|
|||||||
4. 轮询内容(多轮递进):
|
4. 轮询内容(多轮递进):
|
||||||
a. `--action list --labels test-code` — 先捡带 `test-code` 标签的 Issue
|
a. `--action list --labels test-code` — 先捡带 `test-code` 标签的 Issue
|
||||||
b. `--action list` 无过滤,筛选 title 带 `[test]` 前缀的无标签 Issue
|
b. `--action list` 无过滤,筛选 title 带 `[test]` 前缀的无标签 Issue
|
||||||
c. 都无则分析无标签、无标识的 Issue,判断是否在 QE 域内
|
c. `--action blocked-check` — 检查 blocked Issue,若阻塞已解除则自动移除 blocked 标签
|
||||||
d. 同时检查 `--labels acceptance-failure`
|
d. 都无则分析无标签、无标识的 Issue,判断是否在 QE 域内
|
||||||
5. 有 issue → 走完整闭环处理(Step 2-8)
|
e. 同时检查 `--labels acceptance-failure`
|
||||||
6. 无 issue → 简短报告 "main healthy",等待下次轮询
|
5. 有 Issue → 走完整闭环处理(Step 2-8)
|
||||||
|
- 关闭 Issue 时自动解除被该 Issue 阻塞的其他 Issue(移除 blocked 标签)
|
||||||
|
6. 无 Issue → 简短报告 "main healthy",等待下次轮询
|
||||||
7. 同时保持对话开放,随时响应用户指令
|
7. 同时保持对话开放,随时响应用户指令
|
||||||
|
|
||||||
这样 QE-Agent 真正做到 **"默认轮询 + 随时互动"**。
|
这样 QE-Agent 真正做到 **"默认轮询 + 随时互动"**。
|
||||||
@@ -69,6 +71,13 @@ python scripts/agent_poller.py --action list
|
|||||||
**第三轮:分析无标识 Issue**
|
**第三轮:分析无标识 Issue**
|
||||||
如果以上两轮都无结果,分析所有无标签、无 title 标识的 Issue,判断是否属于 QE 域。
|
如果以上两轮都无结果,分析所有无标签、无 title 标识的 Issue,判断是否属于 QE 域。
|
||||||
|
|
||||||
|
**blocked Issue 处理**:
|
||||||
|
- 不要直接跳过 `blocked` 标签的 Issue
|
||||||
|
- 运行 `--action blocked-check` 检查阻塞状态是否已解除
|
||||||
|
- 如果所有阻塞 Issue 已关闭 → blocked 标签自动移除 → 正常处理
|
||||||
|
- 如果仍有未解决的阻塞 → 跳过,等待阻塞解除
|
||||||
|
- 关闭 Issue 时会自动检查并解除被其阻塞的 Issue(auto-unblock)
|
||||||
|
|
||||||
同时检查 `acceptance-failure` 标签的 issue:
|
同时检查 `acceptance-failure` 标签的 issue:
|
||||||
```bash
|
```bash
|
||||||
python scripts/agent_poller.py --action list --labels acceptance-failure
|
python scripts/agent_poller.py --action list --labels acceptance-failure
|
||||||
@@ -294,12 +303,13 @@ QE-Agent 领取 (step 1-2)
|
|||||||
|
|
||||||
## 关键约束
|
## 关键约束
|
||||||
|
|
||||||
1. **只修改 `tests/acceptance/`** — 不碰应用代码、不碰 `skills/`、不碰 `scripts/`(除非是修复 agent_poller 或 create_failure_issue)
|
1. **任何对 git 管理内容的修改必须走完整流程**:开 Issue → 改动 → 提交 PR → CI 通过 → merge → close Issue。无论是自主轮询还是与用户互动触发的改动,一律遵守此规则。绝不直接改文件而不走 Issue 流程。
|
||||||
2. **不碰 `tests/unit/`、`tests/integration/`** — 那是开发团队维护的
|
2. **只修改 `tests/acceptance/`** — 不碰应用代码、不碰 `skills/`、不碰 `scripts/`(除非是修复 agent_poller 或 create_failure_issue)
|
||||||
3. **每次只处理一个 issue** — 不混入多个 issue 的改动
|
3. **不碰 `tests/unit/`、`tests/integration/`** — 那是开发团队维护的
|
||||||
4. **`Closes #<N>` 必须出现在 commit message 中**
|
4. **每次只处理一个 issue** — 不混入多个 issue 的改动
|
||||||
5. **本地验证必须通过再 push** — 至少 Layer A + Layer B
|
5. **`Closes #<N>` 必须出现在 commit message 中**
|
||||||
6. **如果 Layer C(QE Audit)需要验证但 API 不可用** — 在 issue 下评论注明,标记 `--run-acceptance` 通过后 merge
|
6. **本地验证必须通过再 push** — 至少 Layer A + Layer B
|
||||||
|
7. **如果 Layer C(QE Audit)需要验证但 API 不可用** — 在 issue 下评论注明,标记 `--run-acceptance` 通过后 merge
|
||||||
|
|
||||||
## Session 收尾
|
## Session 收尾
|
||||||
|
|
||||||
|
|||||||
+141
-3
@@ -16,6 +16,7 @@ Usage:
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import urllib.error
|
import urllib.error
|
||||||
@@ -73,6 +74,73 @@ def list_issues(labels: list[str] | None = None):
|
|||||||
return issues
|
return issues
|
||||||
|
|
||||||
|
|
||||||
|
def _get_blocking_refs(issue_num: int) -> set[int]:
|
||||||
|
"""Extract all issue references from an issue body + comments.
|
||||||
|
|
||||||
|
Scans both the issue body and all comments for #N patterns,
|
||||||
|
returning a set of referenced issue numbers.
|
||||||
|
"""
|
||||||
|
refs: set[int] = set()
|
||||||
|
# Body
|
||||||
|
issue = _req("GET", f"/issues/{issue_num}")
|
||||||
|
body = issue.get("body", "") or ""
|
||||||
|
refs.update(int(m.group(1)) for m in re.finditer(r'#(\d+)', body))
|
||||||
|
# Comments
|
||||||
|
try:
|
||||||
|
comments = _req("GET", f"/issues/{issue_num}/comments")
|
||||||
|
for c in comments:
|
||||||
|
cbody = c.get("body", "") or ""
|
||||||
|
refs.update(int(m.group(1)) for m in re.finditer(r'#(\d+)', cbody))
|
||||||
|
except SystemExit:
|
||||||
|
pass
|
||||||
|
return refs
|
||||||
|
|
||||||
|
|
||||||
|
def blocked_check():
|
||||||
|
"""Check all blocked issues: if blocking issues are now closed, unblock.
|
||||||
|
|
||||||
|
Scans issue body + comments for blocking references.
|
||||||
|
If no references found or all referenced issues are closed,
|
||||||
|
removes the 'blocked' label.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
all_blocked = _req("GET", "/issues?state=open&labels=blocked")
|
||||||
|
except SystemExit:
|
||||||
|
print("No blocked issues found.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not all_blocked:
|
||||||
|
print("No blocked issues found.")
|
||||||
|
return
|
||||||
|
|
||||||
|
unblocked_count = 0
|
||||||
|
for issue in all_blocked:
|
||||||
|
blocking_nums = _get_blocking_refs(issue["number"])
|
||||||
|
|
||||||
|
all_resolved = True
|
||||||
|
for blk in blocking_nums:
|
||||||
|
try:
|
||||||
|
blk_issue = _req("GET", f"/issues/{blk}")
|
||||||
|
if blk_issue.get("state") != "closed":
|
||||||
|
all_resolved = False
|
||||||
|
break
|
||||||
|
except SystemExit:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if all_resolved:
|
||||||
|
current_label_names = [l["name"] for l in issue.get("labels", [])]
|
||||||
|
new_label_names = [l for l in current_label_names if l != "blocked"]
|
||||||
|
new_label_ids = _label_names_to_ids(new_label_names)
|
||||||
|
_req("PUT", f"/issues/{issue['number']}/labels", {"labels": new_label_ids})
|
||||||
|
reason = "所有阻塞 Issue 均已关闭" if blocking_nums else "无阻塞引用,移除残留 blocked 标签"
|
||||||
|
print(f"Unblocked #{issue['number']}: {issue['title']}")
|
||||||
|
comment_issue(issue["number"], f"阻塞已解除:{reason}。")
|
||||||
|
unblocked_count += 1
|
||||||
|
|
||||||
|
if unblocked_count == 0:
|
||||||
|
print(f"Checked {len(all_blocked)} blocked issue(s): still blocked.")
|
||||||
|
|
||||||
|
|
||||||
def get_issue(num):
|
def get_issue(num):
|
||||||
i = _req("GET", f"/issues/{num}")
|
i = _req("GET", f"/issues/{num}")
|
||||||
print(f"## #{i['number']}: {i['title']}")
|
print(f"## #{i['number']}: {i['title']}")
|
||||||
@@ -91,14 +159,61 @@ def comment_issue(num, body):
|
|||||||
|
|
||||||
|
|
||||||
def close_issue(num, body=None):
|
def close_issue(num, body=None):
|
||||||
"""Close an issue, optionally with a final comment (signature auto-appended)."""
|
"""Close an issue, optionally with a final comment (signature auto-appended).
|
||||||
|
|
||||||
|
After closing, automatically unblocks any issues that were blocked by this one
|
||||||
|
if no other blocking issues remain open.
|
||||||
|
"""
|
||||||
if body:
|
if body:
|
||||||
comment_issue(num, body) # comment_issue already appends AGENT_SIG
|
comment_issue(num, body) # comment_issue already appends AGENT_SIG
|
||||||
i = _req("PATCH", f"/issues/{num}", {"state": "closed"})
|
i = _req("PATCH", f"/issues/{num}", {"state": "closed"})
|
||||||
print(f"Issue #{num} closed")
|
print(f"Issue #{num} closed")
|
||||||
|
_unblock_issues_blocked_by(num)
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
def _unblock_issues_blocked_by(closed_num):
|
||||||
|
"""Check issues blocked by *closed_num* and unblock if all blockers resolved.
|
||||||
|
|
||||||
|
Scans both body and comments for #N references. If *closed_num* appears
|
||||||
|
in any blocked issue and all referenced issues are now closed,
|
||||||
|
removes the 'blocked' label and comments on the unblocked issue.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
all_blocked = _req("GET", "/issues?state=open&labels=blocked")
|
||||||
|
except SystemExit:
|
||||||
|
return
|
||||||
|
if not all_blocked:
|
||||||
|
return
|
||||||
|
|
||||||
|
for issue in all_blocked:
|
||||||
|
blocking_nums = _get_blocking_refs(issue["number"])
|
||||||
|
if closed_num not in blocking_nums:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Check all referenced issues — are they all closed?
|
||||||
|
all_resolved = True
|
||||||
|
for blk in blocking_nums:
|
||||||
|
if blk == closed_num:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
blk_issue = _req("GET", f"/issues/{blk}")
|
||||||
|
if blk_issue.get("state") != "closed":
|
||||||
|
all_resolved = False
|
||||||
|
break
|
||||||
|
except SystemExit:
|
||||||
|
pass # Inaccessible → treat as resolved
|
||||||
|
|
||||||
|
if all_resolved:
|
||||||
|
current_label_names = [l["name"] for l in issue.get("labels", [])]
|
||||||
|
new_label_names = [l for l in current_label_names if l != "blocked"]
|
||||||
|
new_label_ids = _label_names_to_ids(new_label_names)
|
||||||
|
_req("PUT", f"/issues/{issue['number']}/labels", {"labels": new_label_ids})
|
||||||
|
print(f" -> Unblocked #{issue['number']}: all blocking issues resolved")
|
||||||
|
comment_issue(issue["number"],
|
||||||
|
f"阻塞已解除:#{closed_num} 及其他阻塞 Issue 均已关闭。")
|
||||||
|
|
||||||
|
|
||||||
def create_issue(title, body=None, labels=None):
|
def create_issue(title, body=None, labels=None):
|
||||||
"""Create a new Gitea issue.
|
"""Create a new Gitea issue.
|
||||||
|
|
||||||
@@ -110,7 +225,11 @@ def create_issue(title, body=None, labels=None):
|
|||||||
if body:
|
if body:
|
||||||
payload["body"] = body + AGENT_SIG
|
payload["body"] = body + AGENT_SIG
|
||||||
if labels:
|
if labels:
|
||||||
payload["labels"] = [l.strip() for l in labels.split(",") if l.strip()]
|
label_names = [l.strip() for l in labels.split(",") if l.strip()]
|
||||||
|
# Gitea 1.22 expects label IDs (int64). Resolve names → IDs.
|
||||||
|
label_ids = _label_names_to_ids(label_names)
|
||||||
|
if label_ids:
|
||||||
|
payload["labels"] = label_ids
|
||||||
i = _req("POST", "/issues", payload)
|
i = _req("POST", "/issues", payload)
|
||||||
issue_labels = [l["name"] for l in i.get("labels", [])]
|
issue_labels = [l["name"] for l in i.get("labels", [])]
|
||||||
print(f"Issue #{i['number']} created: {i['title']}")
|
print(f"Issue #{i['number']} created: {i['title']}")
|
||||||
@@ -120,6 +239,22 @@ def create_issue(title, body=None, labels=None):
|
|||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
def _label_names_to_ids(names: list[str]) -> list[int]:
|
||||||
|
"""Resolve label names to Gitea label IDs. Returns empty list on failure."""
|
||||||
|
try:
|
||||||
|
all_labels = _req("GET", "/labels")
|
||||||
|
name_to_id = {l["name"]: l["id"] for l in all_labels}
|
||||||
|
ids = []
|
||||||
|
for name in names:
|
||||||
|
if name in name_to_id:
|
||||||
|
ids.append(name_to_id[name])
|
||||||
|
else:
|
||||||
|
print(f"Warning: label '{name}' not found, skipping", file=sys.stderr)
|
||||||
|
return ids
|
||||||
|
except SystemExit:
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
# ── PR operations ────────────────────────────────────────────────────────────
|
# ── PR operations ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
def create_pr(issue_num, branch, body=None):
|
def create_pr(issue_num, branch, body=None):
|
||||||
@@ -234,7 +369,8 @@ def main():
|
|||||||
parser = argparse.ArgumentParser(description="Dev agent Gitea helper")
|
parser = argparse.ArgumentParser(description="Dev agent Gitea helper")
|
||||||
parser.add_argument("--action", required=True,
|
parser.add_argument("--action", required=True,
|
||||||
choices=["list", "get", "comment", "close-issue",
|
choices=["list", "get", "comment", "close-issue",
|
||||||
"create-issue", "create-pr", "pr-status", "merge-pr", "lifecycle"])
|
"create-issue", "create-pr", "pr-status", "merge-pr", "lifecycle",
|
||||||
|
"blocked-check"])
|
||||||
parser.add_argument("--issue", type=int)
|
parser.add_argument("--issue", type=int)
|
||||||
parser.add_argument("--pr", type=int)
|
parser.add_argument("--pr", type=int)
|
||||||
parser.add_argument("--title", help="Issue title (for 'create-issue' action)")
|
parser.add_argument("--title", help="Issue title (for 'create-issue' action)")
|
||||||
@@ -286,6 +422,8 @@ def main():
|
|||||||
print("--pr is required for 'merge-pr' action", file=sys.stderr)
|
print("--pr is required for 'merge-pr' action", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
merge_pr(args.pr)
|
merge_pr(args.pr)
|
||||||
|
elif args.action == "blocked-check":
|
||||||
|
blocked_check()
|
||||||
elif args.action == "lifecycle":
|
elif args.action == "lifecycle":
|
||||||
if not args.issue:
|
if not args.issue:
|
||||||
print("--issue is required for 'lifecycle' action", file=sys.stderr)
|
print("--issue is required for 'lifecycle' action", file=sys.stderr)
|
||||||
|
|||||||
@@ -880,10 +880,14 @@ def run_ensemble_semantic_index(doc: dict) -> dict:
|
|||||||
if v:
|
if v:
|
||||||
print(f" {k}: {len(v)} 个问题")
|
print(f" {k}: {len(v)} 个问题")
|
||||||
|
|
||||||
# Feedback retry: re-run with coverage feedback (one retry)
|
# Feedback retry: re-run with coverage feedback (up to 2 retries)
|
||||||
|
retry_count = 0
|
||||||
|
while retry_count < 2:
|
||||||
feedback = _build_coverage_feedback(gaps)
|
feedback = _build_coverage_feedback(gaps)
|
||||||
if feedback:
|
if not feedback:
|
||||||
print(f"\n 覆盖反馈重试 (feedback长度={len(feedback)}字符)...", flush=True)
|
break
|
||||||
|
retry_count += 1
|
||||||
|
print(f"\n 覆盖反馈重试 #{retry_count} (feedback长度={len(feedback)}字符)...", flush=True)
|
||||||
try:
|
try:
|
||||||
retry_prompt = build_prompt(doc, feedback, all_paths)
|
retry_prompt = build_prompt(doc, feedback, all_paths)
|
||||||
print(f" 重试 prompt 长度: {len(retry_prompt)} 字符", flush=True)
|
print(f" 重试 prompt 长度: {len(retry_prompt)} 字符", flush=True)
|
||||||
@@ -892,17 +896,15 @@ def run_ensemble_semantic_index(doc: dict) -> dict:
|
|||||||
n_retry_concepts = len(retry_result.get("concepts", []))
|
n_retry_concepts = len(retry_result.get("concepts", []))
|
||||||
print(f" 重试返回: {n_retry_concepts} 概念, {n_retry_units} 功能单元", flush=True)
|
print(f" 重试返回: {n_retry_concepts} 概念, {n_retry_units} 功能单元", flush=True)
|
||||||
if n_retry_units > 0:
|
if n_retry_units > 0:
|
||||||
# Check which new sections were covered
|
|
||||||
retry_sections = set()
|
retry_sections = set()
|
||||||
for fu in retry_result.get("function_units", []):
|
for fu in retry_result.get("function_units", []):
|
||||||
for src in fu.get("sources", []):
|
for src in fu.get("sources", []):
|
||||||
if src.get("section"):
|
if src.get("section"):
|
||||||
retry_sections.add(src["section"])
|
retry_sections.add(src["section"])
|
||||||
print(f" 重试新增 sections: {sorted(retry_sections)}", flush=True)
|
print(f" 重试新增 sections: {sorted(retry_sections)}", flush=True)
|
||||||
# Merge retry into results and re-validate
|
|
||||||
semantic_indices.append(retry_result)
|
semantic_indices.append(retry_result)
|
||||||
merged = ensemble_merge(semantic_indices)
|
merged = ensemble_merge(semantic_indices)
|
||||||
merged["ensemble_temperatures"] = list(temperatures) + ["feedback_retry"]
|
merged["ensemble_temperatures"] = list(temperatures) + [f"feedback_retry_{retry_count}"]
|
||||||
passed, gaps = _quick_validate(merged, doc, all_paths)
|
passed, gaps = _quick_validate(merged, doc, all_paths)
|
||||||
merged["validation_passed"] = passed
|
merged["validation_passed"] = passed
|
||||||
merged["validation_gaps"] = {
|
merged["validation_gaps"] = {
|
||||||
@@ -913,6 +915,7 @@ def run_ensemble_semantic_index(doc: dict) -> dict:
|
|||||||
print(f" 覆盖反馈重试失败: {e}", flush=True)
|
print(f" 覆盖反馈重试失败: {e}", flush=True)
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
break
|
||||||
|
|
||||||
return merged
|
return merged
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,27 @@ def _normalize_rule(rule: dict) -> dict:
|
|||||||
"value": "active"
|
"value": "active"
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
# Ensure table/text sources have a section field (defensive against LLM omission)
|
||||||
|
sources = rule.get("sources", [])
|
||||||
|
if sources:
|
||||||
|
# try to infer a default section from sibling sources or the rule path
|
||||||
|
default_section = ""
|
||||||
|
for s in sources:
|
||||||
|
sec = s.get("section", "")
|
||||||
|
if sec and sec.strip():
|
||||||
|
default_section = sec.strip()
|
||||||
|
break
|
||||||
|
if not default_section:
|
||||||
|
path = rule.get("path", "")
|
||||||
|
if path:
|
||||||
|
default_section = path.split(" > ")[0] if " > " in path else path
|
||||||
|
|
||||||
|
for src in sources:
|
||||||
|
stype = src.get("type", "")
|
||||||
|
if stype in ("table", "text"):
|
||||||
|
if not src.get("section"):
|
||||||
|
src["section"] = default_section
|
||||||
|
|
||||||
return rule
|
return rule
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -465,3 +465,49 @@ class TestNormalizeRule:
|
|||||||
normalized = _normalize_rule(rule)
|
normalized = _normalize_rule(rule)
|
||||||
assert normalized["trigger"]["operator"] == "AND"
|
assert normalized["trigger"]["operator"] == "AND"
|
||||||
assert normalized["trigger"]["conditions"][0]["operator"] == ">="
|
assert normalized["trigger"]["conditions"][0]["operator"] == ">="
|
||||||
|
|
||||||
|
def test_normalize_source_missing_section_from_sibling(self):
|
||||||
|
"""Table/text sources without section get it from sibling sources."""
|
||||||
|
rule = {
|
||||||
|
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
|
||||||
|
"sources": [
|
||||||
|
{"type": "table", "section": "3.1.1 系统限制", "row": 1},
|
||||||
|
{"type": "text", "text_snippet": "missing section"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
normalized = _normalize_rule(rule)
|
||||||
|
assert normalized["sources"][1]["section"] == "3.1.1 系统限制"
|
||||||
|
|
||||||
|
def test_normalize_source_missing_section_from_path(self):
|
||||||
|
"""Table/text sources without section and no sibling fall back to rule path."""
|
||||||
|
rule = {
|
||||||
|
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
|
||||||
|
"path": "4.2 关闭流程 > decision_speed > action_disable",
|
||||||
|
"sources": [
|
||||||
|
{"type": "table", "row": 3, "text_snippet": "no section anywhere"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
normalized = _normalize_rule(rule)
|
||||||
|
assert normalized["sources"][0]["section"] == "4.2 关闭流程"
|
||||||
|
|
||||||
|
def test_normalize_source_keeps_existing_section(self):
|
||||||
|
"""Sources that already have section are not modified."""
|
||||||
|
rule = {
|
||||||
|
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
|
||||||
|
"sources": [
|
||||||
|
{"type": "table", "section": "1.0 概述", "row": 1},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
normalized = _normalize_rule(rule)
|
||||||
|
assert normalized["sources"][0]["section"] == "1.0 概述"
|
||||||
|
|
||||||
|
def test_normalize_source_skips_logic_tree(self):
|
||||||
|
"""Logic tree sources are not touched (don't need section)."""
|
||||||
|
rule = {
|
||||||
|
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
|
||||||
|
"sources": [
|
||||||
|
{"type": "logic_tree", "image_id": "img1", "node_ids": ["n1"]},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
normalized = _normalize_rule(rule)
|
||||||
|
assert "section" not in normalized["sources"][0]
|
||||||
|
|||||||
@@ -291,6 +291,85 @@ def _measure_coverage(ir_data: dict, parsed_data: dict) -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_measure_coverage_excludes_zero_dimensions():
|
||||||
|
"""#36: dimensions with total=0 must not drag down the overall rate.
|
||||||
|
|
||||||
|
When diagram total=0, the overall should be computed from sections and tables
|
||||||
|
only, not include a 0% diagram entry that makes the goal unreachable.
|
||||||
|
"""
|
||||||
|
parsed_data = {
|
||||||
|
"sections": [
|
||||||
|
{"source": "3.1.1 功能A", "blocks": [
|
||||||
|
{"type": "table", "rows": [{"cell": "1"}, {"cell": "2"}]}
|
||||||
|
]}
|
||||||
|
],
|
||||||
|
"image_analysis": [], # no diagrams → total=0
|
||||||
|
}
|
||||||
|
# IR that covers the section but no table rows (table coverage = 0/2)
|
||||||
|
ir_data = {
|
||||||
|
"rules": [
|
||||||
|
{"sources": [{"section": "3.1.1"}]} # 1 section covered, 0 tables
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
cov = _measure_coverage(ir_data, parsed_data)
|
||||||
|
|
||||||
|
# Section: 1/1 = 100%, Table: 0/2 = 0%, Diagram: total=0 → excluded
|
||||||
|
assert cov["section_coverage"]["total"] == 1
|
||||||
|
assert cov["section_coverage"]["rate"] == 1.0
|
||||||
|
assert cov["table_coverage"]["total_rows"] == 2
|
||||||
|
assert cov["table_coverage"]["rate"] == 0.0
|
||||||
|
assert cov["diagram_coverage"]["total"] == 0
|
||||||
|
assert cov["diagram_coverage"]["rate"] == 1.0 # _safe_rate: 0/0 → 1.0
|
||||||
|
|
||||||
|
# Key assertion: diagram (total=0) is excluded from overall
|
||||||
|
# overall = (1.0 + 0.0) / 2 = 0.5
|
||||||
|
# NOT (1.0 + 0.0 + 1.0) / 3 = 0.667
|
||||||
|
assert cov["overall_rate"] == 0.5, (
|
||||||
|
f"Expected overall 0.5 (sections + tables only), got {cov['overall_rate']}. "
|
||||||
|
f"Zero-content dimension may be leaking into the average."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_measure_coverage_all_dimensions_have_content():
|
||||||
|
"""When all dimensions have content, all should be included."""
|
||||||
|
parsed_data = {
|
||||||
|
"sections": [
|
||||||
|
{"source": "3.1.1 功能A", "blocks": [
|
||||||
|
{"type": "table", "rows": [{"cell": "1"}]}
|
||||||
|
]}
|
||||||
|
],
|
||||||
|
"image_analysis": [{"type": "flowchart", "rid": "img_001"}],
|
||||||
|
}
|
||||||
|
ir_data = {
|
||||||
|
"rules": [
|
||||||
|
{"sources": [{"section": "3.1.1"}]},
|
||||||
|
{"sources": [{"type": "table", "section": "3.1.1", "row": 0}]},
|
||||||
|
{"sources": [{"type": "logic_tree", "image_id": "img_001"}]},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
cov = _measure_coverage(ir_data, parsed_data)
|
||||||
|
|
||||||
|
# All three dimensions have content → all included
|
||||||
|
assert cov["section_coverage"]["total"] == 1
|
||||||
|
assert cov["table_coverage"]["total_rows"] == 1
|
||||||
|
assert cov["diagram_coverage"]["total"] == 1
|
||||||
|
# overall = (1.0 + 1.0 + 1.0) / 3 = 1.0
|
||||||
|
assert cov["overall_rate"] == 1.0, (
|
||||||
|
f"Expected overall 1.0 (all covered), got {cov['overall_rate']}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_measure_coverage_no_content_returns_zero():
|
||||||
|
"""When no dimensions have content, overall should be 0.0."""
|
||||||
|
parsed_data = {"sections": [], "image_analysis": []}
|
||||||
|
ir_data = {"rules": []}
|
||||||
|
|
||||||
|
cov = _measure_coverage(ir_data, parsed_data)
|
||||||
|
assert cov["overall_rate"] == 0.0
|
||||||
|
|
||||||
|
|
||||||
def test_layer_b_coverage(
|
def test_layer_b_coverage(
|
||||||
ir_data: dict,
|
ir_data: dict,
|
||||||
parsed_data: dict | None,
|
parsed_data: dict | None,
|
||||||
|
|||||||
Reference in New Issue
Block a user