fix: stale types test and unreachable ralph full-reset API path

- Remove tests for createSuccessResponse and ErrorMessages which were
  removed/made private during the type system refactoring (15 failures)
- Fix RalphConfigSchema to accept 'full' string for reset field,
  matching the route handler's fullReset() code path

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-03-01 17:17:05 +01:00
co-authored by Claude Opus 4.6
parent bdaa43bc5c
commit f94ab08cbe
4 changed files with 21 additions and 110 deletions
+2 -1
View File
@@ -485,13 +485,14 @@ Use `LRUMap` for bounded caches with eviction, `StaleExpirationMap` for TTL-base
| **SSE events** | Search `broadcast(` in `server.ts` and route modules |
| **Session statuses** | `SessionStatus` in `src/types/session.ts` |
| **Error codes** | `createErrorResponse()` in `src/types/api.ts` |
| **Refactoring phases** | `docs/phase1-implementation-plan.md` through `docs/phase5-frontend-modularization-plan.md` |
| **Refactoring phases** | `docs/phase1-implementation-plan.md` through `docs/phase7-test-infrastructure-plan.md` |
| **Test utilities** | `test/respawn-test-utils.ts` |
| **Mobile test suite** | `mobile-test/README.md` |
| **OpenCode integration** | `docs/opencode-integration.md` |
| **Local echo overlay** | `docs/local-echo-overlay-plan.md` |
| **Performance investigation** | `docs/performance-investigation-report.md` |
| **First-load optimization** | `docs/first-load-optimization-plan.md`, `docs/perf-audit-first-load.md` |
| **Codebase quality / refactoring summary** | `docs/code-structure-findings.md` |
| **Dead code audit** | `docs/cleanup-findings.md` |
| **TypeScript improvements** | `docs/typescript-improvement-suggestions.md` |
| **Browser testing** | `docs/browser-testing-guide.md` |
+17
View File
@@ -450,6 +450,23 @@ See [CLAUDE.md](./CLAUDE.md) for full documentation.
---
## Codebase Quality
The codebase went through a comprehensive 7-phase refactoring that eliminated god objects, centralized configuration, and established modular architecture:
| Phase | What changed | Impact |
|-------|-------------|--------|
| **Performance** | Cached endpoints, SSE adaptive batching, buffer chunking | Sub-16ms terminal latency |
| **Route extraction** | `server.ts` split into 12 domain route modules + auth middleware + port interfaces | **−60%** server.ts LOC (6,736 → 2,697) |
| **Domain splitting** | `types.ts` → 14 domain files, `ralph-tracker` → 7 files, `respawn-controller` → 5 files, `session` → 6 files | No more god files |
| **Frontend modules** | `app.js` → 8 extracted modules (constants, mobile, voice, notifications, keyboard, API, subagent windows) | **−24%** app.js LOC (15.2K → 11.5K) |
| **Config consolidation** | ~70 scattered magic numbers → 9 domain-focused config files | Zero cross-file duplicates |
| **Test infrastructure** | Shared mock library, 12 route test files, consolidated MockSession | Testable route handlers via `app.inject()` |
Full details: [`docs/code-structure-findings.md`](docs/code-structure-findings.md)
---
## Published Packages
### [`xterm-zerolag-input`](https://www.npmjs.com/package/xterm-zerolag-input)
+1 -1
View File
@@ -343,7 +343,7 @@ export const RalphConfigSchema = z.object({
enabled: z.boolean().optional(),
completionPhrase: z.string().max(500).optional(),
maxIterations: z.number().int().min(0).max(10000).optional(),
reset: z.boolean().optional(),
reset: z.union([z.boolean(), z.literal('full')]).optional(),
disableAutoEnable: z.boolean().optional(),
});
+1 -108
View File
@@ -8,11 +8,9 @@
import { describe, it, expect } from 'vitest';
import {
createErrorResponse,
createSuccessResponse,
createInitialRalphTrackerState,
createInitialRalphSessionState,
createInitialState,
ErrorMessages,
ApiErrorCode,
DEFAULT_CONFIG,
isError,
@@ -26,7 +24,7 @@ describe('types utility functions', () => {
expect(response.success).toBe(false);
expect(response.errorCode).toBe('NOT_FOUND');
expect(response.error).toBe(ErrorMessages.NOT_FOUND);
expect(response.error).toBe('The requested resource was not found');
});
it('should create error response with custom details', () => {
@@ -85,86 +83,6 @@ describe('types utility functions', () => {
});
});
describe('createSuccessResponse', () => {
it('should create success response without data', () => {
const response = createSuccessResponse();
expect(response.success).toBe(true);
expect(response.data).toBeUndefined();
});
it('should create success response with data', () => {
const data = { id: '123', name: 'test' };
const response = createSuccessResponse(data);
expect(response.success).toBe(true);
expect(response.data).toEqual(data);
});
it('should handle null data', () => {
const response = createSuccessResponse(null);
expect(response.success).toBe(true);
expect(response.data).toBeNull();
});
it('should handle undefined explicitly', () => {
const response = createSuccessResponse(undefined);
expect(response.success).toBe(true);
expect(response.data).toBeUndefined();
});
it('should handle array data', () => {
const data = [1, 2, 3, { nested: true }];
const response = createSuccessResponse(data);
expect(response.data).toEqual(data);
});
it('should handle nested object data', () => {
const data = {
level1: {
level2: {
level3: {
value: 'deep',
},
},
},
};
const response = createSuccessResponse(data);
expect(response.data).toEqual(data);
});
it('should handle string data', () => {
const response = createSuccessResponse('simple string');
expect(response.data).toBe('simple string');
});
it('should handle number data', () => {
const response = createSuccessResponse(42);
expect(response.data).toBe(42);
});
it('should handle boolean data', () => {
const response = createSuccessResponse(true);
expect(response.data).toBe(true);
});
it('should handle Date data', () => {
const date = new Date('2024-01-15');
const response = createSuccessResponse(date);
expect(response.data).toEqual(date);
});
it('should handle empty object data', () => {
const response = createSuccessResponse({});
expect(response.data).toEqual({});
});
it('should handle empty array data', () => {
const response = createSuccessResponse([]);
expect(response.data).toEqual([]);
});
});
describe('createInitialRalphTrackerState', () => {
it('should create initial Ralph tracker state', () => {
const state = createInitialRalphTrackerState();
@@ -315,31 +233,6 @@ describe('types utility functions', () => {
});
});
describe('ErrorMessages', () => {
it('should have messages for all error codes', () => {
const codes: ApiErrorCode[] = [
ApiErrorCode.NOT_FOUND,
ApiErrorCode.INVALID_INPUT,
ApiErrorCode.SESSION_BUSY,
ApiErrorCode.OPERATION_FAILED,
ApiErrorCode.ALREADY_EXISTS,
ApiErrorCode.INTERNAL_ERROR,
];
for (const code of codes) {
expect(ErrorMessages[code]).toBeDefined();
expect(typeof ErrorMessages[code]).toBe('string');
expect(ErrorMessages[code].length).toBeGreaterThan(0);
}
});
it('should have unique messages', () => {
const messages = Object.values(ErrorMessages);
const uniqueMessages = new Set(messages);
expect(uniqueMessages.size).toBe(messages.length);
});
});
describe('DEFAULT_CONFIG', () => {
it('should have sensible default poll interval', () => {
expect(DEFAULT_CONFIG.pollIntervalMs).toBeGreaterThanOrEqual(100);