Repository navigation
fix(studio-server): renaming a nested folder rewrites the paths files beside it use - #6367
miguel-heygen wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
Verdict: REQUEST CHANGES · 1 blocker · 1 important · 0 nits · head 2027b9d5
- blocker —
Commentsis red on this head:comment-ratchet.mjsreportsfiles.tscomment share 5.8% → 5.9% (225/3853 → 231/3938, 6 comment lines added). CONTRIBUTING.md: "A package file's comment share may not rise", and the PR body doesn't explain it. Cutting 2 comment lines gets it back to ≤ base; therewriteWithandreachescomments repeat the PR description.
Scope
Read files.ts diff end-to-end and the 8 new route tests. Built parsers/lint/studio-server/core and ran src/routes/: 657/657 pass. Probed over the route: file rename (url(a.png), ./, ?v=), a 3-level nested rename, srcset + inline style + inline script in HTML, md/json left alone, cross-folder move. All correct except the cross-folder HTML case inline. Required CI: green so far, edit-accuracy shards and windows engine-cli still running when I posted.
| const [from, to] = [oldPath.slice(at + 1), posix.relative(dir, newPath)]; | ||
| parentFolderEdits.set(dir, { | ||
| css: referenceEdits(from, to, isDirectory, inside, { targets: null }), | ||
| html: referenceEdits(from, to, isDirectory, inside, { targets: filesOnly(inside) }), |
There was a problem hiding this comment.
important — HTML never takes the folder reading on a cross-folder move. targets holds only paths under dir/, but to = posix.relative(dir, newPath) starts with ../ when the folder leaves dir, so reaches can't match it. Repro: assets/clips/a.png plus assets/i.html <img src="clips/a.png">, then move assets/clips → media/clips. The CSS beside it becomes url(../media/clips/a.png), but the HTML keeps clips/a.png. Before the move that path resolved beside the page; afterwards it resolves to nothing. This isn't a wrong rewrite, just one that's missing, and the PR's list of what it didn't exercise doesn't mention it. A fix is to check existence project-wide against posix.join(dir, to + rest), or note it in the body.
Edit accuracy: accurate 273 (base branch 271), smooth 75 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) |
906e7ac to
b9978f7
Compare
|
This PR has had no activity for 14 days, so it is marked stale and will close in 7 days. Push a commit or leave a comment to keep it open. A maintainer can add |
…der-references # Conflicts: # packages/studio-server/src/routes/files.ts
|
Merged main in at
The merge carries the change onto main's refactored On Linux:
|
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit 8660dac (the non-test diff read in full by me). This is my first review of this PR; the open change request on it is another reviewer's.
Verdict: approved, good to ship. A correctness fix for renames, not a security change; I found no defect by reading.
Summary
Renaming a nested file or folder rewrote references written from the project root, but not the ones a neighbouring file writes relative to its own folder. The rename now also builds, for each parent folder of the renamed path, a second matcher for folder-relative references, used only for HTML and CSS files that sit in that folder, and applies both sets of edits in one pass.
Blockers
None.
What I checked
- Which files are rewritten and how they are written is unchanged: the same walk, the same safe-path and writable checks, the same atomic replace with the file's mode kept.
- The folder-relative matcher is narrower than the root one: only a bare or
./lead, never in script files, never when the rest of the reference climbs out of the renamed folder, and in HTML only when the rewritten path names a file that exists. - Edits from the two matchers are sorted and an overlapping later edit is dropped, so one reference is never rewritten twice.
- The text scanned after a match is capped at 256 characters, so the existence check stays bounded.
Non-blockers
- In CSS the folder-relative rewrite does not check that the new path exists (HTML does). A CSS string that merely looks like the old relative name would be rewritten; the tests may cover this, but it is the looser of the two.
CI: 64 pass, 17 skipped, none failing; 2 pending when I posted (Windows jobs for the engine and CLI packages, which this PR does not touch). The studio-server tests, Fallow audit and Typecheck pass.
|
Thanks. On the non-blocker (CSS doesn't check that the new path exists): that's deliberate. A relative You're right that it's looser in one case: a CSS string outside |
|
@heygengenesis review: both findings from your review at |
…der-references # Conflicts: # packages/studio-server/src/routes/files.ts
|
Fixed the non-blocking finding in a2e0a90: a page's minified
|
vanceingalls
left a comment
There was a problem hiding this comment.
Re-review at a2e0a90a. Approving.
The delta since my approval at 73b26a0d is one commit, a2e0a90a, touching two files: a one-line change to REFERENCE_END in fileReferences.ts and one new route test. Nothing from main came in.
- Fix: the closing
)of aurl()may now be followed by},!,)or/, as well as whitespace,;and,. That coversurl(clips/a.png)}andurl(clips/a.png)!importantin a minified<style>, and a nestedimage-set(url(...)). It is only used by the existence check for HTML, so CSS files and the root pass are unchanged. - Quoted and data URLs: a quoted url ends at the quote, so the text after the match is empty and still hits
$. Adata:url cannot name a project file. The existing quoted-url tests still cover this. - Test: it runs
}and!importantthrough a rename, and theimage-set(... 1x)case rides along. It carries thefails without the fixnote. The nested))and/endings have no test of their own. I'm not asking for one. - Genesis's earlier points: the cross-folder HTML case is fixed in
b9978f77, and the comment cut is inec0ea540. Neither is reintroduced, and the Comments check is green. - CI: every check is green on this head, including the Windows engine-cli job.
- Visible UI: none. This is studio-server only.
One non-blocking item: the PR body's "Not covered" section still describes the cross-folder move as unhandled, which b9978f77 fixed. Worth deleting that line.
jrusso1020
left a comment
There was a problem hiding this comment.
Verdict: APPROVE at a2e0a90a1bf50dc6a59ed522a59149bf300bc111.
There is one commit since my approval at 73b26a0d, and it fixes my non-blocking nit:
fileReferences.ts:412:REFERENCE_ENDnow also accepts},!,)and/after a closing). A folder-relativeurl()at the end of a minified rule (url(clips/a.png)}), before!important, or insideimage-set(url(...) 1x)now follows a rename.- The new test "in HTML follows a folder-relative url() in a minified style" covers all three shapes and checks the file as written.
Local runs (files.renameReferences.test.ts):
- At this head: 67/67 pass.
- With
fileReferences.tsset back to73b26a0d, the new test fails (1 fail / 66 pass). That matches its 'fails without the fix:' line. - The merge with main is unchanged from
73b26a0d, and only those two files changed.
Need · Size · Reuse · Simpler · Structure: closes the url() gap · one regex and a test · n/a · minimal · ok
Risk: low. The boundary only accepts more of the characters that can follow a closing ) in CSS.
— Rames
|
Correction to the description's "Not covered" section, which can't be edited here: that case is covered now. Moving a folder out of the folder an HTML file reads beside ( |
…der-references # Conflicts: # packages/studio-server/src/routes/files.ts
jerry-heygen
left a comment
There was a problem hiding this comment.
Changes requested at 414aef56. The HTML folder-relative pass checks whether the rewritten path exists, but it scans past the end of an unquoted URL into the next attribute. For example, with assets/clips/a.png and assets/i.html containing <img src=clips/a.png alt=preview>, renaming assets/clips to assets/takes leaves the image pointing at clips/a.png. In packages/studio-server/src/helpers/fileReferences.ts:349–360, restAfter passes /a.png alt=preview to the existence check. REFERENCE_END does not accept the next attribute as a boundary, and the project-root pass does not match clips/a.png.
Please bound the existence check to the URL span the scanner has already identified, and cover an unquoted src followed by another attribute in the route tests. The prior cross-folder HTML and minified-style fixes are present; the exact-head preview regression and Windows Studio server files checks passed. I did not run a live Studio rename.
— Jerrai (pr-review)
|
@jerry-heygen fixed at
@heygengenesis your 10-26 blocker at Not exercised: a live Studio rename, Windows. |
jerry-heygen
left a comment
There was a problem hiding this comment.
Approved at c4dcdcc7. The folder-relative existence check now stops at the scanner’s URL boundary, so it no longer mistakes the next HTML attribute for part of an unquoted path. The new route test covers both src and href and checks that the following attributes are preserved. The earlier cross-folder and minified-style cases remain covered.
The exact-head preview-regression and Windows Studio server files workflows passed. I did not run a live Studio rename.
— Jerrai (pr-review)
What changed
Renaming a folder inside another folder (say
assets/clipstoassets/takes) left references that files inassets/write relative to themselves, such asurl(clips/a.png), pointing at the old name. The rename already rewrote project-root paths; each file in a folder that holds the renamed path now also gets its own relative spelling rewritten (bare or./), with the same sibling and existing-path guards.CSS takes that reading always (a stylesheet resolves paths relative to itself). HTML takes it only where the complete target is an existing file in that folder, else the path stays for the project-root pass, the same rule the runtime uses. Scripts, JSON, Markdown and inline
<script>blocks resolve against the page, so they take the project-root pass only.Edits from both readings are collected from the original text and applied once, so neither rewrites the other's output. Only the renamed path's parent folders get the second reading, so the work stays one pass per file.
This re-ports the earlier change onto the current reference rewriter (entity, URL, srcset and CSS-escape spellings):
referenceRewriternow builds edits per reading andrewriteWithapplies them together.What I measured
The 8 new route tests in
files.renameReferences.test.tscover: a stylesheet's bare and./paths, root paths and sibling-folder paths left alone, a new path that holds the old folder's name, the folder reading winning where both match, paths that climb back out of the folder, HTML existence rules, and a path the runtime reads from the root. With the folder reading switched off, 6 of the 65 tests in the file fail; with it on, all 65 pass, and the whole routes suite passes (657/657). A page that moves its folder out (assets/clipstomedia/clips, pageassets/i.html) now gets../media/clips/a.png: the existence check looks at every project file relative to the page's folder, not only those inside it. The new test passes 3 runs in a row (66/66) and fails with that change reverted.fails without the fix: packages/studio-server/src/routes/files.renameReferences.test.ts "in HTML follows a folder moved out of the page's folder"
What I did NOT exercise
..(../clips/a.pngfromassets/other/) is left as written...is left as written, as before...further out is not seen, which can only skip a rewrite, never make a wrong one.tscfor the package was not clean on the test machine because the core build output was missing there; no type error comes from this change.Replaces #4959.
Not covered
Moving a folder out of the folder an HTML file reads beside (for example
assets/clipstomedia/clips, withassets/i.htmlholding<img src="clips/a.png">) rewrites the CSS beside it but leaves that HTML reference as it was. The rename case in this PR is unchanged by it.