M1.4: desktop bridge: engine events to the window, folder picker, live project tree

The desktop host publishes every engine event, from commands and from a
pump thread that calls Engine::pump_vfs every 100 ms, to control channel
subscribers and to the window as the Tauri event engine://event, in engine
order. ui/src/ipc.ts gets a typed onEngineEvent; its first subscription
calls engine_ready, and the host replays the current project and buffers,
so a project opened from the command line (lutra-desktop --control PORT
PATH) reaches the UI. project.openDialog returns Effect::PickFolder; the
host shows the native folder picker (tauri-plugin-dialog, licence checked)
and opens the choice, one picker at a time, cancel is not an error.
Capabilities shrink to event listen/unlisten.

Contract fix: the M1.5 project UI assumed shapes the engine does not use.
engineEvents.ts now translates engine events ({kind: projectOpened, ...})
and project.children results ({dir, entries, truncated}) into the UI types,
keeping role and truncated; the store maps listings through
toTreeEntries() and the project tests use the real engine shapes.

Verified in the running app on Windows 11: tree of a project given on the
command line, expanding src, a file created on disk appearing live, the
folder picker opening one dialog and opening the chosen folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-15 06:41:49 +02:00
parent 69130d1efb
commit dd98636de4
23 changed files with 751 additions and 99 deletions

View file

@ -11,12 +11,26 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const invoke = vi.hoisted(() => vi.fn());
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
import { emitEngineEvent, type TreeEntry } from "../../src/components/project/engineEvents";
import { emitEngineEvent } from "../../src/components/project/engineEvents";
import ProjectToolWindow from "../../src/components/project/ProjectToolWindow.vue";
import { useProjectStore } from "../../src/stores/project";
/** An entry as the engine's `project.children` returns it. */
interface EngineEntry {
/** Display name. */
name: string;
/** Project-relative path. */
path: string;
/** Engine kind. */
kind: "directory" | "file" | "other";
/** Matched by an ignore rule. */
ignored: boolean;
/** Lutra's role for the entry. */
role: "normal" | "library" | "excluded";
}
/** In-memory folder listings by directory, as `project.children` returns them. */
let folder: Record<string, TreeEntry[]>;
let folder: Record<string, EngineEntry[]>;
/**
* Builds an entry.
@ -25,8 +39,10 @@ let folder: Record<string, TreeEntry[]>;
* @param kind - entry kind.
* @param ignored - ignore flag.
*/
function entry(path: string, kind: "dir" | "file", ignored = false): TreeEntry {
return { name: path.split("/").pop() ?? path, path, kind, ignored };
function entry(path: string, kind: "dir" | "file", ignored = false): EngineEntry {
const engineKind = kind === "dir" ? "directory" : "file";
const role = path === "node_modules" ? "excluded" : path === "vendor" ? "library" : "normal";
return { name: path.split("/").pop() ?? path, path, kind: engineKind, ignored, role };
}
/** Mock engine: answers `project.children`, accepts other commands. */
@ -38,7 +54,7 @@ function engine(command: string, args: { command: string; params: { dir?: string
const dir = args.params.dir ?? "";
const entries = folder[dir];
return entries
? Promise.resolve(entries)
? Promise.resolve({ dir, entries, truncated: false })
: Promise.reject(Object.assign(new Error(`cannot list ${dir}`), { code: "not_found" }));
}
return Promise.resolve(null);
@ -47,7 +63,7 @@ function engine(command: string, args: { command: string; params: { dir?: string
/** Mounts the tool window and opens the mock project through an event. */
async function mountOpen(): Promise<VueWrapper> {
const wrapper = mount(ProjectToolWindow, { attachTo: document.body });
emitEngineEvent({ type: "ProjectOpened", root: { path: "/tmp/demo", name: "demo" } });
emitEngineEvent({ kind: "projectOpened", root: "/tmp/demo", name: "demo" });
await flushPromises();
return wrapper;
}
@ -183,7 +199,7 @@ describe("ProjectToolWindow", () => {
await press(wrapper, "ArrowRight");
expect(selectedPath(wrapper)).toBe("src/Controller");
folder.src = [entry("src/App.php", "file"), entry("src/Kernel.php", "file")];
emitEngineEvent({ type: "TreeChanged", dir: "src" });
emitEngineEvent({ kind: "treeChanged", dir: "src" });
await flushPromises();
expect(paths(wrapper)).toEqual(["src", "src/App.php", "src/Kernel.php", "vendor", "node_modules", "index.php"]);
expect(selectedPath(wrapper)).toBeNull();
@ -194,7 +210,7 @@ describe("ProjectToolWindow", () => {
it("ignores TreeChanged for directories never loaded", async () => {
wrapper = await mountOpen();
emitEngineEvent({ type: "TreeChanged", dir: "vendor" });
emitEngineEvent({ kind: "treeChanged", dir: "vendor" });
await flushPromises();
expect(childrenCalls()).toEqual([""]);
});
@ -211,7 +227,7 @@ describe("ProjectToolWindow", () => {
it("keeps old entries when a refresh fails", async () => {
wrapper = await mountOpen();
Reflect.deleteProperty(folder, "");
emitEngineEvent({ type: "TreeChanged", dir: "" });
emitEngineEvent({ kind: "treeChanged", dir: "" });
await flushPromises();
expect(wrapper.get("[data-test=tree-error]").text()).toBe("cannot list");
expect(paths(wrapper)).toEqual(["src", "vendor", "node_modules", "index.php"]);
@ -219,12 +235,12 @@ describe("ProjectToolWindow", () => {
it("returns to the empty state on ProjectClosed and unsubscribes on unmount", async () => {
wrapper = await mountOpen();
emitEngineEvent({ type: "ProjectClosed" });
emitEngineEvent({ kind: "projectClosed" });
await flushPromises();
expect(wrapper.find("[data-test=project-empty]").exists()).toBe(true);
wrapper.unmount();
wrapper = null;
emitEngineEvent({ type: "ProjectOpened", root: { path: "/tmp/other", name: "other" } });
emitEngineEvent({ kind: "projectOpened", root: "/tmp/other", name: "other" });
expect(useProjectStore().root).toBeNull();
});
});