Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
import { describe, it, expect, vi } from "vitest";
import * as runtimeQueries from "../../src/db/queries/runtime";
function createMockDb(rows: any[]) {
const chain: any = {};
chain.select = vi.fn(() => chain);
chain.from = vi.fn(() => chain);
chain.leftJoin = vi.fn(() => chain);
chain.where = vi.fn(() => Promise.resolve(rows));
return chain;
}
describe("updateRuntimeCliVersionByDaemon", () => {
function createUpdateMockDb() {
const chain: any = {};
chain.update = vi.fn(() => chain);
chain.set = vi.fn(() => chain);
chain.where = vi.fn(() => Promise.resolve(undefined));
return chain;
}
it("no-ops without touching DB when cliVersion is empty", async () => {
const mockDb = createUpdateMockDb();
await runtimeQueries.updateRuntimeCliVersionByDaemon(mockDb, "d1", "ws1", "");
expect(mockDb.update).not.toHaveBeenCalled();
});
it("issues a scoped update patching cli_version into metadata", async () => {
const mockDb = createUpdateMockDb();
await runtimeQueries.updateRuntimeCliVersionByDaemon(mockDb, "d1", "ws1", "1.2.3");
expect(mockDb.update).toHaveBeenCalledOnce();
expect(mockDb.set).toHaveBeenCalledOnce();
expect(mockDb.where).toHaveBeenCalledOnce();
const setArg = mockDb.set.mock.calls[0][0];
expect(setArg).toHaveProperty("metadata");
expect(setArg).toHaveProperty("updatedAt");
});
});
describe("getAgentRuntimesForWorkspace", () => {
it("returns empty array for empty ids without querying DB", async () => {
const result = await runtimeQueries.getAgentRuntimesForWorkspace(null as any, [], "ws1");
expect(result).toEqual([]);
});
it("queries DB and returns runtimes when ids is non-empty", async () => {
const mockRows = [
{ id: "rt1", workspaceId: "ws1", runtimeMode: "local", machineLastSeenAt: null },
{ id: "rt2", workspaceId: "ws1", runtimeMode: "cloud", machineLastSeenAt: "2026-01-01" },
];
const mockDb = createMockDb(mockRows);
const result = await runtimeQueries.getAgentRuntimesForWorkspace(mockDb, ["rt1", "rt2"], "ws1");
expect(mockDb.select).toHaveBeenCalledOnce();
expect(mockDb.from).toHaveBeenCalledOnce();
expect(mockDb.leftJoin).toHaveBeenCalledOnce();
expect(mockDb.where).toHaveBeenCalledOnce();
expect(result).toEqual(mockRows);
});
it("returns single runtime for single id input", async () => {
const mockRows = [{ id: "rt1", workspaceId: "ws1", runtimeMode: "local", machineLastSeenAt: null }];
const mockDb = createMockDb(mockRows);
const result = await runtimeQueries.getAgentRuntimesForWorkspace(mockDb, ["rt1"], "ws1");
expect(result).toHaveLength(1);
expect(result[0].id).toBe("rt1");
});
});