Files
ruflo/v3/@claude-flow/cli/__tests__
ReuvenandRuFlo 1884ed1010 fix(3.7.0-alpha.12): batch resolve issue-fix loop #1839-#1847
Closes #1839, #1840, #1841, #1842, #1843, #1844, #1845, #1846, #1847.

#1839 — bin/cli.js, bin/mcp-server.js, config-adapter.ts: rename
  serverInfo.name 'claude-flow' → 'ruflo' so MCP wire identity matches the
  package name. Live probe of `ruflo mcp start` now returns
  `serverInfo.name="ruflo"` (verified post-build).

#1840 — init/executor.ts: detectExistingRufloMCP() now also walks
  parsed.projects[*].mcpServers.ruflo with normalized path matching
  (lowercase + forward-slash) so `claude mcp add ruflo` registrations
  stored project-scoped in ~/.claude.json are detected and init skips
  writing a duplicate .mcp.json.

#1841 — init/mcp-generator.ts: generated .mcp.json now keys
  `mcpServers.ruflo` instead of legacy `mcpServers['claude-flow']`. The
  printed `claude mcp add` instructions match. Prevents the
  duplicate-tool-prefix problem when init runs over an existing ruflo
  registration.

#1842 — commands/doctor.ts: checkMcpServers() now traverses
  ~/.claude.json.projects[*].mcpServers in addition to top-level
  mcpServers, so doctor stops warning "No MCP config found" when a
  working project-scoped ruflo registration exists.

#1843 — mcp-tools/system-tools.ts: exclude `unknown` from health
  denominator (was dragging the score down even when actionable checks
  were green) and surface as `advisory` count. Add YAML config and
  sql.js/HNSW/.swarm/ruvector memory paths to detection. Local probe:
  4 healthy / 5 actionable = 80% (was 4/8 = 50%) with 3 advisory.

#1844 — services/worker-daemon.ts: WorkerDaemon now reads
  .claude-flow/config.yaml (and .yml) when config.json is absent, with
  lazy `yaml` import so missing dep falls back to a clear warning.
  Adds yaml@^2.8.0 to runtime deps. Logs the chosen source.

#1845 — services/worker-daemon.ts + mcp-tools/hooks-tools.ts: durable
  queue boundary between MCP dispatch and daemon. mcp__hooks_worker-
  dispatch now writes .claude-flow/daemon-queue/<id>.json (the
  process-local Map was invisible to the daemon). The daemon polls this
  directory every 5s, executes triggerWorker(), and moves processed
  entries to .processed/. Adds `mcp-only` status for queue-write
  failures so we never claim `queued` without proof on disk.

#1846 — mcp-tools/memory-tools.ts + commands/memory.ts: feature-detect
  smartSearch on the resolved @claude-flow/memory build. When absent
  (older published memory packages predate the export), fall through to
  plain semantic search with an explicit warning + `smartFallback`
  field on the response, instead of throwing
  `smartSearch is not a function`.

#1847 — mcp-tools/hooks-tools.ts: hooks_pretrain now emits an explicit
  note when a non-empty corpus produces zero patterns, naming the
  supported extraction extensions (.ts/.js/.py/.go/.rs/.java) and
  clarifying that pretrain is a separate axis from live trajectories
  and statusline state. Local probe on a Markdown vault returns the
  new note correctly.

src/index.ts: pre-existing TS strict-null error in showCommandHelp()
  that was preventing `npm run build` (introduced by #1791.4 / 93b97548e)
  fixed by extracting a non-null `current: Command` local instead of
  reassigning the optional `command`. Unblocks publish + restores the
  integration-docker `npm run build succeeds` test.

Verification:
- 1963 tests pass / 0 fail (was 1962 / 1 due to the index.ts TS error)
- Live MCP probe: serverInfo.name="ruflo" ✅
- Live mcp-generator: emits mcpServers.ruflo ✅
- Live system_health: 80% (4/5 healthy, 3 advisory) ✅
- Live hooks_pretrain on Markdown vault: emits explicit note ✅

Published @claude-flow/cli@3.7.0-alpha.12, claude-flow@3.7.0-alpha.12,
ruflo@3.7.0-alpha.12 with all dist-tags (alpha, latest, v3alpha for
cli/claude-flow; alpha, latest for ruflo).

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-08 09:36:58 -04:00
..
2026-01-04 20:41:12 +00:00
2026-01-04 20:37:19 +00:00
2026-01-04 20:37:19 +00:00

CLI Module Tests

This directory contains comprehensive tests for the V3 CLI module using Vitest.

Test Files

1. cli.test.ts (~15+ tests)

Tests for the main CLI class covering:

  • Version command (--version, -V)
  • Help output (--help, -h)
  • Command parsing (long flags, short flags, equals syntax)
  • Positional arguments
  • Boolean flags and negation
  • Global flags (--quiet, --format, --config, --no-color)
  • Error handling (unknown commands, missing options)
  • Subcommand execution and aliases
  • Exit codes

2. mcp-client.test.ts (~10+ tests)

Tests for MCP tool invocation:

  • callMCPTool() - Tool execution with various inputs
  • getToolMetadata() - Metadata retrieval
  • listMCPTools() - Tool listing and filtering by category
  • hasTool() - Tool existence checks
  • getToolCategories() - Category enumeration
  • validateToolInput() - Input validation against schemas
  • MCPClientError - Custom error handling

3. commands.test.ts (~48+ tests)

Tests for all CLI commands:

Agent Commands (spawn, list, status, stop, metrics):

  • Spawning agents with various configurations
  • Listing agents with filters
  • Getting agent status and metrics
  • Stopping agents (graceful/force)
  • Agent performance metrics

Swarm Commands (init, start, status, stop, scale, coordinate):

  • Initializing swarms with different topologies
  • Starting swarm execution with objectives
  • Checking swarm status
  • Stopping and scaling swarms
  • V3 15-agent coordination structure

Memory Commands (store, retrieve, search, list, delete, stats, configure):

  • Storing data in memory (with/without vectors)
  • Retrieving data by key
  • Semantic/vector search
  • Listing memory entries
  • Deleting entries
  • Viewing statistics
  • Backend configuration

Config Commands (init, get, set, providers, reset, export, import):

  • Initializing configuration
  • Getting/setting config values
  • Managing AI providers
  • Resetting to defaults
  • Exporting/importing configuration

Mocking Strategy

MCP Tools

All MCP tools are mocked at the module level to prevent actual tool execution:

  • agent-tools.js - Mocked agent operations
  • swarm-tools.js - Mocked swarm coordination
  • memory-tools.js - Mocked memory operations
  • config-tools.js - Mocked configuration

Output

The output module is fully mocked to capture formatted output without console pollution.

Prompts

Interactive prompts (select, confirm, input, multiSelect) are mocked to return default values for non-interactive testing.

Process

process.exit() is mocked to throw errors instead of terminating the test process.

Running Tests

# Run all CLI tests
npm test -- v3/@claude-flow/cli/__tests__/

# Run specific test file
npm test -- v3/@claude-flow/cli/__tests__/cli.test.ts

# Run with coverage
npm test -- v3/@claude-flow/cli/__tests__/ --coverage

# Run in watch mode
npm test -- v3/@claude-flow/cli/__tests__/ --watch

Test Coverage Goals

  • Statements: >80%
  • Branches: >75%
  • Functions: >80%
  • Lines: >80%

Key Testing Patterns

1. Command Execution

const result = await command.action!(ctx);
expect(result.success).toBe(true);
expect(result.data).toHaveProperty('expectedField');

2. Flag Parsing

ctx.flags = { myFlag: 'value', _: [] };
await command.action!(ctx);
// Assertions in action callback

3. Error Handling

try {
  await cli.run(['invalid-command']);
} catch (e) {
  expect((e as Error).message).toContain('process.exit');
}

4. Output Validation

const output = consoleOutput.join('');
expect(output).toContain('Expected text');

Notes

  • All tests are non-interactive (interactive: false)
  • Console output is captured for verification
  • Process exits are converted to exceptions
  • MCP client is fully isolated from actual MCP server
  • Tests use unique command names to avoid conflicts