import { test } from "node:test";
import assert from "node:assert/strict";
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { syncBuiltinESMExports } from "node:module";
import { tmpdir } from "node:os";
import path, { join } from "node:path";
import { diffChangedFiles, snapshotFiles, snapshotProject } from "../src/projectSnapshot.mjs";
// fails without the fix: snapshotProject keyed entries with raw path.relative(), which emits backslashes on Windows,
// while excludedFromSnapshot normalized with path.sep.
test("snapshotProject, snapshotFiles, and ignore matching share forward-slash keys with Windows-style relative paths", async (t) => {
const dir = await mkdtemp(join(tmpdir(), "hf-share-win-snapshot-"));
const originalRelative = path.relative;
path.relative = (...args) => path.win32.relative(...args);
syncBuiltinESMExports();
t.after(async () => {
path.relative = originalRelative;
syncBuiltinESMExports();
await rm(dir, { recursive: true, force: true });
});
await writeFile(join(dir, "index.html"), "
Film
");
await writeFile(join(dir, ".hyperframesignore"), "assets/raw.mov\n");
const before = await snapshotProject(dir);
await mkdir(join(dir, "boards"), { recursive: true });
await mkdir(join(dir, "compositions"), { recursive: true });
await mkdir(join(dir, "assets"), { recursive: true });
await writeFile(join(dir, "boards", "storyboard.html"), "Board
");
await writeFile(join(dir, "compositions", "title.html"), "Title
");
await writeFile(join(dir, "assets", "raw.mov"), "ignored");
const after = await snapshotProject(dir);
assert.deepEqual([...after.keys()].sort(), [
"boards/storyboard.html",
"compositions/title.html",
"index.html",
]);
assert.deepEqual(diffChangedFiles(before, after).sort(), [
"boards/storyboard.html",
"compositions/title.html",
]);
const picked = await snapshotFiles(dir, ["boards\\storyboard.html", "assets\\raw.mov"]);
assert.ok(picked);
assert.deepEqual([...picked.keys()].sort(), ["assets/raw.mov", "boards/storyboard.html"]);
assert.notEqual(picked.get("boards/storyboard.html"), undefined);
assert.equal(picked.get("assets/raw.mov"), undefined);
});