Fix telemetry shutdown noise and improve token usage diagnostics (#444)
Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
01adc828b5
commit
995a7f070d
59
tests/unit/app-routes.test.ts
Normal file
59
tests/unit/app-routes.test.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import type { IncomingMessage, ServerResponse } from 'http';
|
||||
|
||||
const runOpenClawDoctorMock = vi.fn();
|
||||
const runOpenClawDoctorFixMock = vi.fn();
|
||||
const sendJsonMock = vi.fn();
|
||||
const sendNoContentMock = vi.fn();
|
||||
|
||||
vi.mock('@electron/utils/openclaw-doctor', () => ({
|
||||
runOpenClawDoctor: (...args: unknown[]) => runOpenClawDoctorMock(...args),
|
||||
runOpenClawDoctorFix: (...args: unknown[]) => runOpenClawDoctorFixMock(...args),
|
||||
}));
|
||||
|
||||
vi.mock('@electron/api/route-utils', () => ({
|
||||
setCorsHeaders: vi.fn(),
|
||||
parseJsonBody: vi.fn().mockResolvedValue({}),
|
||||
sendJson: (...args: unknown[]) => sendJsonMock(...args),
|
||||
sendNoContent: (...args: unknown[]) => sendNoContentMock(...args),
|
||||
}));
|
||||
|
||||
describe('handleAppRoutes', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it('runs openclaw doctor through the host api', async () => {
|
||||
runOpenClawDoctorMock.mockResolvedValueOnce({ success: true, exitCode: 0 });
|
||||
const { handleAppRoutes } = await import('@electron/api/routes/app');
|
||||
|
||||
const handled = await handleAppRoutes(
|
||||
{ method: 'POST' } as IncomingMessage,
|
||||
{} as ServerResponse,
|
||||
new URL('http://127.0.0.1:3210/api/app/openclaw-doctor'),
|
||||
{} as never,
|
||||
);
|
||||
|
||||
expect(handled).toBe(true);
|
||||
expect(runOpenClawDoctorMock).toHaveBeenCalledTimes(1);
|
||||
expect(sendJsonMock).toHaveBeenCalledWith(expect.anything(), 200, { success: true, exitCode: 0 });
|
||||
});
|
||||
|
||||
it('runs openclaw doctor fix when requested', async () => {
|
||||
const { parseJsonBody } = await import('@electron/api/route-utils');
|
||||
vi.mocked(parseJsonBody).mockResolvedValueOnce({ mode: 'fix' });
|
||||
runOpenClawDoctorFixMock.mockResolvedValueOnce({ success: false, exitCode: 1 });
|
||||
const { handleAppRoutes } = await import('@electron/api/routes/app');
|
||||
|
||||
const handled = await handleAppRoutes(
|
||||
{ method: 'POST' } as IncomingMessage,
|
||||
{} as ServerResponse,
|
||||
new URL('http://127.0.0.1:3210/api/app/openclaw-doctor'),
|
||||
{} as never,
|
||||
);
|
||||
|
||||
expect(handled).toBe(true);
|
||||
expect(runOpenClawDoctorFixMock).toHaveBeenCalledTimes(1);
|
||||
expect(sendJsonMock).toHaveBeenCalledWith(expect.anything(), 200, { success: false, exitCode: 1 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user