mirror of
https://github.com/harivansh-afk/clanker-agent.git
synced 2026-04-15 22:03:44 +00:00
Complete the remaining pi-to-companion rename across companion-os, web, vm-orchestrator, docker, and archived fixtures. Verification: - semantic rg sweeps for Pi/piConfig/getPi/.pi runtime references - npm run check in apps/companion-os (fails in this worktree: biome not found) Co-authored-by: Codex <noreply@openai.com>
101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { GatewayRuntime } from "../src/core/gateway/runtime.js";
|
|
|
|
function createMockSession(options?: { sessionName?: string }) {
|
|
return {
|
|
sessionId: "session-1",
|
|
sessionName: options?.sessionName,
|
|
messages: [],
|
|
prompt: vi.fn().mockResolvedValue(undefined),
|
|
steer: vi.fn().mockResolvedValue(undefined),
|
|
abort: vi.fn().mockResolvedValue(undefined),
|
|
dispose: vi.fn(),
|
|
subscribe: vi.fn(() => () => {}),
|
|
sessionManager: {
|
|
getSessionDir: () => "/tmp/companion-gateway-test",
|
|
appendSessionInfo: vi.fn(),
|
|
appendLabelChange: vi.fn(),
|
|
},
|
|
};
|
|
}
|
|
|
|
function createRuntime(session = createMockSession()) {
|
|
return new GatewayRuntime({
|
|
config: {
|
|
bind: "127.0.0.1",
|
|
port: 0,
|
|
session: {
|
|
idleMinutes: 5,
|
|
maxQueuePerSession: 4,
|
|
},
|
|
webhook: {
|
|
enabled: false,
|
|
basePath: "/webhooks",
|
|
},
|
|
},
|
|
primarySessionKey: "primary",
|
|
primarySession: session as never,
|
|
createSession: async () => session as never,
|
|
});
|
|
}
|
|
|
|
function addManagedSession(
|
|
runtime: GatewayRuntime,
|
|
sessionKey: string,
|
|
session: ReturnType<typeof createMockSession>,
|
|
) {
|
|
const managedSession = {
|
|
sessionKey,
|
|
session,
|
|
queue: [],
|
|
processing: false,
|
|
activeAssistantMessage: null,
|
|
pendingToolResults: [],
|
|
createdAt: Date.now(),
|
|
lastActiveAt: Date.now(),
|
|
listeners: new Set(),
|
|
unsubscribe: () => {},
|
|
};
|
|
|
|
(runtime as unknown as { sessions: Map<string, unknown> }).sessions.set(
|
|
sessionKey,
|
|
managedSession,
|
|
);
|
|
|
|
return managedSession;
|
|
}
|
|
|
|
describe("GatewayRuntime session titles", () => {
|
|
it("includes the session name in snapshots", () => {
|
|
const session = createMockSession({ sessionName: "Generated title" });
|
|
const runtime = createRuntime(session);
|
|
addManagedSession(runtime, "chat", session);
|
|
|
|
expect(runtime.listSessions()).toEqual([
|
|
expect.objectContaining({
|
|
sessionKey: "chat",
|
|
name: "Generated title",
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it("persists renamed sessions via session_info entries", async () => {
|
|
const session = createMockSession();
|
|
const runtime = createRuntime(session);
|
|
addManagedSession(runtime, "chat", session);
|
|
|
|
await (
|
|
runtime as unknown as {
|
|
handlePatchSession: (
|
|
sessionKey: string,
|
|
patch: { name?: string },
|
|
) => Promise<void>;
|
|
}
|
|
).handlePatchSession("chat", { name: "Renamed title" });
|
|
|
|
expect(session.sessionManager.appendSessionInfo).toHaveBeenCalledWith(
|
|
"Renamed title",
|
|
);
|
|
expect(session.sessionManager.appendLabelChange).not.toHaveBeenCalled();
|
|
});
|
|
});
|