2026-02-21 04:17:31 +00:00
|
|
|
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
|
|
|
import { mkdtempSync, rmSync } from 'node:fs';
|
|
|
|
|
import { join } from 'node:path';
|
|
|
|
|
import { tmpdir } from 'node:os';
|
|
|
|
|
import { createStatusCommand } from '../../src/commands/status.js';
|
2026-02-24 23:52:04 +00:00
|
|
|
import type { StatusCommandDeps } from '../../src/commands/status.js';
|
2026-02-21 04:17:31 +00:00
|
|
|
import { saveConfig, DEFAULT_CONFIG } from '../../src/config/index.js';
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
import { saveCredentials } from '../../src/auth/index.js';
|
2026-02-21 04:17:31 +00:00
|
|
|
|
|
|
|
|
let tempDir: string;
|
|
|
|
|
let output: string[];
|
2026-02-24 23:52:04 +00:00
|
|
|
let written: string[];
|
2026-02-21 04:17:31 +00:00
|
|
|
|
|
|
|
|
function log(...args: string[]) {
|
|
|
|
|
output.push(args.join(' '));
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 23:52:04 +00:00
|
|
|
function write(text: string) {
|
|
|
|
|
written.push(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function baseDeps(overrides?: Partial<StatusCommandDeps>): Partial<StatusCommandDeps> {
|
|
|
|
|
return {
|
|
|
|
|
configDeps: { configDir: tempDir },
|
|
|
|
|
credentialsDeps: { configDir: tempDir },
|
|
|
|
|
log,
|
|
|
|
|
write,
|
|
|
|
|
checkHealth: async () => true,
|
|
|
|
|
isTTY: false,
|
|
|
|
|
...overrides,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 04:17:31 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
|
tempDir = mkdtempSync(join(tmpdir(), 'mcpctl-status-test-'));
|
|
|
|
|
output = [];
|
2026-02-24 23:52:04 +00:00
|
|
|
written = [];
|
2026-02-21 04:17:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
rmSync(tempDir, { recursive: true, force: true });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('status command', () => {
|
|
|
|
|
it('shows status in table format', async () => {
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps());
|
2026-02-21 04:17:31 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
const out = output.join('\n');
|
|
|
|
|
expect(out).toContain('mcpctl v');
|
|
|
|
|
expect(out).toContain('mcplocal:');
|
|
|
|
|
expect(out).toContain('mcpd:');
|
|
|
|
|
expect(out).toContain('connected');
|
2026-02-21 04:17:31 +00:00
|
|
|
});
|
|
|
|
|
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
it('shows unreachable when daemons are down', async () => {
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps({ checkHealth: async () => false }));
|
2026-02-21 04:17:31 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
expect(output.join('\n')).toContain('unreachable');
|
|
|
|
|
});
|
|
|
|
|
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
it('shows not logged in when no credentials', async () => {
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps());
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
expect(output.join('\n')).toContain('not logged in');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows logged in user when credentials exist', async () => {
|
|
|
|
|
saveCredentials({ token: 'tok', mcpdUrl: 'http://x:3100', user: 'alice@example.com' }, { configDir: tempDir });
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps());
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
expect(output.join('\n')).toContain('logged in as alice@example.com');
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-21 04:17:31 +00:00
|
|
|
it('shows status in JSON format', async () => {
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps());
|
2026-02-21 04:17:31 +00:00
|
|
|
await cmd.parseAsync(['-o', 'json'], { from: 'user' });
|
|
|
|
|
const parsed = JSON.parse(output[0]) as Record<string, unknown>;
|
|
|
|
|
expect(parsed['version']).toBe('0.1.0');
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
expect(parsed['mcplocalReachable']).toBe(true);
|
|
|
|
|
expect(parsed['mcpdReachable']).toBe(true);
|
2026-02-21 04:17:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows status in YAML format', async () => {
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps({ checkHealth: async () => false }));
|
2026-02-21 04:17:31 +00:00
|
|
|
await cmd.parseAsync(['-o', 'yaml'], { from: 'user' });
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
expect(output[0]).toContain('mcplocalReachable: false');
|
2026-02-21 04:17:31 +00:00
|
|
|
});
|
|
|
|
|
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
it('checks correct URLs from config', async () => {
|
|
|
|
|
saveConfig({ ...DEFAULT_CONFIG, mcplocalUrl: 'http://local:3200', mcpdUrl: 'http://remote:3100' }, { configDir: tempDir });
|
|
|
|
|
const checkedUrls: string[] = [];
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps({
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
checkHealth: async (url) => {
|
|
|
|
|
checkedUrls.push(url);
|
2026-02-21 04:17:31 +00:00
|
|
|
return false;
|
|
|
|
|
},
|
2026-02-24 23:52:04 +00:00
|
|
|
}));
|
2026-02-21 04:17:31 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00
|
|
|
expect(checkedUrls).toContain('http://local:3200');
|
|
|
|
|
expect(checkedUrls).toContain('http://remote:3100');
|
2026-02-21 04:17:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows registries from config', async () => {
|
|
|
|
|
saveConfig({ ...DEFAULT_CONFIG, registries: ['official'] }, { configDir: tempDir });
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps());
|
2026-02-21 04:17:31 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
expect(output.join('\n')).toContain('official');
|
|
|
|
|
expect(output.join('\n')).not.toContain('glama');
|
|
|
|
|
});
|
2026-02-24 22:48:17 +00:00
|
|
|
|
|
|
|
|
it('shows LLM not configured hint when no LLM is set', async () => {
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps());
|
2026-02-24 22:48:17 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
const out = output.join('\n');
|
|
|
|
|
expect(out).toContain('LLM:');
|
|
|
|
|
expect(out).toContain('not configured');
|
|
|
|
|
expect(out).toContain('mcpctl config setup');
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-24 23:52:04 +00:00
|
|
|
it('shows green check when LLM is healthy (non-TTY)', async () => {
|
2026-02-24 22:48:17 +00:00
|
|
|
saveConfig({ ...DEFAULT_CONFIG, llm: { provider: 'anthropic', model: 'claude-haiku-3-5-20241022' } }, { configDir: tempDir });
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps({ checkLlm: async () => 'ok' }));
|
2026-02-24 22:48:17 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
const out = output.join('\n');
|
|
|
|
|
expect(out).toContain('anthropic / claude-haiku-3-5-20241022');
|
2026-02-24 23:52:04 +00:00
|
|
|
expect(out).toContain('✓ ok');
|
2026-02-24 23:24:31 +00:00
|
|
|
});
|
|
|
|
|
|
2026-02-24 23:52:04 +00:00
|
|
|
it('shows red cross when LLM check fails (non-TTY)', async () => {
|
2026-02-24 23:24:31 +00:00
|
|
|
saveConfig({ ...DEFAULT_CONFIG, llm: { provider: 'gemini-cli', model: 'gemini-2.5-flash' } }, { configDir: tempDir });
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps({ checkLlm: async () => 'not authenticated' }));
|
2026-02-24 23:24:31 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
const out = output.join('\n');
|
2026-02-24 23:52:04 +00:00
|
|
|
expect(out).toContain('✗ not authenticated');
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-25 00:03:25 +00:00
|
|
|
it('shows error message from mcplocal', async () => {
|
2026-02-24 23:52:04 +00:00
|
|
|
saveConfig({ ...DEFAULT_CONFIG, llm: { provider: 'gemini-cli', model: 'gemini-2.5-flash' } }, { configDir: tempDir });
|
|
|
|
|
const cmd = createStatusCommand(baseDeps({ checkLlm: async () => 'binary not found' }));
|
|
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
expect(output.join('\n')).toContain('✗ binary not found');
|
2026-02-24 23:24:31 +00:00
|
|
|
});
|
|
|
|
|
|
2026-02-25 00:03:25 +00:00
|
|
|
it('queries mcplocal URL for LLM health', async () => {
|
|
|
|
|
saveConfig({ ...DEFAULT_CONFIG, mcplocalUrl: 'http://custom:9999', llm: { provider: 'gemini-cli', model: 'gemini-2.5-flash' } }, { configDir: tempDir });
|
|
|
|
|
let queriedUrl = '';
|
|
|
|
|
const cmd = createStatusCommand(baseDeps({
|
|
|
|
|
checkLlm: async (url) => { queriedUrl = url; return 'ok'; },
|
|
|
|
|
}));
|
|
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
expect(queriedUrl).toBe('http://custom:9999');
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-24 23:52:04 +00:00
|
|
|
it('uses spinner on TTY and writes final result', async () => {
|
2026-02-24 23:24:31 +00:00
|
|
|
saveConfig({ ...DEFAULT_CONFIG, llm: { provider: 'gemini-cli', model: 'gemini-2.5-flash' } }, { configDir: tempDir });
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps({
|
|
|
|
|
isTTY: true,
|
|
|
|
|
checkLlm: async () => 'ok',
|
|
|
|
|
}));
|
2026-02-24 23:24:31 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
2026-02-24 23:52:04 +00:00
|
|
|
// On TTY, the final LLM line goes through write(), not log()
|
|
|
|
|
const finalWrite = written[written.length - 1];
|
|
|
|
|
expect(finalWrite).toContain('gemini-cli / gemini-2.5-flash');
|
|
|
|
|
expect(finalWrite).toContain('✓ ok');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('uses spinner on TTY and shows failure', async () => {
|
|
|
|
|
saveConfig({ ...DEFAULT_CONFIG, llm: { provider: 'gemini-cli', model: 'gemini-2.5-flash' } }, { configDir: tempDir });
|
|
|
|
|
const cmd = createStatusCommand(baseDeps({
|
|
|
|
|
isTTY: true,
|
|
|
|
|
checkLlm: async () => 'not authenticated',
|
|
|
|
|
}));
|
|
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
const finalWrite = written[written.length - 1];
|
|
|
|
|
expect(finalWrite).toContain('✗ not authenticated');
|
2026-02-24 22:48:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows not configured when LLM provider is none', async () => {
|
|
|
|
|
saveConfig({ ...DEFAULT_CONFIG, llm: { provider: 'none' } }, { configDir: tempDir });
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps());
|
2026-02-24 22:48:17 +00:00
|
|
|
await cmd.parseAsync([], { from: 'user' });
|
|
|
|
|
expect(output.join('\n')).toContain('not configured');
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-24 23:24:31 +00:00
|
|
|
it('includes llm and llmStatus in JSON output', async () => {
|
2026-02-24 22:48:17 +00:00
|
|
|
saveConfig({ ...DEFAULT_CONFIG, llm: { provider: 'gemini-cli', model: 'gemini-2.5-flash' } }, { configDir: tempDir });
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps({ checkLlm: async () => 'ok' }));
|
2026-02-24 22:48:17 +00:00
|
|
|
await cmd.parseAsync(['-o', 'json'], { from: 'user' });
|
|
|
|
|
const parsed = JSON.parse(output[0]) as Record<string, unknown>;
|
|
|
|
|
expect(parsed['llm']).toBe('gemini-cli / gemini-2.5-flash');
|
2026-02-24 23:24:31 +00:00
|
|
|
expect(parsed['llmStatus']).toBe('ok');
|
2026-02-24 22:48:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('includes null llm in JSON output when not configured', async () => {
|
2026-02-24 23:52:04 +00:00
|
|
|
const cmd = createStatusCommand(baseDeps());
|
2026-02-24 22:48:17 +00:00
|
|
|
await cmd.parseAsync(['-o', 'json'], { from: 'user' });
|
|
|
|
|
const parsed = JSON.parse(output[0]) as Record<string, unknown>;
|
|
|
|
|
expect(parsed['llm']).toBeNull();
|
2026-02-24 23:24:31 +00:00
|
|
|
expect(parsed['llmStatus']).toBeNull();
|
2026-02-24 22:48:17 +00:00
|
|
|
});
|
2026-02-21 04:17:31 +00:00
|
|
|
});
|