fix(generator): refuse to regenerate templates from empty resolved source#100
Merged
Conversation
…urce 2026-07-05 incident: a bulk regen in attune-ai ran against a wrong project root, resolved every feature's source globs to zero files, computed source_hash of the empty string (e3b0c442...), and rewrote 36 existing .help/templates files with drastically degraded content (1044 insertions vs 2609 deletions). The pipeline generated happily from empty input instead of failing. Guard (prepare_polish_phase, before any mkdir/write): when globs match nothing — or every matched file is empty/unreadable — and generated output already exists on disk, raise EmptySourceError instead of overwriting. Scaffolding a brand-new feature from empty source (nothing on disk yet) stays allowed, per the documented zero-match scaffold contract in test_generator.py. - staleness.py: EMPTY_SOURCE_SHA256 constant + EmptySourceError - generator.py: overwrite guard covering help templates and project-doc kinds; both hash paths (byte and semantic) produce the empty-string SHA on empty input, so one sentinel covers both - cli.py: catch EmptySourceError at the run_command boundary and exit 1 with the message (RuntimeError subclass on purpose — the batch-submit path swallows ValueError as "nothing to do" exit 0) - run_maintenance/batch submit propagate it, so `regenerate` aborts loudly rather than recording a silent per-feature failure Tests: tests/test_empty_source_guard.py — refusal preserves on-disk content, zero-byte source refused, scaffold-from-empty still allowed, healthy source unaffected, CLI exits 1 without traceback. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Codecov flagged the guard at 80.76% patch coverage (target 86.93%). Covers: an unrecognized depth name outside _ALL_TEMPLATE_NAMES is skipped rather than crashing the at-risk scan, and a project-doc kind (how-to/tutorial/cli-reference/architecture) resolves its at-risk path via _project_doc_output_path, not just .help/ template_dir.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
🤖 Generated with Claude Code