mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-05-06 17:49:07 -05:00
The previous scaffold only stubbed scenario and realistic_solution with <TODO> placeholders. That meant authors had to know about the markup conventions from somewhere else (the regex in validate_drafts.py, the SCHEMA_SUMMARY in generate_question_for_gap.py, or the paragraph in ARCHITECTURE.md §3.6.1) — none of which a new contributor would find. Now `vault new` produces a YAML with the canonical bold markers pre-written. Authors fill in the content between markers; they can't forget to use them. Templates extracted as module-level constants (COMMON_MISTAKE_TEMPLATE and NAPKIN_MATH_TEMPLATE in commands/authoring.py) so they're testable in isolation. New tests in test_authoring_scaffold.py guard against accidental marker removal — if a contributor edits the scaffold and drops, say, **The Rationale:**, the test fails immediately rather than every new question silently failing the format gate downstream. 77 / 77 pytest pass (was 74; added 3) ruff clean vault check --strict — 10,711 loaded, 0 invariant failures CORPUS_HARDENING_PLAN.md Phase 2.
60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
"""Tests for the `vault new` scaffold templates.
|
|
|
|
Guards against accidental removal or rewording of the markup-convention
|
|
markers in `vault new`'s scaffolded YAML. The format-compliance gate
|
|
(currently in validate_drafts.py; CORPUS_HARDENING_PLAN.md Phase 6
|
|
lifts it into vault check --strict) requires these exact bold markers
|
|
to be present in every published common_mistake / napkin_math block.
|
|
|
|
If a contributor removes one of the markers from the scaffold (e.g.,
|
|
dropping `**The Rationale:**` to "save space"), every new question
|
|
authored via `vault new` would fail the format gate. These tests
|
|
catch that at the contract level instead of after a CI red.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from vault_cli.commands.authoring import (
|
|
COMMON_MISTAKE_TEMPLATE,
|
|
NAPKIN_MATH_TEMPLATE,
|
|
)
|
|
|
|
# Markers required by the format-compliance gate. Mirrored from
|
|
# interviews/vault-cli/scripts/validate_drafts.py so a marker rename
|
|
# in either place breaks the test loudly.
|
|
COMMON_MISTAKE_REQUIRED = (
|
|
"**The Pitfall:**",
|
|
"**The Rationale:**",
|
|
"**The Consequence:**",
|
|
)
|
|
NAPKIN_MATH_REQUIRED = (
|
|
"**Assumptions", # accepts "Assumptions & Constraints" or "Assumptions:"
|
|
"**Calculations:**",
|
|
"**Conclusion", # accepts "Conclusion:" or "Conclusion & Interpretation:"
|
|
)
|
|
|
|
|
|
def test_common_mistake_template_has_all_required_markers() -> None:
|
|
for marker in COMMON_MISTAKE_REQUIRED:
|
|
assert marker in COMMON_MISTAKE_TEMPLATE, (
|
|
f"vault new common_mistake scaffold is missing {marker!r}; "
|
|
f"new questions would fail the format-compliance gate."
|
|
)
|
|
|
|
|
|
def test_napkin_math_template_has_all_required_markers() -> None:
|
|
for marker in NAPKIN_MATH_REQUIRED:
|
|
assert marker in NAPKIN_MATH_TEMPLATE, (
|
|
f"vault new napkin_math scaffold is missing {marker!r}; "
|
|
f"new questions would fail the format-compliance gate."
|
|
)
|
|
|
|
|
|
def test_templates_are_strings_with_todo_markers() -> None:
|
|
"""Sanity: scaffolds are plain strings and contain <TODO so authors
|
|
see what to fill in."""
|
|
assert isinstance(COMMON_MISTAKE_TEMPLATE, str)
|
|
assert isinstance(NAPKIN_MATH_TEMPLATE, str)
|
|
assert "<TODO" in COMMON_MISTAKE_TEMPLATE
|
|
assert "<TODO" in NAPKIN_MATH_TEMPLATE
|