Stabilize async server lifecycle tests (#3060)
* test(server): stabilize async lifecycle coverage * test(server): name teardown dependencies
This commit is contained in:
@@ -22,6 +22,22 @@ function createRealAgentManager(storage: AgentStorage): AgentManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function removeRealAgentManagerWorkdir({
|
||||||
|
agentManager,
|
||||||
|
storage,
|
||||||
|
workdir,
|
||||||
|
}: {
|
||||||
|
agentManager: AgentManager;
|
||||||
|
storage: AgentStorage;
|
||||||
|
workdir: string;
|
||||||
|
}): Promise<void> {
|
||||||
|
agentManager.prepareForShutdown();
|
||||||
|
await Promise.all(agentManager.listAgents().map((agent) => agentManager.closeAgent(agent.id)));
|
||||||
|
await agentManager.flushForShutdown();
|
||||||
|
await storage.flush();
|
||||||
|
rmSync(workdir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
|
||||||
// Creates a worktree directory under repoRoot and reports it back as a fresh
|
// Creates a worktree directory under repoRoot and reports it back as a fresh
|
||||||
// workspace so the command can stamp the agent with it (mirrors the production
|
// workspace so the command can stamp the agent with it (mirrors the production
|
||||||
// worktree service).
|
// worktree service).
|
||||||
@@ -238,7 +254,7 @@ test("session create stamps the requested workspaceId when no worktree setup run
|
|||||||
const stored = await storage.get(snapshot.id);
|
const stored = await storage.get(snapshot.id);
|
||||||
expect(stored?.workspaceId).toBe("ws-source");
|
expect(stored?.workspaceId).toBe("ws-source");
|
||||||
} finally {
|
} finally {
|
||||||
rmSync(workdir, { recursive: true, force: true });
|
await removeRealAgentManagerWorkdir({ agentManager, storage, workdir });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -273,7 +289,7 @@ test("session create stamps the new worktree's workspaceId when a setup continua
|
|||||||
const stored = await storage.get(snapshot.id);
|
const stored = await storage.get(snapshot.id);
|
||||||
expect(stored?.workspaceId).toBe("ws-new-worktree");
|
expect(stored?.workspaceId).toBe("ws-new-worktree");
|
||||||
} finally {
|
} finally {
|
||||||
rmSync(workdir, { recursive: true, force: true });
|
await removeRealAgentManagerWorkdir({ agentManager, storage, workdir });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -324,7 +340,7 @@ test("mcp create stamps the new worktree's workspaceId, not the parent's", async
|
|||||||
expect(storedChild?.workspaceId).toBe("ws-new-worktree");
|
expect(storedChild?.workspaceId).toBe("ws-new-worktree");
|
||||||
expect(child.cwd).toBe(join(workdir, "worktree", "packages", "app"));
|
expect(child.cwd).toBe(join(workdir, "worktree", "packages", "app"));
|
||||||
} finally {
|
} finally {
|
||||||
rmSync(workdir, { recursive: true, force: true });
|
await removeRealAgentManagerWorkdir({ agentManager, storage, workdir });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -376,7 +392,7 @@ test("mcp create exposes the created worktree before dispatching the initial pro
|
|||||||
|
|
||||||
expect(observed).toEqual({ createdWorktree, lifecycle: "idle" });
|
expect(observed).toEqual({ createdWorktree, lifecycle: "idle" });
|
||||||
} finally {
|
} finally {
|
||||||
rmSync(workdir, { recursive: true, force: true });
|
await removeRealAgentManagerWorkdir({ agentManager, storage, workdir });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -414,7 +430,7 @@ test("session create keeps the prompt title after the initial prompt settles", a
|
|||||||
const settled = await storage.get(snapshot.id);
|
const settled = await storage.get(snapshot.id);
|
||||||
expect(settled?.title).toBe(title);
|
expect(settled?.title).toBe(title);
|
||||||
} finally {
|
} finally {
|
||||||
rmSync(workdir, { recursive: true, force: true });
|
await removeRealAgentManagerWorkdir({ agentManager, storage, workdir });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -452,6 +468,6 @@ test("session create keeps an explicit title after the initial prompt settles",
|
|||||||
const settled = await storage.get(snapshot.id);
|
const settled = await storage.get(snapshot.id);
|
||||||
expect(settled?.title).toBe(title);
|
expect(settled?.title).toBe(title);
|
||||||
} finally {
|
} finally {
|
||||||
rmSync(workdir, { recursive: true, force: true });
|
await removeRealAgentManagerWorkdir({ agentManager, storage, workdir });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -203,7 +203,10 @@ class ControlledAgentClient implements AgentClient {
|
|||||||
resumes = 0;
|
resumes = 0;
|
||||||
createdConfigs: AgentSessionConfig[] = [];
|
createdConfigs: AgentSessionConfig[] = [];
|
||||||
|
|
||||||
constructor(private readonly client: AgentClient) {
|
constructor(
|
||||||
|
private readonly client: AgentClient,
|
||||||
|
private readonly internalClient: AgentClient,
|
||||||
|
) {
|
||||||
this.provider = client.provider;
|
this.provider = client.provider;
|
||||||
this.capabilities = client.capabilities;
|
this.capabilities = client.capabilities;
|
||||||
}
|
}
|
||||||
@@ -230,6 +233,9 @@ class ControlledAgentClient implements AgentClient {
|
|||||||
launchContext?: AgentLaunchContext,
|
launchContext?: AgentLaunchContext,
|
||||||
options?: AgentCreateSessionOptions,
|
options?: AgentCreateSessionOptions,
|
||||||
): Promise<AgentSession> {
|
): Promise<AgentSession> {
|
||||||
|
if (config.internal) {
|
||||||
|
return this.internalClient.createSession(config, launchContext, options);
|
||||||
|
}
|
||||||
this.creations++;
|
this.creations++;
|
||||||
this.createdConfigs.push({ ...config });
|
this.createdConfigs.push({ ...config });
|
||||||
this.creationObserved.resolve();
|
this.creationObserved.resolve();
|
||||||
@@ -242,6 +248,9 @@ class ControlledAgentClient implements AgentClient {
|
|||||||
overrides?: Partial<AgentSessionConfig>,
|
overrides?: Partial<AgentSessionConfig>,
|
||||||
launchContext?: AgentLaunchContext,
|
launchContext?: AgentLaunchContext,
|
||||||
): Promise<AgentSession> {
|
): Promise<AgentSession> {
|
||||||
|
if (overrides?.internal) {
|
||||||
|
return this.internalClient.resumeSession(handle, overrides, launchContext);
|
||||||
|
}
|
||||||
this.resumes++;
|
this.resumes++;
|
||||||
return this.client.resumeSession(handle, overrides, launchContext);
|
return this.client.resumeSession(handle, overrides, launchContext);
|
||||||
}
|
}
|
||||||
@@ -438,6 +447,7 @@ export class HubRelationshipHarness {
|
|||||||
this.providerPrompts.push(prompt);
|
this.providerPrompts.push(prompt);
|
||||||
},
|
},
|
||||||
}).codex,
|
}).codex,
|
||||||
|
createTestAgentClients({ supportsMcpServers: mcpEnabled }).codex,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user