mirror of
https://github.com/ruvnet/RuView
synced 2026-07-27 18:11:43 +00:00
fix: complete sensing server API, WebSocket connectivity, and mobile tests (#125)
The web UI had persistent 404 errors on model, recording, and training endpoints, and the sensing WebSocket never connected on Dashboard/Live Demo tabs because sensingService.start() was only called lazily on Sensing tab visit. Server (main.rs): - Add 14 fully-functional Axum handlers: model CRUD (7), recording lifecycle (4), training control (3) - Scan data/models/ and data/recordings/ at startup - Recording writes CSI frames to .jsonl via tokio background task - Model load/unload lifecycle with state tracking Web UI (app.js): - Import and start sensingService early in initializeServices() so Dashboard and Live Demo tabs connect to /ws/sensing immediately Mobile (ws.service.ts): - Fix WebSocket URL builder to use same-origin port instead of hardcoded port 3001 Mobile (jest.config.js): - Fix testPathIgnorePatterns that was ignoring the entire test directory Mobile (25 test files): - Replace all it.todo() placeholder tests with real implementations covering components, services, stores, hooks, screens, and utils ADR-043 documents all changes.
This commit is contained in:
@@ -1,5 +1,71 @@
|
||||
describe('placeholder', () => {
|
||||
it('passes', () => {
|
||||
expect(true).toBe(true);
|
||||
import { valueToColor } from '@/utils/colorMap';
|
||||
|
||||
describe('valueToColor', () => {
|
||||
it('returns blue at 0', () => {
|
||||
const [r, g, b] = valueToColor(0);
|
||||
expect(r).toBe(0);
|
||||
expect(g).toBe(0);
|
||||
expect(b).toBe(1);
|
||||
});
|
||||
|
||||
it('returns green at 0.5', () => {
|
||||
const [r, g, b] = valueToColor(0.5);
|
||||
expect(r).toBe(0);
|
||||
expect(g).toBe(1);
|
||||
expect(b).toBe(0);
|
||||
});
|
||||
|
||||
it('returns red at 1', () => {
|
||||
const [r, g, b] = valueToColor(1);
|
||||
expect(r).toBe(1);
|
||||
expect(g).toBe(0);
|
||||
expect(b).toBe(0);
|
||||
});
|
||||
|
||||
it('clamps values below 0 to the same as 0', () => {
|
||||
const [r, g, b] = valueToColor(-0.5);
|
||||
const [r0, g0, b0] = valueToColor(0);
|
||||
expect(r).toBe(r0);
|
||||
expect(g).toBe(g0);
|
||||
expect(b).toBe(b0);
|
||||
});
|
||||
|
||||
it('clamps values above 1 to the same as 1', () => {
|
||||
const [r, g, b] = valueToColor(1.5);
|
||||
const [r1, g1, b1] = valueToColor(1);
|
||||
expect(r).toBe(r1);
|
||||
expect(g).toBe(g1);
|
||||
expect(b).toBe(b1);
|
||||
});
|
||||
|
||||
it('interpolates between blue and green for 0.25', () => {
|
||||
const [r, g, b] = valueToColor(0.25);
|
||||
expect(r).toBe(0);
|
||||
expect(g).toBeCloseTo(0.5);
|
||||
expect(b).toBeCloseTo(0.5);
|
||||
});
|
||||
|
||||
it('interpolates between green and red for 0.75', () => {
|
||||
const [r, g, b] = valueToColor(0.75);
|
||||
expect(r).toBeCloseTo(0.5);
|
||||
expect(g).toBeCloseTo(0.5);
|
||||
expect(b).toBe(0);
|
||||
});
|
||||
|
||||
it('returns a 3-element tuple', () => {
|
||||
const result = valueToColor(0.5);
|
||||
expect(result).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('all channels are in [0, 1] range for edge values', () => {
|
||||
for (const v of [-1, 0, 0.1, 0.5, 0.9, 1, 2]) {
|
||||
const [r, g, b] = valueToColor(v);
|
||||
expect(r).toBeGreaterThanOrEqual(0);
|
||||
expect(r).toBeLessThanOrEqual(1);
|
||||
expect(g).toBeGreaterThanOrEqual(0);
|
||||
expect(g).toBeLessThanOrEqual(1);
|
||||
expect(b).toBeGreaterThanOrEqual(0);
|
||||
expect(b).toBeLessThanOrEqual(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,147 @@
|
||||
describe('placeholder', () => {
|
||||
it('passes', () => {
|
||||
expect(true).toBe(true);
|
||||
import { RingBuffer } from '@/utils/ringBuffer';
|
||||
|
||||
describe('RingBuffer', () => {
|
||||
describe('constructor', () => {
|
||||
it('creates a buffer with the given capacity', () => {
|
||||
const buf = new RingBuffer<number>(5);
|
||||
expect(buf.toArray()).toEqual([]);
|
||||
});
|
||||
|
||||
it('floors fractional capacity', () => {
|
||||
const buf = new RingBuffer<number>(3.9);
|
||||
buf.push(1);
|
||||
buf.push(2);
|
||||
buf.push(3);
|
||||
buf.push(4);
|
||||
// capacity is 3 (floored), so oldest is evicted
|
||||
expect(buf.toArray()).toEqual([2, 3, 4]);
|
||||
});
|
||||
|
||||
it('throws on zero capacity', () => {
|
||||
expect(() => new RingBuffer<number>(0)).toThrow('capacity must be greater than 0');
|
||||
});
|
||||
|
||||
it('throws on negative capacity', () => {
|
||||
expect(() => new RingBuffer<number>(-1)).toThrow('capacity must be greater than 0');
|
||||
});
|
||||
|
||||
it('throws on NaN capacity', () => {
|
||||
expect(() => new RingBuffer<number>(NaN)).toThrow('capacity must be greater than 0');
|
||||
});
|
||||
|
||||
it('throws on Infinity capacity', () => {
|
||||
expect(() => new RingBuffer<number>(Infinity)).toThrow('capacity must be greater than 0');
|
||||
});
|
||||
});
|
||||
|
||||
describe('push', () => {
|
||||
it('adds values in order', () => {
|
||||
const buf = new RingBuffer<number>(5);
|
||||
buf.push(10);
|
||||
buf.push(20);
|
||||
buf.push(30);
|
||||
expect(buf.toArray()).toEqual([10, 20, 30]);
|
||||
});
|
||||
|
||||
it('evicts oldest when capacity is exceeded', () => {
|
||||
const buf = new RingBuffer<number>(3);
|
||||
buf.push(1);
|
||||
buf.push(2);
|
||||
buf.push(3);
|
||||
buf.push(4);
|
||||
expect(buf.toArray()).toEqual([2, 3, 4]);
|
||||
});
|
||||
|
||||
it('evicts multiple oldest values over time', () => {
|
||||
const buf = new RingBuffer<number>(2);
|
||||
buf.push(1);
|
||||
buf.push(2);
|
||||
buf.push(3);
|
||||
buf.push(4);
|
||||
buf.push(5);
|
||||
expect(buf.toArray()).toEqual([4, 5]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toArray', () => {
|
||||
it('returns a copy of the internal array', () => {
|
||||
const buf = new RingBuffer<number>(5);
|
||||
buf.push(1);
|
||||
buf.push(2);
|
||||
const arr = buf.toArray();
|
||||
arr.push(99);
|
||||
expect(buf.toArray()).toEqual([1, 2]);
|
||||
});
|
||||
|
||||
it('returns an empty array when buffer is empty', () => {
|
||||
const buf = new RingBuffer<number>(5);
|
||||
expect(buf.toArray()).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('clear', () => {
|
||||
it('empties the buffer', () => {
|
||||
const buf = new RingBuffer<number>(5);
|
||||
buf.push(1);
|
||||
buf.push(2);
|
||||
buf.clear();
|
||||
expect(buf.toArray()).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('max', () => {
|
||||
it('returns null on empty buffer', () => {
|
||||
const buf = new RingBuffer<number>(5, (a, b) => a - b);
|
||||
expect(buf.max).toBeNull();
|
||||
});
|
||||
|
||||
it('throws without comparator', () => {
|
||||
const buf = new RingBuffer<number>(5);
|
||||
buf.push(1);
|
||||
expect(() => buf.max).toThrow('Comparator required for max()');
|
||||
});
|
||||
|
||||
it('returns the maximum value', () => {
|
||||
const buf = new RingBuffer<number>(5, (a, b) => a - b);
|
||||
buf.push(3);
|
||||
buf.push(1);
|
||||
buf.push(5);
|
||||
buf.push(2);
|
||||
expect(buf.max).toBe(5);
|
||||
});
|
||||
|
||||
it('returns the maximum with a single element', () => {
|
||||
const buf = new RingBuffer<number>(5, (a, b) => a - b);
|
||||
buf.push(42);
|
||||
expect(buf.max).toBe(42);
|
||||
});
|
||||
});
|
||||
|
||||
describe('min', () => {
|
||||
it('returns null on empty buffer', () => {
|
||||
const buf = new RingBuffer<number>(5, (a, b) => a - b);
|
||||
expect(buf.min).toBeNull();
|
||||
});
|
||||
|
||||
it('throws without comparator', () => {
|
||||
const buf = new RingBuffer<number>(5);
|
||||
buf.push(1);
|
||||
expect(() => buf.min).toThrow('Comparator required for min()');
|
||||
});
|
||||
|
||||
it('returns the minimum value', () => {
|
||||
const buf = new RingBuffer<number>(5, (a, b) => a - b);
|
||||
buf.push(3);
|
||||
buf.push(1);
|
||||
buf.push(5);
|
||||
buf.push(2);
|
||||
expect(buf.min).toBe(1);
|
||||
});
|
||||
|
||||
it('returns the minimum with a single element', () => {
|
||||
const buf = new RingBuffer<number>(5, (a, b) => a - b);
|
||||
buf.push(42);
|
||||
expect(buf.min).toBe(42);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,76 @@
|
||||
describe('placeholder', () => {
|
||||
it('passes', () => {
|
||||
expect(true).toBe(true);
|
||||
import { validateServerUrl } from '@/utils/urlValidator';
|
||||
|
||||
describe('validateServerUrl', () => {
|
||||
it('accepts valid http URL', () => {
|
||||
const result = validateServerUrl('http://localhost:3000');
|
||||
expect(result.valid).toBe(true);
|
||||
expect(result.error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('accepts valid https URL', () => {
|
||||
const result = validateServerUrl('https://example.com');
|
||||
expect(result.valid).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts valid ws URL', () => {
|
||||
const result = validateServerUrl('ws://192.168.1.1:8080');
|
||||
expect(result.valid).toBe(true);
|
||||
});
|
||||
|
||||
it('accepts valid wss URL', () => {
|
||||
const result = validateServerUrl('wss://example.com/ws');
|
||||
expect(result.valid).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects empty string', () => {
|
||||
const result = validateServerUrl('');
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.error).toBe('URL must be a non-empty string.');
|
||||
});
|
||||
|
||||
it('rejects whitespace-only string', () => {
|
||||
const result = validateServerUrl(' ');
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.error).toBe('URL must be a non-empty string.');
|
||||
});
|
||||
|
||||
it('rejects null input', () => {
|
||||
const result = validateServerUrl(null as unknown as string);
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.error).toBe('URL must be a non-empty string.');
|
||||
});
|
||||
|
||||
it('rejects undefined input', () => {
|
||||
const result = validateServerUrl(undefined as unknown as string);
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.error).toBe('URL must be a non-empty string.');
|
||||
});
|
||||
|
||||
it('rejects numeric input', () => {
|
||||
const result = validateServerUrl(123 as unknown as string);
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.error).toBe('URL must be a non-empty string.');
|
||||
});
|
||||
|
||||
it('rejects ftp protocol', () => {
|
||||
const result = validateServerUrl('ftp://files.example.com');
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.error).toBe('URL must use http, https, ws, or wss.');
|
||||
});
|
||||
|
||||
it('rejects file protocol', () => {
|
||||
const result = validateServerUrl('file:///etc/passwd');
|
||||
expect(result.valid).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects malformed URL', () => {
|
||||
const result = validateServerUrl('not-a-url');
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.error).toBe('Invalid URL format.');
|
||||
});
|
||||
|
||||
it('rejects URL with no host', () => {
|
||||
const result = validateServerUrl('http://');
|
||||
expect(result.valid).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user