Skip to content

armgit / clipy

Public Imported from GitHub
0

The AI-native screen recorder. Record your screen and talk; the people you share it with and your AI agents both get it.

2.7 KB
Raw Blame
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
import { readArec } from "./vendor/arec/validator/validate.mjs";

const desktop = fileURLToPath(new URL("../", import.meta.url));
const cli = path.join(desktop, "scripts/vendor/arec/bin/arec-validate.mjs");

test("Clipy Local's preparing and completed ARECs pass the strict producer check", {
  skip: process.platform !== "darwin" && "the desktop fixture runs on macOS",
}, (t) => {
  const take = mkdtempSync(path.join(tmpdir(), "clipy-arec-"));
  t.after(() => rmSync(take, { recursive: true, force: true }));
  // test-rust.sh can fetch FFmpeg. This test only uses pre-staged desktop dependencies.
  const ffmpeg = path.join(desktop, "src-tauri/target/native-deps/Spacedrive.framework/Libraries");
  assert.ok(statSync(ffmpeg, { throwIfNoEntry: false })?.isDirectory(),
    "Run pnpm setup:native-deps in desktop before the offline AREC test.");
  execFileSync("bash", ["scripts/test-rust.sh", "--locked", "--offline", "--lib", "--",
    "--ignored", "--exact", "local::tests::write_synthetic_arec"], {
    cwd: desktop, env: { ...process.env, CLIPY_LOCAL_TEST_OUTPUT: take }, stdio: "inherit",
  });
  execFileSync(process.execPath, [cli, "--strict", "preparing.arec", "recording.arec"], {
    cwd: take, stdio: "inherit",
  });

  // Strict mode also exits zero for legacy documents and for profile recommendations.
  // Local has neither an intent classifier nor a summary generator (AREC 1.4 §3.3).
  const expectedWarnings = [
    "Profile recording usually contains a `Intent` section.",
    "Profile recording usually contains a `Summary` section.",
  ];
  const expectedMoments = {
    "preparing.arec": [],
    "recording.arec": [
      { t_ms: 500, caption: "Clicked Save", frame_url: "frames/000000000500.jpg", source: "click", x: 0.25, y: 0.75 },
      { t_ms: 800, caption: "Spoken reference to the save location", frame_url: "frames/000000000800.jpg", source: "deixis" },
    ],
  };
  for (const [file, moments] of Object.entries(expectedMoments)) {
    const { document, legacy, warnings } = readArec(readFileSync(path.join(take, file), "utf8"));
    assert.equal(legacy, false, file);
    assert.equal(document.profile, "recording", file);
    assert.deepEqual(warnings.filter((w) => !expectedWarnings.includes(w)), [], file);
    assert.deepEqual(document.keyMoments, moments, file);
    for (const { frame_url } of document.keyMoments) {
      assert.ok(statSync(path.join(take, frame_url)).size > 0, frame_url);
    }
  }
});