121 lines
3.5 KiB
Python
121 lines
3.5 KiB
Python
from pathlib import Path
|
|
|
|
import rdb_discovery.discovery as discovery_mod
|
|
|
|
|
|
def test_core_questions_returns_10_items() -> None:
|
|
questions = discovery_mod.core_questions()
|
|
assert len(questions) == 10
|
|
|
|
|
|
def test_append_creates_file_when_missing(tmp_path: Path) -> None:
|
|
log_path = tmp_path / "context" / "discovery-log.md"
|
|
assert not log_path.exists()
|
|
|
|
discovery_mod.append_discovery_answer(
|
|
tmp_path,
|
|
question_id="Q-001",
|
|
question="What problem are we solving?",
|
|
answer="A great app",
|
|
confidence="High",
|
|
follow_up_needed="No",
|
|
)
|
|
|
|
assert log_path.exists()
|
|
|
|
|
|
def test_append_records_all_fields(tmp_path: Path) -> None:
|
|
discovery_mod.append_discovery_answer(
|
|
tmp_path,
|
|
question_id="Q-001",
|
|
question="What problem are we solving?",
|
|
answer="A great app",
|
|
confidence="High",
|
|
follow_up_needed="No",
|
|
)
|
|
|
|
content = (tmp_path / "context" / "discovery-log.md").read_text(encoding="utf-8")
|
|
assert "| Q-001 |" in content
|
|
assert "What problem are we solving?" in content
|
|
assert "A great app" in content
|
|
assert "High" in content
|
|
assert "No" in content
|
|
|
|
|
|
def test_append_escapes_pipe_in_answer(tmp_path: Path) -> None:
|
|
discovery_mod.append_discovery_answer(
|
|
tmp_path,
|
|
question_id="Q-001",
|
|
question="What | is this?",
|
|
answer="A | B",
|
|
confidence="High",
|
|
follow_up_needed="No",
|
|
)
|
|
|
|
content = (tmp_path / "context" / "discovery-log.md").read_text(encoding="utf-8")
|
|
# Piped answers should be escaped so the table row doesn't break
|
|
assert "\\|" in content
|
|
|
|
|
|
def test_append_escapes_newline_in_answer(tmp_path: Path) -> None:
|
|
discovery_mod.append_discovery_answer(
|
|
tmp_path,
|
|
question_id="Q-001",
|
|
question="Multi\nline?",
|
|
answer="A\nB\nC",
|
|
confidence="High",
|
|
follow_up_needed="No",
|
|
)
|
|
|
|
content = (tmp_path / "context" / "discovery-log.md").read_text(encoding="utf-8")
|
|
# Data rows should each be a single line — no embedded newlines
|
|
data_lines = [l for l in content.splitlines() if l.startswith("| Q-")]
|
|
assert len(data_lines) == 1
|
|
assert "\n" not in data_lines[0]
|
|
|
|
|
|
def test_append_preserves_existing_history(tmp_path: Path) -> None:
|
|
log_path = tmp_path / "context" / "discovery-log.md"
|
|
|
|
discovery_mod.append_discovery_answer(
|
|
tmp_path,
|
|
question_id="Q-001",
|
|
question="First?",
|
|
answer="Ans 1",
|
|
confidence="High",
|
|
follow_up_needed="No",
|
|
)
|
|
|
|
assert log_path.read_text(encoding="utf-8").count("Ans 1") == 1
|
|
|
|
discovery_mod.append_discovery_answer(
|
|
tmp_path,
|
|
question_id="Q-002",
|
|
question="Second?",
|
|
answer="Ans 2",
|
|
confidence="Low",
|
|
follow_up_needed="Yes",
|
|
)
|
|
|
|
content = log_path.read_text(encoding="utf-8")
|
|
assert "Ans 1" in content
|
|
assert "Ans 2" in content
|
|
# Two data rows, not one
|
|
data_rows = [l for l in content.splitlines() if l.startswith("| Q-")]
|
|
assert len(data_rows) == 2
|
|
|
|
|
|
def test_header_is_written_on_create(tmp_path: Path) -> None:
|
|
discovery_mod.append_discovery_answer(
|
|
tmp_path,
|
|
question_id="Q-001",
|
|
question="Test?",
|
|
answer="T",
|
|
confidence="High",
|
|
follow_up_needed="No",
|
|
)
|
|
|
|
content = (tmp_path / "context" / "discovery-log.md").read_text(encoding="utf-8")
|
|
assert "# Discovery Log" in content
|
|
assert "| ID | Question | Answer | Confidence | Follow-up needed | Linked decision | Linked task | Date |" in content
|