fix(local): honor server LLM for keyless missions

This commit is contained in:
Joseph Magly authored and GitHub committed 2026-07-15 18:13:27 -04:00
1 parent 600f43b8b1
commit 4b81bf6436
5 files changed
+91 -33

No files matched your search

@@ -3,6 +3,7 @@ import { readFileSync } from 'fs';
import { join } from 'path';
const serverSource = readFileSync(join(process.cwd(), 'src/server.ts'), 'utf8');
const uiSource = readFileSync(join(process.cwd(), 'docs/index.html'), 'utf8');
function sourceBlock(startMarker: string, endMarker: string): string {
const start = serverSource.indexOf(startMarker);
@@ -17,6 +18,34 @@ function routeBlock(startMarker: string, endMarker: string): string {
}
describe('local API authorization hardening invariants', () => {
it('server mission/general routes default to the configured LLM instead of hardcoded OpenRouter', () => {
const resolver = routeBlock('function resolveGeneralLLMConfig(', '/**\n * Bring a planned mission UP for real');
const missionRoute = routeBlock("app.post('/api/mission/start'", "app.get('/api/mission/report'");
const generalRoutes = routeBlock("app.post('/api/general/plan'", '// =============================================================================\n// THE ADMIRAL');
expect(resolver).toContain('config.getLLMConfig()');
expect(resolver).toContain('provider || defaultConfig.provider');
expect(missionRoute).toContain('resolveGeneralLLMConfig(provider, model, apiKey)');
expect(`${missionRoute}\n${generalRoutes}`).not.toMatch(/provider\s*=\s*['"]openrouter['"]/);
expect(`${missionRoute}\n${generalRoutes}`).not.toMatch(/model\s*=\s*['"]anthropic\/claude-sonnet-4['"]/);
});
it('health and LLM status count keyless local backends as configured', () => {
const health = routeBlock('function healthPayload()', '// =============================================================================\n// API ENDPOINTS - HEALTH & STATUS');
const llmStatus = routeBlock("app.get('/api/llm/status'", '// =============================================================================\n// TOOL EXECUTION ENDPOINTS');
expect(health).toContain('providerRunsKeyless(llmConfig.provider)');
expect(llmStatus).toContain('providerRunsKeyless(llmConfig.provider)');
});
it('War Room no-key/no-agent backend dispatch defers to the server-configured LLM', () => {
expect(uiSource).toContain("serverLLM: null");
expect(uiSource).toContain('this.serverLLM = data.llm');
expect(uiSource).toContain('No browser API key — using the server-configured LLM backend');
expect(uiSource).toContain('LLM backend: server default — no browser API key sent');
expect(uiSource).not.toMatch(/let provider = ['"]openrouter['"];\s*\n\s*let model = state\.settings\.selectedModel/);
});
it('/api/events does not grant wildcard CORS and rejects foreign browser origins before opening SSE', () => {
const route = routeBlock("app.get('/api/events'", '// =============================================================================\n// API ENDPOINTS - HEALTH & STATUS');