Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 473a3c8d4f | |||
| 5f094a9a48 | |||
| 7c02db907b | |||
| d682f64c01 | |||
| a24408521c | |||
| c091b6c256 | |||
| cbafd30ec7 | |||
| f84908aa36 | |||
| 500152510a | |||
| 0d5bfa9276 | |||
| eb2af77c90 | |||
| eccaa28b1d | |||
| 2101a43b68 | |||
| 9f0872c36a | |||
| d73da7cda9 |
+6
-3
@@ -126,9 +126,11 @@ python scripts/agent_poller.py --action get --issue N
|
|||||||
1. git pull origin main
|
1. git pull origin main
|
||||||
2. git checkout -b dev/issue-N-<slug>
|
2. git checkout -b dev/issue-N-<slug>
|
||||||
3. 修改功能代码 + 更新/补充 UT 和接口集成测试
|
3. 修改功能代码 + 更新/补充 UT 和接口集成测试
|
||||||
4. python -m pytest -v # 本地全量测试
|
4. python -m pytest -v # 本地全量 UT/集成测试
|
||||||
5. git commit -m "fix: <描述> - Closes #N"
|
5. python scripts/run_pipeline.py --input "input/<文档>.docx" # 运行完整 pipeline
|
||||||
6. git push origin dev/issue-N-<slug>
|
6. python -m pytest tests/acceptance/ -v --run-acceptance # e2e 验收 (Layer A+B+C)
|
||||||
|
7. git commit -m "fix: <描述> - Closes #N"
|
||||||
|
8. git push origin dev/issue-N-<slug>
|
||||||
```
|
```
|
||||||
|
|
||||||
**开发原则:**
|
**开发原则:**
|
||||||
@@ -137,6 +139,7 @@ python scripts/agent_poller.py --action get --issue N
|
|||||||
- 关注 IR 一致性:对同一输入的多次运行结果应尽量稳定
|
- 关注 IR 一致性:对同一输入的多次运行结果应尽量稳定
|
||||||
- 关注功能覆盖率:确保 IR 覆盖了输入文档中的功能点
|
- 关注功能覆盖率:确保 IR 覆盖了输入文档中的功能点
|
||||||
- **验证是实际功能验证,不是 dry-run**:`pytest` 通过只是门槛,必须用真实输入文档实际运行 pipeline 确认功能生效
|
- **验证是实际功能验证,不是 dry-run**:`pytest` 通过只是门槛,必须用真实输入文档实际运行 pipeline 确认功能生效
|
||||||
|
- **PR 前必须通过 e2e 验收 (Layer A+B+C)**:防止修复引入回归。若无法运行完整 pipeline(API 不可用等),至少在 PR 描述中注明
|
||||||
|
|
||||||
### 4. 提交 PR
|
### 4. 提交 PR
|
||||||
|
|
||||||
|
|||||||
+52
-24
@@ -56,6 +56,27 @@ def _req(method, path, data=None):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def _req_safe(method, path, data=None):
|
||||||
|
"""Like _req but returns None on HTTPError instead of crashing.
|
||||||
|
Used for probing issue/PR existence where the caller can handle absence.
|
||||||
|
"""
|
||||||
|
url = f"{BASE}{path}"
|
||||||
|
payload = json.dumps(data).encode("utf-8") if data else None
|
||||||
|
req = urllib.request.Request(url, data=payload, method=method)
|
||||||
|
req.add_header("Authorization", f"token {GITEA_TOKEN}")
|
||||||
|
req.add_header("Content-Type", "application/json")
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req) as resp:
|
||||||
|
raw = resp.read()
|
||||||
|
if not raw:
|
||||||
|
return {}
|
||||||
|
return json.loads(raw)
|
||||||
|
except urllib.error.HTTPError as e:
|
||||||
|
body = e.read().decode()
|
||||||
|
print(f"API Error {e.code}: {body}", file=sys.stderr)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
# ── Issue operations ─────────────────────────────────────────────────────────
|
# ── Issue operations ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
def list_issues(labels: list[str] | None = None):
|
def list_issues(labels: list[str] | None = None):
|
||||||
@@ -82,17 +103,17 @@ def _get_blocking_refs(issue_num: int) -> set[int]:
|
|||||||
"""
|
"""
|
||||||
refs: set[int] = set()
|
refs: set[int] = set()
|
||||||
# Body
|
# Body
|
||||||
issue = _req("GET", f"/issues/{issue_num}")
|
issue = _req_safe("GET", f"/issues/{issue_num}")
|
||||||
|
if issue is None:
|
||||||
|
return refs # API error → return empty set, keep blocked
|
||||||
body = issue.get("body", "") or ""
|
body = issue.get("body", "") or ""
|
||||||
refs.update(int(m.group(1)) for m in re.finditer(r'#(\d+)', body))
|
refs.update(int(m.group(1)) for m in re.finditer(r'#(\d+)', body))
|
||||||
# Comments
|
# Comments
|
||||||
try:
|
comments = _req_safe("GET", f"/issues/{issue_num}/comments")
|
||||||
comments = _req("GET", f"/issues/{issue_num}/comments")
|
if comments:
|
||||||
for c in comments:
|
for c in comments:
|
||||||
cbody = c.get("body", "") or ""
|
cbody = c.get("body", "") or ""
|
||||||
refs.update(int(m.group(1)) for m in re.finditer(r'#(\d+)', cbody))
|
refs.update(int(m.group(1)) for m in re.finditer(r'#(\d+)', cbody))
|
||||||
except SystemExit:
|
|
||||||
pass
|
|
||||||
return refs
|
return refs
|
||||||
|
|
||||||
|
|
||||||
@@ -103,12 +124,7 @@ def blocked_check():
|
|||||||
If no references found or all referenced issues are closed,
|
If no references found or all referenced issues are closed,
|
||||||
removes the 'blocked' label.
|
removes the 'blocked' label.
|
||||||
"""
|
"""
|
||||||
try:
|
all_blocked = _req_safe("GET", "/issues?state=open&labels=blocked")
|
||||||
all_blocked = _req("GET", "/issues?state=open&labels=blocked")
|
|
||||||
except SystemExit:
|
|
||||||
print("No blocked issues found.")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not all_blocked:
|
if not all_blocked:
|
||||||
print("No blocked issues found.")
|
print("No blocked issues found.")
|
||||||
return
|
return
|
||||||
@@ -119,13 +135,13 @@ def blocked_check():
|
|||||||
|
|
||||||
all_resolved = True
|
all_resolved = True
|
||||||
for blk in blocking_nums:
|
for blk in blocking_nums:
|
||||||
try:
|
blk_issue = _req_safe("GET", f"/issues/{blk}")
|
||||||
blk_issue = _req("GET", f"/issues/{blk}")
|
if blk_issue is None:
|
||||||
|
all_resolved = False # API error → keep blocked
|
||||||
|
break
|
||||||
if blk_issue.get("state") != "closed":
|
if blk_issue.get("state") != "closed":
|
||||||
all_resolved = False
|
all_resolved = False
|
||||||
break
|
break
|
||||||
except SystemExit:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if all_resolved:
|
if all_resolved:
|
||||||
current_label_names = [l["name"] for l in issue.get("labels", [])]
|
current_label_names = [l["name"] for l in issue.get("labels", [])]
|
||||||
@@ -172,6 +188,15 @@ def close_issue(num, body=None):
|
|||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
def reopen_issue(num, body=None):
|
||||||
|
"""Reopen a closed issue, optionally with a reason comment."""
|
||||||
|
if body:
|
||||||
|
comment_issue(num, f"## REOPEN\n\n{body}")
|
||||||
|
i = _req("PATCH", f"/issues/{num}", {"state": "open"})
|
||||||
|
print(f"Issue #{num} reopened")
|
||||||
|
return i
|
||||||
|
|
||||||
|
|
||||||
def _unblock_issues_blocked_by(closed_num):
|
def _unblock_issues_blocked_by(closed_num):
|
||||||
"""Check issues blocked by *closed_num* and unblock if all blockers resolved.
|
"""Check issues blocked by *closed_num* and unblock if all blockers resolved.
|
||||||
|
|
||||||
@@ -179,10 +204,7 @@ def _unblock_issues_blocked_by(closed_num):
|
|||||||
in any blocked issue and all referenced issues are now closed,
|
in any blocked issue and all referenced issues are now closed,
|
||||||
removes the 'blocked' label and comments on the unblocked issue.
|
removes the 'blocked' label and comments on the unblocked issue.
|
||||||
"""
|
"""
|
||||||
try:
|
all_blocked = _req_safe("GET", "/issues?state=open&labels=blocked")
|
||||||
all_blocked = _req("GET", "/issues?state=open&labels=blocked")
|
|
||||||
except SystemExit:
|
|
||||||
return
|
|
||||||
if not all_blocked:
|
if not all_blocked:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -196,13 +218,13 @@ def _unblock_issues_blocked_by(closed_num):
|
|||||||
for blk in blocking_nums:
|
for blk in blocking_nums:
|
||||||
if blk == closed_num:
|
if blk == closed_num:
|
||||||
continue
|
continue
|
||||||
try:
|
blk_issue = _req_safe("GET", f"/issues/{blk}")
|
||||||
blk_issue = _req("GET", f"/issues/{blk}")
|
if blk_issue is None:
|
||||||
|
all_resolved = False # API error → keep blocked
|
||||||
|
break
|
||||||
if blk_issue.get("state") != "closed":
|
if blk_issue.get("state") != "closed":
|
||||||
all_resolved = False
|
all_resolved = False
|
||||||
break
|
break
|
||||||
except SystemExit:
|
|
||||||
pass # Inaccessible → treat as resolved
|
|
||||||
|
|
||||||
if all_resolved:
|
if all_resolved:
|
||||||
current_label_names = [l["name"] for l in issue.get("labels", [])]
|
current_label_names = [l["name"] for l in issue.get("labels", [])]
|
||||||
@@ -369,7 +391,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", "reopen-issue",
|
||||||
|
"create-pr", "pr-status", "merge-pr", "lifecycle",
|
||||||
"blocked-check"])
|
"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)
|
||||||
@@ -407,6 +430,11 @@ def main():
|
|||||||
print("--title is required for 'create-issue' action", file=sys.stderr)
|
print("--title is required for 'create-issue' action", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
create_issue(args.title, args.body, args.labels)
|
create_issue(args.title, args.body, args.labels)
|
||||||
|
elif args.action == "reopen-issue":
|
||||||
|
if not args.issue:
|
||||||
|
print("--issue is required for 'reopen-issue' action", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
reopen_issue(args.issue, args.body)
|
||||||
elif args.action == "create-pr":
|
elif args.action == "create-pr":
|
||||||
if not args.issue or not args.branch:
|
if not args.issue or not args.branch:
|
||||||
print("--issue and --branch are required for 'create-pr' action", file=sys.stderr)
|
print("--issue and --branch are required for 'create-pr' action", file=sys.stderr)
|
||||||
|
|||||||
@@ -172,10 +172,9 @@ def _normalize_rule(rule: dict) -> dict:
|
|||||||
# Ensure table/text sources have a section field (defensive against LLM omission)
|
# Ensure table/text sources have a section field (defensive against LLM omission)
|
||||||
# Also normalize invalid source types (LLM hallucinations like function_unit_description)
|
# Also normalize invalid source types (LLM hallucinations like function_unit_description)
|
||||||
sources = rule.get("sources", [])
|
sources = rule.get("sources", [])
|
||||||
if sources:
|
|
||||||
valid_types = {"table", "text", "logic_tree"}
|
valid_types = {"table", "text", "logic_tree"}
|
||||||
|
|
||||||
# try to infer a default section from sibling sources or the rule path
|
# try to infer a default section from the rule path
|
||||||
default_section = ""
|
default_section = ""
|
||||||
for s in sources:
|
for s in sources:
|
||||||
sec = s.get("section", "")
|
sec = s.get("section", "")
|
||||||
@@ -187,15 +186,22 @@ def _normalize_rule(rule: dict) -> dict:
|
|||||||
if path:
|
if path:
|
||||||
default_section = path.split(" > ")[0] if " > " in path else path
|
default_section = path.split(" > ")[0] if " > " in path else path
|
||||||
|
|
||||||
|
if sources:
|
||||||
for src in sources:
|
for src in sources:
|
||||||
stype = src.get("type", "")
|
stype = src.get("type", "")
|
||||||
# Normalize invalid source types to "text"
|
|
||||||
if stype and stype not in valid_types:
|
if stype and stype not in valid_types:
|
||||||
src["type"] = "text"
|
src["type"] = "text"
|
||||||
stype = "text"
|
stype = "text"
|
||||||
if stype in ("table", "text"):
|
if stype in ("table", "text"):
|
||||||
if not src.get("section"):
|
if not src.get("section"):
|
||||||
src["section"] = default_section
|
src["section"] = default_section
|
||||||
|
else:
|
||||||
|
# Empty sources list — add a minimal text source (defensive against schema failure)
|
||||||
|
src = {"type": "text", "text_snippet": "inferred from rule context"}
|
||||||
|
if default_section:
|
||||||
|
src["section"] = default_section
|
||||||
|
sources.append(src)
|
||||||
|
rule["sources"] = sources
|
||||||
|
|
||||||
return rule
|
return rule
|
||||||
|
|
||||||
|
|||||||
@@ -526,3 +526,15 @@ class TestNormalizeRule:
|
|||||||
assert normalized["sources"][0]["type"] == "text"
|
assert normalized["sources"][0]["type"] == "text"
|
||||||
assert normalized["sources"][1]["type"] == "text"
|
assert normalized["sources"][1]["type"] == "text"
|
||||||
assert normalized["sources"][0]["section"] == "3.1 功能"
|
assert normalized["sources"][0]["section"] == "3.1 功能"
|
||||||
|
|
||||||
|
def test_normalize_empty_sources(self):
|
||||||
|
"""Rules with empty sources get a minimal text source (defensive)."""
|
||||||
|
rule = {
|
||||||
|
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
|
||||||
|
"path": "3.1 策略 > decision_speed",
|
||||||
|
"sources": [],
|
||||||
|
}
|
||||||
|
normalized = _normalize_rule(rule)
|
||||||
|
assert len(normalized["sources"]) == 1
|
||||||
|
assert normalized["sources"][0]["type"] == "text"
|
||||||
|
assert normalized["sources"][0]["section"] == "3.1 策略"
|
||||||
|
|||||||
@@ -140,9 +140,32 @@ def ir_path(request) -> str:
|
|||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def ir_data(ir_path: str) -> dict:
|
def ir_data(ir_path: str) -> dict:
|
||||||
"""Load the IR JSON data."""
|
"""Load the IR JSON data, normalizing each rule for defensive schema fixes."""
|
||||||
with open(ir_path, "r", encoding="utf-8") as f:
|
with open(ir_path, "r", encoding="utf-8") as f:
|
||||||
return json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
|
# Apply normalize to every rule so old IR files benefit from latest fixes
|
||||||
|
# (invalid source types, missing section fields, trigger nulls, etc.)
|
||||||
|
sys.path.insert(0, str(_PROJECT_ROOT / "skills" / "ir_generation_skill"))
|
||||||
|
from step3_merge_and_audit import _normalize_rule
|
||||||
|
rules = data.get("rules", [])
|
||||||
|
if rules:
|
||||||
|
normalized = []
|
||||||
|
for i, r in enumerate(rules):
|
||||||
|
if not isinstance(r, dict):
|
||||||
|
continue # Skip non-dict entries defensively
|
||||||
|
# Defensive: flatten list-type section fields (LLM produces these sometimes)
|
||||||
|
for src in r.get("sources", []):
|
||||||
|
sec = src.get("section")
|
||||||
|
if isinstance(sec, list):
|
||||||
|
src["section"] = sec[0] if sec else ""
|
||||||
|
try:
|
||||||
|
normalized.append(_normalize_rule(r))
|
||||||
|
except Exception:
|
||||||
|
normalized.append(r) # Fallback: use raw rule if normalize crashes
|
||||||
|
data["rules"] = normalized
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
|
|||||||
Reference in New Issue
Block a user