Files
hyperframes/packages/cli/src/utils/privateProjectFile.test.ts
T
Michael WangandClaude Opus 5.5 c96ff540c4 fix(cli): harden lambda destroy, snapshot media, upgrade and project file serving (#7509)
* fix(cli): lambda destroy runs SAM in a private folder and acts only on the selected stack

- sam delete outside a checkout runs in a fresh private temp folder,
  removed afterwards, instead of the shared temp directory.
- A stack state file must name the stack it is selected by.
- destroy and deploy derive the video repository name from the stack
  name instead of trusting the recorded value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): snapshot keeps remote clips in a private folder and reads only allowed URLs

- A video URL the download policy refuses (plain http, or a private,
  loopback or link-local host) is no longer handed to FFmpeg; the clip
  is skipped instead, as render does.
- Remote clips are cached in a per-user, owner-only temp folder; a
  folder open to other users is never reused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): upgrade --project writes package.json through an exclusive temp file

The rewrite now uses the shared atomic replace, which creates a fresh,
unpredictable sibling with exclusive creation, so an existing
package.json.tmp entry is never written through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): keep env files, Git data and tool records out of served and uploaded projects

- play and present answer 404 for .env files, .git and the tools'
  private .hyperframes records, as Studio's preview does for the records.
- publish and cloud render never stage an env file or tool record, even
  when markup references it, and never pull in an env file from outside
  the project.
- Cloud site uploads (Lambda and Cloud Run deploySite) leave env files out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): lambda commands accept a state file whose stack name differs only in case

On a case-insensitive disk, deploy --stack-name=Demo and --stack-name=demo share one
state file, so a name that matches apart from case is the same stack the user deployed
and keeps working as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): snapshot's fallback media folder uses createStagingDir

The repository check forbids bare mkdtemp beside a caller-supplied path, because it
fails past 260 characters on Windows. Also trims a comment so the new helper file stays
within its package's comment share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): snapshot never hands FFmpeg a remote URL

FFmpeg follows redirects and resolves hosts on its own, so a clip the downloader could
not fetch must not reach it as a URL. Snapshot now leaves such a clip out and warns,
as render does. A fallback media folder is removed when the process exits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): cover .envrc, .env-local and .env_prod, and test present's private-file 404

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 20:00:58 +00:00

56 lines
2.2 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { isEnvOrGitPath, isPrivateCompositionFile } from "./privateProjectFile.js";
let dir: string | undefined;
afterEach(() => {
if (dir) rmSync(dir, { recursive: true, force: true });
dir = undefined;
});
describe("isEnvOrGitPath", () => {
it("names env files and Git folders, whatever the letter case", () => {
expect(isEnvOrGitPath("/home/me/.env")).toBe(true);
expect(isEnvOrGitPath("a\\.Env.Local")).toBe(true);
expect(isEnvOrGitPath("repo/.git/config")).toBe(true);
expect(isEnvOrGitPath(".envrc")).toBe(true);
expect(isEnvOrGitPath("sub/.env-local")).toBe(true);
expect(isEnvOrGitPath(".env_prod")).toBe(true);
expect(isEnvOrGitPath(".environment.json")).toBe(false);
expect(isEnvOrGitPath("assets/environment.png")).toBe(false);
expect(isEnvOrGitPath("dotfiles.git/logo.png")).toBe(false);
});
});
describe("isPrivateCompositionFile", () => {
it("covers env files, Git data and tool records, not composition assets", () => {
dir = mkdtempSync(join(tmpdir(), "hf-private-file-"));
const at = (path: string) => isPrivateCompositionFile(dir!, join(dir!, path));
expect(at(".env")).toBe(true);
expect(at(".env.production")).toBe(true);
expect(at("sub/.env")).toBe(true);
expect(at(".git/HEAD")).toBe(true);
expect(at(".hyperframes/history-turn.json")).toBe(true);
expect(at(".hyperframes/prepared-assets/gif/a.webm")).toBe(false);
expect(at(".media/clip.mp4")).toBe(false);
expect(at("environment.png")).toBe(false);
expect(at("index.html")).toBe(false);
});
it.skipIf(process.platform === "win32")(
"follows a link inside the project to an env file",
() => {
dir = mkdtempSync(join(tmpdir(), "hf-private-file-"));
writeFileSync(join(dir, ".env"), "KEY=secret");
mkdirSync(join(dir, "assets"));
symlinkSync(join(dir, ".env"), join(dir, "assets", "logo.png"));
expect(isPrivateCompositionFile(dir, join(dir, "assets", "logo.png"))).toBe(true);
},
);
});