Files
noteflow/client/e2e-native/observability.spec.ts
Travis Vasceannie 100ca5596b
Some checks failed
CI / test-python (push) Failing after 16m26s
CI / test-rust (push) Has been cancelled
CI / test-typescript (push) Has been cancelled
mac
2026-01-24 12:47:35 -05:00

168 lines
5.4 KiB
TypeScript

/**
* Observability E2E Tests
*
* Tests for logs and performance metrics.
*/
/// <reference path="./globals.d.ts" />
import { waitForAppReady } from './fixtures';
describe('Observability', () => {
before(async () => {
await waitForAppReady();
});
describe('getRecentLogs', () => {
it('should retrieve recent logs', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const response = await api?.getRecentLogs({ limit: 50 });
return { success: true, ...response };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result).toBeDefined();
if (result.success) {
expect(result).toHaveProperty('logs');
expect(Array.isArray(result.logs)).toBe(true);
}
});
it('should filter logs by level', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const response = await api?.getRecentLogs({ limit: 20, level: 'error' });
return { success: true, ...response };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result).toBeDefined();
});
it('should filter logs by source', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const response = await api?.getRecentLogs({ limit: 20, source: 'grpc' });
return { success: true, ...response };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result).toBeDefined();
});
it('should respect limit parameter', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const response = await api?.getRecentLogs({ limit: 5 });
return { success: true, logs: response?.logs, count: response?.logs?.length ?? 0 };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result).toBeDefined();
if (result.success) {
expect(result.count).toBeLessThanOrEqual(5);
}
});
});
describe('getPerformanceMetrics', () => {
it('should retrieve performance metrics', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const response = await api?.getPerformanceMetrics({ history_limit: 10 });
return { success: true, ...response };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result).toBeDefined();
if (result.success) {
expect(result).toHaveProperty('current');
expect(result).toHaveProperty('history');
}
});
it('should include current CPU and memory metrics', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const response = await api?.getPerformanceMetrics({});
return { success: true, current: response?.current };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result).toBeDefined();
if (result.success && result.current) {
expect(result.current).toHaveProperty('cpu_percent');
expect(result.current).toHaveProperty('memory_percent');
expect(typeof result.current.cpu_percent).toBe('number');
expect(typeof result.current.memory_percent).toBe('number');
}
});
it('should include historical metrics', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const response = await api?.getPerformanceMetrics({ history_limit: 5 });
return {
success: true,
history: response?.history,
count: response?.history?.length ?? 0,
};
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result).toBeDefined();
if (result.success) {
expect(Array.isArray(result.history)).toBe(true);
}
});
it('should measure metrics roundtrip latency', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
if (!api?.getPerformanceMetrics) {
return { success: false, error: 'API unavailable' };
}
const samples: number[] = [];
for (let i = 0; i < 5; i++) {
const start = performance.now();
await api.getPerformanceMetrics({ history_limit: 1 });
samples.push(performance.now() - start);
}
const total = samples.reduce((sum, value) => sum + value, 0);
const avg = samples.length > 0 ? total / samples.length : 0;
return { success: true, samples, avg };
});
expect(result).toBeDefined();
if (result.success) {
expect(result.avg).toBeGreaterThan(0);
expect(Array.isArray(result.samples)).toBe(true);
}
});
});
});