mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
test(agent-manager): add test for loading persisted agent and sending new prompt
This commit is contained in:
@@ -1 +1,14 @@
|
||||
[]
|
||||
[
|
||||
{
|
||||
"id": "fc818184-5676-4f24-a92a-77e9e15c515d",
|
||||
"title": "Agent fc818184",
|
||||
"sessionId": null,
|
||||
"options": {
|
||||
"type": "claude",
|
||||
"sessionId": null
|
||||
},
|
||||
"createdAt": "2025-10-26T06:59:13.289Z",
|
||||
"lastActivityAt": "2025-10-26T06:59:22.379Z",
|
||||
"cwd": "/var/folders/xl/kkk9drfd3ms_t8x7rmy4z6900000gn/T/acp-test-wm5mun"
|
||||
}
|
||||
]
|
||||
@@ -86,4 +86,55 @@ describe("AgentManager", () => {
|
||||
},
|
||||
120000
|
||||
);
|
||||
|
||||
it(
|
||||
"should load persisted agent and send new prompt",
|
||||
async () => {
|
||||
const agentId = await manager.createAgent({
|
||||
cwd: tmpDir,
|
||||
});
|
||||
|
||||
await manager.sendPrompt(agentId, "echo 'first message'");
|
||||
|
||||
let status = manager.getAgentStatus(agentId);
|
||||
let attempts = 0;
|
||||
while (status !== "completed" && status !== "failed" && attempts < 60) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
status = manager.getAgentStatus(agentId);
|
||||
attempts++;
|
||||
}
|
||||
|
||||
expect(status).toBe("completed");
|
||||
|
||||
await manager.killAgent(agentId);
|
||||
|
||||
const newManager = new AgentManager();
|
||||
await newManager.initialize();
|
||||
|
||||
const agents = newManager.listAgents();
|
||||
const loadedAgent = agents.find((a) => a.id === agentId);
|
||||
|
||||
expect(loadedAgent).toBeDefined();
|
||||
expect(loadedAgent?.id).toBe(agentId);
|
||||
expect(loadedAgent?.cwd).toBe(tmpDir);
|
||||
|
||||
await newManager.sendPrompt(agentId, "echo 'second message'");
|
||||
|
||||
status = newManager.getAgentStatus(agentId);
|
||||
attempts = 0;
|
||||
while (status !== "completed" && status !== "failed" && attempts < 60) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
status = newManager.getAgentStatus(agentId);
|
||||
attempts++;
|
||||
}
|
||||
|
||||
expect(status).toBe("completed");
|
||||
|
||||
const finalUpdates = newManager.getAgentUpdates(agentId);
|
||||
expect(finalUpdates.length).toBeGreaterThan(0);
|
||||
|
||||
await newManager.killAgent(agentId);
|
||||
},
|
||||
120000
|
||||
);
|
||||
});
|
||||
|
||||
@@ -510,12 +510,13 @@ export class AgentManager {
|
||||
const runtime = this.getRuntime(agent);
|
||||
|
||||
// Persist current state before killing
|
||||
// Clear sessionId so next start creates a new session
|
||||
if (runtime) {
|
||||
await this.persistence.upsert({
|
||||
id: agent.id,
|
||||
title: agent.title || `Agent ${agent.id.slice(0, 8)}`,
|
||||
sessionId: runtime.sessionId,
|
||||
options: agent.options,
|
||||
sessionId: null,
|
||||
options: { ...agent.options, sessionId: null },
|
||||
createdAt: agent.createdAt.toISOString(),
|
||||
lastActivityAt: agent.lastActivityAt.toISOString(),
|
||||
cwd: agent.cwd,
|
||||
|
||||
Reference in New Issue
Block a user