Skip to content

Seed preview projects for local/preview work - #964

Open
DNR500 wants to merge 4 commits into
mainfrom
add-seed-data-for-project-preview
Open

Seed preview projects for local/preview work#964
DNR500 wants to merge 4 commits into
mainfrom
add-seed-data-for-project-preview

Conversation

@DNR500

@DNR500 DNR500 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Arises from issue: 1653

Summary

Adds unowned Blocks (code_editor_scratch) templates to test seeds so Experience CS project previews can be loaded from editor-api without auth (and without waiting on ExCS content sync).
Pairs with the classroom preview route work in editor-standalone - see this editor-standalone PR.

  • Seed excs-preview-starter as a public Scratch template (user_id / school_id nil) with real Scratch JSON and instruction steps
  • Also seed the same identifier in fr-FR with a French name and instructions, so locale-aware ProjectLoader requests return translated project content instead of falling back to English
  • Wire create/destroy into test_seeds:create / test_seeds:destroy (and thus /test/reseed)
  • Cover create, destroy, idempotent instruction updates, and the French locale row in spec/lib/test_seeds_spec.rb

Why

#1653 needs a stable public Blocks project that classroom can open at a preview URL while logged out. Production templates will come from ExCS sync later; this seed unblocks local and PR testing.

How to try it

docker compose exec api bundle exec rake test_seeds:create
# or
curl -X POST http://localhost:3009/test/reseed -H "X-RESEED-API-KEY: $RESEED_API_KEY"
curl -s 'http://localhost:3009/api/projects/excs-preview-starter?locale=en' | head
curl -s 'http://localhost:3009/api/projects/excs-preview-starter?locale=fr-FR' | head
curl -s 'http://localhost:3009/api/scratch/projects/excs-preview-starter' | head

English and French project metadata should differ; Scratch content is shared.

Note: if the API process has been up a long time, restart it (or run rake test_seeds:create in a fresh docker compose exec) so reseed picks up the new rake task code.

DNR500 added 2 commits August 13, 2026 18:22
Add an unowned Blocks template to test seeds so local and preview
work can load Scratch content without auth.
Add an fr-FR row for excs-preview-starter so locale-aware preview
loads can return translated name and instructions instead of falling
back to English.
@cla-bot cla-bot Bot added the cla-signed label Aug 13, 2026
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

Test coverage

92.3% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/31731838748

Move the public Scratch preview seed helpers out of SeedsHelper so
RuboCop Metrics/ModuleLength stays under the limit.

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

Adds a public (unowned) Scratch/Blocks “preview starter” template into the test seeding flow so classroom preview routes can load a stable project from editor-api without authentication, including a French locale variant to validate locale-aware loading.

Changes:

  • Introduces ProjectPreviewSeedsHelper to upsert/destroy an unowned code_editor_scratch template (excs-preview-starter) with seeded Scratch JSON and instruction steps (EN + FR).
  • Wires preview project create/destroy into test_seeds:create and test_seeds:destroy.
  • Extends spec/lib/test_seeds_spec.rb to cover creation, destruction, and instruction updates, including the fr-FR row.

Reviewed changes

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

Show a summary per file
File Description
spec/lib/test_seeds_spec.rb Adds specs asserting the preview template is created (EN/FR), updated, and removed via test seed tasks.
lib/tasks/test_seeds.rake Hooks preview template lifecycle into the test reseed rake tasks.
lib/tasks/seeds_helper.rb Pulls preview seeding helpers/constants into the existing seeding helper module.
lib/tasks/project_preview_seeds_helper.rb Implements upsert/destroy logic for the public Scratch preview template and reads seed JSON from disk.
lib/tasks/seed_data/excs_preview_starter.json Adds seeded Scratch project JSON payload for the preview template.
lib/tasks/seed_data/excs_preview_starter_instructions.json Adds English instruction steps for the preview template.
lib/tasks/seed_data/excs_preview_starter_instructions_fr.json Adds French instruction steps for the preview template.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/tasks/project_preview_seeds_helper.rb
Comment thread lib/tasks/project_preview_seeds_helper.rb
Comment thread lib/tasks/test_seeds.rake Outdated
@DNR500
DNR500 marked this pull request as ready for review August 13, 2026 18:47
@jamiebenstead
jamiebenstead requested a balanced review from Copilot August 14, 2026 08:25

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 7 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (1)

lib/tasks/project_preview_seeds_helper.rb:44

  • For an existing preview project, changing project.scratch_component.content is not persisted by project.save!: this has_one association does not enable autosave, so Rails only saves a new associated record automatically. The current reseed therefore updates instructions but leaves stale Scratch JSON in the database; assigning a blank ScratchComponent.new can also save it before content is set. Build missing components through the association and save the component explicitly.
    project.scratch_component ||= ScratchComponent.new
    project.scratch_component.content = public_scratch_preview_content
    project.save!

@jamiebenstead jamiebenstead 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.

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants