fix(ui): read Usage Total Requests tile from gateway request counts (#39963)

This commit is contained in:
devin-ai-integration[bot] 2026-09-05 16:20:56 -07:00 • committed by GitHub
parent 587311d0e4
commit 9a5564f00e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 13 deletions

View file

@ -424,17 +424,14 @@ describe("UsagePage", () => {
// Check that key metrics are displayed
const totalRequestElements = screen.getAllByText("Total Requests");
expect(totalRequestElements.length).toBeGreaterThan(0);
expect(screen.getByText("1,500")).toBeInTheDocument();
const successfulRequestLabelElements = screen.getAllByText("Successful Requests");
expect(successfulRequestLabelElements.length).toBeGreaterThan(0);
// Successful and Failed Requests both read the gateway counter, not the
// spend-derived 1,450 / 50 that the same payload carries for the per-key and
// per-model breakdowns. They must share a source, or the tiles contradict the
// endpoint breakdown chart below them.
await waitFor(() => {
expect(screen.getAllByText("424,242").length).toBeGreaterThan(0);
});
expect(screen.getAllByText("909").length).toBeGreaterThan(0);
expect(screen.getByText("425,151")).toBeInTheDocument();
expect(screen.queryByText("1,500")).not.toBeInTheDocument();
expect(screen.queryByText("1,450")).not.toBeInTheDocument();
});
@ -454,7 +451,7 @@ describe("UsagePage", () => {
renderWithProviders(<UsagePage {...defaultProps} />);
await waitFor(() => {
expect(screen.getAllByText("1,500").length).toBeGreaterThan(0);
expect(screen.getAllByText("75,000").length).toBeGreaterThan(0);
});
await act(async () => {
@ -464,13 +461,13 @@ describe("UsagePage", () => {
await waitFor(() => {
expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalledTimes(2);
});
expect(screen.queryByText("1,500")).not.toBeInTheDocument();
expect(screen.queryByText("75,000")).not.toBeInTheDocument();
await act(async () => {
releaseSecondFetch();
});
await waitFor(() => {
expect(screen.getAllByText("1,500").length).toBeGreaterThan(0);
expect(screen.getAllByText("75,000").length).toBeGreaterThan(0);
});
});
@ -485,8 +482,10 @@ describe("UsagePage", () => {
await waitFor(() => {
expect(screen.getAllByText("1,450").length).toBeGreaterThan(0);
});
expect(screen.getByText("1,500")).toBeInTheDocument();
expect(screen.queryByText("424,242")).not.toBeInTheDocument();
expect(screen.queryByText("909")).not.toBeInTheDocument();
expect(screen.queryByText("425,151")).not.toBeInTheDocument();
expect(screen.queryByTestId("gateway-requests-by-endpoint")).not.toBeInTheDocument();
});
@ -499,6 +498,7 @@ describe("UsagePage", () => {
expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalled();
});
expect(mockGatewayDailyActivityCall).not.toHaveBeenCalled();
expect(screen.getByText("1,500")).toBeInTheDocument();
expect(screen.queryByText("424,242")).not.toBeInTheDocument();
expect(screen.queryByTestId("gateway-requests-by-endpoint")).not.toBeInTheDocument();
});
@ -1045,7 +1045,7 @@ describe("UsagePage", () => {
});
// Should still render the data from the paginated fallback, which lands a render after the call
expect(await screen.findByText("1,500")).toBeInTheDocument();
expect(await screen.findByText("75,000")).toBeInTheDocument();
});
it("should stop showing the previous range's paginated pages while a new range is in flight", async () => {
@ -1069,7 +1069,7 @@ describe("UsagePage", () => {
renderWithProviders(<UsagePage {...defaultProps} />);
await waitFor(() => {
expect(screen.getAllByText("1,500").length).toBeGreaterThan(0);
expect(screen.getAllByText("75,000").length).toBeGreaterThan(0);
});
await act(async () => {
@ -1079,13 +1079,13 @@ describe("UsagePage", () => {
await waitFor(() => {
expect(mockUserDailyActivityAggregatedCall).toHaveBeenCalledTimes(2);
});
expect(screen.queryByText("1,500")).not.toBeInTheDocument();
expect(screen.queryByText("75,000")).not.toBeInTheDocument();
await act(async () => {
releaseSecondAggregated();
});
await waitFor(() => {
expect(screen.getAllByText("1,500").length).toBeGreaterThan(0);
expect(screen.getAllByText("75,000").length).toBeGreaterThan(0);
});
});

View file

@ -573,7 +573,10 @@ const UsagePage: React.FC<UsagePageProps> = ({ teams, organizations }) => {
<CardContent>
<h3 className="text-lg font-medium text-foreground">Total Requests</h3>
<p className="text-2xl font-bold mt-2">
{userSpendData.metadata?.total_api_requests?.toLocaleString() || 0}
{(gatewayActivity
? gatewayActivity.total_successful_requests + gatewayActivity.total_failed_requests
: userSpendData.metadata?.total_api_requests
)?.toLocaleString() || 0}
</p>
</CardContent>
</ShadcnCard>