mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-07 17:04:42 +00:00
* feat(plugin): expose stable sidebar entity data across hosts Collections return interned references and preserve their arrays when membership and order stay unchanged. Entity selectors share one hook with identity defaults for full snapshots and shallow defaults for selections. The app caches host projections and shares underlying store and host subscriptions. Browser render counts exercise the real session store and plugin provider without memoized rows. Terminal hooks consume the collection source port; daemon-wide terminal discovery is the separate terminal phase. * feat(plugin): let users select a sidebar view An exclusive view replaces the sidebar content while the host retains navigation, callouts, and footer. The device remembers the selection, unavailable views fall back to the default, and throwing views provide recovery. Device-scoped plugin settings persist locally with schema validation and revision conflicts. Web E2E and Android tablet QA cover selection, preserved chrome, disabled-view fallback, and error recovery. * feat(plugin): add sidebar view examples and ref actions Keep sidebar layout and gestures inside the plugin while routing entity handles to their owning hosts. Examples cover empty projects, pinned workspaces, task sections, nested agents and device-local label folders. * feat(plugin): observe terminals across connected hosts Share host-wide terminal observations across plugin surfaces and gate them on terminalCollection. Keep directory observations compatible, and carry creation time in worker v6 state so v5 terminals can drain with an unknown timestamp.
98 lines
3.7 KiB
TypeScript
98 lines
3.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { defineSettings } from "@getpaseo/plugin";
|
|
import { z } from "zod";
|
|
import { createDeviceSettings } from "./device";
|
|
|
|
function device(records = new Map<string, string>()) {
|
|
return createDeviceSettings({
|
|
getItem: async (key) => records.get(key) ?? null,
|
|
setItem: async (key, value) => {
|
|
records.set(key, value);
|
|
},
|
|
});
|
|
}
|
|
const definition = defineSettings({
|
|
id: "layout",
|
|
scope: "device",
|
|
version: 1,
|
|
schema: z.object({ collapsed: z.array(z.string()).default([]) }),
|
|
});
|
|
|
|
describe("device plugin settings", () => {
|
|
it("shares one installation across hosts and keeps other installations separate", async () => {
|
|
const settings = device();
|
|
const first = settings("plugin", definition);
|
|
const second = settings("plugin", definition);
|
|
const before = await first.read();
|
|
expect(before).toEqual({ status: "ready", revision: "missing", values: { collapsed: [] } });
|
|
const saved = await first.write({ revision: before.revision, values: { collapsed: ["work"] } });
|
|
expect(saved.status).toBe("saved");
|
|
expect(await second.read()).toMatchObject({ status: "ready", values: { collapsed: ["work"] } });
|
|
expect(await settings("other", definition).read()).toEqual(before);
|
|
});
|
|
it("serializes competing writes and resets through the same revision contract", async () => {
|
|
const settings = device()("plugin", definition);
|
|
const initial = await settings.read();
|
|
const results = await Promise.all([
|
|
settings.write({ revision: initial.revision, values: { collapsed: ["a"] } }),
|
|
settings.write({ revision: initial.revision, values: { collapsed: ["b"] } }),
|
|
]);
|
|
expect(results.map((result) => result.status)).toEqual(["saved", "conflict"]);
|
|
const current = await settings.read();
|
|
expect(await settings.reset({ revision: current.revision })).toMatchObject({
|
|
status: "saved",
|
|
values: { collapsed: [] },
|
|
});
|
|
});
|
|
it("validates writes and migrates saved layout values", async () => {
|
|
const settings = device();
|
|
const first = settings("plugin", definition);
|
|
expect(await first.write({ revision: "missing", values: { collapsed: 3 } })).toMatchObject({
|
|
status: "invalid",
|
|
});
|
|
await first.write({ revision: "missing", values: { collapsed: ["a"] } });
|
|
const upgraded = settings(
|
|
"plugin",
|
|
defineSettings({
|
|
...definition,
|
|
version: 2,
|
|
migrate: (_values, from) => ({ collapsed: [`v${from}`] }),
|
|
}),
|
|
);
|
|
expect(await upgraded.read()).toMatchObject({ status: "ready", values: { collapsed: ["v1"] } });
|
|
});
|
|
});
|
|
|
|
it("persists a validated migration once and returns the persisted revision across restarts", async () => {
|
|
const records = new Map<string, string>();
|
|
const settings = device(records);
|
|
await settings("plugin", definition).write({ revision: "missing", values: { collapsed: ["a"] } });
|
|
let migrations = 0;
|
|
const upgraded = defineSettings({
|
|
...definition,
|
|
version: 2,
|
|
migrate: () => {
|
|
migrations++;
|
|
return { collapsed: ["migrated"] };
|
|
},
|
|
});
|
|
const first = await settings("plugin", upgraded).read();
|
|
const restarted = device(records)("plugin", upgraded);
|
|
expect(await restarted.read()).toEqual(first);
|
|
expect(migrations).toBe(1);
|
|
expect(first).toEqual({
|
|
status: "ready",
|
|
revision: JSON.stringify({ version: 2, values: { collapsed: ["migrated"] } }),
|
|
values: { collapsed: ["migrated"] },
|
|
});
|
|
expect(
|
|
await restarted.write({
|
|
revision: JSON.stringify({ version: 1, values: { collapsed: ["a"] } }),
|
|
values: { collapsed: [] },
|
|
}),
|
|
).toMatchObject({ status: "conflict" });
|
|
expect(
|
|
await restarted.write({ revision: first.revision, values: { collapsed: [] } }),
|
|
).toMatchObject({ status: "saved" });
|
|
});
|