|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | | -import { mkdtempSync, writeFileSync } from "node:fs"; |
3 | | -import { join } from "node:path"; |
| 2 | +import { spawnSync } from "node:child_process"; |
| 3 | +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 4 | +import { join, resolve } from "node:path"; |
4 | 5 | import { tmpdir } from "node:os"; |
| 6 | +import { fileURLToPath } from "node:url"; |
5 | 7 |
|
6 | 8 | import { |
7 | 9 | resolveAspectRatioForSubmit, |
| 10 | + validateDryRunSource, |
8 | 11 | validateResolutionFormatCombo, |
9 | 12 | type ProjectInputSource, |
10 | 13 | } from "./render.js"; |
11 | 14 |
|
| 15 | +const cliEntry = resolve(fileURLToPath(import.meta.url), "..", "..", "..", "cli.ts"); |
| 16 | + |
12 | 17 | // errorBox writes to console; silence it so test output stays clean. |
13 | 18 | beforeEach(() => { |
14 | 19 | vi.spyOn(console, "log").mockImplementation(() => undefined); |
@@ -51,6 +56,76 @@ describe("validateResolutionFormatCombo", () => { |
51 | 56 | }); |
52 | 57 | }); |
53 | 58 |
|
| 59 | +describe("validateDryRunSource", () => { |
| 60 | + it("accepts a local directory and rejects already-uploaded sources", () => { |
| 61 | + const exit = trapExit(); |
| 62 | + expect(() => validateDryRunSource({ kind: "dir", dir: "." }, true)).not.toThrow(); |
| 63 | + expect(() => validateDryRunSource({ kind: "asset_id", assetId: "asst_123" }, true)).toThrow( |
| 64 | + "process.exit:1", |
| 65 | + ); |
| 66 | + expect(() => |
| 67 | + validateDryRunSource({ kind: "url", url: "https://example.com/project.zip" }, true), |
| 68 | + ).toThrow("process.exit:1"); |
| 69 | + expect(exit).toHaveBeenCalledTimes(2); |
| 70 | + }); |
| 71 | +}); |
| 72 | + |
| 73 | +describe("cloud render --dry-run", () => { |
| 74 | + it("reports the real archive without contacting the cloud", () => { |
| 75 | + const dir = writeComposition(1920, 1080); |
| 76 | + try { |
| 77 | + writeFileSync( |
| 78 | + join(dir, "index.html"), |
| 79 | + `<!doctype html><html data-composition-variables='[{"id":"title","type":"string","label":"Title","default":"x"}]'><body><div data-composition-id="main" data-width="1920" data-height="1080"></div></body></html>`, |
| 80 | + "utf-8", |
| 81 | + ); |
| 82 | + writeFileSync(join(dir, "asset.bin"), "archive-input", "utf-8"); |
| 83 | + const result = spawnSync( |
| 84 | + "bun", |
| 85 | + [ |
| 86 | + "run", |
| 87 | + cliEntry, |
| 88 | + "cloud", |
| 89 | + "render", |
| 90 | + dir, |
| 91 | + "--dry-run", |
| 92 | + "--json", |
| 93 | + "--variables", |
| 94 | + '{"extra":1}', |
| 95 | + ], |
| 96 | + { |
| 97 | + encoding: "utf-8", |
| 98 | + timeout: 30_000, |
| 99 | + env: { |
| 100 | + ...process.env, |
| 101 | + CI: "1", |
| 102 | + HEYGEN_API_URL: "http://127.0.0.1:1", |
| 103 | + HYPERFRAMES_NO_UPDATE_CHECK: "1", |
| 104 | + }, |
| 105 | + }, |
| 106 | + ); |
| 107 | + |
| 108 | + expect(result.status).toBe(0); |
| 109 | + const payload = JSON.parse(result.stdout) as { |
| 110 | + archive: { |
| 111 | + file_count: number; |
| 112 | + size_bytes: number; |
| 113 | + upload_limit_bytes: number; |
| 114 | + exceeds_upload_limit: boolean; |
| 115 | + largest_files: Array<{ path: string }>; |
| 116 | + }; |
| 117 | + }; |
| 118 | + expect(payload.archive.file_count).toBe(2); |
| 119 | + expect(payload.archive.size_bytes).toBeGreaterThan(0); |
| 120 | + expect(payload.archive.upload_limit_bytes).toBe(200 * 1024 * 1024); |
| 121 | + expect(payload.archive.exceeds_upload_limit).toBe(false); |
| 122 | + expect(payload.archive.largest_files.map((file) => file.path)).toContain("asset.bin"); |
| 123 | + } finally { |
| 124 | + rmSync(dir, { recursive: true, force: true }); |
| 125 | + } |
| 126 | + }); |
| 127 | +}); |
| 128 | + |
54 | 129 | describe("resolveAspectRatioForSubmit — non-local sources", () => { |
55 | 130 | it("trusts an explicit flag for asset_id / url", () => { |
56 | 131 | trapExit(); |
|
0 commit comments