Files
hyperframes/packages/cli/src/share/render.test.ts
T
terencecho 04947d99f7 feat(cli): share rendered videos through unified reviews (#7135)
* feat(cli): share rendered videos through unified reviews (#7135)

* feat(share): attach editable project sources to reviews (#7137)

* feat(share): measure local sharing outcomes (#7138)

* feat(cli): stage the sixty-day publish transition (#7136)

* feat(studio): share review pages from local preview (#7140)

Advertise the CLI sharing bridge before bootstrapping it so standalone Studio does not
request unsupported routes. Preserve origin and session checks.

Budget the intended sharing artifact: clean main packs at 8,060,519 bytes versus
8,162,979 with sharing (8,169,168 in CI). Required policy and Unicode tables, bundled
sharing code, and Studio controls account for the growth. Set the packed-only budget
to 8,577,627, following the 5% headroom convention; retain the unpacked cap and all
package checks.

* fix(share): persist refusals and improve CLI retry feedback

* fix(ci): restore render diagnostics and include sharing workspace

* fix(cli): keep sharing owner error codes stable

* fix(share): clarify update feedback and align audience changes

* fix(share): clarify updates and avoid scratch-file rerenders

* fix(cli): report active shares and preserve update channels

* fix(cli): resolve update channel when checking registry

* fix(ci): refresh sharing package budgets after rebase

* fix(share): require consent before uploading project files
2026-11-11 06:26:24 +00:00

90 lines
3.9 KiB
TypeScript

import { mkdtempSync, mkdirSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { projectFingerprint } from "@hyperframes/share";
import { latestShareRender, prepareShareRender, shareContentFingerprint } from "./render.js";
const rendering = vi.hoisted(() => ({ execute: vi.fn() }));
vi.mock("../commands/render/plan.js", () => ({ createRenderPlan: (plan: unknown) => plan }));
vi.mock("../commands/render/execute.js", () => ({ executeRenderPlan: rendering.execute }));
vi.mock("../commands/render.js", () => ({
renderLocal: vi.fn(),
checkRenderResolutionPreflight: vi.fn(),
}));
const dirs: string[] = [];
function folder() {
const dir = realpathSync(mkdtempSync(join(tmpdir(), "hf-share-")));
dirs.push(dir);
return dir;
}
afterEach(() => {
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
});
describe("local sharing render boundary", () => {
it("rejects a symlinked state directory before creating descendants", async () => {
const dir = folder();
const outside = folder();
writeFileSync(join(dir, "index.html"), "<html></html>");
symlinkSync(outside, join(dir, ".hyperframes"));
await expect(prepareShareRender(dir)).rejects.toThrow("without symlinks");
});
it("does not accept a sidecar pointing outside the project", () => {
const dir = folder();
mkdirSync(join(dir, ".hyperframes"));
writeFileSync(
join(dir, ".hyperframes", "share-render.json"),
JSON.stringify({ id: "../../escape", path: "/tmp/escape.mp4", fingerprint: "f" }),
);
expect(latestShareRender(dir)).toBeNull();
});
it("reuses only the exact locally recorded file", () => {
const dir = folder();
const id = "41c4587b-abcd-42ab-87ab-21a7b64cc010";
const output = join(dir, ".hyperframes", "share-renders", `${id}.mp4`);
mkdirSync(join(dir, ".hyperframes", "share-renders"), { recursive: true });
writeFileSync(output, "video");
writeFileSync(
join(dir, ".hyperframes", "share-render.json"),
JSON.stringify({ id, path: output, fingerprint: "f" }),
);
expect(latestShareRender(dir)).toEqual({ id, path: output, fingerprint: "f" });
});
it.each([".media/voice.mp3", ".hyperframes/studio-manual-edits.json"])(
"invalidates a cached render when %s changes",
async (path) => {
const dir = folder();
writeFileSync(join(dir, "index.html"), '<audio src=".media/voice.mp3"></audio>');
mkdirSync(dirname(join(dir, path)), { recursive: true });
writeFileSync(join(dir, path), "original");
rendering.execute.mockImplementation(async ({ output }: { output: string }) => {
writeFileSync(output, "rendered video");
});
await prepareShareRender(dir);
const original = latestShareRender(dir);
const watcher = await projectFingerprint(dir);
await prepareShareRender(dir);
expect(latestShareRender(dir)?.id).toBe(original?.id);
writeFileSync(join(dir, path), "changed");
expect(await projectFingerprint(dir)).toBe(watcher);
expect(await shareContentFingerprint(dir)).not.toBe(original?.contentFingerprint);
await prepareShareRender(dir);
expect(latestShareRender(dir)?.id).not.toBe(original?.id);
},
);
});
it("reuses the video when only a scratch log is added", async () => {
const dir = folder();
writeFileSync(join(dir, "index.html"), "<html></html>");
rendering.execute.mockImplementation(async ({ output }: { output: string }) =>
writeFileSync(output, "video"),
);
await prepareShareRender(dir);
const original = latestShareRender(dir);
rendering.execute.mockClear();
writeFileSync(join(dir, "other.log"), "scratch output");
await prepareShareRender(dir);
expect(rendering.execute).not.toHaveBeenCalled();
expect(latestShareRender(dir)?.id).toBe(original?.id);
});