Repository navigation
Fix code_generator.py to ensure unique, tutorial-specific output (not identical boilerplate) #123
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or requestneeds-triagepriority:highquestionFurther information is requestedFurther information is requested
Description
Problem Statement
The code_generator.py module was introduced with PR #103 which added Stage 2 Semantic Logic Parsing with BuildPlan support. However, the implementation contained a critical bug in the _build_generation_context() method that would cause a NameError when the code attempted to generate projects.
Root Cause
The _build_generation_context() method (lines 1200-1290) had broken if/else logic:
- Undefined Variables: The variables
features,summary, andkey_conceptswere referenced in lines 1278, 1287-1288 but were never defined in either code path - Broken Control Flow: Lines 1252-1257 appeared outside the if block but before the else block, creating impossible-to-execute code
- Missing Variable Extraction: The
summaryandkey_conceptsextraction logic was entirely missing from both the BuildPlan path and the legacy fallback path
Example Error
# Line 1278 - features is never defined
"features": features, # NameError: name 'features' is not defined
# Lines 1287-1288 - summary and key_concepts are never defined
"summary": summary, # NameError: name 'summary' is not defined
"key_concepts": key_concepts, # NameError: name 'key_concepts' is not definedSolution Implemented
1. Fixed Control Flow
- Moved
summaryandkey_conceptsextraction to the top of the method (lines 1214-1219) - Properly structured if/else blocks for BuildPlan vs legacy extraction
- Ensured all variables are defined in all code paths
2. BuildPlan Path (lines 1222-1243)
When a BuildPlan is available:
- Extract
title,technologies,features, andtutorial_stepsfrom the BuildPlan - Create a complete
extracted_infodict with all required fields - Log success with BuildPlan title
3. Legacy Fallback Path (lines 1244-1281)
When no BuildPlan is available:
- Extract title from multiple fallback sources
- Extract technologies from ai_analysis or metadata
- Extract features from extracted_info or ai_analysis
- Derive tutorial_steps using existing helper method
- Update extracted_info with all fields
4. Video-Specific Output Enhancement
Added title comment to styles.css generation to ensure video traceability in all generated files.
Test Results
All uniqueness tests now pass:
tests/test_code_generator_unique_output.py::test_different_videos_produce_different_js PASSED
tests/test_code_generator_unique_output.py::test_different_videos_produce_different_css PASSED
tests/test_code_generator_unique_output.py::test_same_video_produces_deterministic_output PASSED
tests/test_code_generator_unique_output.py::test_title_appears_in_all_generated_files PASSED
tests/test_code_generator_unique_output.py::test_fingerprint_is_unique_per_video PASSED
tests/test_code_generator_unique_output.py::test_accent_color_varies PASSED
Impact
Before Fix:
- Code would crash with NameError when attempting to generate any project
- BuildPlan integration from PR feat: Stage 2 Semantic Logic Parsing — structured BuildPlan extraction #103 was completely broken
- No projects could be generated successfully
After Fix:
- Both BuildPlan and legacy extraction paths work correctly
- Each video produces unique, tutorial-specific output
- Fingerprinting ensures different videos get different colors, content, and structure
- Generated code includes video title, steps, concepts, and features
Files Changed
src/youtube_extension/backend/code_generator.py(lines 1200-1288)- Fixed
_build_generation_context()method - Updated
_generate_vanilla_styles_css()to include title parameter - Updated caller to pass title to CSS generator
- Fixed
Related
- Introduced in: PR feat: Stage 2 Semantic Logic Parsing — structured BuildPlan extraction #103
- Fixes critical bug from: Stage 2 Semantic Logic Parsing implementation
- Tests:
tests/test_code_generator_unique_output.py
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or requestneeds-triagepriority:highquestionFurther information is requestedFurther information is requested
Activity
github-actions commentedon Mar 20, 2026
👋 Thanks for opening this issue! It has been automatically labeled for triage.
groupthinking commentedon Mar 20, 2026
Closing: duplicate of #122.
fix(ci): harden repository reconciliation drift detection (#1788)
fix(reconciliation): accept same-repo qualified issue refs (#1825)