Java Lab2: add support for image and audio assets#73259
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Java Lab 2 (Codebridge-based) support for image/audio assets by representing assets as URL-backed file entries in the flat main.json source shape, extracting them server-side into the existing assetUrls contract for Javabuilder, and handling legacy starter_assets mappings when seeding sources.
Changes:
- Add URL-backed asset entries (
url,flagged) to Java Lab 2’s flat source format and conversion logic (flat ↔ multifile), including correct ownership typing for safe delete/unflag behavior. - Strip URL-backed asset entries out of
main.jsonon the dashboard before sending sources to Javabuilder, folding them intoassetUrlsas absolute URLs. - Merge legacy level
starter_assetsmappings into seeded lab2 sources (start/template/exemplar) and add javalab to image moderation.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| dashboard/test/models/javalab_test.rb | Adds tests for starterAssets in lab2 level properties and for frozen mapping behavior in add_starter_asset!. |
| dashboard/test/helpers/javalab_files_helper_test.rb | Adds coverage for stripping/extracting URL-backed asset entries into assetUrls. |
| dashboard/test/controllers/level_starter_assets_controller_test.rb | Ensures /uuid/ upload does not mutate starter_assets for lab2 javalab levels. |
| dashboard/config/levels/custom/javalab/Allthethings Java Lab2 Validation.level | Updates level config to include URL-backed starter assets in start_sources. |
| dashboard/app/models/levels/javalab.rb | Freezes starter_assets writes for lab2 and includes starterAssets in lab2 level properties (template precedence). |
| dashboard/app/helpers/javalab_files_helper.rb | Extracts URL-backed asset entries from main.json and override sources into assetUrls. |
| apps/test/unit/javalab/lab2/starterAssetsTest.ts | Tests starter-asset URL helpers and merge behavior for legacy starter_assets. |
| apps/test/unit/javalab/lab2/sourceConverterTest.ts | Tests conversion behavior for URL-backed asset files, including starter vs channel assets and round-tripping. |
| apps/test/unit/javalab/lab2/Javalab2ViewTest.tsx | Tests that legacy starter_assets are merged into seeded sources, but not into server-loaded projects. |
| apps/test/unit/javalab/lab2/javabuilderRunUtilsTest.ts | Pins the overrideSources wire contract including URL-backed assets. |
| apps/src/util/moderateImage.ts | Enables image moderation for javalab uploads. |
| apps/src/javalab/lab2/types.ts | Extends flat-file shape to include url and flagged fields for asset entries. |
| apps/src/javalab/lab2/starterAssets.ts | Implements legacy mapping → URL-backed STARTER files merge and helper utilities. |
| apps/src/javalab/lab2/sourceConverter.ts | Adds URL/flagged persistence in conversions and derives asset file typing from URL prefix. |
| apps/src/javalab/lab2/README.md | Documents asset URL-backed source entries, server stripping, frozen mapping behavior, and limitations. |
| apps/src/javalab/lab2/Javalab2View.tsx | Merges legacy starter assets into seeded level sources (start/template/exemplar) before passing to Codebridge. |
| apps/src/javalab/lab2/constants.ts | Expands supported file types to include image/audio uploads while keeping editable types unchanged. |
| def add_starter_asset!(friendly_name, uuid_name) | ||
| return true if uses_lab2? | ||
| self.starter_assets ||= {} | ||
| self.starter_assets[friendly_name] = uuid_name | ||
| save! |
There was a problem hiding this comment.
lab2 never exercises the remove path here, so I'm going to leave as-is
| # get level assets | ||
| # get level assets. | ||
| # TODO: determine if this is needed for lab2. We may be able to skip this as if it's not needed for | ||
| # backwards compatiblity. |
There was a problem hiding this comment.
Note: I am keeping this line for both lab2 and legacy for now, although I think it's only going to be needed for legacy. It is harmless for lab2; if I upload a file named cute_dog, the resulting assetUrls object contains two entries:
Note the second entry uses the uuid for cute_dog as the filename. I am keeping it in case it's useful for backwards compatibility, but it shouldn't confuse javabuilder to have extra entries.
| 'spritelab', | ||
| 'poetry', | ||
| 'game_design', | ||
| 'javalab', |
There was a problem hiding this comment.
@fisher-alice my understanding is this is safe to add since it's only exercised by the new lab2 java lab, which goes through the same codebridge upload pipeline. LMK if that's correct or not!
This adds support for image and audio asset files in Java Lab on lab2, for both user-uploaded files and levelbuilder-added starter assets. In legacy Java Lab, starter assets are stored in a separate
starter_assetsfield on the level. In codebridge, assets are part of the main file object, and the object links out to the S3 location where the asset lives. This work allows both paths to work; if there are starter assets on the level, we copy them into the project on initial load. Right now we allow them to be renamed/deleted, but as a follow-up I'm going to make all legacy starter assets 'locked', which is consistent with legacy behavior (right now we don't yet have 'locked' support in lab2 java lab). The user can also add image and audio files to their own project via upload. In addition, if editing a lab2 java lab level we will add the files to the start sources as url-based files, consistent with web lab 2.When sending sources to javabuilder, we extract out the url-based files and put them in the
assetUrlsobject that javabuilder already uses to map image/audio assets to S3 links.Note: about 3/4 of the lines of this PR are tests/level files, so it's not as big as it seems!
I've tested that we are sending what we expect to Javabuilder, but can't actually fully test this yet for two reasons. Mainly that the only mini app that uses images/audio is theater, which I haven't implemented here yet. This is the pre-work for theater. Second, once I have theater set up I will need to set this up on an adhoc to actually test it, because the image/audio asset pipeline is the one place where javabuilder talks to dashboard, which doesn't work when you are running on localhost.
Testing story
Tested locally that we are sending the correct urls as part of
assetUrls, and legacy java lab is unaffected.