mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-02 13:39:41 +02:00
Overlay renderer (xterm-zerolag-input): - Add charTop/charHeight to CellDimensions and RenderParams for precise vertical text positioning matching xterm's canvas renderer - Convert device.char dimensions to CSS pixels via devicePixelRatio - Extend line div background 1px past cell boundary to cover compositing seam between overlay layer (z-index:7) and canvas layer below - Remove -webkit-font-smoothing/text-rendering overrides that made overlay text thinner than canvas text - Add per-span height/lineHeight for natural CSS vertical centering - Add setPrompt() method for runtime prompt strategy switching (fixes tab switching crash with "setPrompt is not a function") app.js duplicate class members: - Remove dead formatTokens duplicate (line ~5590 shadowed precise version) - Remove fire-and-forget resetCircuitBreaker duplicate (shadowed notification version) - Rename mux-panel killAllSessions to killAllMuxSessions (was shadowing Codeman session killer, breaking Ctrl+K) Other: - Update index.html onclick to use killAllMuxSessions - Add getTeamTasks mock to test route context Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
122 lines
3.9 KiB
TypeScript
122 lines
3.9 KiB
TypeScript
/**
|
|
* Mock context for route handler testing.
|
|
*
|
|
* Satisfies ALL port interfaces (SessionPort, EventPort, RespawnPort,
|
|
* ConfigPort, InfraPort, AuthPort) so any route module can be tested.
|
|
* Override specific methods in individual tests as needed.
|
|
*
|
|
* Uses app.inject() — no real HTTP ports needed.
|
|
*/
|
|
import { vi } from 'vitest';
|
|
import { MockSession, createMockSession } from './mock-session.js';
|
|
|
|
/**
|
|
* Creates a mock context that satisfies all port interfaces.
|
|
* Pre-populated with one session for convenience.
|
|
*/
|
|
export function createMockRouteContext(options?: { sessionId?: string }) {
|
|
const sessionId = options?.sessionId ?? 'test-session-1';
|
|
const session = createMockSession(sessionId);
|
|
const sessions = new Map<string, MockSession>();
|
|
sessions.set(sessionId, session);
|
|
|
|
return {
|
|
// -- SessionPort --
|
|
sessions,
|
|
addSession: vi.fn((s: MockSession) => {
|
|
sessions.set(s.id, s);
|
|
}),
|
|
cleanupSession: vi.fn(async () => {}),
|
|
setupSessionListeners: vi.fn(async () => {}),
|
|
persistSessionState: vi.fn(),
|
|
persistSessionStateNow: vi.fn(),
|
|
getSessionStateWithRespawn: vi.fn((s: MockSession) => s.toState()),
|
|
|
|
// -- EventPort --
|
|
broadcast: vi.fn(),
|
|
sendPushNotifications: vi.fn(),
|
|
batchTerminalData: vi.fn(),
|
|
broadcastSessionStateDebounced: vi.fn(),
|
|
batchTaskUpdate: vi.fn(),
|
|
|
|
// -- RespawnPort --
|
|
respawnControllers: new Map(),
|
|
respawnTimers: new Map(),
|
|
setupRespawnListeners: vi.fn(),
|
|
setupTimedRespawn: vi.fn(),
|
|
restoreRespawnController: vi.fn(),
|
|
saveRespawnConfig: vi.fn(),
|
|
|
|
// -- ConfigPort --
|
|
store: {
|
|
getConfig: vi.fn(() => ({ ralphEnabled: false, maxConcurrentSessions: 5 })),
|
|
getSessions: vi.fn(() => ({})),
|
|
getSession: vi.fn(),
|
|
setSession: vi.fn(),
|
|
removeSession: vi.fn(),
|
|
getSettings: vi.fn(() => ({})),
|
|
setSettings: vi.fn(),
|
|
getRalphLoopState: vi.fn(() => ({})),
|
|
setRalphLoopState: vi.fn(),
|
|
getTasks: vi.fn(() => ({})),
|
|
save: vi.fn(),
|
|
load: vi.fn(),
|
|
incrementSessionsCreated: vi.fn(),
|
|
setConfig: vi.fn(),
|
|
getAggregateStats: vi.fn(() => ({ totalInputTokens: 0, totalOutputTokens: 0, totalCost: 0 })),
|
|
getGlobalStats: vi.fn(() => ({ sessionsCreated: 0 })),
|
|
getDailyStats: vi.fn(() => []),
|
|
cleanupStaleSessions: vi.fn(() => ({ count: 0, cleaned: [] })),
|
|
},
|
|
port: 3000,
|
|
https: false,
|
|
testMode: true,
|
|
serverStartTime: Date.now(),
|
|
getGlobalNiceConfig: vi.fn(async () => undefined),
|
|
getModelConfig: vi.fn(async () => null),
|
|
getClaudeModeConfig: vi.fn(async () => ({})),
|
|
getDefaultClaudeMdPath: vi.fn(async () => undefined),
|
|
getLightState: vi.fn(() => ({ sessions: [], status: 'ok' })),
|
|
getLightSessionsState: vi.fn(() => {
|
|
const result: Record<string, unknown>[] = [];
|
|
for (const s of sessions.values()) {
|
|
result.push(s.toState());
|
|
}
|
|
return result;
|
|
}),
|
|
startTranscriptWatcher: vi.fn(),
|
|
stopTranscriptWatcher: vi.fn(),
|
|
|
|
// -- InfraPort --
|
|
mux: {
|
|
createSession: vi.fn(),
|
|
killSession: vi.fn(),
|
|
listSessions: vi.fn(() => []),
|
|
getStats: vi.fn(() => ({})),
|
|
updateSessionName: vi.fn(() => true),
|
|
getSession: vi.fn(() => null),
|
|
clearRespawnConfig: vi.fn(),
|
|
updateRespawnConfig: vi.fn(),
|
|
},
|
|
runSummaryTrackers: new Map(),
|
|
activePlanOrchestrators: new Map(),
|
|
scheduledRuns: new Map(),
|
|
teamWatcher: { getTeams: vi.fn(() => []), getTeamTasks: vi.fn(() => []), hasActiveTeammates: vi.fn(() => false) },
|
|
tunnelManager: null,
|
|
pushStore: null,
|
|
startScheduledRun: vi.fn(),
|
|
stopScheduledRun: vi.fn(),
|
|
|
|
// -- AuthPort --
|
|
authSessions: null,
|
|
qrAuthFailures: null,
|
|
// https already declared above in ConfigPort (shared property)
|
|
|
|
// Convenience accessors (not part of any port interface)
|
|
_session: session,
|
|
_sessionId: sessionId,
|
|
};
|
|
}
|
|
|
|
export type MockRouteContext = ReturnType<typeof createMockRouteContext>;
|