Merge branch 'harness/C-verification' into harness/A-integration
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
"""원장에 적힌 관문이 **그 원장의 대상**에 돌았는지 (R5).
|
||||
|
||||
원장은 명령 문자열과 종료 코드를 적는다. 그런데 그 명령이 어느 대상에 돌았는지는 아무도
|
||||
안 봤다 — 다른 프로젝트에 돌려 받은 exit 0 을 적어도 통과로 셌다.
|
||||
|
||||
**정상 원장이 그대로 통과하는 대조를 함께 둔다.** 무조건 거절로 성공률을 올리는 것이
|
||||
R-003 이 든 실패다.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import glob
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
|
||||
def _module():
|
||||
path = os.path.join(ROOT, "scripts", "verify-pipeline-run.py")
|
||||
spec = importlib.util.spec_from_file_location("verify_pipeline_run", path)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
|
||||
def _a_ledger() -> dict | None:
|
||||
for p in sorted(glob.glob(os.path.join(ROOT, "runs", "*", "*", "run.json"))):
|
||||
d = json.load(open(p, encoding="utf-8"))
|
||||
gates = [g for st in d.get("stages", []) for g in (st.get("gates") or [])]
|
||||
if any("docs/" in str(g.get("cmd", "")) for g in gates):
|
||||
return d
|
||||
return None
|
||||
|
||||
|
||||
def _verify(doc: dict) -> object:
|
||||
with tempfile.NamedTemporaryFile("w", suffix=".json", delete=False,
|
||||
dir=os.path.join(ROOT, "runs"), encoding="utf-8") as f:
|
||||
json.dump(doc, f, ensure_ascii=False)
|
||||
path = f.name
|
||||
try:
|
||||
return _module().verify(path)
|
||||
finally:
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
class GateRanAgainstTheLedgersTarget(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.doc = _a_ledger()
|
||||
if self.doc is None:
|
||||
self.skipTest("대상 경로가 있는 원장이 이 저장소에 없다")
|
||||
|
||||
def test_untouched_ledger_still_passes(self) -> None:
|
||||
"""대조군 — 손대지 않은 원장은 이 규칙으로 새 error 를 얻지 않는다."""
|
||||
rep = _verify(self.doc)
|
||||
self.assertNotIn("관문이 다른 대상에 돌았다", rep.errors)
|
||||
|
||||
def test_gate_on_another_project_is_an_error(self) -> None:
|
||||
other = "n+1liner" if self.doc["project"] != "n+1liner" else "keycloak"
|
||||
if not os.path.isdir(os.path.join(ROOT, "docs", other)):
|
||||
self.skipTest("대조에 쓸 다른 프로젝트가 없다")
|
||||
bad = copy.deepcopy(self.doc)
|
||||
swapped = False
|
||||
for st in bad["stages"]:
|
||||
for g in st.get("gates") or []:
|
||||
cmd = str(g.get("cmd") or "")
|
||||
if not swapped and f"docs/{bad['project']}/" in cmd:
|
||||
g["cmd"] = cmd.replace(f"docs/{bad['project']}/", f"docs/{other}/")
|
||||
swapped = True
|
||||
self.assertTrue(swapped, "바꿀 관문을 못 찾았다")
|
||||
rep = _verify(bad)
|
||||
self.assertIn("관문이 다른 대상에 돌았다", rep.errors)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -70,6 +70,38 @@ MEASUREMENT_GATES = ("style_profile.mjs",)
|
||||
ORDER = ["S1", "S2", "S3", "S4", "S5", "S6", "S7"]
|
||||
|
||||
|
||||
def _known_projects() -> set[str]:
|
||||
docs = os.path.join(ROOT, "docs")
|
||||
if not os.path.isdir(docs):
|
||||
return set()
|
||||
return {d for d in os.listdir(docs)
|
||||
if os.path.isdir(os.path.join(docs, d)) and not d.startswith(("_", "."))}
|
||||
|
||||
|
||||
def _wrong_target(cmd: str, project: str, known: set[str]) -> str | None:
|
||||
"""이 관문이 **다른 프로젝트**에 돌지 않았는지 본다 (R5).
|
||||
|
||||
원장은 관문의 명령 문자열과 종료 코드를 적는다. 그런데 그 명령이 어느 대상에 돌았는지는
|
||||
아무도 안 봤다 — 다른 프로젝트에 돌려 exit 0 을 받아 적어도 통과로 셌다.
|
||||
`docs/<이름>/` 경로와 명령 인자로 오는 프로젝트 이름 둘 다 본다.
|
||||
|
||||
**유효 범위 — 「다른 프로젝트」만 본다.** 같은 프로젝트 안의 **다른 기록**에 돌린 관문은
|
||||
안 잡는다. `docs/<프로젝트>/` 가 같으면 통과한다. 기록 단위까지 보려면 원장의 `record` 와
|
||||
대조해야 하고, 그러면 프로젝트 단위로 도는 관문(`verify-tech-log-tree.py <프로젝트>`)이
|
||||
전부 걸리므로 관문마다 대상 단위를 따로 적어야 한다. 그것은 이 검사기가 아니라 계약이
|
||||
먼저 정할 일이다.
|
||||
"""
|
||||
for m in re.finditer(r"docs/([A-Za-z0-9_.+-]+)/", cmd):
|
||||
if m.group(1) != project:
|
||||
return f"docs/{m.group(1)}/"
|
||||
for other in known:
|
||||
if other == project:
|
||||
continue
|
||||
if re.search(rf"(?<![\w/.-]){re.escape(other)}(?![\w/.-])", cmd):
|
||||
return other
|
||||
return None
|
||||
|
||||
|
||||
def _norm(text: str) -> str:
|
||||
"""공백을 하나로 접는다. 인용을 줄바꿈까지 똑같이 옮기라고 요구하지 않는다."""
|
||||
return re.sub(r"\s+", " ", text).strip()
|
||||
@@ -168,6 +200,7 @@ def verify(path: str) -> Report:
|
||||
rep.error("원장에 칸이 없다", key)
|
||||
project = run.get("project") or ""
|
||||
rep.facts["project"] = project or "—"
|
||||
known_projects = _known_projects()
|
||||
|
||||
stages = {s.get("id"): s for s in run.get("stages") or []}
|
||||
missing = [sid for sid in ORDER if sid not in stages]
|
||||
@@ -228,6 +261,11 @@ def verify(path: str) -> Report:
|
||||
|
||||
gates = st.get("gates") or []
|
||||
cmds = " ; ".join(str(g.get("cmd") or "") for g in gates)
|
||||
for g in gates:
|
||||
other = _wrong_target(str(g.get("cmd") or ""), project, known_projects)
|
||||
if other:
|
||||
rep.error("관문이 다른 대상에 돌았다",
|
||||
f"{where} — {str(g.get('cmd'))[:60]} → {other} (원장은 {project})")
|
||||
for token in spec["gates"]:
|
||||
if token not in cmds:
|
||||
rep.error("관문이 빠졌다", f"{where} — {token}")
|
||||
|
||||
@@ -295,8 +295,7 @@ class _OutputReport:
|
||||
# CLAUDE.md 「검사」 절이 게시 전에 돌리라고 적은 것인데 verify-pipeline.py 가 부르지 않아,
|
||||
# 결함이 있는 채로 전체가 PASS 로 보고됐다 (V-001 verdict R3).
|
||||
#
|
||||
# 셋째로 `check-required-content.py <프로젝트>` 가 들어갈 자리다. B-003 의 신규 파일이라
|
||||
# 그 작업이 accept 된 뒤에 아래 튜플에 한 줄 더한다 — 없는 스크립트를 부르면 전체가 깨진다.
|
||||
# 셋째 `check-required-content.py` 는 B-003 이 들어온 뒤에 더했다 (R12).
|
||||
# 명령이 실재하지 않으면 건너뛰도록 아래 verify_outputs 가 파일 존재를 먼저 본다.
|
||||
OUTPUT_CHECKS = (
|
||||
("check-figure-text",
|
||||
@@ -305,6 +304,9 @@ OUTPUT_CHECKS = (
|
||||
lambda root, proj: ["node",
|
||||
str(root / ".agents" / "skills" / "writing-tech-log-records"
|
||||
/ "scripts" / "check_evidence.mjs"), proj, "--repo"]),
|
||||
("check-required-content",
|
||||
lambda root, proj: [sys.executable,
|
||||
str(root / "scripts" / "check-required-content.py"), proj]),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user