|
1 | | -import { existsSync, mkdtempSync, mkdirSync, writeFileSync } from "node:fs"; |
| 1 | +import { existsSync, linkSync, mkdtempSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; |
2 | 2 | import { tmpdir } from "node:os"; |
3 | 3 | import { join } from "node:path"; |
4 | 4 | import { beforeAll, describe, expect, it } from "vitest"; |
@@ -28,6 +28,29 @@ describe("keyframes direct composition scope", () => { |
28 | 28 | }); |
29 | 29 |
|
30 | 30 | describe("keyframes shot output", () => { |
| 31 | + it("rejects an output path that would overwrite the composition source", () => { |
| 32 | + const projectDir = mkdtempSync(join(tmpdir(), "hf-keyframes-shot-source-")); |
| 33 | + const sourcePath = join(projectDir, "index.html"); |
| 34 | + writeFileSync(sourcePath, wrap("")); |
| 35 | + |
| 36 | + expect(() => ensureShotOutputDir(sourcePath, sourcePath)).toThrow( |
| 37 | + /must not overwrite the composition source/, |
| 38 | + ); |
| 39 | + expect(readFileSync(sourcePath, "utf8")).toBe(wrap("")); |
| 40 | + }); |
| 41 | + |
| 42 | + it("rejects an existing output alias that refers to the composition source", () => { |
| 43 | + const projectDir = mkdtempSync(join(tmpdir(), "hf-keyframes-shot-alias-")); |
| 44 | + const sourcePath = join(projectDir, "index.html"); |
| 45 | + const aliasPath = join(projectDir, "shot.png"); |
| 46 | + writeFileSync(sourcePath, wrap("")); |
| 47 | + linkSync(sourcePath, aliasPath); |
| 48 | + |
| 49 | + expect(() => ensureShotOutputDir(aliasPath, sourcePath)).toThrow( |
| 50 | + /must not overwrite the composition source/, |
| 51 | + ); |
| 52 | + }); |
| 53 | + |
31 | 54 | it("creates a missing parent directory before writing --shot", () => { |
32 | 55 | const projectDir = mkdtempSync(join(tmpdir(), "hf-keyframes-shot-dir-")); |
33 | 56 | const outputDir = join(projectDir, "nested", "proofs"); |
|
0 commit comments