From 0959c90d3620b65b1c1dab6c18d54d9db0231845 Mon Sep 17 00:00:00 2001 From: Manus Date: Fri, 20 Mar 2026 21:15:55 -0400 Subject: [PATCH] Checkpoint: Fix: agents.list tRPC procedure now uses getAllAgents() instead of getUserAgents(SYSTEM_USER_ID=1). Root cause: seed creates agents with userId=0 but router queried userId=1. Added getAllAgents() and getSystemAgents() helpers. 86 tests pass. --- server/agents.test.ts | 22 ++++++++++++++++++++++ server/agents.ts | 31 +++++++++++++++++++++++++++++++ server/routers.ts | 5 +++-- todo.md | 6 ++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/server/agents.test.ts b/server/agents.test.ts index 1ec22c7..324a810 100644 --- a/server/agents.test.ts +++ b/server/agents.test.ts @@ -60,4 +60,26 @@ describe("Agents Module", () => { expect(result).toEqual([]); }); }); + + describe("getAllAgents", () => { + it("should return empty array when database is unavailable", async () => { + const result = await agentsModule.getAllAgents(); + expect(result).toEqual([]); + }); + + it("should be exported from agents module", () => { + expect(typeof agentsModule.getAllAgents).toBe("function"); + }); + }); + + describe("getSystemAgents", () => { + it("should return empty array when database is unavailable", async () => { + const result = await agentsModule.getSystemAgents(); + expect(result).toEqual([]); + }); + + it("should be exported from agents module", () => { + expect(typeof agentsModule.getSystemAgents).toBe("function"); + }); + }); }); diff --git a/server/agents.ts b/server/agents.ts index f368b9c..c71c446 100644 --- a/server/agents.ts +++ b/server/agents.ts @@ -56,6 +56,37 @@ export async function getUserAgents(userId: number): Promise { } } +/** + * Получить все агенты (системные + пользовательские) + * Используется для страницы /agents в Control Center + */ +export async function getAllAgents(): Promise { + const db = await getDb(); + if (!db) return []; + + try { + return await db.select().from(agents).orderBy(agents.id); + } catch (error) { + console.error("[DB] Failed to get all agents:", error); + return []; + } +} + +/** + * Получить только системные агенты (isSystem=true) + */ +export async function getSystemAgents(): Promise { + const db = await getDb(); + if (!db) return []; + + try { + return await db.select().from(agents).where(eq(agents.isSystem, true)).orderBy(agents.id); + } catch (error) { + console.error("[DB] Failed to get system agents:", error); + return []; + } +} + /** * Обновить конфигурацию агента */ diff --git a/server/routers.ts b/server/routers.ts index 85beec8..b392538 100644 --- a/server/routers.ts +++ b/server/routers.ts @@ -121,8 +121,9 @@ export const appRouter = router({ */ agents: router({ list: publicProcedure.query(async () => { - const { getUserAgents } = await import("./agents"); - return getUserAgents(SYSTEM_USER_ID); + // getAllAgents returns both system agents (userId=0) and user-created agents + const { getAllAgents } = await import("./agents"); + return getAllAgents(); }), get: publicProcedure.input(z.object({ id: z.number() })).query(async ({ input }) => { diff --git a/todo.md b/todo.md index 195fb99..6e4559a 100644 --- a/todo.md +++ b/todo.md @@ -201,3 +201,9 @@ - [x] Connect header stats to real tRPC endpoints (agents count from DB, nodes/CPU/MEM from Docker API) - [x] Write vitest tests for header stats procedure (82 tests total, all pass) - [x] Commit to Gitea and deploy to production (Phase 14) — verified: nodes=6/6, agents=6, CPU=0.2%, MEM=645MB, gatewayOnline=true + +## Phase 15 (Bug Fix): Agents Page Shows Empty List +- [x] Diagnose: find why /agents page shows no agents (userId=0 in seed vs SYSTEM_USER_ID=1 in router) +- [x] Fix agents tRPC query: getAllAgents() instead of getUserAgents(SYSTEM_USER_ID) +- [x] Update vitest tests (86 tests, all pass) +- [ ] Deploy to production (Phase 15)