Files
ruvnet__ruflo/v3/@claude-flow/cli/__tests__/validate-input-agent-spawn.test.ts
rUv 01070ede81 fix: Tier A blockers #1596, #1567, #1556 (v3.5.80) (#1598)
* fix: resolve Tier A blockers #1596, #1567, #1556

#1596 — CLI lazy-command routing:
  `ruflo daemon start` was mis-routed to the top-level `start` command
  because the parser only registered the 10 core sync commands and its
  greedy Pass 1 walk happily matched `start` as the command with `daemon`
  left as a positional. Teach the parser about lazy command names via
  `registerLazyCommandName()`, stop Pass 1 at the first non-flag
  positional, and recognize lazy names in Pass 2 so commandPath becomes
  `['daemon', 'start']`. The existing positional-based subcommand
  fallback in CLI.run() then dispatches correctly. Affects every
  lazy-loaded command (daemon, doctor, embeddings, neural, config,
  workflow, hive-mind, ...).

#1567 — agent_spawn Zod field mismatch:
  validate-input.ts was passing `{ agentType, name }` to
  @claude-flow/security's SpawnAgentSchema, which expects `{ type, id }`,
  so every MCP agent_spawn call failed with `type: Required`. Align the
  field names. Also swallow `invalid_enum_value` issues because the
  schema enumerates only 15 built-in agent types — we support custom
  types and the inline identifier validator already gated unsafe input.

#1556 — AutoMemoryBridge destroys hand-curated MEMORY.md:
  `curateIndex()` fired on every Stop hook tick and overwrote MEMORY.md
  with a single-line title stub whenever none of the files in memoryDir
  matched the 7 hardcoded DEFAULT_TOPIC_MAPPING filenames — which is
  exactly the situation for any project using Claude Code's native
  `<type>_<topic>.md` memory convention. Skip the write entirely when
  there are no sections to curate and emit `index:skipped` instead;
  `curate` must be non-destructive when there's nothing to curate.

Tests:
  - __tests__/parser.test.ts: 4 new cases cover lazy command routing,
    bare lazy commands, and global flags before a lazy command.
  - __tests__/validate-input-agent-spawn.test.ts: built-in type, custom
    type, bad identifier, and no-domain cases.
  - src/auto-memory-bridge.test.ts: new #1556 case + updated empty-file
    case to assert the new non-destructive semantics.
  All 120 CLI + 74 memory tests pass locally.

Co-Authored-By: claude-flow <ruv@ruv.net>

* chore: bump to 3.5.80 / memory 3.0.0-alpha.14 for Tier A fixes

- @claude-flow/cli 3.5.78 → 3.5.80
- @claude-flow/memory 3.0.0-alpha.13 → 3.0.0-alpha.14
- claude-flow umbrella 3.5.78 → 3.5.80
- ruflo umbrella 3.5.78 → 3.5.80

Also fixes memory package's prebuild script to clean
tsconfig.tsbuildinfo so tsc --incremental produces fresh
output after rm -rf dist.

Matches published npm artifacts for issues #1596, #1567, #1556.

Co-Authored-By: claude-flow <ruv@ruv.net>

---------

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-04-11 12:20:01 -04:00

44 lines
1.7 KiB
TypeScript

/**
* Regression test for #1567: validateAgentSpawn's Zod call was passing
* `{ agentType, name }` to `@claude-flow/security`'s SpawnAgentSchema, which
* expects `{ type, id }` — so every call failed with "type: Required" and
* the MCP agent_spawn tool returned an input validation error for every
* possible input. The fix aligns the field names AND swallows
* `invalid_enum_value` errors so custom agent types (beyond the 15-type
* hardcoded enum) continue to work.
*/
import { describe, it, expect } from 'vitest';
import { validateAgentSpawn } from '../src/mcp-tools/validate-input.js';
describe('validateAgentSpawn (#1567)', () => {
it('accepts a built-in agent type like "tester"', async () => {
const r = await validateAgentSpawn({ agentType: 'tester', agentId: 'tester-1' });
expect(r.valid).toBe(true);
expect(r.errors).toEqual([]);
});
it('accepts a custom agent type not in the SpawnAgentSchema enum', async () => {
// "memory-specialist" is not one of the 15 types that
// @claude-flow/security's AgentTypeSchema enumerates, but it's a valid
// Claude Flow agent type and should NOT be rejected.
const r = await validateAgentSpawn({ agentType: 'memory-specialist', agentId: 'mem-1' });
expect(r.valid).toBe(true);
expect(r.errors).toEqual([]);
});
it('still rejects an agentId with invalid characters', async () => {
const r = await validateAgentSpawn({
agentType: 'tester',
agentId: 'has spaces and $pecials',
});
expect(r.valid).toBe(false);
expect(r.errors.length).toBeGreaterThan(0);
});
it('does not require the domain field', async () => {
const r = await validateAgentSpawn({ agentType: 'coder', agentId: 'c1' });
expect(r.valid).toBe(true);
});
});