Files
ruflo/v3/@claude-flow/cli/__tests__
rUvandr 52327803a5 feat: ruflo phone — pair the RuFlo/Orca phone app with the CLI (opt-in @claude-flow/phone-host 1.0.0) (#5204)
* feat(cli): ruflo phone + phone_* MCP tools over the opt-in @claude-flow/phone-host

`ruflo phone setup` installs @claude-flow/phone-host into ~/.ruflo/phone-host
(RUFLO_PHONE_HOST_PREFIX, absolute only); it is never a dependency of the CLI.
start | daemon start|stop|status | pair | devices | revoke | interfaces run the
package bin with inherited stdio; argv is rebuilt from declared options and any
other flag is refused. Without the package they point at `phone setup`, exit 1.

MCP tools phone_status/setup/daemon/pair/devices/revoke import the package
lazily, validate inputs at the boundary, and build results from field
whitelists, so no pairing code, link or QR reaches tool output. phone_pair
shows the QR in a window or file only.

Init CLAUDE.md/AGENTS.md: "Phone (RuFlo / Orca app)" replaces the #5198 ruPro
section; agents may now pair phones, including with full access.

A subcommand's string --version no longer prints the CLI version.

Co-Authored-By: RuFlo <ruv@ruv.net>

* fix(cli): phone — keep ^ through cmd.exe, refuse flags on bare 'phone daemon', looser device names

Co-Authored-By: RuFlo <ruv@ruv.net>

* fix(cli): phone_pair name defaults to "Phone"; tell the bin it runs as `ruflo phone`

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(phone-host): full access (terminals, agent tabs), workspace reads, project/workspace scope, orca links

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(phone-host): background daemon, agent-safe pairing (QR page), revoke closes terminals, RuFlo bundle ef1e43563, 1.0.0

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(phone-host): print `ruflo phone` in hints when the ruflo CLI runs the bin

Co-Authored-By: RuFlo <ruv@ruv.net>

* ci(phone-host): own test job (Linux/macOS, Node 20/24); root vitest skips its node:test files

Co-Authored-By: RuFlo <ruv@ruv.net>

* fix(phone-host): open Codex tabs without the update screen

Codex shows "update available" at start when a release is out; choosing
update quits it and the phone's next message lands in the shell.

Co-Authored-By: RuFlo <ruv@ruv.net>

* test(phone-host): wait for pwd's output instead of assuming it came with echo's

Co-Authored-By: RuFlo <ruv@ruv.net>

* fix(phone-host): phone terminals don't inherit the starting agent's session

When Claude Code (or Codex, or ruflo) starts the host, its session markers
reached every phone terminal: the phone's Claude ran as a child of that
session, with its session id, message socket and token, and transcript
saving off. Those variables are now removed; user settings stay.

Co-Authored-By: RuFlo <ruv@ruv.net>

---------

Co-authored-by: r <r@x>
2026-11-30 15:21:19 -05: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