fix(loader): resolve relative asset paths against the scenario, not the CWD - #200
Merged
Merged
Conversation
…he CWD "src": "assets/logo.png" resolved against the process working directory, so the same file rendered from its own folder and failed from anywhere else — the studio runs from the repository root, which is why a scenario authored beside its assets showed nothing there. `include` had always resolved relative to the including file. Two path-like fields in one document following two different rules is the trap, and it is the single cause behind a family of "component X does not render" reports: a hard error for image and gif, a warning for video, silence for an audio track feeding a waveform. Rewrite on the raw JSON before deserialisation, so no component changes: by the time an image or an audio track is constructed its src is already absolute. Applied in the JSON loader, the HTML loader, the CLI's validation pipeline, and per included file — an include's assets belong to the file that names them, not to the parent that pulled it in. Deliberately conservative: a path is rewritten only when the file exists next to the scenario. Anything else is left exactly as written, so a path that used to resolve against the working directory still does, and a genuine typo still reaches the validator with the author's own spelling. `track` is rewritten alongside `src`: the audio analysis is cached under the track's src and a waveform finds it by track, so rewriting one and not the other would make every lookup miss.
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.
Closes #186.
What
"src": "assets/dot.png"resolved against the process working directory. This is the single cause behind a family of "component X does not render" reports: a scenario authored beside its assets works, then the studio — which runs from the repository root — resolves nothing. The symptom varied by component (hard error forimage/gif, a warning forvideo, silence for anaudiotrack feeding awaveform), which made it look like several unrelated bugs.includehad always resolved relative to the including file. Two path-like fields in one document following two different rules is the trap.How
One pass over the raw JSON, before deserialisation, so no component changes: by the time an
imageor anaudiotrack is constructed, itssrcis already absolute. Applied in four places, all of which already hold both the JSON and its file path:trackis rewritten alongsidesrc: the audio analysis is cached under the track'ssrcand awaveformfinds it bytrack, so rewriting one and not the other would make every lookup miss.Deliberately conservative
A path is rewritten only when the file exists next to the scenario. Anything else is left exactly as written, which means:
Absolute paths,
http(s)://anddata:are untouched.Tests
Six on the rewrite itself (absolute result, independence from the CWD, missing file left alone, absolute/remote left alone,
src/trackagreeing, unrelated keys untouched) and one through the loader asserting a scenario'saudio[0].srccomes back absolute and pointing at the real file — the end-to-end property the issue is about.cargo test --workspacegreen,cargo fmt --checkandcargo clippy --all-targets -- -D warningsclean. Verified by hand: the failing command above now renders from/, byte-identical to the run from the scenario's own directory.