a796c1d2f7
Establish English as the canonical ADR language with Korean translations held in a parallel docs/adr-ko/ tree as derived artifacts (1:1 mirror). Promotion from adr-proposed/ to adr/ now writes English to adr/ and the Korean to adr-ko/; bidirectional sync rule documented in CLAUDE.md. - Migrate 30 ADRs in docs/adr/: 28 Korean-only translated to English, 2 bilingual pairs (ADR-0020, ADR-0023) consolidated (.en.md suffix dropped). ADR-0023 EN regenerated against KO source which had newer HW Realization Notes (D16-D23) section. - docs/adr-history/ left frozen by design (transitional state). - CLAUDE.md (Part 2): update ADR Lifecycle for 4-folder layout, mark docs/adr-ko/ as a Derived Artifact, add ADR Translation Discipline section covering bidirectional sync, conflict resolution (EN wins), and proposed-language freedom. - tools/verify_adr_lang_pairs.py: new verification tool checking pair completeness, filename mirroring, ADR-ID match, Status byte-equality. Pre-commit hook intentionally not added; run on demand or in CI. - tests/test_verify_adr_lang_pairs.py: 11 cases including CRLF/LF normalization, em-dash title separator, underscore-slug edge case. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
120 lines
4.3 KiB
Python
120 lines
4.3 KiB
Python
"""Tests for tools/verify_adr_lang_pairs.py."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
_REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(_REPO_ROOT / "tools"))
|
|
|
|
import verify_adr_lang_pairs as v # noqa: E402
|
|
|
|
|
|
def _make_adr(
|
|
path: Path,
|
|
title_id: str,
|
|
title_text: str = "Some Title",
|
|
status: str = "Accepted",
|
|
) -> None:
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(
|
|
f"# ADR-{title_id}: {title_text}\n\n"
|
|
f"## Status\n\n{status}\n\n"
|
|
f"## Context\n\nbody\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
|
|
def test_complete_pairs_pass(tmp_path: Path) -> None:
|
|
_make_adr(tmp_path / "docs/adr/ADR-0001-foo-bar.md", "0001", "Foo EN")
|
|
_make_adr(tmp_path / "docs/adr-ko/ADR-0001-foo-bar.md", "0001", "Foo KO")
|
|
assert v.verify(tmp_path) == []
|
|
|
|
|
|
def test_empty_dirs_pass(tmp_path: Path) -> None:
|
|
assert v.verify(tmp_path) == []
|
|
|
|
|
|
def test_missing_ko_fails(tmp_path: Path) -> None:
|
|
_make_adr(tmp_path / "docs/adr/ADR-0001-foo-bar.md", "0001")
|
|
errs = v.verify(tmp_path)
|
|
assert any("missing KO" in e and "ADR-0001-foo-bar.md" in e for e in errs)
|
|
|
|
|
|
def test_orphan_ko_fails(tmp_path: Path) -> None:
|
|
_make_adr(tmp_path / "docs/adr-ko/ADR-0001-foo-bar.md", "0001")
|
|
errs = v.verify(tmp_path)
|
|
assert any("orphan KO" in e and "ADR-0001-foo-bar.md" in e for e in errs)
|
|
|
|
|
|
def test_status_mismatch_fails(tmp_path: Path) -> None:
|
|
_make_adr(tmp_path / "docs/adr/ADR-0001-foo-bar.md", "0001", status="Accepted")
|
|
_make_adr(tmp_path / "docs/adr-ko/ADR-0001-foo-bar.md", "0001", status="Proposed")
|
|
errs = v.verify(tmp_path)
|
|
assert any("Status block mismatch" in e for e in errs)
|
|
|
|
|
|
def test_title_id_mismatch_fails(tmp_path: Path) -> None:
|
|
_make_adr(tmp_path / "docs/adr/ADR-0001-foo-bar.md", "0002")
|
|
_make_adr(tmp_path / "docs/adr-ko/ADR-0001-foo-bar.md", "0001")
|
|
errs = v.verify(tmp_path)
|
|
assert any("EN title ADR-ID" in e for e in errs)
|
|
|
|
|
|
def test_multiline_status_with_parenthetical_passes(tmp_path: Path) -> None:
|
|
"""Real ADRs like ADR-0001 have multi-line Status with revision notes."""
|
|
multiline_status = (
|
|
"Accepted (Revision 2 - 2026-04-27: concrete bit layout,\n"
|
|
"Supersedes ADR-0031.)"
|
|
)
|
|
_make_adr(
|
|
tmp_path / "docs/adr/ADR-0001-foo-bar.md", "0001", status=multiline_status
|
|
)
|
|
_make_adr(
|
|
tmp_path / "docs/adr-ko/ADR-0001-foo-bar.md", "0001", status=multiline_status
|
|
)
|
|
assert v.verify(tmp_path) == []
|
|
|
|
|
|
def test_crlf_normalization(tmp_path: Path) -> None:
|
|
"""KO has CRLF, EN has LF; Status content is otherwise identical -> pass."""
|
|
en = tmp_path / "docs/adr/ADR-0001-foo-bar.md"
|
|
ko = tmp_path / "docs/adr-ko/ADR-0001-foo-bar.md"
|
|
en.parent.mkdir(parents=True, exist_ok=True)
|
|
ko.parent.mkdir(parents=True, exist_ok=True)
|
|
en.write_bytes(
|
|
b"# ADR-0001: Foo\n\n## Status\n\nAccepted\n\n## Context\n\nbody\n"
|
|
)
|
|
ko.write_bytes(
|
|
b"# ADR-0001: Foo\r\n\r\n## Status\r\n\r\nAccepted\r\n\r\n## Context\r\n\r\nbody\r\n"
|
|
)
|
|
assert v.verify(tmp_path) == []
|
|
|
|
|
|
def test_em_dash_title_separator_recognized(tmp_path: Path) -> None:
|
|
"""ADR-0033 uses ' — ' instead of ': ' between ADR-NNNN and the title."""
|
|
en = tmp_path / "docs/adr/ADR-0033-foo-bar.md"
|
|
ko = tmp_path / "docs/adr-ko/ADR-0033-foo-bar.md"
|
|
en.parent.mkdir(parents=True, exist_ok=True)
|
|
ko.parent.mkdir(parents=True, exist_ok=True)
|
|
body = "## Status\n\nAccepted\n\n## Context\n\nbody\n"
|
|
en.write_text("# ADR-0033 — Latency Model\n\n" + body, encoding="utf-8")
|
|
ko.write_text("# ADR-0033 — Latency Model\n\n" + body, encoding="utf-8")
|
|
assert v.verify(tmp_path) == []
|
|
|
|
|
|
def test_underscore_in_slug_recognized(tmp_path: Path) -> None:
|
|
"""ADR-0013 uses an underscore in its slug; the regex must accept it."""
|
|
_make_adr(tmp_path / "docs/adr/ADR-0013-ver-verification_strategy.md", "0013")
|
|
_make_adr(tmp_path / "docs/adr-ko/ADR-0013-ver-verification_strategy.md", "0013")
|
|
assert v.verify(tmp_path) == []
|
|
|
|
|
|
def test_main_exit_codes(tmp_path: Path, capsys) -> None:
|
|
assert v.main(["--root", str(tmp_path)]) == 0
|
|
_make_adr(tmp_path / "docs/adr/ADR-0001-foo-bar.md", "0001")
|
|
assert v.main(["--root", str(tmp_path)]) == 1
|
|
out = capsys.readouterr().out
|
|
assert "FAILED" in out
|