Files
hyperframes/packages/cli/src/utils/checkSnapshotDirectory.test.ts
T
Miguel Ángel db845d9409 fix(cli): retire old snapshot run folders (#5635)
* fix(cli): retire old snapshot run folders

* chore: satisfy snapshot comment limit

* fix(history): read and release snapshot leases through verified handles

* test(history): run lease races in Node and check released markers

* fix(studio): verify snapshot leases from open descriptors
2026-10-15 04:59:59 +00:00

34 lines
1.3 KiB
TypeScript

import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, expect, it } from "vitest";
import {
beginCheckSnapshots,
checkSnapshotDirectory,
finishCheckSnapshots,
} from "./checkSnapshotDirectory.js";
const roots: string[] = [];
afterEach(() => {
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
});
it("keeps a shared check capture leased until all concurrent checks finish", async () => {
const project = mkdtempSync(join(tmpdir(), "hf-check-capture-"));
roots.push(project);
beginCheckSnapshots(project);
beginCheckSnapshots(project);
const path = checkSnapshotDirectory(project);
expect(checkSnapshotDirectory(project)).toBe(path);
await finishCheckSnapshots(project);
expect(existsSync(join(path, ".capture-owner.json"))).toBe(true);
expect(JSON.parse(readFileSync(join(path, ".capture-owner.json"), "utf8")).released).not.toBe(
true,
);
expect(checkSnapshotDirectory(project)).toBe(path);
await finishCheckSnapshots(project);
expect(JSON.parse(readFileSync(join(path, ".capture-owner.json"), "utf8")).released).toBe(true);
beginCheckSnapshots(project);
const next = checkSnapshotDirectory(project);
expect(next).not.toBe(path);
await finishCheckSnapshots(project);
});