Skip to content

Commit 290f6d2

Browse files
committed
refactor(test): run_all 拆分 harness/subsets + CI coverage 报告
- tests/run_all.py 809→63 行:夹具抽 _harness.py(ok/skip/run_hook/ make_repo)、8 个回归子集抽 _subsets.py;CLI 签名与逐字节输出不变 (golden diff 验证,唯一差异为 tempfile 随机名 5 行;子集分解 25+29+23+11+12+8+35+1=144 吻合) - CI:unittest 由 coverage 包装 + advisory 覆盖率报告步(非门禁) - CHANGELOG.md 补 v0.15.4 段(0.15.3 为未发布中间 bump 态) - README 双语:parity 门禁 test_local_link_targets_exist 抓到 W3 归档 后的 verification.md 断链,已改指 archive 路径(双语同 commit) 验证:run_all 144/0/0 · parity 6/6 · openspec strict 18/18 · diff clean
1 parent b291a51 commit 290f6d2

7 files changed

Lines changed: 796 additions & 759 deletions

File tree

‎.github/workflows/skills-check.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ jobs:
2828
- name: Verify lockfile pins still match upstream refs and content
2929
run: python3 scripts/vendor/skill_vendor.py check
3030
- name: Exercise vendor and manifest behavior
31-
run: python3 -m unittest discover -s tests -p 'test_*.py' -v
31+
run: python3 -m pip install --disable-pip-version-check coverage && python3 -m coverage run -m unittest discover -s tests -p 'test_*.py' -v
32+
- name: Coverage report (advisory, non-gating)
33+
run: python3 -m coverage report --include='scripts/**,hooks/**' --skip-empty
3234
- name: Validate languages.json schema
3335
run: python3 scripts/validate_languages_json.py
3436
- name: Run plugin regression suite

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
## v0.15.x — Git 归因收敛与诊断安全
66

7+
- **v0.15.4** 测试卫生与可见性(0.15.3 为未发布的中间 bump 态,不对外):`tests/run_all.py`(809 行)拆分为
8+
`_harness.py`(共享夹具)+ `_subsets.py`(8 个回归子集),入口签名与
9+
逐字节输出保持不变(golden diff 验证);CI 单测改由 coverage 包装并
10+
追加 advisory 覆盖率报告(非门禁)。
711
- **v0.15.2** 发版链 fail-loud(bump 漂移即抛错);非 Shell 间接 git 归因收紧;`hook-protocol` 归因 delta 并入主规格。
812
- **v0.15.1** 诊断日志改为私有原子落盘;准确 Git 快照的 index 与 HEAD 身份复核。
913
- **v0.15.0** 点前缀目录与文件默认忽略(代码 + 提示词双层硬约束)。

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ ruff check hooks scripts tests
146146

147147
Tests include real temporary Git repositories, native subprocess fixtures and official-SDK stdio MCP calls. Fixture wrapper success is not a real Maven/Gradle integration build. Live Codex/ZCode/Kimi loading, real project builds, online CVE scanner runs and precision/recall benchmarks require separate acceptance.
148148

149-
Current implementation and evidence: [architecture and extension guide](docs/current-architecture.md), [refactor verification](openspec/changes/refactor-codeguard-architecture/verification.md). Earlier documents remain historical context: [verdict and Java architecture](docs/verdict-java-architecture.md), [prior verification](docs/verification-verdict-java.md), [original architecture](docs/partme-codeguard-plugin-Architecture.zh_CN.md), [roadmap](docs/technical-roadmap.zh_CN.md).
149+
Current implementation and evidence: [architecture and extension guide](docs/current-architecture.md), [refactor verification](openspec/changes/archive/2026-09-23-refactor-codeguard-architecture/verification.md). Earlier documents remain historical context: [verdict and Java architecture](docs/verdict-java-architecture.md), [prior verification](docs/verification-verdict-java.md), [original architecture](docs/partme-codeguard-plugin-Architecture.zh_CN.md), [roadmap](docs/technical-roadmap.zh_CN.md).
150150

151151
Version history: see [CHANGELOG.md](CHANGELOG.md) for release highlights by version.
152152

‎README.zh-CN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ ruff check hooks scripts tests
146146

147147
测试包含真实临时 Git 仓库、原生子进程 fixture 与官方 SDK stdio MCP 调用。fixture wrapper 成功不是真实 Maven/Gradle 集成构建。Codex/ZCode/Kimi 当前版本加载、真实项目构建、在线漏洞扫描与准确率/召回率基准仍需独立验收。
148148

149-
当前实现与证据:[架构及扩展指南](docs/current-architecture.md)、[重构验证记录](openspec/changes/refactor-codeguard-architecture/verification.md)。旧文档保留为历史参考:[判定与 Java 架构](docs/verdict-java-architecture.md)、[此前验证报告](docs/verification-verdict-java.md)、[原架构](docs/partme-codeguard-plugin-Architecture.zh_CN.md)、[路线图](docs/technical-roadmap.zh_CN.md)。
149+
当前实现与证据:[架构及扩展指南](docs/current-architecture.md)、[重构验证记录](openspec/changes/archive/2026-09-23-refactor-codeguard-architecture/verification.md)。旧文档保留为历史参考:[判定与 Java 架构](docs/verdict-java-architecture.md)、[此前验证报告](docs/verification-verdict-java.md)、[原架构](docs/partme-codeguard-plugin-Architecture.zh_CN.md)、[路线图](docs/technical-roadmap.zh_CN.md)。
150150

151151
版本历史见 [CHANGELOG.md](CHANGELOG.md)(按版本段落的主题摘要)。
152152

‎tests/_harness.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""tests/_harness.py:run_all 回归集共享夹具(ok/skip 收集、宿主协议钩子触发、临时 git 仓)。"""
2+
from __future__ import annotations
3+
4+
import json
5+
import os
6+
import subprocess
7+
import sys
8+
import tempfile
9+
from pathlib import Path
10+
11+
PLUGIN = Path(__file__).resolve().parents[1]
12+
HOOKS = PLUGIN / "hooks"
13+
sys.path.insert(0, str(PLUGIN / "scripts"))
14+
sys.path.insert(0, str(HOOKS))
15+
16+
PASS, FAIL, SKIP = [], [], []
17+
18+
19+
def ok(name, cond, note=""):
20+
(PASS if cond else FAIL).append(name)
21+
print(f" {'✅' if cond else '❌'} {name}" + (f" — {note}" if note and not cond else ""))
22+
23+
24+
def skip(name, why):
25+
SKIP.append(name)
26+
print(f" ⏭️ {name} — {why}")
27+
28+
29+
def run_hook(script: str, payload: dict | None, cwd: Path, env_extra: dict | None = None):
30+
"""按宿主协议触发钩子:stdin JSON → (exit, stdout, stderr)"""
31+
env = {**os.environ, "PYTHONIOENCODING": "utf-8", **(env_extra or {})}
32+
return subprocess.run(
33+
[sys.executable, str(HOOKS / script)],
34+
input=json.dumps(payload) if payload is not None else "",
35+
capture_output=True, check=False, text=True, cwd=cwd, timeout=120, env=env,
36+
)
37+
38+
39+
def git(repo: Path, *args: str):
40+
return subprocess.run(["git", *args], cwd=repo, capture_output=True, check=False, text=True)
41+
42+
43+
def make_repo() -> Path:
44+
"""临时 git 仓(含一个必被 shellcheck 抓到的坏脚本)"""
45+
repo = Path(tempfile.mkdtemp(prefix="cg-test-"))
46+
git(repo, "init", "-q")
47+
git(repo, "config", "user.email", "t@t")
48+
git(repo, "config", "user.name", "t")
49+
(repo / "scripts").mkdir()
50+
(repo / "scripts" / "deploy.sh").write_text(
51+
'#!/bin/bash\nif [ $foo = bar ]; then echo hi; fi\n'
52+
)
53+
git(repo, "add", "-A")
54+
git(repo, "commit", "-q", "-m", "init")
55+
return repo

0 commit comments

Comments
 (0)