mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
The desktop application capture workflow constructed the desktop provider's X11 window observer and content store and called its session runner, application inventory, program lookup and home-folder walker directly. src/ports/DesktopApplicationSession.ts now names them as DesktopCaptureProvider, with the plan, outcome, request and walk types they exchange; src/desktop/DesktopCaptureProvider.ts implements it and the CLI passes it in the capture host. application -> desktop entry imports: 20 -> 14. Refs #11583
91 lines
3.1 KiB
TypeScript
91 lines
3.1 KiB
TypeScript
import { chmod, mkdir, symlink, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
|
|
import { DesktopContentStore } from "../../desktop/DesktopContentStore.js";
|
|
import { walkHomeState } from "../../desktop/HomeStateWalker.js";
|
|
import { CheckpointRecorder } from "./DesktopCheckpointRecorder.js";
|
|
|
|
const unprivileged = process.platform !== "win32" && process.getuid?.() !== 0;
|
|
|
|
it.skipIf(process.platform === "win32")(
|
|
"records baseline non-file paths without following symlinks",
|
|
async () => {
|
|
const root = await createTestTempDirectory("desktop-recorder-nonfiles-");
|
|
const home = join(root, "home");
|
|
const directory = join(home, "app");
|
|
const link = join(directory, "state.db-wal");
|
|
await mkdir(directory, { recursive: true });
|
|
await symlink("elsewhere", link);
|
|
await mkdir(join(root, "capture"));
|
|
const store = new DesktopContentStore(join(root, "capture"), 1024, 4096);
|
|
await store.prepare();
|
|
const recorder = new CheckpointRecorder(
|
|
{
|
|
roots: [home],
|
|
contentRoots: [directory],
|
|
stateDirectories: [directory],
|
|
excluded: [],
|
|
maxEntries: 100,
|
|
},
|
|
store,
|
|
walkHomeState,
|
|
);
|
|
await recorder.record("baseline", "baseline", 0);
|
|
expect(recorder.baselineNonFiles).toContainEqual({
|
|
path: link,
|
|
type: "symlink",
|
|
});
|
|
},
|
|
);
|
|
|
|
describe.skipIf(!unprivileged)("CheckpointRecorder", () => {
|
|
it("does not pair a later file version with a digest read from an earlier one", async () => {
|
|
const root = await createTestTempDirectory("desktop-recorder-");
|
|
const home = join(root, "home");
|
|
const directory = join(home, "app");
|
|
const file = join(directory, "state.txt");
|
|
await mkdir(directory, { recursive: true });
|
|
await writeFile(file, "v1");
|
|
await mkdir(join(root, "capture"));
|
|
const store = new DesktopContentStore(join(root, "capture"), 1024, 4096);
|
|
await store.prepare();
|
|
const recorder = new CheckpointRecorder(
|
|
{
|
|
roots: [home],
|
|
contentRoots: [directory],
|
|
stateDirectories: [directory],
|
|
excluded: [],
|
|
maxEntries: 100,
|
|
},
|
|
store,
|
|
walkHomeState,
|
|
);
|
|
await recorder.record("baseline", "baseline", 0);
|
|
// The directory cannot be listed while the file changes.
|
|
await writeFile(file, "version two");
|
|
await chmod(directory, 0o000);
|
|
try {
|
|
await recorder.record("hidden", "request", 1);
|
|
} finally {
|
|
await chmod(directory, 0o755);
|
|
}
|
|
await recorder.record("visible", "request", 2);
|
|
await writeFile(file, "version three!");
|
|
await recorder.record("edited", "request", 3);
|
|
|
|
const [, hidden, visible, edited] = recorder.checkpoints;
|
|
expect(hidden?.unconfirmed_changes).toBe(1);
|
|
expect(visible?.changes).toEqual([]);
|
|
expect(edited?.changes).toEqual([
|
|
expect.objectContaining({
|
|
path: file,
|
|
kind: "modified",
|
|
before: expect.objectContaining({ sha256: null }),
|
|
}),
|
|
]);
|
|
});
|
|
});
|