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.
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -56,6 +56,37 @@ export async function getUserAgents(userId: number): Promise<Agent[]> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить все агенты (системные + пользовательские)
|
||||
* Используется для страницы /agents в Control Center
|
||||
*/
|
||||
export async function getAllAgents(): Promise<Agent[]> {
|
||||
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<Agent[]> {
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновить конфигурацию агента
|
||||
*/
|
||||
|
||||
@@ -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 }) => {
|
||||
|
||||
6
todo.md
6
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)
|
||||
|
||||
Reference in New Issue
Block a user