|
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 3 | +import { tmpdir } from "node:os"; |
| 4 | +import { join } from "node:path"; |
| 5 | + |
| 6 | +// Number-mode stats report one identity for every path, as Windows file ids above 2^53 can. |
| 7 | +vi.mock("node:fs", async (importOriginal) => { |
| 8 | + const actual = await importOriginal<typeof import("node:fs")>(); |
| 9 | + const statSync = ((path: string, options?: { bigint?: boolean }) => |
| 10 | + options?.bigint |
| 11 | + ? actual.statSync(path, options as never) |
| 12 | + : { ...actual.statSync(path), dev: 1, ino: 2 ** 53 }) as typeof actual.statSync; |
| 13 | + return { ...actual, statSync }; |
| 14 | +}); |
| 15 | + |
| 16 | +const { mirrorGlobalSkills } = await import("./utils/skillsMirror.js"); |
| 17 | +const { ensureShotOutputDir } = await import("./commands/motionShot.js"); |
| 18 | + |
| 19 | +const homes: string[] = []; |
| 20 | +afterEach(() => { |
| 21 | + for (const home of homes.splice(0)) rmSync(home, { recursive: true, force: true }); |
| 22 | +}); |
| 23 | + |
| 24 | +describe("same-file checks on colliding number inodes", () => { |
| 25 | + it("still mirrors an agent whose dir only collides with the store in number precision", () => { |
| 26 | + const home = mkdtempSync(join(tmpdir(), "mirror-ino-")); |
| 27 | + homes.push(home); |
| 28 | + mkdirSync(join(home, ".claude", "skills", "hyperframes"), { recursive: true }); |
| 29 | + writeFileSync(join(home, ".claude", "skills", "hyperframes", "SKILL.md"), "# hf\n"); |
| 30 | + mkdirSync(join(home, ".config", "goose"), { recursive: true }); |
| 31 | + |
| 32 | + const { mirrored, skipped } = mirrorGlobalSkills({ |
| 33 | + skills: ["hyperframes"], |
| 34 | + home, |
| 35 | + platform: "linux", |
| 36 | + env: {}, |
| 37 | + }); |
| 38 | + expect(skipped).toEqual([]); |
| 39 | + expect(mirrored.map((m) => m.agent)).toContain("goose"); |
| 40 | + }); |
| 41 | + |
| 42 | + it("lets a rerun overwrite its previous shot next to the composition", () => { |
| 43 | + const home = mkdtempSync(join(tmpdir(), "shot-ino-")); |
| 44 | + homes.push(home); |
| 45 | + writeFileSync(join(home, "index.html"), "<html></html>"); |
| 46 | + writeFileSync(join(home, "shot.png"), "png"); |
| 47 | + expect(() => |
| 48 | + ensureShotOutputDir(join(home, "shot.png"), join(home, "index.html")), |
| 49 | + ).not.toThrow(); |
| 50 | + }); |
| 51 | +}); |
0 commit comments