@@ -213,6 +213,55 @@ describe("gateway-cli coverage", () => {
|
213 | 213 | }); |
214 | 214 | }); |
215 | 215 | |
| 216 | +it("scopes usage-cost to a specific agent via --agent", async () => { |
| 217 | +callGateway.mockClear(); |
| 218 | + |
| 219 | +await runGatewayCommand(["gateway", "usage-cost", "--agent", "alpha", "--days", "7", "--json"]); |
| 220 | + |
| 221 | +expect(callGateway).toHaveBeenCalledTimes(1); |
| 222 | +const costCall = firstMockArg(callGateway) as { method?: string; params?: unknown }; |
| 223 | +expect(costCall?.method).toBe("usage.cost"); |
| 224 | +expect(costCall?.params).toEqual({ days: 7, agentId: "alpha" }); |
| 225 | +}); |
| 226 | + |
| 227 | +it("omits agentId from usage-cost when --agent is absent or blank", async () => { |
| 228 | +callGateway.mockClear(); |
| 229 | + |
| 230 | +await runGatewayCommand(["gateway", "usage-cost", "--agent", " ", "--days", "7", "--json"]); |
| 231 | + |
| 232 | +expect(callGateway).toHaveBeenCalledTimes(1); |
| 233 | +const costCall = firstMockArg(callGateway) as { method?: string; params?: unknown }; |
| 234 | +expect(costCall?.method).toBe("usage.cost"); |
| 235 | +expect(costCall?.params).toEqual({ days: 7 }); |
| 236 | +}); |
| 237 | + |
| 238 | +it("aggregates usage-cost across agents via --all-agents", async () => { |
| 239 | +callGateway.mockClear(); |
| 240 | + |
| 241 | +await runGatewayCommand(["gateway", "usage-cost", "--all-agents", "--days", "7", "--json"]); |
| 242 | + |
| 243 | +expect(callGateway).toHaveBeenCalledTimes(1); |
| 244 | +const costCall = firstMockArg(callGateway) as { method?: string; params?: unknown }; |
| 245 | +expect(costCall?.method).toBe("usage.cost"); |
| 246 | +expect(costCall?.params).toEqual({ days: 7, agentScope: "all" }); |
| 247 | +}); |
| 248 | + |
| 249 | +it("rejects combining --agent with --all-agents for usage-cost", async () => { |
| 250 | +callGateway.mockClear(); |
| 251 | + |
| 252 | +await expectGatewayExit([ |
| 253 | +"gateway", |
| 254 | +"usage-cost", |
| 255 | +"--agent", |
| 256 | +"alpha", |
| 257 | +"--all-agents", |
| 258 | +"--json", |
| 259 | +]); |
| 260 | + |
| 261 | +expect(callGateway).not.toHaveBeenCalled(); |
| 262 | +expect(runtimeErrors.join("\n")).toContain("Use --agent or --all-agents, not both"); |
| 263 | +}); |
| 264 | + |
216 | 265 | it("writes JSON for gateway health transport failures in JSON mode", async () => { |
217 | 266 | const error = new Error("gateway closed (1006)"); |
218 | 267 | const payload = { |
|