merge: PR #33을 합친 검사 브랜치에 넣는다

This commit is contained in:
DongHyeonka
2026-11-13 07:16:02 +09:00
3 changed files with 72 additions and 9 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ scripts/verify.sh <단계> [대상…] [--on here|<호스트>] [--log <이름>]
| `docs` | 작업 매뉴얼 검사(`scripts/check-work-docs.py`)와 장부 형식 | 여기(노트북) |
| `hooks` | repo 훅·검사기·장부 시험(`python3 -m unittest discover -s scripts/tests`) | 여기 |
| `gate <ID>…` | 게이트마다 `corepack pnpm ci:gate <ID>`, CI env로 | desktop |
| `parts <ID>` | 그 게이트의 명령(`commandIds`)을 하나씩 끝까지. 음성 fixture(`expect: fail`)는 정해진 종료 코드면 통과 | desktop |
| `parts <ID>` | 그 게이트의 명령(`commandIds`)을 `args`와 함께 하나씩 끝까지. 음성 fixture(`expect: fail`)는 `ci:gate`처럼 정해진 종료 코드와 정해진 진단 문구(`expectedDiagnosticId`)가 둘 다 있어야 통과 | desktop |
| `script <이름>… [-- 인자…]` | package script를 하나씩(예: `verify:documentation`). `--` 뒤 인자는 script가 하나일 때만 넘긴다(예: `scripts/verify.sh script test:sample-removal -- --feature=<id>`) | desktop |
| `exec -- <명령…>` | 명령 하나. 한 테스트 파일(`node scripts/run-vitest.ts run <파일>`)이나 package script가 아닌 node 스크립트 | desktop |
| stage id | `config/ci/gates.json` `stages`의 그 단계 `gateIds` 전부 | desktop |
+39
View File
@@ -90,6 +90,45 @@ class StagePlanTest(unittest.TestCase):
expected.append(" ".join(words))
self.assertEqual([line.split(": ", 1)[1] for line in result.stdout.splitlines()], expected)
def test_parts_passes_a_negative_fixture_only_with_its_registered_diagnostic(self) -> None:
# run-ci-gate.ts passes an expect=fail command only when it exits with its code and prints its
# diagnostic. parts saw the exit code alone, so a checker broken into an unrelated exit 1 (a
# TypeError) still counted as its negative fixture passing.
contract = gates()
commands = {c["id"]: c for c in contract["commands"]}
gate = next(g for g in contract["gates"] if g["id"] == "FE-GATE-029")
negatives = [commands[c] for c in gate["commandIds"] if commands[c].get("expect") == "fail"]
self.assertTrue(any(c.get("expectedDiagnosticId") for c in negatives))
with tempfile.TemporaryDirectory() as tmp:
fake = Path(tmp) / "corepack"
# Answers `corepack pnpm -s <script> ...args` as the contract registers that command:
# pass commands exit 0, negative fixtures exit with their code and print DIAGNOSTIC_MODE.
fake.write_text(f"""#!/usr/bin/env python3
import json, os, sys
script, args = sys.argv[3], sys.argv[4:]
for command in json.load(open({str(REPO / "config/ci/gates.json")!r}))["commands"]:
if command["script"] == script and command.get("args", []) == args:
break
else:
sys.exit(97)
if command.get("expect") != "fail":
sys.exit(0)
if os.environ["DIAGNOSTIC_MODE"] == "registered":
print("checker refused the fixture:", command.get("expectedDiagnosticId", ""))
else:
print("TypeError: Cannot read properties of undefined")
sys.exit(command.get("expectedExitCode", 1))
""", encoding="utf-8")
fake.chmod(0o755)
env = {"PATH": f"{tmp}:{os.environ['PATH']}"}
wrong = sh([str(VERIFY), "parts", "FE-GATE-029", "--on", "here"], cwd=REPO, check=False,
env={**env, "DIAGNOSTIC_MODE": "unrelated"})
self.assertEqual(wrong.returncode, 1, wrong.stdout + wrong.stderr)
self.assertIn("diagnostic", wrong.stderr)
right = sh([str(VERIFY), "parts", "FE-GATE-029", "--on", "here"], cwd=REPO, check=False,
env={**env, "DIAGNOSTIC_MODE": "registered"})
self.assertEqual(right.returncode, 0, right.stdout + right.stderr)
def test_arguments_after_the_separator_go_to_the_one_script_or_command_as_given(self) -> None:
result = sh([str(VERIFY), "script", "test:sample-removal", "--dry-run", "--", "--feature=invoice-feature"],
cwd=REPO)
+32 -8
View File
@@ -70,7 +70,8 @@ elif kind == "scripts":
command = commands[command_id]
# \x1f between fields keeps an empty exit code a field; \x1e between the command's args.
args = "\x1e".join(command.get("args", []))
print(f'{command["script"]}\x1f{command.get("expect", "pass")}\x1f{command.get("expectedExitCode", "")}\x1f{args}')
print(f'{command["script"]}\x1f{command.get("expect", "pass")}\x1f{command.get("expectedExitCode", "")}'
f'\x1f{args}\x1f{command.get("expectedDiagnosticId", "")}')
PY
}
@@ -119,8 +120,18 @@ step() {
start=$(date +%s)
log=${VERIFY_STEP_LOGS:+$VERIFY_STEP_LOGS/$(printf '%s' "$name" | tr ' /:' '___').log}
set +e
if [ -n "$log" ]; then "$@" > "$log" 2>&1; else "$@"; fi
rc=$?
# STEP_CAPTURE: also keep the output in that file (run_parts reads a negative fixture's diagnostic).
if [ -n "$log" ]; then
"$@" > "$log" 2>&1
rc=$?
[ -z "${STEP_CAPTURE:-}" ] || cp "$log" "$STEP_CAPTURE"
elif [ -n "${STEP_CAPTURE:-}" ]; then
"$@" 2>&1 | tee "$STEP_CAPTURE"
rc=${PIPESTATUS[0]}
else
"$@"
rc=$?
fi
set -e
echo "$name rc=$rc $(( $(date +%s) - start ))s" | tee -a "${VERIFY_SUMMARY:-/dev/null}"
return "$rc"
@@ -148,20 +159,33 @@ run_gates() {
}
run_parts() {
local gate=$1 failed=0 script expect code argtext rc args prefix
local gate=$1 failed=0 script expect code argtext diagnostic rc args prefix capture
[ "$DRY_RUN" = 1 ] || ci_env
gates_json scripts "$gate" > /dev/null || { echo "verify: config/ci/gates.json에 없는 게이트: $gate" >&2; return 2; }
prefix=$(host_prefix "$gate")
while IFS=$'\x1f' read -r script expect code argtext; do
while IFS=$'\x1f' read -r script expect code argtext diagnostic; do
rc=0
args=()
# The command's args, as run-ci-gate.ts passes them (`pnpm <script> ...args`).
[ -z "$argtext" ] || IFS=$'\x1e' read -r -a args <<< "$argtext"
capture=""
if [ "$expect" = fail ] && [ "$DRY_RUN" != 1 ]; then
capture=$(mktemp)
TMP_FILES+=("$capture")
fi
# shellcheck disable=SC2086
step "$gate $script" $prefix corepack pnpm -s "$script" ${args[@]+"${args[@]}"} || rc=$?
# expect=fail인 명령(음성 fixture)은 정해진 종료 코드로 실패해야 통과다.
STEP_CAPTURE=$capture step "$gate $script" $prefix corepack pnpm -s "$script" ${args[@]+"${args[@]}"} || rc=$?
# expect=fail인 명령(음성 fixture)은 run-ci-gate.ts처럼 정해진 종료 코드로 실패하고 정해진 진단 문구를
# 출력해야 통과다. 종료 코드만 보면 엉뚱한 원인의 exit 1(깨진 검사기)도 통과로 센다.
if [ "$expect" = fail ]; then
[ "$DRY_RUN" = 1 ] || [ "$rc" = "${code:-1}" ] || failed=1
[ "$DRY_RUN" = 1 ] && continue
if [ "$rc" != "${code:-1}" ]; then
echo "verify: $gate $script: expected exit ${code:-1}, got $rc" >&2
failed=1
elif [ -n "$diagnostic" ] && ! grep -qF -- "$diagnostic" "$capture"; then
echo "verify: $gate $script: exit $rc without the registered diagnostic: $diagnostic" >&2
failed=1
fi
elif [ "$rc" != 0 ]; then
failed=1
fi