Files
claw3d/tests/unit/agentFleetHydration.test.ts
gsknnft a18c8c630c fix: surface upstream gateway timeout for remote OpenClaw/Tailscale connections (#94)
* surface gateway timeout for tailscale

* talescale fix #2 - attempt 1

* luke findings fix#1

* add narrow log for clientId

* prod safe proxy log

* fix log visibility

* LAN connection & subagent SOUL|IDENTITY fixes

* Initialize missing files for subagent SOUL|IDENTITY

* surface missing files in UI

* capturing agent - runtime,identity,session

* plugin-install fix

* fix: recover agent workspace for marketplace installs

* fix: recover agent workspace and identity name from file provenance

* fix: tolerate webchat session patch blocks during permission updates
2026-04-03 17:57:36 -05:00

180 lines
5.2 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { hydrateAgentFleetFromGateway } from "@/features/agents/operations/agentFleetHydration";
import { createDefaultAgentAvatarProfile } from "@/lib/avatars/profile";
import type { StudioSettings } from "@/lib/studio/settings";
describe("hydrateAgentFleetFromGateway", () => {
it("maps_gateway_results_into_seeds_and_selects_latest_assistant_agent", async () => {
const gatewayUrl = "ws://127.0.0.1:18789";
const settings: StudioSettings = {
version: 1,
gateway: null,
focused: {},
avatars: {
[gatewayUrl]: {
"agent-1": createDefaultAgentAvatarProfile("persisted-seed"),
},
},
deskAssignments: {},
analytics: {},
voiceReplies: {},
office: {},
};
const call = vi.fn(async (method: string, params: unknown) => {
if (method === "config.get") {
return {
hash: "hash-1",
config: {
agents: {
defaults: {
model: "openai/gpt-5",
},
list: [],
},
},
};
}
if (method === "agents.list") {
return {
defaultId: "agent-1",
mainKey: "main",
agents: [
{
id: "agent-1",
name: "One",
identity: { name: "Main Persona", avatarUrl: "https://example.com/one.png" },
},
{
id: "agent-2",
name: "Two",
identity: { avatarUrl: "https://example.com/two.png" },
},
],
};
}
if (method === "agents.files.get") {
const record = params as Record<string, unknown>;
if (record.agentId === "agent-2" && record.name === "IDENTITY.md") {
return {
workspace: "/tmp/workspace-agent-2",
file: {
missing: false,
content: "# IDENTITY.md - Who Am I?\n\n- Name: GLaDOS\n",
path: "/tmp/workspace-agent-2/IDENTITY.md",
},
};
}
return {
workspace: "/tmp/workspace-agent-1",
file: {
missing: false,
content: "# IDENTITY.md - Who Am I?\n\n- Name: Main Persona\n",
path: "/tmp/workspace-agent-1/IDENTITY.md",
},
};
}
if (method === "exec.approvals.get") {
return {
file: {
agents: {
"agent-1": { security: "allowlist", ask: "always" },
"agent-2": { security: "full", ask: "off" },
},
},
};
}
if (method === "sessions.list") {
const { agentId, search } = params as Record<string, unknown>;
return {
sessions: [
{
key: search,
updatedAt: 1,
displayName: "Main",
thinkingLevel: "medium",
modelProvider: "openai",
model: agentId === "agent-2" ? "gpt-5" : "gpt-4.1",
},
],
};
}
if (method === "status") {
return {
sessions: {
recent: [],
byAgent: [],
},
};
}
if (method === "sessions.preview") {
return {
ts: 1,
previews: [
{
key: "agent:agent-1:main",
status: "ok",
items: [
{ role: "assistant", text: "one", timestamp: "2026-02-10T00:00:00Z" },
],
},
{
key: "agent:agent-2:main",
status: "ok",
items: [
{ role: "assistant", text: "two", timestamp: "2026-02-10T01:00:00Z" },
],
},
],
};
}
throw new Error(`Unhandled method: ${method}`);
});
const result = await hydrateAgentFleetFromGateway({
client: { call },
gatewayUrl,
cachedConfigSnapshot: null,
loadStudioSettings: async () => settings,
isDisconnectLikeError: () => false,
});
expect(call).toHaveBeenCalledWith("agents.list", {});
expect(call).toHaveBeenCalledWith("exec.approvals.get", {});
expect(result.seeds).toHaveLength(2);
expect(result.seeds[0]).toEqual(
expect.objectContaining({
agentId: "agent-1",
name: "Main Persona",
runtimeName: "One",
identityName: "Main Persona",
sessionDisplayName: "Main",
sessionKey: "agent:agent-1:main",
avatarUrl: "https://example.com/one.png",
model: "openai/gpt-4.1",
thinkingLevel: "medium",
sessionExecHost: "gateway",
sessionExecSecurity: "allowlist",
sessionExecAsk: "always",
})
);
expect(result.seeds[1]).toEqual(
expect.objectContaining({
agentId: "agent-2",
name: "GLaDOS",
runtimeName: "Two",
identityName: "GLaDOS",
sessionExecHost: "gateway",
sessionExecSecurity: "full",
sessionExecAsk: "off",
})
);
expect(result.sessionCreatedAgentIds).toEqual(["agent-1", "agent-2"]);
expect(result.sessionSettingsSyncedAgentIds).toEqual([]);
expect(result.suggestedSelectedAgentId).toBe("agent-2");
expect(result.summaryPatches.length).toBeGreaterThan(0);
});
});