agora.plan.test_scaffolder
Pure helpers for the plan_scaffold_tests framework stage.
Generates a tests/test_<x>.py skeleton whose imports match the actual
project layout and whose function bodies are pytest.skip('TODO: ...')
stubs — one per bullet in plan/brief.md’s ## Key deliverables
section. The tester LLM then only has to replace each pytest.skip(...)
with real assertions; it never has to reconstruct boilerplate or guess
at import paths.
All functions are side-effect-free except discover_modules() which
reads from the filesystem. Parsing / rendering are pure.
Functions
|
Walk |
|
Extract the bullets under |
|
Emit the test file content as a string. |
|
Replace the body of |
|
Convert |
- agora.plan.test_scaffolder.parse_deliverables(brief_text)[source]
Extract the bullets under
## Key deliverablesfrombrief.md.Returns a list of stripped bullet strings (without ``- `` prefix). Returns an empty list if the section isn’t found or has no bullets; callers should fall back to a single generic test stub in that case.
- agora.plan.test_scaffolder.discover_modules(work_dir)[source]
Walk
<work_dir>/src/**for importable modules.Returns a mapping of
dotted.module.path -> [public_top_level_names]. Uses a lightweight AST parse so we never execute any of the discovered source. Skips__init__.py,conftest.py, test files, and modules whose stem starts with_(private).If the project uses a flat
src/<modname>.pylayout, dotted paths are rooted at the parent package (e.g.src/__init__.pypresent →<workdir_basename>.<modname>). Otherwise modules appear as bare names.Returns an empty dict if
src/doesn’t exist.
- agora.plan.test_scaffolder.snake_from_deliverable(bullet)[source]
Convert
'Add a long URL and get a short 6-char hash back'to'test_add_long_url_and_get_short_hash_back'.Keeps [a-z0-9], collapses whitespace to underscores, truncates to 50 chars, ensures
test_prefix, dedupes double underscores.
- agora.plan.test_scaffolder.render_scaffold(modules, deliverables, *, header='', mode='impl', api_spec_imports=None)[source]
Emit the test file content as a string.
modulesis the output ofdiscover_modules().deliverablesis the list of bullets.headeris an optional one-line docstring summarizing the project; empty → default.Each deliverable becomes a test function with a
pytest.skip('TODO: ...')body so the file runs green out of the box — the tester’s LLM stage replaces each skip with real assertions.modecontrols how imports are shaped:"impl"(default, Sprint 5 behavior): module-levelfrom pkg.x import namefor every discovered module. Used when the test file is authored AFTER the implementer tasks have produced the source, so the imports always resolve at collection time."contract": NO module-level imports. Header doc notes that imports must be deferred INSIDE each test function body. Used by contract tests that run before implementer tasks — module-level imports would fail collection; deferred imports let the file load and each test FAIL loudly when the implementation is missing, which is the right signal for a contract gate.
api_spec_imports(Sprint 7.5) — when provided, the scaffolder emits REAL module-levelfrom src.X import Ylines from the shared API spec, regardless ofmode. This is safe in contract mode too because theseed_workspacestep pre-wrote matching src/ stubs (with NotImplementedError bodies) before the scaffolder runs — the imports always resolve at collection time, and tests fail loudly when they INVOKE a stub (NotImplementedError), not at import time.
- agora.plan.test_scaffolder.replace_test_body(source, test_name, body_code)[source]
Replace the body of
def test_name()insourcewithbody_code.Pure string transformation. Preserves the docstring (first statement if a bare string literal) and
defsignature; replaces everything else in the function body withbody_codelines, normalized to 4-space indent (one standard indent level under the def).body_codemay have any indentation; it’s dedented first, then re-indented to 4 spaces uniformly. Multi-line code is supported — continuation lines get the same 4-space indent + any relative indent the dedented source had.:raises -
ValueErroriftest_nameisn’t found: :raises -ValueErrorifbody_codeis empty or parses to nothing: :raises -SyntaxErrorif the resulting file wouldn’t parse: (caller can surface this to the LLM for retry)Used by the
fill_test_bodyinner tool — the framework owns the surgical edit so the 7B can just emit the body as plain Python text without wrestling with edit_file_replace’s whitespace matching.