Files
paseo/packages/app/src/utils/agent-snapshots.test.ts
T
Mohamed BoudraandGitHub 53c14d9855 Extract client SDK package (#1052)
* Extract client SDK package

* Polish SDK client identity defaults

* Build client before dependent CI jobs

* Restore daemon client server export

* Extract protocol and client SDK packages

* Fix provider override schema validation

* Fix app test daemon client imports

* Simplify workspace build targets

* Fix CLI test server build bootstrap

* Run SDK package tests in CI

* Fix rebase package split drift

* Restore lockfile registry metadata

* Update SDK config test for prompt default

* Move terminal stream router test to client package

* Fix rebase drift for protocol imports

* Fix SDK agent capability fixture

* Restore legacy server client exports

* Fix server export compatibility test

* Advertise custom mode icon client capability

* Remove server daemon-client exports

* Format rebased mode control import

* Fix rebase drift for protocol imports

Files added by upstream PRs (#893, #1147, #1154) referenced the pre-split
shared/ paths that this branch moves into @getpaseo/protocol. Redirect
those imports to the protocol package so typecheck stays green after the
rebase.
2026-05-28 01:58:18 +08:00

75 lines
2.5 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 } 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",
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("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();
});
});