From 4a59fef2d0b91de31f97e4a8d9b9071a3e8330c9 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 17 Nov 2026 18:50:20 +0000 Subject: [PATCH] fix(cli): say a listed received file is gone, and drop a media file's line on rename (#8098) * fix(cli): say a listed received file is gone, and drop a media file's line on rename Follow-up to the change that keeps a deleted received page listed. - The render warning for a listed file that no longer exists now says it is gone and how to clear it. - A listed file whose name was already a media name drops its old line when renamed to another media name, so repeated renames leave no dead lines. - The docs say that any listed file that is not media by its first bytes stays listed after a delete, and that the line can sit in a record above or inside the project. - A test restores content after a plain Studio delete and checks that outside files stay refused. * test(cli): match the gone-file warning without a POSIX path, for Windows --- docs/packages/cli.mdx | 11 +++++--- .../studioServer.receivedRecord.test.ts | 28 +++++++++++++++++++ .../cli/src/utils/receivedRecordFollow.ts | 2 +- packages/cli/src/utils/receivedRender.ts | 17 +++++++---- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index a42b3b7719..87a8d0829b 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -2017,10 +2017,13 @@ A composition that needs the left-out script stops with a script-load error. A received-files record lists the files in a folder that came from someone else. When a record in the project, or in a folder above it, lists anything but media, fonts and images, the render leaves out every file from outside the -project folder and warns with each one's name. When you delete a listed page, -stylesheet or script in Studio, its line stays, so whatever is later written in -its place still counts as received; take the line out of -`.hyperframes/received-files.json` yourself once you know the content is gone. +project folder and warns with each one's name. When you delete a listed file in +Studio that is not media, a font or an image by its first bytes, its line stays, +and so does the old line of such a file you rename to a media name. Whatever is +later written in its place still counts as received, and the warning says the +file is gone. To clear it, take the line out of the received-files record that +lists it, which is the project's `.hyperframes/received-files.json` or one in a +folder above or inside the project. A `--docker` render makes this check on your machine, where the folders above the project are visible, and passes `--refuse-outside-files` into the container, so it leaves out the same files a local render would. diff --git a/packages/cli/src/server/studioServer.receivedRecord.test.ts b/packages/cli/src/server/studioServer.receivedRecord.test.ts index db9ffad614..192093eab3 100644 --- a/packages/cli/src/server/studioServer.receivedRecord.test.ts +++ b/packages/cli/src/server/studioServer.receivedRecord.test.ts @@ -285,6 +285,34 @@ describe("a Studio rename, move or delete in a project with a received-files rec expect(allowed(projectDir)).toBe(false); }); + it("keeps refusing outside files when content comes back after a plain Studio delete, and says the file was gone", async () => { + const { projectDir, app } = studio(); + withRecord(projectDir); + const intro = join(projectDir, "scenes", "intro.html"); + const before = readFileSync(intro); + expect((await app.request(fileUrl("scenes/intro.html"), { method: "DELETE" })).status).toBe( + 200, + ); + write(join(projectDir, "index.html"), ``); + const warnings: string[] = []; + expect(outsideAssetsAllowed(projectDir, "index.html", (line) => warnings.push(line))).toBe( + false, + ); + expect(warnings.join("\n")).toMatch(/intro\.html came from someone else and is gone/); + writeFileSync(intro, before); + expect(listed(projectDir)).toContain("scenes/intro.html"); + expect(receivedFiles(projectDir)("scenes/intro.html")).toBe(true); + expect(allowed(projectDir)).toBe(false); + }); + + it("drops the old line when a received file with a media name but other bytes is renamed to another media name", async () => { + const { projectDir, app } = studio(); + withRecord(projectDir); + write(join(projectDir, "scenes", "logo.png"), "not a picture"); + expect((await move(app, "scenes/logo.png", "scenes/logo.webp")).status).toBe(200); + expect(listed(projectDir)).toEqual(["scenes/intro.html", "scenes/logo.webp"]); + }); + it("drops the old line when a received image is renamed to another image name", async () => { const { projectDir, app } = studio(); withRecord(projectDir); diff --git a/packages/cli/src/utils/receivedRecordFollow.ts b/packages/cli/src/utils/receivedRecordFollow.ts index 1d6f72d9b7..9603f13467 100644 --- a/packages/cli/src/utils/receivedRecordFollow.ts +++ b/packages/cli/src/utils/receivedRecordFollow.ts @@ -139,7 +139,7 @@ export async function plannedReceivedChange( const toKey = keyIn(folder, to); push(change.leaving, folder, { ...left, - stays: left.stays === true && isMediaName(toKey + rest), + stays: left.stays === true && !isMediaName(line) && isMediaName(toKey + rest), }); if (leavesFolder(toKey)) push(change.arriving, root, keyIn(root, to) + rest); else push(change.arriving, folder, toKey + rest); diff --git a/packages/cli/src/utils/receivedRender.ts b/packages/cli/src/utils/receivedRender.ts index 20c3a5702a..8a0e1791c6 100644 --- a/packages/cli/src/utils/receivedRender.ts +++ b/packages/cli/src/utils/receivedRender.ts @@ -307,6 +307,16 @@ function receivedContentRefusal(projectDir: string, hashes: string[]): Refusal | return { reason, alwaysWarn: false }; } +function nonMediaRefusal(listed: string[], shown: (path: string) => string): Refusal | null { + const nonMedia = listed.find((path) => !isMediaFontOrImage(path)); + if (nonMedia === undefined) return null; + const what = isFile(nonMedia) + ? "is not a media, font or image file" + : "is gone but still listed; take its line out of the received-files record that lists it to clear this"; + const reason = `${shown(nonMedia)} came from someone else and ${what}, ${READS_NOTHING_OUTSIDE}`; + return { reason, alwaysWarn: false }; +} + function receivedRefusal( projectDir: string, record: { path: string; listed: string[] | null; hashes: string[] } | "unchecked", @@ -319,11 +329,8 @@ function receivedRefusal( if (record.listed === null) { return { reason: `Could not read ${record.path}, ${READS_NOTHING_OUTSIDE}`, alwaysWarn: true }; } - const nonMedia = record.listed.find((path) => !isMediaFontOrImage(path)); - if (nonMedia !== undefined) { - const reason = `${shown(nonMedia)} came from someone else and is not a media, font or image file, ${READS_NOTHING_OUTSIDE}`; - return { reason, alwaysWarn: false }; - } + const listedRefusal = nonMediaRefusal(record.listed, shown); + if (listedRefusal !== null) return listedRefusal; const contentRefusal = receivedContentRefusal(projectDir, record.hashes); if (contentRefusal !== null || record.listed.length === 0) return contentRefusal; const received = receivedIdentities(record.listed);