Skip to content

Restore tutorial-specific code generation for BuildPlan and legacy paths - #149

Merged
groupthinking merged 4 commits into
mainfrom
copilot/fix-undefined-variables-code-generator
Apr 1, 2026
Merged

Restore tutorial-specific code generation for BuildPlan and legacy paths#149
groupthinking merged 4 commits into
mainfrom
copilot/fix-undefined-variables-code-generator

Conversation

Copilot AI commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Template-based generation was collapsing into generic output because the generation context was inconsistent across code paths: BuildPlan-backed requests could drop tutorial-specific fields, step metadata was normalized incorrectly, and dict-based build plans could fail during result packaging. This PR tightens context assembly so generated projects keep the source tutorial’s title, concepts, steps, and summary without reintroducing boilerplate fallbacks.

  • Context assembly

    • Normalize build_plan inputs to a plain dict before downstream use.
    • Preserve features, summary, and key_concepts in both BuildPlan and legacy extraction paths.
    • Remove the dead fallback branch that attempted to derive steps from a missing build plan.
  • BuildPlan step handling

    • Prefer order for structured steps, with fallback to legacy step_number and then positional index.
    • Keep tutorial step strings aligned with the actual BuildStep schema instead of relying on non-existent fields.
  • Generated output

    • Ensure vanilla project artifacts carry tutorial-specific identity across all generated files.
    • Remove timestamp-based noise from generated content so repeated generation for the same tutorial stays deterministic.
  • Result packaging

    • Return normalized dict-based build plans directly instead of calling .to_dict() on plain dicts.
  • Regression coverage

    • Add focused tests for:
      • different BuildPlan-backed videos producing different main.js and styles.css
      • same BuildPlan input producing deterministic output
      • tutorial titles appearing across all generated vanilla assets

Example of the step normalization applied in the generator:

step_num = step.get("order", step.get("step_number", idx + 1))

@vercel

vercel Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
v0-uvai Error Error Apr 1, 2026 8:31am

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 800eb4c.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

Agent-Logs-Url: https://github.com/groupthinking/EventRelay/sessions/66cebfea-a2bd-4579-a88f-c036944c77f2

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
@groupthinking
groupthinking marked this pull request as ready for review April 1, 2026 08:05
@groupthinking
groupthinking self-requested a review as a code owner April 1, 2026 08:05
@groupthinking
groupthinking requested review from Copilot and removed request for groupthinking April 1, 2026 08:05
@groupthinking groupthinking assigned Claude and Codex and unassigned groupthinking Apr 1, 2026
@groupthinking
groupthinking enabled auto-merge April 1, 2026 08:06
Agent-Logs-Url: https://github.com/groupthinking/EventRelay/sessions/66cebfea-a2bd-4579-a88f-c036944c77f2

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
auto-merge was automatically disabled April 1, 2026 08:07

Head branch was pushed to by a user without write access

Copilot AI changed the title [WIP] Fix undefined variables in code_generator.py for unique outputs Restore tutorial-specific code generation for BuildPlan and legacy paths Apr 1, 2026
Copilot AI requested a review from groupthinking April 1, 2026 08:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

build_plan = video_analysis.get("build_plan") or extracted_info.get("build_plan")
# Upstream callers may pass either a Pydantic BuildPlan or a plain dict.
if hasattr(build_plan, "model_dump"):
build_plan = build_plan.model_dump()

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build_plan.model_dump() may leave StepAction enum instances inside the resulting dict (Pydantic v2 default "python" mode). Downstream code formats step["action"] into README strings and may emit StepAction.CREATE_FILE instead of create_file, and it can also complicate JSON serialization. Consider using model_dump(mode="json") (or otherwise normalizing step actions to plain strings) when converting BuildPlan to a dict.

Suggested change
build_plan = build_plan.model_dump()
build_plan = build_plan.model_dump(mode="json")

Copilot uses AI. Check for mistakes.
Comment thread src/youtube_extension/backend/code_generator.py Outdated
Comment on lines +12 to +21
def _tempdir_factory(*paths: Path):
remaining = iter(paths)

def _mkdtemp(prefix: str) -> str:
path = next(remaining)
path.mkdir()
return str(path)

return _mkdtemp

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test module appears to duplicate the same helper functions and test cases found in tests/unit/test_code_generator.py. Keeping both copies will run the same assertions twice and increases maintenance overhead. Consider consolidating these tests into a single location (or factoring shared helpers into fixtures) and deleting the duplicate file/tests.

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +21
def _tempdir_factory(*paths: Path):
remaining = iter(paths)

def _mkdtemp(prefix: str) -> str:
path = next(remaining)
path.mkdir()
return str(path)

return _mkdtemp

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file duplicates the same helper functions and test cases found in tests/test_code_generator.py. Duplicated tests increase runtime and maintenance burden; consider consolidating into one module (unit vs integration) and sharing helpers via fixtures to avoid two identical copies.

Copilot uses AI. Check for mistakes.
@groupthinking

Copy link
Copy Markdown
Owner

C
R
_
I
n
t
e
l
l
i
g
e
n
c
e

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
metadata = video_analysis.get("metadata") or video_analysis.get("video_data") or {}
ai_analysis = video_analysis.get("ai_analysis") or {}
build_plan = video_analysis.get("build_plan") or extracted_info.get("build_plan")
# Upstream callers may pass either a Pydantic BuildPlan or a plain dict.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using hasattr() for Pydantic BaseModel detection is less safe and less explicit than using isinstance() type checking

Fix on Vercel

build_plan = video_analysis.get("build_plan") or extracted_info.get("build_plan")
# Upstream callers may pass either a Pydantic BuildPlan or a plain dict.
if hasattr(build_plan, "model_dump"):
build_plan = build_plan.model_dump()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
build_plan = build_plan.model_dump()
build_plan = build_plan.model_dump(mode="json")

Pydantic model_dump() preserves enum instances instead of converting them to JSON-serializable strings

Fix on Vercel

@groupthinking
groupthinking merged commit b8402d8 into main Apr 1, 2026
15 of 17 checks passed
@groupthinking
groupthinking deleted the copilot/fix-undefined-variables-code-generator branch April 1, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Fix code_generator.py: undefined variables cause identical boilerplate instead of unique tutorial-specific output

5 participants