mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-11 02:46:29 +00:00
* feat(sync): restore host directories before reconnect Persist complete project, workspace, and active-agent replicas so every registered host can paint immediately, including offline hosts. Reconcile those replicas through monotonic per-entity cursors on the existing directory RPCs without retaining an event journal. * fix(sync): preserve active turn identity during catch-up Own Agent-to-wire projection beside the existing snapshot normalizer so replica persistence does not reach through directory-sync internals. This also keeps identified active turns intact when unchanged agents are folded into an incremental directory response. * test(e2e): inspect the real IndexedDB replica Keep cache setup, reload, and hydration coverage on the production browser storage backend after the replica moved off localStorage. Measure writes at the actual IndexedDB put boundary as well. * fix warm reconnect cache paths * feat(sync): persist project icons and deepen directory sync * fix(sync): preserve project update order * fix(cache): preserve validated replica persistence * fix(sync): retain cached agents during catch-up
108 lines
3.6 KiB
TypeScript
108 lines
3.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { AgentSnapshotPayload } from "@getpaseo/protocol/messages";
|
|
import { PARENT_AGENT_ID_LABEL } from "@getpaseo/protocol/agent-labels";
|
|
import { normalizeAgentSnapshot, projectAgentSnapshot } from "./agent-snapshots";
|
|
|
|
function createSnapshot(
|
|
input: Partial<Omit<AgentSnapshotPayload, "labels">> & {
|
|
labels?: Record<string, unknown>;
|
|
} = {},
|
|
): AgentSnapshotPayload {
|
|
return {
|
|
id: input.id ?? "agent-1",
|
|
provider: input.provider ?? "codex",
|
|
cwd: input.cwd ?? "/repo",
|
|
model: input.model ?? null,
|
|
createdAt: input.createdAt ?? "2026-04-20T00:00:00.000Z",
|
|
updatedAt: input.updatedAt ?? "2026-04-20T00:01:00.000Z",
|
|
lastUserMessageAt: input.lastUserMessageAt ?? null,
|
|
status: input.status ?? "idle",
|
|
activeTurn: input.activeTurn,
|
|
capabilities: input.capabilities ?? {
|
|
supportsStreaming: true,
|
|
supportsSessionPersistence: true,
|
|
supportsDynamicModes: true,
|
|
supportsMcpServers: true,
|
|
supportsReasoningStream: true,
|
|
supportsToolInvocations: true,
|
|
},
|
|
currentModeId: input.currentModeId ?? null,
|
|
availableModes: input.availableModes ?? [],
|
|
pendingPermissions: input.pendingPermissions ?? [],
|
|
persistence: input.persistence ?? null,
|
|
title: input.title ?? null,
|
|
labels: (input.labels ?? {}) as AgentSnapshotPayload["labels"],
|
|
};
|
|
}
|
|
|
|
describe("normalizeAgentSnapshot", () => {
|
|
it("round-trips identified active turns through the canonical snapshot boundary", () => {
|
|
const snapshot = createSnapshot({
|
|
status: "running",
|
|
activeTurn: { turnId: "turn-1", startedAt: "2026-07-31T12:00:00.000Z" },
|
|
});
|
|
|
|
expect(projectAgentSnapshot(normalizeAgentSnapshot(snapshot, "server-1"))).toMatchObject({
|
|
status: "running",
|
|
activeTurn: snapshot.activeTurn,
|
|
});
|
|
});
|
|
|
|
it("normalizes identified and legacy active turns at the snapshot boundary", () => {
|
|
const startedAt = "2026-07-31T12:00:00.000Z";
|
|
expect(
|
|
normalizeAgentSnapshot(
|
|
createSnapshot({
|
|
status: "running",
|
|
activeTurn: { turnId: "turn-1", startedAt },
|
|
}),
|
|
"server-1",
|
|
).activeTurn,
|
|
).toEqual({ turnId: "turn-1", startedAt: new Date(startedAt) });
|
|
|
|
expect(
|
|
normalizeAgentSnapshot(
|
|
createSnapshot({ status: "running", lastUserMessageAt: startedAt }),
|
|
"server-1",
|
|
).activeTurn,
|
|
).toEqual({ turnId: null, startedAt: new Date(startedAt) });
|
|
});
|
|
|
|
it("derives parentAgentId from the parent label while preserving labels", () => {
|
|
const labels = {
|
|
[PARENT_AGENT_ID_LABEL]: "parent-1",
|
|
"custom.label": "still-here",
|
|
};
|
|
|
|
const agent = normalizeAgentSnapshot(createSnapshot({ labels }), "server-1");
|
|
|
|
expect(agent.parentAgentId).toBe("parent-1");
|
|
expect(agent.labels).toEqual(labels);
|
|
});
|
|
|
|
it("trims whitespace around the parent label", () => {
|
|
const agent = normalizeAgentSnapshot(
|
|
createSnapshot({ labels: { [PARENT_AGENT_ID_LABEL]: " parent-1 \n" } }),
|
|
"server-1",
|
|
);
|
|
|
|
expect(agent.parentAgentId).toBe("parent-1");
|
|
});
|
|
|
|
it("maps missing, empty, and non-string parent labels to null", () => {
|
|
const missing = normalizeAgentSnapshot(createSnapshot(), "server-1");
|
|
const empty = normalizeAgentSnapshot(
|
|
createSnapshot({ labels: { [PARENT_AGENT_ID_LABEL]: " " } }),
|
|
"server-1",
|
|
);
|
|
const nonString = normalizeAgentSnapshot(
|
|
createSnapshot({ labels: { [PARENT_AGENT_ID_LABEL]: 42 } }),
|
|
"server-1",
|
|
);
|
|
|
|
expect(missing.parentAgentId).toBeNull();
|
|
expect(empty.parentAgentId).toBeNull();
|
|
expect(nonString.parentAgentId).toBeNull();
|
|
});
|
|
});
|