dsh-project-dept 1.0.1 → 1.0.2
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/package.json +1 -1
- package/skills/project-dept/README.md +366 -8
- package/skills/project-dept/README_EN.md +436 -7
- package/skills/project-dept/SKILL.md +10 -21
- package/skills/project-dept/evals/evals.json +252 -7
- package/skills/project-dept/manifest.yaml +29 -3
- package/skills/project-dept/references/blind-review.md +35 -0
- package/skills/project-dept/references/project-scaffold.md +10 -4
- package/skills/project-dept/scripts/check_review_form.py +649 -0
- package/skills/project-dept/scripts/check_skill.py +943 -0
- package/skills/project-dept/scripts/dept_gate.py +90 -7
- package/skills/project-dept/scripts/run_evals.py +1344 -0
- package/skills/project-dept/static/core/output-contract.md +7 -1
- package/skills/project-dept/static/core/workflow.md +3 -2
- package/skills/project-dept/tests/test_check_review_form.py +453 -0
- package/skills/project-dept/tests/test_check_skill.py +620 -0
- package/skills/project-dept/tests/test_dept_gate_baseline.py +229 -0
- package/skills/project-dept/tests/test_dept_gate_json.py +116 -0
- package/skills/project-dept/tests/test_run_evals.py +644 -0
- package/tests/bundle.test.js +6 -3
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""v1.3.5 P-15-9:基准作废必须有变更记录(dept_gate 7b)。
|
|
3
|
+
|
|
4
|
+
判据要挂在强制产出物上,否则 agent 拿到全文也不执行(v1.3.0 A/B 实测)。
|
|
5
|
+
这组用例把「作废行 + 缺记录 ⇒ 阻断」钉死;同时保证「没作废行时不误伤」。
|
|
6
|
+
"""
|
|
7
|
+
import io
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import shutil
|
|
11
|
+
import sys
|
|
12
|
+
import tempfile
|
|
13
|
+
import unittest
|
|
14
|
+
|
|
15
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
16
|
+
SKILL_ROOT = os.path.dirname(HERE)
|
|
17
|
+
sys.path.insert(0, os.path.join(SKILL_ROOT, "scripts"))
|
|
18
|
+
|
|
19
|
+
import dept_gate # noqa: E402
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def build_project(root, baseline_lines, changelog_text=None, config_extra=None):
|
|
23
|
+
"""搭一个能被闸门跑通的最小项目;返回 None。"""
|
|
24
|
+
ledger = os.path.join(root, "_team")
|
|
25
|
+
os.makedirs(os.path.join(ledger, "岗位"), exist_ok=True)
|
|
26
|
+
os.makedirs(os.path.join(ledger, "out"), exist_ok=True)
|
|
27
|
+
|
|
28
|
+
board = [
|
|
29
|
+
"# 看板",
|
|
30
|
+
"",
|
|
31
|
+
"## 当前板块",
|
|
32
|
+
"板块 1(进行中)",
|
|
33
|
+
"",
|
|
34
|
+
"## 未完成事项(债务账本)",
|
|
35
|
+
"- [x] D1 已处置",
|
|
36
|
+
"",
|
|
37
|
+
"## 方向复盘(pre-mortem)",
|
|
38
|
+
"1. 若结论错,最可能错在方法层:已填",
|
|
39
|
+
"",
|
|
40
|
+
]
|
|
41
|
+
io.open(os.path.join(ledger, "看板.md"), "w", encoding="utf-8",
|
|
42
|
+
newline="\n").write("\n".join(board))
|
|
43
|
+
io.open(os.path.join(ledger, "工作流.md"), "w", encoding="utf-8",
|
|
44
|
+
newline="\n").write("# 工作流\n\nStep 0 gate, then Steps 1-6\n")
|
|
45
|
+
io.open(os.path.join(ledger, "交付登记簿.md"), "w", encoding="utf-8",
|
|
46
|
+
newline="\n").write("# 交付登记簿\n\n| 日期 | 板块 | 结论 |\n|---|---|---|\n"
|
|
47
|
+
"| 2026-11-25 | 板块 1 | 通过 |\n")
|
|
48
|
+
io.open(os.path.join(ledger, "基准清单.md"), "w", encoding="utf-8",
|
|
49
|
+
newline="\n").write("# 基准清单\n\n" + "\n".join(baseline_lines) + "\n")
|
|
50
|
+
for role in ("lead", "geom", "sim", "write", "audit", "reviewer"):
|
|
51
|
+
io.open(os.path.join(ledger, "岗位", role + ".md"), "w", encoding="utf-8",
|
|
52
|
+
newline="\n").write("# %s\n" % role)
|
|
53
|
+
if changelog_text is not None:
|
|
54
|
+
io.open(os.path.join(ledger, "基准变更记录.md"), "w", encoding="utf-8",
|
|
55
|
+
newline="\n").write(changelog_text)
|
|
56
|
+
|
|
57
|
+
config = {
|
|
58
|
+
"project_name": os.path.basename(root),
|
|
59
|
+
"ledger_dir": "_team",
|
|
60
|
+
"board_file": "看板.md",
|
|
61
|
+
"flow_file": "工作流.md",
|
|
62
|
+
"register_file": "交付登记簿.md",
|
|
63
|
+
"baseline_file": "基准清单.md",
|
|
64
|
+
"role_dir": "岗位",
|
|
65
|
+
"artefact_dir": "out",
|
|
66
|
+
"required_roles": ["lead", "geom", "sim", "write", "audit", "reviewer"],
|
|
67
|
+
}
|
|
68
|
+
if config_extra:
|
|
69
|
+
config.update(config_extra)
|
|
70
|
+
io.open(os.path.join(root, "dept.config.json"), "w", encoding="utf-8",
|
|
71
|
+
newline="\n").write(json.dumps(config, ensure_ascii=False, indent=2) + "\n")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def run_gate(root):
|
|
75
|
+
"""跑闸门,返回 (exit_code, stdout)。"""
|
|
76
|
+
buf = io.StringIO()
|
|
77
|
+
old = sys.stdout
|
|
78
|
+
try:
|
|
79
|
+
sys.stdout = buf
|
|
80
|
+
code = dept_gate.main(["--root", root])
|
|
81
|
+
finally:
|
|
82
|
+
sys.stdout = old
|
|
83
|
+
return code, buf.getvalue()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class TestBaselineChangelogGate(unittest.TestCase):
|
|
87
|
+
"""作废行必须有变更记录,否则结构性阻断。"""
|
|
88
|
+
|
|
89
|
+
def setUp(self):
|
|
90
|
+
self.root = tempfile.mkdtemp(prefix="gate7b_")
|
|
91
|
+
self.addCleanup(shutil.rmtree, self.root, True)
|
|
92
|
+
|
|
93
|
+
def test_retired_row_without_changelog_blocks(self):
|
|
94
|
+
build_project(
|
|
95
|
+
self.root,
|
|
96
|
+
baseline_lines=["| B1 | 相关长度 | [已作废] 旧值 0.896 |", "| B2 | CFL | 0.25 |"],
|
|
97
|
+
changelog_text=None,
|
|
98
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
99
|
+
)
|
|
100
|
+
code, out = run_gate(self.root)
|
|
101
|
+
self.assertEqual(code, dept_gate.EXIT_BLOCKED, out)
|
|
102
|
+
self.assertIn("基准变更记录.md", out)
|
|
103
|
+
self.assertIn("已作废", out)
|
|
104
|
+
|
|
105
|
+
def test_retired_row_with_empty_changelog_blocks(self):
|
|
106
|
+
build_project(
|
|
107
|
+
self.root,
|
|
108
|
+
baseline_lines=["| B1 | 相关长度 | [superseded] 旧值 0.896 |"],
|
|
109
|
+
changelog_text="# 基准变更记录\n\n## B-01\n",
|
|
110
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
111
|
+
)
|
|
112
|
+
code, out = run_gate(self.root)
|
|
113
|
+
self.assertEqual(code, dept_gate.EXIT_BLOCKED, out)
|
|
114
|
+
|
|
115
|
+
def test_retired_row_with_changelog_passes(self):
|
|
116
|
+
build_project(
|
|
117
|
+
self.root,
|
|
118
|
+
baseline_lines=["| B1 | 相关长度 | [已作废] 旧值 0.896 |"],
|
|
119
|
+
changelog_text=(
|
|
120
|
+
"# 基准变更记录\n\n## B-01 相关长度\n\n- 旧值:0.896\n"
|
|
121
|
+
"- 新值:按 acf_integral 口径复现 0.8958643\n- superseded_by:基准清单:112-128\n"
|
|
122
|
+
"- 下游影响:第 3 章补口径\n- 重跑状态:不重跑\n"),
|
|
123
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
124
|
+
)
|
|
125
|
+
code, out = run_gate(self.root)
|
|
126
|
+
self.assertEqual(code, dept_gate.EXIT_PASS, out)
|
|
127
|
+
self.assertIn("基准变更记录", out)
|
|
128
|
+
|
|
129
|
+
def test_short_but_complete_record_passes(self):
|
|
130
|
+
"""v1.3.6:不许再用未声明的长度阈值 —— 38 字的完整记录也算有记录。"""
|
|
131
|
+
build_project(
|
|
132
|
+
self.root,
|
|
133
|
+
baseline_lines=["| B1 | 相关长度 | [已作废] 0.896 |"],
|
|
134
|
+
# 全文含标题只有 ~32 字符:只为证明「非空即算有记录」,撞不出任何长度阈值
|
|
135
|
+
changelog_text="# 基准变更记录\n- 旧值 0.896 → 0.8958643\n",
|
|
136
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
137
|
+
)
|
|
138
|
+
code, out = run_gate(self.root)
|
|
139
|
+
self.assertEqual(code, dept_gate.EXIT_PASS, out)
|
|
140
|
+
self.assertIn("基准变更记录", out)
|
|
141
|
+
|
|
142
|
+
def test_uppercase_superseded_marker_is_detected(self):
|
|
143
|
+
"""v1.3.6:行首 [Superseded] 的大小写变体也要拦(表格路径本来就大小写不敏感)。"""
|
|
144
|
+
build_project(
|
|
145
|
+
self.root,
|
|
146
|
+
baseline_lines=["[Superseded] 旧口径 CFL 0.32", "| B2 | CFL | 0.25 |"],
|
|
147
|
+
changelog_text=None,
|
|
148
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
149
|
+
)
|
|
150
|
+
code, out = run_gate(self.root)
|
|
151
|
+
self.assertEqual(code, dept_gate.EXIT_BLOCKED, out)
|
|
152
|
+
self.assertIn("已作废", out)
|
|
153
|
+
|
|
154
|
+
def test_retired_row_without_config_key_blocks(self):
|
|
155
|
+
"""v1.3.6:有作废行但没配 baseline_changelog 不能只告警 —— 否则这条规矩可绕过。"""
|
|
156
|
+
build_project(
|
|
157
|
+
self.root,
|
|
158
|
+
baseline_lines=["| B1 | 相关长度 | [已作废] 0.896 |"],
|
|
159
|
+
changelog_text="# 基准变更记录\n\n- 旧值 0.896 → 新值 0.8958643\n",
|
|
160
|
+
config_extra={},
|
|
161
|
+
)
|
|
162
|
+
code, out = run_gate(self.root)
|
|
163
|
+
self.assertEqual(code, dept_gate.EXIT_BLOCKED, out)
|
|
164
|
+
self.assertIn("baseline_changelog", out)
|
|
165
|
+
|
|
166
|
+
def test_no_retired_rows_does_not_require_changelog(self):
|
|
167
|
+
build_project(
|
|
168
|
+
self.root,
|
|
169
|
+
baseline_lines=["| B1 | 相关长度 | 0.8958643 |"],
|
|
170
|
+
changelog_text=None,
|
|
171
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
172
|
+
)
|
|
173
|
+
code, out = run_gate(self.root)
|
|
174
|
+
self.assertEqual(code, dept_gate.EXIT_PASS, out)
|
|
175
|
+
self.assertNotIn("基准变更记录", out)
|
|
176
|
+
|
|
177
|
+
def test_marker_in_table_cell_without_leading_pipe_is_detected(self):
|
|
178
|
+
"""v1.3.7:合法表格行没有首竖线(B2 | ... | [已作废] |)也必须被拦。"""
|
|
179
|
+
build_project(
|
|
180
|
+
self.root,
|
|
181
|
+
baseline_lines=["| ID | 名称 | 状态 |",
|
|
182
|
+
"B2 | 相关长度 | [已作废] |"],
|
|
183
|
+
# 配了键但文件不存在:只有「真的认出了这行标记」才会阻断;认不出就会 exit 0
|
|
184
|
+
changelog_text=None,
|
|
185
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
186
|
+
)
|
|
187
|
+
code, out = run_gate(self.root)
|
|
188
|
+
self.assertEqual(code, dept_gate.EXIT_BLOCKED, out)
|
|
189
|
+
|
|
190
|
+
def test_marker_in_bullet_is_detected(self):
|
|
191
|
+
"""v1.3.7:`- [superseded]` 这种列表形态也要拦。"""
|
|
192
|
+
build_project(
|
|
193
|
+
self.root,
|
|
194
|
+
baseline_lines=["- [superseded] CFL 0.32", "| B2 | CFL | 0.25 |"],
|
|
195
|
+
changelog_text=None,
|
|
196
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
197
|
+
)
|
|
198
|
+
code, out = run_gate(self.root)
|
|
199
|
+
self.assertEqual(code, dept_gate.EXIT_BLOCKED, out)
|
|
200
|
+
|
|
201
|
+
def test_marker_in_ordered_list_is_detected(self):
|
|
202
|
+
"""v1.3.7:`1. [已作废]` 这种有序列表形态也要拦。"""
|
|
203
|
+
build_project(
|
|
204
|
+
self.root,
|
|
205
|
+
baseline_lines=["1. [已作废] 长宽比 14.2", "| B2 | CFL | 0.25 |"],
|
|
206
|
+
changelog_text=None,
|
|
207
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
208
|
+
)
|
|
209
|
+
code, out = run_gate(self.root)
|
|
210
|
+
self.assertEqual(code, dept_gate.EXIT_BLOCKED, out)
|
|
211
|
+
|
|
212
|
+
def test_marker_with_inner_spaces_is_detected(self):
|
|
213
|
+
"""v1.3.8:方括号内含空白(含全角空格)也是合法写法,必须拦。"""
|
|
214
|
+
for raw in ("[ 已作废 ] 旧值 0.896", "[superseded ] CFL 0.32", "[\u3000superseded\u3000] 长宽比 14.2"):
|
|
215
|
+
with self.subTest(marker=raw):
|
|
216
|
+
root = tempfile.mkdtemp(prefix="gate8_")
|
|
217
|
+
self.addCleanup(shutil.rmtree, root, True)
|
|
218
|
+
build_project(
|
|
219
|
+
root,
|
|
220
|
+
baseline_lines=["| B2 | CFL | 0.25 |", raw],
|
|
221
|
+
changelog_text=None,
|
|
222
|
+
config_extra={"baseline_changelog": "基准变更记录.md"},
|
|
223
|
+
)
|
|
224
|
+
code, out = run_gate(root)
|
|
225
|
+
self.assertEqual(code, dept_gate.EXIT_BLOCKED, out)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
if __name__ == "__main__":
|
|
229
|
+
unittest.main(verbosity=2)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""tests/test_dept_gate_json.py — dept_gate.py 的 --json 输出契约。
|
|
3
|
+
|
|
4
|
+
回归点:v1.1.0 的 --json 把 `[anchor]` 行、分隔线、人类可读结论一起打到 stdout,
|
|
5
|
+
只有最后一行能解析;复核脚本只能靠「取末行」,很脆。v1.1.1 起 `--json` 的 stdout
|
|
6
|
+
必须是**纯 JSON**(整段可直接 json.loads)。
|
|
7
|
+
|
|
8
|
+
运行:
|
|
9
|
+
python -m unittest tests.test_dept_gate_json -v
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
import tempfile
|
|
18
|
+
import unittest
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
PKG_ROOT = Path(__file__).resolve().parents[1]
|
|
22
|
+
GATE = PKG_ROOT / "scripts" / "dept_gate.py"
|
|
23
|
+
|
|
24
|
+
CONFIG = """{
|
|
25
|
+
"project_name": "gate-json-fixture",
|
|
26
|
+
"ledger_dir": "_team",
|
|
27
|
+
"board_file": "看板.md",
|
|
28
|
+
"flow_file": "工作流.md",
|
|
29
|
+
"register_file": "交付登记簿.md",
|
|
30
|
+
"baseline_file": "基准清单.md",
|
|
31
|
+
"role_dir": "岗位",
|
|
32
|
+
"required_roles": ["lead", "audit", "reviewer"],
|
|
33
|
+
"artefact_dir": "out",
|
|
34
|
+
"scratch_patterns": ["probe_*"]
|
|
35
|
+
}
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
BOARD = """# 看板
|
|
39
|
+
|
|
40
|
+
## 当前板块
|
|
41
|
+
|
|
42
|
+
板块 9「gate json 夹具」。
|
|
43
|
+
|
|
44
|
+
## 未完成事项(债务账本)
|
|
45
|
+
|
|
46
|
+
- [x] **D1** 夹具里的已完成债
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def write(p: Path, text: str) -> None:
|
|
51
|
+
p.parent.mkdir(parents=True, exist_ok=True)
|
|
52
|
+
p.write_text(text, encoding="utf-8")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def make_project(base: Path) -> Path:
|
|
56
|
+
root = base / "gate-json-fixture"
|
|
57
|
+
root.mkdir(parents=True)
|
|
58
|
+
write(root / "dept.config.json", CONFIG)
|
|
59
|
+
team = root / "_team"
|
|
60
|
+
write(team / "看板.md", BOARD)
|
|
61
|
+
write(team / "工作流.md", "# 工作流\n\n夹具。\n")
|
|
62
|
+
write(team / "交付登记簿.md", "# 交付登记簿\n\n| 日期 | 结论 |\n|---|---|\n")
|
|
63
|
+
write(team / "基准清单.md", "# 基准清单\n\n| # | 说法 | 出处 | 等级 |\n|---|---|---|---|\n")
|
|
64
|
+
for role in ("lead", "audit", "reviewer"):
|
|
65
|
+
write(team / "岗位" / f"{role}.md", f"# {role}\n\n夹具岗位卡。\n")
|
|
66
|
+
(team / "out").mkdir(parents=True, exist_ok=True)
|
|
67
|
+
return root
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def run_gate(*args):
|
|
71
|
+
env = dict(os.environ)
|
|
72
|
+
env["PYTHONIOENCODING"] = "utf-8"
|
|
73
|
+
env["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
74
|
+
return subprocess.run(
|
|
75
|
+
[sys.executable, str(GATE), *map(str, args)],
|
|
76
|
+
capture_output=True, text=True, encoding="utf-8", errors="replace", env=env,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class TestDeptGateJson(unittest.TestCase):
|
|
81
|
+
def setUp(self):
|
|
82
|
+
self._tmp = tempfile.TemporaryDirectory()
|
|
83
|
+
self.tmp = Path(self._tmp.name)
|
|
84
|
+
self.root = make_project(self.tmp)
|
|
85
|
+
|
|
86
|
+
def tearDown(self):
|
|
87
|
+
self._tmp.cleanup()
|
|
88
|
+
|
|
89
|
+
def test_json_stdout_is_pure_json(self):
|
|
90
|
+
proc = run_gate("--root", self.root, "--json")
|
|
91
|
+
# 整段 stdout 必须能解析(旧版会因为前面有 [anchor]/分隔线而失败)
|
|
92
|
+
try:
|
|
93
|
+
data = json.loads(proc.stdout)
|
|
94
|
+
except json.JSONDecodeError as exc: # pragma: no cover - 失败即回归
|
|
95
|
+
self.fail("--json 的 stdout 不是纯 JSON:%s\n前 200 字符:%r" % (exc, proc.stdout[:200]))
|
|
96
|
+
self.assertIn("anchor", data)
|
|
97
|
+
self.assertIn("code", data)
|
|
98
|
+
self.assertIn("warnings_list", data)
|
|
99
|
+
self.assertIn("violations_list", data)
|
|
100
|
+
self.assertEqual(data["code"], proc.returncode)
|
|
101
|
+
|
|
102
|
+
def test_anchor_has_five_fields(self):
|
|
103
|
+
proc = run_gate("--root", self.root, "--json")
|
|
104
|
+
data = json.loads(proc.stdout)
|
|
105
|
+
parts = data["anchor"].split()
|
|
106
|
+
self.assertEqual(len(parts), 5, parts)
|
|
107
|
+
self.assertTrue(parts[0].startswith("config="), parts)
|
|
108
|
+
|
|
109
|
+
def test_human_mode_still_prints_anchor(self):
|
|
110
|
+
proc = run_gate("--root", self.root)
|
|
111
|
+
self.assertIn("[anchor]", proc.stdout)
|
|
112
|
+
self.assertIn("结论:", proc.stdout)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if __name__ == "__main__":
|
|
116
|
+
unittest.main()
|