mirror of
https://github.com/instructkr/claude-code.git
synced 2026-05-27 16:06:44 +00:00
Constraint: roadmap-next-id.sh must preserve single-id stdout on success while failing closed if duplicate validation cannot run. Rejected: Relying only on CI/pre-push duplicate checks | the helper is used immediately before appending and must not certify an already-poisoned file. Confidence: high Scope-risk: narrow Directive: Keep roadmap-next-id.sh stdout machine-clean; route validation failures and checker availability errors to stderr, and keep focused helper behavior coverage in the docs/ROADMAP CI path. Tested: scripts/roadmap-next-id.sh ROADMAP.md printed 725 before appending #725 and 726 after; temp ROADMAP with duplicate 999 exited nonzero and listed duplicate id; scripts/roadmap-check-ids.sh ROADMAP.md; bash -n scripts/roadmap-next-id.sh scripts/roadmap-check-ids.sh; python -m unittest discover -s tests -p test_roadmap_helpers.py; python -m pytest tests/test_roadmap_helpers.py -q; SKIP_CLAW_PRE_PUSH_BUILD=1 bash .github/hooks/pre-push Not-tested: full cargo workspace build, unchanged docs/script-only path
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
NEXT_ID = REPO_ROOT / 'scripts' / 'roadmap-next-id.sh'
|
|
|
|
|
|
def run_next_id(roadmap: Path, script: Path = NEXT_ID) -> subprocess.CompletedProcess[str]:
|
|
return subprocess.run(
|
|
['bash', str(script), str(roadmap)],
|
|
cwd=REPO_ROOT,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
|
|
|
|
class RoadmapHelperTests(unittest.TestCase):
|
|
def test_roadmap_next_id_prints_only_next_id_after_duplicate_check(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
roadmap = Path(temp_dir) / 'ROADMAP.md'
|
|
roadmap.write_text('721. old\n723. helper era\n724. guard\n')
|
|
|
|
result = run_next_id(roadmap)
|
|
|
|
self.assertEqual(0, result.returncode)
|
|
self.assertEqual('725\n', result.stdout)
|
|
self.assertEqual('', result.stderr)
|
|
|
|
def test_roadmap_next_id_fails_fast_on_helper_era_duplicate(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
roadmap = Path(temp_dir) / 'ROADMAP.md'
|
|
roadmap.write_text('722. legacy\n999. first\n999. duplicate\n')
|
|
|
|
result = run_next_id(roadmap)
|
|
|
|
self.assertNotEqual(0, result.returncode)
|
|
self.assertEqual('', result.stdout)
|
|
self.assertIn('duplicate ROADMAP numeric id(s)', result.stderr)
|
|
self.assertIn('999', result.stderr)
|
|
self.assertNotIn('1000', result.stdout)
|
|
|
|
def test_roadmap_next_id_fails_closed_when_checker_is_unavailable(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
script_dir = Path(temp_dir) / 'scripts'
|
|
script_dir.mkdir()
|
|
copied_next_id = script_dir / 'roadmap-next-id.sh'
|
|
shutil.copy2(NEXT_ID, copied_next_id)
|
|
roadmap = Path(temp_dir) / 'ROADMAP.md'
|
|
roadmap.write_text('724. guard\n')
|
|
|
|
result = run_next_id(roadmap, copied_next_id)
|
|
|
|
self.assertNotEqual(0, result.returncode)
|
|
self.assertEqual('', result.stdout)
|
|
self.assertIn('required ROADMAP id checker not found or not readable', result.stderr)
|
|
self.assertIn('refusing to print a next id', result.stderr)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|