Files
hyperframes/packages/cli/src/commands/compositionRoute.encoding.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

71 lines
2.6 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { Hono } from "hono";
import type { ProjectDir } from "../utils/project.js";
import { registerCompositionRoute } from "./play.js";
import { registerPresentCompositionRoute } from "./present.js";
// Hono's c.req.path leaves %40 %25 %23 %26 %3F encoded; Windows file names cannot hold "?".
const NAMES = [
"A @HyperFrames launch",
"50% off",
"#2 take",
"Tom & Jerry",
...(process.platform === "win32" ? [] : ["why?"]),
"two spaces",
"café crème",
"🎬 film",
];
const ROUTES = [
["play", (app: Hono, project: ProjectDir) => registerCompositionRoute(app, project, false)],
["present", registerPresentCompositionRoute],
] as const;
let dir: string | undefined;
afterEach(() => {
if (dir) rmSync(dir, { recursive: true, force: true });
dir = undefined;
});
async function requestAsset(
register: (app: Hono, project: ProjectDir) => Promise<void>,
name: string,
) {
dir = mkdtempSync(join(tmpdir(), "hf-composition-route-"));
mkdirSync(join(dir, "scenes"));
writeFileSync(join(dir, "scenes", `${name}.txt`), `ASSET ${name}`);
const app = new Hono();
await register(app, { dir, name: "test-project", indexPath: join(dir, "index.html") });
const response = await app.request(`/composition/scenes/${encodeURIComponent(`${name}.txt`)}`);
return { status: response.status, text: await response.text() };
}
describe.each(ROUTES)("%s /composition/*", (_route, register) => {
it.each(NAMES)("serves an asset named %j", async (name) => {
const result = await requestAsset(register, name);
expect(result.status).toBe(200);
expect(result.text).toBe(`ASSET ${name}`);
});
it("does not serve env files, Git data or the tools' own records", async () => {
dir = mkdtempSync(join(tmpdir(), "hf-composition-route-"));
mkdirSync(join(dir, ".git"));
mkdirSync(join(dir, ".hyperframes"));
for (const name of [".env", ".envrc", ".env-local", ".git/config", ".hyperframes/x.json"]) {
writeFileSync(join(dir, name), "KEY=secret");
}
writeFileSync(join(dir, "logo.png"), "png");
const app = new Hono();
await register(app, { dir, name: "test-project", indexPath: join(dir, "index.html") });
for (const path of [".env", ".envrc", ".env-local", ".git/config", ".hyperframes/x.json"]) {
expect((await app.request(`/composition/${path}`)).status).toBe(404);
}
expect((await app.request("/composition/logo.png")).status).toBe(200);
});
});