feat(rulebook): port script — parse FabledRulebook .md → Scribe DB
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Sample Rulebook
|
||||
|
||||
This is a fixture for testing the port script.
|
||||
@@ -0,0 +1,19 @@
|
||||
# git-workflow
|
||||
|
||||
Lead paragraph describing the topic.
|
||||
|
||||
## dev is home
|
||||
|
||||
Work directly on dev; no feature branches.
|
||||
|
||||
**Why:** It minimises ceremony for a solo developer.
|
||||
|
||||
**How to apply:** Default for all repo work. Switch to a feature branch only when explicitly asked.
|
||||
|
||||
## no-force-push
|
||||
|
||||
Never force-push to main.
|
||||
|
||||
**Why:** Force-pushing rewrites shared history.
|
||||
|
||||
**How to apply:** Anytime you're about to run `git push --force`, stop and check the target branch.
|
||||
@@ -0,0 +1,46 @@
|
||||
"""Tests for scripts/import_fabledrulebook.py — parser fixtures only.
|
||||
|
||||
The CLI / DB-writing portion is exercised manually on remote dev — it's a
|
||||
one-shot script.
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures" / "fabledrulebook_sample"
|
||||
|
||||
|
||||
def test_parse_topic_file_extracts_topic_title_and_rules():
|
||||
from scripts.import_fabledrulebook import parse_topic_file
|
||||
topic_title, description, rules = parse_topic_file(FIXTURES / "git-workflow.md")
|
||||
|
||||
assert topic_title == "git-workflow"
|
||||
assert "Lead paragraph" in description
|
||||
assert len(rules) == 2
|
||||
assert rules[0]["title"] == "dev is home"
|
||||
assert "Work directly on dev" in rules[0]["statement"]
|
||||
assert "minimises ceremony" in rules[0]["why"]
|
||||
assert "Default for all repo work" in rules[0]["how_to_apply"]
|
||||
|
||||
|
||||
def test_parse_rule_body_without_why_treats_whole_body_as_statement():
|
||||
from scripts.import_fabledrulebook import parse_rule_body
|
||||
out = parse_rule_body("test", "Just a body with no markers.")
|
||||
assert out["statement"] == "Just a body with no markers."
|
||||
assert out["why"] == ""
|
||||
assert out["how_to_apply"] == ""
|
||||
|
||||
|
||||
def test_parse_rule_body_handles_only_why():
|
||||
from scripts.import_fabledrulebook import parse_rule_body
|
||||
out = parse_rule_body("test", "Statement.\n\n**Why:** Because.")
|
||||
assert out["statement"] == "Statement."
|
||||
assert out["why"] == "Because."
|
||||
assert out["how_to_apply"] == ""
|
||||
|
||||
|
||||
def test_parse_rule_body_handles_only_how_to_apply():
|
||||
from scripts.import_fabledrulebook import parse_rule_body
|
||||
out = parse_rule_body("test", "Statement.\n\n**How to apply:** Do it now.")
|
||||
assert out["statement"] == "Statement."
|
||||
assert out["why"] == ""
|
||||
assert out["how_to_apply"] == "Do it now."
|
||||
Reference in New Issue
Block a user