Files
ruflo/v3/@claude-flow/cli/__tests__
rUvandClaude 6cdad1ae0e dream(security): #4229 DENYLISTED_ENV_NAMES gaps — git/perl/ruby/java hijack family (evaluated, ACCEPT) (#4230)
* dream(security): denylist gaps in validateEnv() for git/perl/ruby/java env-var hijack family

DENYLISTED_ENV_NAMES (v3/@claude-flow/cli-core/src/mcp-tools/validate-input.ts)
covered loader-hijack and the 2026-09-21 search-path-family fix, but missed
credential/arbitrary-command vars in the same git family (GIT_ASKPASS,
GIT_PROXY_COMMAND), interpreter-flag-injection vars for Perl/Ruby/Java
(PERL5OPT/RUBYOPT/JAVA_TOOL_OPTIONS/_JAVA_OPTIONS/JDK_JAVA_OPTIONS), two more
search-path vars (PYTHONHOME, CLASSPATH), and git's numbered
GIT_CONFIG_KEY_<n>/VALUE_<n>/COUNT runtime-config-injection family (added via
a new regex, not a fixed name — strictly broader than any single name).
PYTHONSTARTUP included for defense-in-depth with an honest caveat (interactive-
REPL-only, not live-exploitable through today's non-interactive execSync path).
Researched and explicitly rejected: PYTHONEXECUTABLE (cosmetic, macOS-only),
PSModulePath (single-source, Grade C evidence only).

18 new discriminating tests added to validate-input-env.test.ts, matching the
file's existing pattern. Stash-isolated: 18/18 fail against baseline, 51/51
pass on candidate. Full @claude-flow/cli suite: byte-identical 60-failure set
baseline vs candidate (zero regressions). tsc --noEmit: 0 errors.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H

* dream(security): fix-forward post-critique — correct test counts, document GIT_CONFIG_NOSYSTEM/PYTHONSTARTUP caveats

Independent adversarial critic caught: (1) an arithmetic error in this
session's own evaluation writeup (32 pre-existing tests, not 33; 19 new
tests of which 18 discriminate, not 18 flat); (2) GIT_CONFIG_NOSYSTEM's
denylist rationale was undocumented despite guidance/mod-sources.ts's git()
helper setting that same var defensively elsewhere in this repo; (3) the
PYTHONSTARTUP comment overclaimed that execSync's non-interactive child
"cannot enter" Python's interactive mode — a caller-supplied `python3 -i`
can still trigger it. All three addressed: gist corrected, source comments
now document the real rationale for both. Net security conclusion for
PYTHONSTARTUP unchanged (defense-in-depth, no new capability — the caller
already controls the full command string). Re-verified: 51/51 tests,
tsc --noEmit clean.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H

* dream(security): update LEDGER.md for 2026-10-16 (#4229/#4230)

Appends tonight's row, confirms #4053/#3977 merged via GitHub MCP tools,
confirms no run-gap for 10-12..10-15, and flags that 10-11's own PR cited
a CVE-2026-25725 that does not resolve in NVD/MITRE.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H

* dream(security): fix CI — bump @claude-flow/cli-core 3.7.3->3.7.4 (leaf-package-publish audit)

The "Plugin package install-safety" CI check's audit-leaf-package-publish.mjs
caught that this PR's source change to v3/@claude-flow/cli-core (not bundled
into the release tarballs, resolved from the registry at the version
v3/@claude-flow/cli/package.json pins) left the leaf's own package.json
version unchanged — per CLAUDE.md's "Publishing Rules" (ruvnet/ruflo#3335,
#3390), that means a release would ship the OLD registry copy and this
fix would reach nobody. PATCH bump per repo semver policy (bug fix, no API
change): 3.7.3 -> 3.7.4. Updated the three places that need to agree:
cli-core's own package.json, @claude-flow/cli's dependency pin, and
v3/pnpm-lock.yaml's specifier for that workspace link.

Re-verified: audit-leaf-package-publish.mjs clean, tsc --noEmit 0 errors,
51/51 tests pass.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H

* dream(security): fix CI — bump root claude-flow's @claude-flow/cli-core range 3.7.3->3.7.4

audit-wrapper-dep-ranges.mjs (ruvnet/ruflo#2127) caught that the root
claude-flow umbrella's own declared dependency range for the just-bumped
@claude-flow/cli-core leaf (3.7.3) no longer includes the workspace's actual
version (3.7.4) after the prior commit's bump. package-lock.json's resolved
node_modules/@claude-flow/cli-core record intentionally left untouched (still
3.7.3, with its real registry integrity hash) since 3.7.4 has not actually
been published yet — see the PR comment on the structural publish blocker.

Re-verified all 5 install-safety audit scripts locally: clean.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H

* Revert "dream(security): fix CI — bump root claude-flow's @claude-flow/cli-core range 3.7.3->3.7.4"

This reverts commit 9dae077cb3.

* dream(security): resolve CI blocker — @claude-flow/cli-core@3.7.4 is now published

A maintainer's 3.57.0 release (main advanced from 1882006a0 to b93144803
while this PR sat open) published @claude-flow/cli-core@3.7.4 to the real
npm registry, containing this exact fix (verified via `npm pack` + diff
against the source on this branch). That resolves the structural blocker
described in this PR's comment: the root claude-flow umbrella's own
dependency range can now safely bump to match, since 3.7.4 genuinely
exists — unlike three days ago, this no longer breaks root `npm ci`/
`npm install` for the rest of the CI matrix.

Re-verified for real this time (not just the static audits): ran
`node scripts/smoke-cli-npx-install.mjs` directly — packs the real CLI
tarball and does a genuine `npm install` into a scratch project — and it
now succeeds end-to-end (previously failed with ETARGET). All 5 install-
safety audit scripts clean. 51/51 tests, tsc --noEmit 0 errors.

Note: main's own source tree (v3/@claude-flow/cli-core/src/mcp-tools/
validate-input.ts) is still at the pre-fix 3.7.3 content as of this
commit — only the npm registry got the fix early, via whatever process
published 3.7.4. Merging this PR is what reconciles main's source with
what's already shipped to real users.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-19 16:55:41 +01: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