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
|
@@ -56,6 +56,12 @@ Block the hand-over when:
|
|
|
56
56
|
- author-stated limitations and reviewer criticism are mixed into one undifferentiated block;
|
|
57
57
|
- an `[Own]` value is presented as if it were `[Origin]`;
|
|
58
58
|
- content was invented to fill a slot;
|
|
59
|
-
- the declared acceptance standard was silently changed during the work
|
|
59
|
+
- the declared acceptance standard was silently changed during the work;
|
|
60
|
+
- a baseline, metric, or definition was retired or replaced, but the delivered package
|
|
61
|
+
has no **baseline changelog table** (old value, new value or reason, `superseded_by`,
|
|
62
|
+
which downstream results were re-run, and what remains un-re-run). Rule retrofitted into
|
|
63
|
+
the deliverable itself, not into a reference page: a rule that lives only in a reference
|
|
64
|
+
does not get executed (measured: v1.3.0 eval A/B, `baseline-is-wrong` rubric item on
|
|
65
|
+
retiring a wrong baseline scored 2/10 for the arm holding the full text).
|
|
60
66
|
|
|
61
67
|
If a blocker cannot be resolved, downgrade to `部分` and name the exact gap. A failing tool run blocks delivery; a passing tool run does **not** prove correctness.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# The
|
|
1
|
+
# The run flow: Step 0 gate, then Steps 1-6
|
|
2
2
|
|
|
3
|
-
The Lead runs
|
|
3
|
+
The Lead runs this flow: a gate (Step 0) and then six steps. Steps 0 and 1 happen before any work is started by anyone.
|
|
4
4
|
|
|
5
5
|
## Step 0 — Run the gate
|
|
6
6
|
|
|
@@ -85,6 +85,7 @@ Deliver → L1 self-check → L2 independent review → L3 final judgement → c
|
|
|
85
85
|
- Record the result in the delivery register (date, package, artefact, acceptance verdict, evidence path).
|
|
86
86
|
- Update the board: package status, debts found, frozen list.
|
|
87
87
|
- Fill the direction pre-mortem three questions (see `references/self-skepticism.md`).
|
|
88
|
+
- Reconcile the baseline changelog: every baseline retired or replaced during this package must have a row (old → new or reason, `superseded_by`, downstream re-runs, what stays un-re-run). A rule that lives only in a reference page does not get executed — measured in the v1.3.0 A/B: the arm holding the full text still scored 2/10 on retiring a wrong baseline, because nothing forced an artefact for it.
|
|
88
89
|
- Only then open the next package.
|
|
89
90
|
|
|
90
91
|
Closing does not mean "verified" if anything was waived — write `未验收(存档)` in the first line of the record when a package is closed for bookkeeping reasons only.
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""tests/test_check_review_form.py — scripts/check_review_form.py 的单元测试。
|
|
3
|
+
|
|
4
|
+
标准库 only(unittest + subprocess + tempfile),不依赖项目夹具。
|
|
5
|
+
每个用例都用 tempfile 现造一份复核单文本,再跑真实 CLI,断言退出码与文案;
|
|
6
|
+
这样「把任何一条规则回退」都会让对应用例失败。
|
|
7
|
+
|
|
8
|
+
Run:
|
|
9
|
+
python -m unittest discover -s tests -v
|
|
10
|
+
"""
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import subprocess
|
|
14
|
+
import sys
|
|
15
|
+
import tempfile
|
|
16
|
+
import unittest
|
|
17
|
+
|
|
18
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
19
|
+
SKILL_ROOT = os.path.dirname(HERE)
|
|
20
|
+
CHECKER = os.path.join(SKILL_ROOT, "scripts", "check_review_form.py")
|
|
21
|
+
PYTHON = sys.executable
|
|
22
|
+
|
|
23
|
+
for stream in (sys.stdout, sys.stderr):
|
|
24
|
+
try:
|
|
25
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
26
|
+
except Exception: # noqa: BLE001
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
DEF_START = "HASH aaaaaaaaaaaa FILES 30 ROOT /tmp/demo"
|
|
30
|
+
DEF_END = "HASH aaaaaaaaaaaa FILES 30 ROOT /tmp/demo"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def build_form(
|
|
34
|
+
snap_start=DEF_START,
|
|
35
|
+
snap_end=DEF_END,
|
|
36
|
+
conclusion="- 两次是否一致:一致(整个复核期包未被改动)",
|
|
37
|
+
verdict="通过但要修",
|
|
38
|
+
verdict_block=None,
|
|
39
|
+
section1_title="## 1. 我的独立结论(在打开作者自检之前完成)",
|
|
40
|
+
with_section2=True,
|
|
41
|
+
evidence_rows=True,
|
|
42
|
+
problem_rows=True,
|
|
43
|
+
extra_problem_row="",
|
|
44
|
+
section2_extra="",
|
|
45
|
+
independence_sentence=True,
|
|
46
|
+
evidence_row_count=2,
|
|
47
|
+
):
|
|
48
|
+
"""造一份结构完整的复核单;各参数用来定点破坏某一条规则。"""
|
|
49
|
+
lines = ["# 复核单 `demo`(盲审)", "", "## 0. 我看了什么", ""]
|
|
50
|
+
lines.append("- 盲审包:`_team/review/blind/demo/`")
|
|
51
|
+
if snap_start:
|
|
52
|
+
lines.append(snap_start)
|
|
53
|
+
if snap_end:
|
|
54
|
+
lines.append(snap_end)
|
|
55
|
+
if conclusion:
|
|
56
|
+
lines.append(conclusion)
|
|
57
|
+
|
|
58
|
+
lines += ["", section1_title, ""]
|
|
59
|
+
if verdict_block is not None:
|
|
60
|
+
lines += list(verdict_block)
|
|
61
|
+
else:
|
|
62
|
+
lines.append("- **判定**:%s" % verdict)
|
|
63
|
+
|
|
64
|
+
lines += ["", "- 我独立做了什么(带命令):", ""]
|
|
65
|
+
lines += ["| # | 我重算/重跑/重查了什么 | 方法或命令 | 结果 |", "|---|---|---|---|"]
|
|
66
|
+
if evidence_rows:
|
|
67
|
+
rows = [
|
|
68
|
+
"| 1 | 重跑检查器 | `python scripts/check_skill.py --root .` | exit 1 |",
|
|
69
|
+
"| 2 | 核产物 sha256 | `sha256sum 产物.py` | 与快照一致 |",
|
|
70
|
+
]
|
|
71
|
+
lines += rows[:max(1, evidence_row_count)]
|
|
72
|
+
|
|
73
|
+
lines += ["", "- **发现的问题**:", ""]
|
|
74
|
+
if problem_rows:
|
|
75
|
+
lines += [
|
|
76
|
+
"| # | 位置(文件:行/节) | 问题 | 为什么是问题(证据) | 严重度 |",
|
|
77
|
+
"|---|---|---|---|---|",
|
|
78
|
+
"| 1 | 结果表第 2 行 | 条件写反 | 复跑后输出与预期不符 | 重要 |",
|
|
79
|
+
]
|
|
80
|
+
if extra_problem_row:
|
|
81
|
+
lines.append(extra_problem_row)
|
|
82
|
+
|
|
83
|
+
if with_section2:
|
|
84
|
+
lines += ["", "## 2. 对照作者自检(判完之后才写)", ""]
|
|
85
|
+
if independence_sentence:
|
|
86
|
+
lines.append(
|
|
87
|
+
"- 独立性:§1 的独立结论写完之后,我才打开作者自检文件对照。"
|
|
88
|
+
)
|
|
89
|
+
lines.append("- 作者声称做过的,我验证的结果:一致")
|
|
90
|
+
|
|
91
|
+
if section2_extra:
|
|
92
|
+
lines += ["", section2_extra]
|
|
93
|
+
return "\n".join(lines) + "\n"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class ReviewFormCheckerTest(unittest.TestCase):
|
|
97
|
+
def setUp(self):
|
|
98
|
+
self._tmpdir = tempfile.mkdtemp(prefix="review_form_")
|
|
99
|
+
|
|
100
|
+
def tearDown(self):
|
|
101
|
+
for name in os.listdir(self._tmpdir):
|
|
102
|
+
try:
|
|
103
|
+
os.unlink(os.path.join(self._tmpdir, name))
|
|
104
|
+
except OSError: # pragma: no cover - 极端清理失败不掩盖测试结果
|
|
105
|
+
pass
|
|
106
|
+
try:
|
|
107
|
+
os.rmdir(self._tmpdir)
|
|
108
|
+
except OSError: # pragma: no cover
|
|
109
|
+
pass
|
|
110
|
+
|
|
111
|
+
# ---------------------------------------------------------------- 辅助
|
|
112
|
+
|
|
113
|
+
def make_file(self, text, name="复核单.md"):
|
|
114
|
+
path = os.path.join(self._tmpdir, name)
|
|
115
|
+
with open(path, "w", encoding="utf-8", newline="\n") as f:
|
|
116
|
+
f.write(text)
|
|
117
|
+
return path
|
|
118
|
+
|
|
119
|
+
def run_cli(self, path, json_mode=False):
|
|
120
|
+
cmd = [PYTHON, CHECKER, path]
|
|
121
|
+
if json_mode:
|
|
122
|
+
cmd.append("--json")
|
|
123
|
+
env = dict(os.environ)
|
|
124
|
+
env["PYTHONIOENCODING"] = "utf-8"
|
|
125
|
+
return subprocess.run(
|
|
126
|
+
cmd,
|
|
127
|
+
capture_output=True,
|
|
128
|
+
text=True,
|
|
129
|
+
encoding="utf-8",
|
|
130
|
+
errors="replace",
|
|
131
|
+
env=env,
|
|
132
|
+
timeout=120,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# ---------------------------------------------------------------- 1 合格
|
|
136
|
+
|
|
137
|
+
def test_valid_form_exits_zero(self):
|
|
138
|
+
r = self.run_cli(self.make_file(build_form()))
|
|
139
|
+
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
|
140
|
+
self.assertIn("结论:合规(exit 0)", r.stdout)
|
|
141
|
+
self.assertEqual(r.stdout.count("[ok]"), 7)
|
|
142
|
+
|
|
143
|
+
# ------------------------------------------------------- 2 缺快照
|
|
144
|
+
|
|
145
|
+
def test_missing_snapshot_is_defect(self):
|
|
146
|
+
text = build_form(snap_start="", snap_end="")
|
|
147
|
+
r = self.run_cli(self.make_file(text))
|
|
148
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
149
|
+
self.assertIn("§0 缺被验快照", r.stdout)
|
|
150
|
+
self.assertIn("无法证明期间文件没被改过", r.stdout)
|
|
151
|
+
|
|
152
|
+
# ----------------------------------------------- 3 两次取值不同
|
|
153
|
+
|
|
154
|
+
def test_differing_hash_without_inconsistency_is_defect(self):
|
|
155
|
+
text = build_form(
|
|
156
|
+
snap_end="HASH bbbbbbbbbbbb FILES 30 ROOT /tmp/demo",
|
|
157
|
+
conclusion="- 两次取值:一致",
|
|
158
|
+
)
|
|
159
|
+
r = self.run_cli(self.make_file(text))
|
|
160
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
161
|
+
self.assertIn("不一致", r.stdout)
|
|
162
|
+
|
|
163
|
+
def test_differing_hash_with_inconsistency_and_limit_is_ok(self):
|
|
164
|
+
text = build_form(
|
|
165
|
+
snap_end="HASH bbbbbbbbbbbb FILES 30 ROOT /tmp/demo",
|
|
166
|
+
conclusion="- 两次不一致,本轮结论只对 start 版有效",
|
|
167
|
+
)
|
|
168
|
+
r = self.run_cli(self.make_file(text))
|
|
169
|
+
self.assertEqual(r.returncode, 0, r.stdout)
|
|
170
|
+
|
|
171
|
+
def test_differing_hash_without_limit_is_defect(self):
|
|
172
|
+
text = build_form(
|
|
173
|
+
snap_end="HASH bbbbbbbbbbbb FILES 30 ROOT /tmp/demo",
|
|
174
|
+
conclusion="- 两次不一致",
|
|
175
|
+
)
|
|
176
|
+
r = self.run_cli(self.make_file(text))
|
|
177
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
178
|
+
self.assertIn("限定", r.stdout)
|
|
179
|
+
|
|
180
|
+
def test_differing_files_count_without_limit_is_defect(self):
|
|
181
|
+
text = build_form(
|
|
182
|
+
snap_end="HASH aaaaaaaaaaaa FILES 29 ROOT /tmp/demo",
|
|
183
|
+
conclusion="- 两次不一致",
|
|
184
|
+
)
|
|
185
|
+
r = self.run_cli(self.make_file(text))
|
|
186
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
187
|
+
self.assertIn("限定", r.stdout)
|
|
188
|
+
|
|
189
|
+
# ------------------------------------------------------ 4 判定
|
|
190
|
+
|
|
191
|
+
def test_verdict_fail_is_legal(self):
|
|
192
|
+
r = self.run_cli(self.make_file(build_form(verdict="不通过")))
|
|
193
|
+
self.assertEqual(r.returncode, 0, r.stdout)
|
|
194
|
+
|
|
195
|
+
def test_verdict_basically_pass_is_illegal(self):
|
|
196
|
+
r = self.run_cli(self.make_file(build_form(verdict="基本通过")))
|
|
197
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
198
|
+
self.assertIn("未给出合法判定", r.stdout)
|
|
199
|
+
|
|
200
|
+
def test_verdict_far_from_keyword_is_defect(self):
|
|
201
|
+
text = build_form(verdict_block=["- **判定**:", "", "", "", "", "- 通过"])
|
|
202
|
+
r = self.run_cli(self.make_file(text))
|
|
203
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
204
|
+
self.assertIn("附近 3 行", r.stdout)
|
|
205
|
+
|
|
206
|
+
def test_verdict_on_next_line_is_accepted(self):
|
|
207
|
+
text = build_form(verdict_block=["- **判定**:", "- 通过"])
|
|
208
|
+
r = self.run_cli(self.make_file(text))
|
|
209
|
+
self.assertEqual(r.returncode, 0, r.stdout)
|
|
210
|
+
|
|
211
|
+
def test_verdict_explicit_bold_is_accepted(self):
|
|
212
|
+
text = build_form(verdict_block=["- **判定**:**通过但要修**"])
|
|
213
|
+
r = self.run_cli(self.make_file(text))
|
|
214
|
+
self.assertEqual(r.returncode, 0, r.stdout)
|
|
215
|
+
|
|
216
|
+
# ------------------------------------------- 5 判通过却有必改项
|
|
217
|
+
|
|
218
|
+
def test_pass_with_unfixed_mustfix_is_defect(self):
|
|
219
|
+
text = build_form(
|
|
220
|
+
verdict="通过",
|
|
221
|
+
extra_problem_row="| 2 | `C.py:20` | 条件写反 | 复跑 exit 1 | 必改 |",
|
|
222
|
+
)
|
|
223
|
+
r = self.run_cli(self.make_file(text))
|
|
224
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
225
|
+
self.assertIn("矛盾", r.stdout)
|
|
226
|
+
|
|
227
|
+
def test_pass_with_fixed_mustfix_is_ok(self):
|
|
228
|
+
text = build_form(
|
|
229
|
+
verdict="通过",
|
|
230
|
+
extra_problem_row="| 2 | `C.py:20` | 条件写反 | 已修:复跑 exit 0 | 必改 |",
|
|
231
|
+
)
|
|
232
|
+
r = self.run_cli(self.make_file(text))
|
|
233
|
+
self.assertEqual(r.returncode, 0, r.stdout)
|
|
234
|
+
|
|
235
|
+
# ------------------------------------------------- 6 禁用证据词
|
|
236
|
+
|
|
237
|
+
def test_banned_phrase_reports_line_number(self):
|
|
238
|
+
bad = "- 这个改动看起来合理,我就没重算。"
|
|
239
|
+
text = build_form(section2_extra=bad)
|
|
240
|
+
expected_line = text.splitlines().index(bad) + 1
|
|
241
|
+
r = self.run_cli(self.make_file(text))
|
|
242
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
243
|
+
self.assertIn("看起来合理", r.stdout)
|
|
244
|
+
self.assertIn("第 %d 行" % expected_line, r.stdout)
|
|
245
|
+
|
|
246
|
+
# -------------------------------------------------- 7 机械证据
|
|
247
|
+
|
|
248
|
+
def test_no_evidence_rows_is_defect(self):
|
|
249
|
+
text = build_form(evidence_rows=False)
|
|
250
|
+
r = self.run_cli(self.make_file(text))
|
|
251
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
252
|
+
self.assertIn("§1 缺机械证据", r.stdout)
|
|
253
|
+
|
|
254
|
+
# ---------------------------------------------------- 8 真问题
|
|
255
|
+
|
|
256
|
+
def test_no_problem_table_and_no_exemption_is_defect(self):
|
|
257
|
+
text = build_form(problem_rows=False)
|
|
258
|
+
r = self.run_cli(self.make_file(text))
|
|
259
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
260
|
+
self.assertIn("无法证明复核人真找了问题", r.stdout)
|
|
261
|
+
|
|
262
|
+
# ------------------------------------------------- 9 独立性
|
|
263
|
+
|
|
264
|
+
def test_missing_self_check_section_is_defect(self):
|
|
265
|
+
text = build_form(section1_title="## 1. 我的独立结论", with_section2=False)
|
|
266
|
+
r = self.run_cli(self.make_file(text))
|
|
267
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
268
|
+
self.assertIn("无法确认独立性", r.stdout)
|
|
269
|
+
|
|
270
|
+
def test_self_check_without_qualifier_is_defect(self):
|
|
271
|
+
text = build_form(section1_title="## 1. 我的独立结论(对照自检)", with_section2=False)
|
|
272
|
+
r = self.run_cli(self.make_file(text))
|
|
273
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
274
|
+
self.assertIn("附近没有", r.stdout)
|
|
275
|
+
|
|
276
|
+
# --------------------------------- 9b v1.3.1 收紧:标题行不算证据
|
|
277
|
+
def test_template_heading_alone_is_not_independence(self):
|
|
278
|
+
text = build_form(independence_sentence=False)
|
|
279
|
+
r = self.run_cli(self.make_file(text))
|
|
280
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
281
|
+
self.assertIn("标题行与模板提示行不算证据", r.stdout)
|
|
282
|
+
|
|
283
|
+
# ------------------------- 9c v1.3.2 修:句中含提示词不该被当成模板行
|
|
284
|
+
def test_sentence_with_hint_word_in_middle_is_still_evidence(self):
|
|
285
|
+
"""正文声明句里顺带出现「要求 / 说明」等词,不能被整句跳过(A1 必改①)。"""
|
|
286
|
+
sentence = (
|
|
287
|
+
"- 独立性:我按要求先写 §1 的独立结论,之后才打开作者自检文件对照。"
|
|
288
|
+
)
|
|
289
|
+
text = build_form(section2_extra=sentence)
|
|
290
|
+
# 关掉默认那句,只留这一句含「要求」的声明
|
|
291
|
+
text = text.replace(
|
|
292
|
+
"- 独立性:§1 的独立结论写完之后,我才打开作者自检文件对照。\n", ""
|
|
293
|
+
)
|
|
294
|
+
r = self.run_cli(self.make_file(text))
|
|
295
|
+
self.assertEqual(r.returncode, 0, r.stdout)
|
|
296
|
+
|
|
297
|
+
def test_template_label_line_is_not_independence(self):
|
|
298
|
+
"""以「必填」开头的模板标签行,即使写着「自检之前」也不算证据。"""
|
|
299
|
+
text = build_form(
|
|
300
|
+
independence_sentence=False,
|
|
301
|
+
section2_extra="- 必填:先在打开作者自检之前写完结论",
|
|
302
|
+
)
|
|
303
|
+
r = self.run_cli(self.make_file(text))
|
|
304
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
305
|
+
|
|
306
|
+
def test_blockquote_hint_line_is_not_independence(self):
|
|
307
|
+
"""> 引用块的提示语同样不算证据。"""
|
|
308
|
+
text = build_form(
|
|
309
|
+
independence_sentence=False,
|
|
310
|
+
section2_extra="> 提示:在打开自检之前写完独立结论",
|
|
311
|
+
)
|
|
312
|
+
r = self.run_cli(self.make_file(text))
|
|
313
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
314
|
+
|
|
315
|
+
# ------------------------- 9d v1.3.3:引用/括号开头的合法声明不能被整行丢掉
|
|
316
|
+
def test_parenthesised_declaration_is_accepted(self):
|
|
317
|
+
text = build_form(
|
|
318
|
+
independence_sentence=False,
|
|
319
|
+
section2_extra="- (1) 我按要求先写 §1 的独立结论,之后才打开作者自检文件对照。",
|
|
320
|
+
)
|
|
321
|
+
r = self.run_cli(self.make_file(text))
|
|
322
|
+
self.assertEqual(r.returncode, 0, r.stdout)
|
|
323
|
+
|
|
324
|
+
def test_blockquote_declaration_is_accepted(self):
|
|
325
|
+
text = build_form(
|
|
326
|
+
independence_sentence=False,
|
|
327
|
+
section2_extra="> 我按要求先写 §1 的独立结论,之后才打开作者自检文件对照。",
|
|
328
|
+
)
|
|
329
|
+
r = self.run_cli(self.make_file(text))
|
|
330
|
+
self.assertEqual(r.returncode, 0, r.stdout)
|
|
331
|
+
|
|
332
|
+
def test_bullet_hint_label_line_is_not_independence(self):
|
|
333
|
+
"""`- 提示:…自检之前…` 这种模板骨架行不能白送通过(v1.3.3 遗留建议)。"""
|
|
334
|
+
text = build_form(
|
|
335
|
+
independence_sentence=False,
|
|
336
|
+
section2_extra="- 提示:先在打开作者自检之前写完结论",
|
|
337
|
+
)
|
|
338
|
+
r = self.run_cli(self.make_file(text))
|
|
339
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
340
|
+
|
|
341
|
+
# ------------------- 9e v1.3.4:标记叠加时也要认得出模板痕迹 / 不误伤合法句
|
|
342
|
+
HINT_FORMS = [
|
|
343
|
+
"- 提示:先在打开作者自检之前写完结论",
|
|
344
|
+
"> 提示:先在打开作者自检之前写完结论",
|
|
345
|
+
"> **提示**:先在打开作者自检之前写完结论",
|
|
346
|
+
">**提示**",
|
|
347
|
+
"(**提示**)",
|
|
348
|
+
"> - **提示**",
|
|
349
|
+
"> - 提示:先看自检再写",
|
|
350
|
+
"- **必填**:先看自检再写结论",
|
|
351
|
+
"(示例)先看自检再写结论",
|
|
352
|
+
"> **说明**:先看自检再写结论",
|
|
353
|
+
]
|
|
354
|
+
LEGIT_FORMS = [
|
|
355
|
+
"- 独立性:我按要求先写 §1 的独立结论,之后才打开作者自检文件对照。",
|
|
356
|
+
"> 我按要求先写 §1 的独立结论,之后才打开作者自检文件对照。",
|
|
357
|
+
"- (1) 我按要求先写 §1 的独立结论,之后才打开作者自检文件对照。",
|
|
358
|
+
"> **我按要求先写 §1 的独立结论,之后才打开作者自检文件对照。**",
|
|
359
|
+
"- **独立性**:先写独立结论,之后才看作者自检。",
|
|
360
|
+
]
|
|
361
|
+
|
|
362
|
+
def test_hint_forms_are_not_independence(self):
|
|
363
|
+
"""十种模板痕迹写法都必须判缺陷(含引用块/列表/强调符叠加)。"""
|
|
364
|
+
for form in self.HINT_FORMS:
|
|
365
|
+
with self.subTest(form=form):
|
|
366
|
+
text = build_form(independence_sentence=False, section2_extra=form)
|
|
367
|
+
r = self.run_cli(self.make_file(text))
|
|
368
|
+
self.assertEqual(r.returncode, 1, "%r ->\n%s" % (form, r.stdout))
|
|
369
|
+
|
|
370
|
+
def test_legit_forms_are_independence(self):
|
|
371
|
+
"""五种合法写法都必须通过(不能被标记剥离逻辑误伤)。"""
|
|
372
|
+
for form in self.LEGIT_FORMS:
|
|
373
|
+
with self.subTest(form=form):
|
|
374
|
+
text = build_form(independence_sentence=False, section2_extra=form)
|
|
375
|
+
r = self.run_cli(self.make_file(text))
|
|
376
|
+
self.assertEqual(r.returncode, 0, "%r ->\n%s" % (form, r.stdout))
|
|
377
|
+
|
|
378
|
+
def test_violation_reports_body_line_not_heading(self):
|
|
379
|
+
"""违规时要指出真正的正文行,而不是被跳过的标题行(A1 必改②)。"""
|
|
380
|
+
body = "- 我看了作者自检后写出上面的结论。"
|
|
381
|
+
text = build_form(
|
|
382
|
+
section1_title="## 1. 我的独立结论(对照作者自检)",
|
|
383
|
+
with_section2=False,
|
|
384
|
+
section2_extra=body,
|
|
385
|
+
)
|
|
386
|
+
expected_line = text.splitlines().index(body) + 1
|
|
387
|
+
r = self.run_cli(self.make_file(text))
|
|
388
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
389
|
+
self.assertIn("第 %d 行" % expected_line, r.stdout)
|
|
390
|
+
|
|
391
|
+
def test_single_evidence_row_is_not_enough(self):
|
|
392
|
+
text = build_form(evidence_row_count=1)
|
|
393
|
+
r = self.run_cli(self.make_file(text))
|
|
394
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
395
|
+
self.assertIn("至少 2 行真实数据", r.stdout)
|
|
396
|
+
|
|
397
|
+
# ------------------------------------------------- 10 --json
|
|
398
|
+
|
|
399
|
+
def test_json_mode_clean_and_exit_code_matches(self):
|
|
400
|
+
r = self.run_cli(self.make_file(build_form()), json_mode=True)
|
|
401
|
+
self.assertEqual(r.returncode, 0, r.stdout)
|
|
402
|
+
self.assertNotIn("REVIEW FORM CHECK", r.stdout)
|
|
403
|
+
self.assertTrue(r.stdout.strip().startswith("{"))
|
|
404
|
+
payload = json.loads(r.stdout)
|
|
405
|
+
self.assertEqual(payload["exit_code"], r.returncode)
|
|
406
|
+
self.assertTrue(payload["ok"])
|
|
407
|
+
self.assertEqual(payload["defects"], [])
|
|
408
|
+
self.assertEqual(payload["warnings"], [])
|
|
409
|
+
|
|
410
|
+
def test_json_mode_defect_payload(self):
|
|
411
|
+
text = build_form(section2_extra="- 这个改动看起来合理。")
|
|
412
|
+
r = self.run_cli(self.make_file(text), json_mode=True)
|
|
413
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
414
|
+
payload = json.loads(r.stdout)
|
|
415
|
+
self.assertEqual(payload["exit_code"], 1)
|
|
416
|
+
self.assertFalse(payload["ok"])
|
|
417
|
+
self.assertTrue(any(d["rule"] == "banned" for d in payload["defects"]))
|
|
418
|
+
for defect in payload["defects"]:
|
|
419
|
+
self.assertIn("rule", defect)
|
|
420
|
+
self.assertIn("line", defect)
|
|
421
|
+
self.assertIn("message", defect)
|
|
422
|
+
self.assertEqual(payload["warnings"], [])
|
|
423
|
+
|
|
424
|
+
# --------------------------------------------- 11 文件不存在
|
|
425
|
+
|
|
426
|
+
def test_missing_file_exits_two(self):
|
|
427
|
+
missing = os.path.join(self._tmpdir, "no_such_review.md")
|
|
428
|
+
r = self.run_cli(missing)
|
|
429
|
+
self.assertEqual(r.returncode, 2)
|
|
430
|
+
self.assertIn("文件不存在", r.stdout)
|
|
431
|
+
|
|
432
|
+
def test_missing_file_json_exits_two(self):
|
|
433
|
+
missing = os.path.join(self._tmpdir, "no_such_review.md")
|
|
434
|
+
r = self.run_cli(missing, json_mode=True)
|
|
435
|
+
self.assertEqual(r.returncode, 2)
|
|
436
|
+
payload = json.loads(r.stdout)
|
|
437
|
+
self.assertEqual(payload["exit_code"], 2)
|
|
438
|
+
self.assertFalse(payload["ok"])
|
|
439
|
+
|
|
440
|
+
# ------------------------------------------- 12 中文 UTF-8
|
|
441
|
+
|
|
442
|
+
def test_chinese_text_not_mojibake(self):
|
|
443
|
+
bad = "- 作者说跑通了,不用复算。"
|
|
444
|
+
text = build_form(section2_extra=bad)
|
|
445
|
+
r = self.run_cli(self.make_file(text))
|
|
446
|
+
self.assertEqual(r.returncode, 1, r.stdout)
|
|
447
|
+
self.assertNotIn("\ufffd", r.stdout)
|
|
448
|
+
self.assertIn("作者说", r.stdout)
|
|
449
|
+
self.assertIn("跑通了", r.stdout)
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
if __name__ == "__main__":
|
|
453
|
+
unittest.main()
|