Files
ruflo/v3/@claude-flow/codex/tests/generators.test.ts
T
rUvandReuven 511b2ac070 feat(codex): finish Codex ↔ Ruflo integration — real codex exec, dual run --worker, tests, CI guard (#1909) (#1911)
* fix(codex): correct codex MCP server subcommand + sync package version

- mcp-bridge: `@openai/codex mcp serve` → `@openai/codex mcp-server`.
  `codex mcp` manages *external* MCP servers (list/get/add/remove);
  `codex mcp-server` is the "start Codex as an MCP server (stdio)"
  command. `codex mcp serve` errors with "unrecognized subcommand
  'serve'", so the `codex` MCP backend never started. Fixed in both
  ruflo/src/mcp-bridge/index.js and ruflo/src/ruvocal/mcp-bridge/index.js.
- @claude-flow/codex: VERSION const was '3.0.0-alpha.8' while
  package.json is '3.0.0-alpha.9' — `--version`/`info` reported the
  wrong version. Synced to alpha.9.

Verified: `codex mcp serve` → error; `codex mcp-server` is valid.
@claude-flow/codex builds clean (tsc), 162 unit tests pass,
`claude-flow-codex` CLI (init/validate/doctor/templates/skills/dual)
all functional.

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

* feat(codex): W1 — dual-mode orchestrator spawns real `codex exec` for codex workers

Previously `codexCommand` defaulted to `'claude'` ("Both use claude CLI")
and every worker — claude or codex — was launched with Claude-CLI flags
(`-p`, `--output-format text`, `--max-turns`), so "dual-mode" was two
Claude instances. Now:
- `codexCommand` defaults to `'codex'`
- `executeHeadless` builds platform-specific args:
  - claude:  `-p <prompt> --output-format text [--max-turns N] [--model M]`
  - codex:   `exec --sandbox workspace-write --skip-git-repo-check [-m M] <prompt>`
    (PROMPT is positional -> last; `codex exec` runs autonomously)

Remaining in W1 (next iterations): update `.claude/agents/dual-mode/
codex-worker.md` + `codex-coordinator.md` to invoke `codex exec` instead
of `claude -p`; add mocked-spawn smoke test (W4). Tracked: #1909.

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

* feat(codex): W1 (cont.) — dual-mode agent defs invoke `codex exec`, not `claude -p`

codex-worker.md / codex-coordinator.md described "headless Codex workers"
but every spawn example was `claude -p "..." --session-id X` with
Claude-only flags (--max-budget-usd, --allowedTools, --output-format).
Updated to match the W1 orchestrator change:
- spawn syntax → `codex exec --sandbox <workspace-write|read-only>
  --skip-git-repo-check "<prompt>" &`
- dropped Claude-only flags; note that mixed-platform runs still use
  `claude -p` for Claude workers
- swarm/memory CLI refs `claude-flow@v3alpha` → `ruflo@latest`
- MCP tool refs `mcp__claude-flow__*` / `mcp__ruv-swarm__*` → `mcp__ruflo__*`

W1 now complete (orchestrator + agent defs). dual-orchestrator.md left
as-is — it correctly documents the mixed Claude+Codex split. Smoke test
is W4. Tracked: #1909.

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

* feat(codex): W2 — `dual run --worker "<platform>:<role>:<prompt>"` + positional template

`dual run` only accepted `--template <name>` / `--config <path>`, so the
custom-worker syntax documented in CLAUDE.md (`dual run --worker
"claude:architect:..." --worker "codex:coder:..."`) didn't exist, and
`dual run feature` (positional) silently fell through to "specify
--template". Now:
- `dual run [template]` — positional alias for `--template`
- `-w, --worker "<platform>:<role>:<prompt>"` (repeatable; platform =
  claude|codex; prompt may contain `:` — split on first two only).
  Workers chain sequentially (each `dependsOn` the previous) unless
  `--parallel-workers`. Unique ids derived from role.
- `parseWorkerSpecs()` exported for testing; clear errors on malformed
  specs / bad platform.
- improved no-args usage text.

build clean (tsc), 162 tests pass. Tracked: #1909 (W2). Tests for
parseWorkerSpecs land in W4.

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

* feat(codex): W3 — standardize CLI ref claude-flow@alpha -> ruflo; fix MCP-server registration

The dual-mode orchestrator/CLI shelled out to `npx claude-flow@alpha
memory ...`, `claude-flow-codex init` registered the MCP server as
`codex mcp add claude-flow -- npx claude-flow mcp start`, and the
config.toml / migration generators emitted `[mcp_servers.claude-flow]`
with `args = ["-y", "@claude-flow/cli@latest"]` — the wrong package, an
inner-package name, and (in config-toml) **missing the `mcp start`
subcommand** so the server never actually started.

- dual-mode/{orchestrator,cli}.ts: `claude-flow@alpha` -> `ruflo@alpha`
- initializer.ts: `codex mcp add claude-flow -- npx claude-flow mcp start`
  -> `codex mcp add ruflo -- npx ruflo mcp start`; "MCP server (ruflo)
  registered"; `npx @claude-flow/cli mcp start` -> `npx ruflo mcp start`
- generators/config-toml.ts: default server `name: 'ruflo'`,
  `args: ['-y', 'ruflo@latest', 'mcp', 'start']` (adds the missing
  subcommand); `[mcp_servers.ruflo]` in all examples; the
  already-configured check accepts both `ruflo` and legacy `claude-flow`
- generators/{agents-md,skill-md}.ts: `npx @claude-flow/cli ...` -> `npx ruflo ...`
- migrations/index.ts: default emitted server -> `[mcp_servers.ruflo]` /
  `args = ["-y", "ruflo@latest", "mcp", "start"]` (user-provided servers
  pass through unchanged)
- validators/index.ts: suggestion text -> `[mcp_servers.ruflo]`
- tests: updated generator/migration assertions to the new output

`npx vitest run` 162/162 pass. Note: `npm run build` (tsc) currently
fails on an UNRELATED uncommitted WIP file `src/loop/index.ts`
(exactOptionalPropertyTypes on prompt/command) — not from this change;
my files compile clean. Branding-only refs (config-toml header, repo
URLs in generated docs, remaining `@claude-flow/cli` in skill-md examples)
deferred to W7. Tracked: #1909 (W3).

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

* test(codex): W4 — dual-mode tests (parseWorkerSpecs, templates, orchestrator leveling, `dual` wiring)

New tests/dual-mode.test.ts (18 tests, no real workers spawned):
- parseWorkerSpecs: single spec, sequential chaining, --parallel-workers,
  colons-in-prompt, id dedup, whitespace trim, and the 3 error paths
  (too-few-colons / empty-prompt / unknown-platform)
- CollaborationTemplates: feature/security/refactor pipelines — ids,
  platforms, dependsOn chains, task interpolation
- `dual` command wiring: run/templates/status subcommands; `run` exposes
  --worker / --parallel-workers / --template and a positional [template]
- DualModeOrchestrator: safe defaults (codexCommand === 'codex'),
  buildDependencyLevels for linear / fan-in / circular cases

Full suite: 184/184 pass (162 prior + 18 new + 4 loop). `npm run build`
still blocked on the unrelated uncommitted `src/loop/index.ts`. Deferred:
a full `CodexInitializer.initialize()` integration test (it shells out
`codex mcp add`, which would touch the user's real codex config — needs
a mock first). Tracked: #1909 (W4).

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

* feat(codex): W5 — generated SKILL.md frontmatter gets version/author/tags

`claude-flow-codex init` / `generate-skill` produced SKILL.md files with
only `name` + `description`, so `claude-flow-codex validate` flagged 3
"Consider adding field: version/author/tags" warnings per skill.

- SkillMdOptions: optional `version` ("1.0.0"), `author` ("rUv"), `tags`
  (defaults to the skill name split on `-`)
- generateSkillMd emits `version: "..."`, `author: ...`, `tags: [...]`
  in the frontmatter; built-in skills (via generateBuiltInSkill) inherit
  the defaults automatically

Verified: a generated built-in skill validates with 0 warnings (was 3);
a bare `generate-skill` stub now has 1 warning ("No examples provided",
expected for a skill with no commands — out of scope here). `init →
validate → doctor` clean on the local build. `npm run build` + 184/184
tests pass. (The ~150 repo `.agents/skills/*/SKILL.md` are generated by
@claude-flow/cli, not this generator — out of scope.) Tracked: #1909 (W5).

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

* ci(codex): W6 — codex-integration-audit guard + workflow

`scripts/audit-codex-integration.mjs` — pure-Node static checks for the
Codex ↔ Ruflo invariants (issue #1909), exits non-zero on any failure:
- `codex` MCP backend uses `mcp-server` (not the invalid `mcp serve`) in
  both ruflo/src/mcp-bridge and ruvocal/mcp-bridge
- @claude-flow/codex VERSION const === its package.json version
- dual-mode orchestrator: `codexCommand` defaults to 'codex', codex
  workers spawn `codex exec --sandbox …`, no 'claude' fallback
- dual-mode agent defs reference `codex exec`, no legacy
  `claude -p … --session-id` worker pattern
- no `claude-flow@alpha` / `@claude-flow/cli@latest` left in codex src
- `dual run` exposes `--worker <spec>` + positional `[template]`,
  `parseWorkerSpecs` exported
- generateSkillMd emits version/author/tags frontmatter
- config.toml generator default MCP server = `ruflo` w/ `mcp start`

`.github/workflows/codex-integration-audit.yml` runs it on PRs / pushes
touching the codex package, mcp-bridge, dual-mode agents, or the script.
No `npm install` needed — build + tests stay in the main CI.

Audit passes on current branch. `npm run build` + 184/184 tests pass.
Tracked: #1909 (W6).

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

* feat(codex): claude-flow-codex loop runner — Codex-native /loop equivalent

Codex doesn't expose Claude Code's ScheduleWakeup, so this is a
process-based runner with the same behaviour:
- `loop run [prompt]` — repeated `codex exec` runs (or a custom
  `--command`), bounded by `--max-iterations`/`--interval`, with
  `--dry-run`, model/sandbox options, and a completion-marker-file
  contract
- `loop status [--name <name>]` / `loop stop [--name <name>]`
- state persisted to `.codex/loop/<name>.json`; stop-file aware
- wired into the CLI (`src/cli.ts`), exported (`src/index.ts`), with a
  `./loop` package export and README docs

(Implemented by rUv; landing it here so it isn't sitting dirty in the
worktree while the #1909 loop commits around it. `npm run build` +
184/184 tests pass; `git diff --check` clean.)

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

* chore(codex): W7 — package.json hygiene + repo URLs ruvnet/claude-flow -> ruvnet/ruflo

- package.json: drop dead `"templates"` from `files` (no templates/ dir
  at the package root — templates compile to dist/templates/); repository
  / homepage / bugs URLs -> ruvnet/ruflo; description -> "Ruflo (claude-flow)"
- src/index.ts: PACKAGE_INFO.repository -> ruvnet/ruflo
- src/initializer.ts, generators/{agents-md,config-toml}.ts: generated
  AGENTS.md / config.toml doc URLs -> ruvnet/ruflo (+ "Ruflo:" label)
- README.md: badge + footer URLs -> ruvnet/ruflo
- tests: assertion for the config.toml Documentation line

`npm run build` + 184/184 tests pass; codex-integration audit passes.
(Committed `.agents/AGENTS.md` / `.agents/config.toml` in the repo still
carry old URLs — generated artifacts; the generators are now fixed so
re-init produces ruvnet/ruflo. The published `claude-flow-codex`
package name stays as-is.) Tracked: #1909 (W7).

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

---------

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-05-11 11:50:56 -04:00

929 lines
30 KiB
TypeScript

/**
* @claude-flow/codex - Generator Tests
*
* Tests for AGENTS.md, SKILL.md, and config.toml generators
*/
import { describe, it, expect, beforeEach } from 'vitest';
import {
generateAgentsMd,
generateSkillMd,
generateConfigToml,
} from '../src/generators/index.js';
import { generateBuiltInSkill } from '../src/generators/skill-md.js';
import {
generateMinimalConfigToml,
generateCIConfigToml,
} from '../src/generators/config-toml.js';
import type {
AgentsMdOptions,
SkillMdOptions,
ConfigTomlOptions,
} from '../src/types.js';
// =============================================================================
// AGENTS.md Generator Tests
// =============================================================================
describe('generateAgentsMd', () => {
describe('minimal template', () => {
it('should generate a minimal AGENTS.md with required sections', async () => {
const options: AgentsMdOptions = {
projectName: 'Test Project',
template: 'minimal',
};
const result = await generateAgentsMd(options);
expect(result).toContain('# Test Project');
expect(result).toContain('## Quick Start');
expect(result).toContain('## Agent Behavior');
expect(result).toContain('## Code Standards');
expect(result).toContain('## Skills');
expect(result).toContain('## Security Rules');
});
it('should include custom description', async () => {
const options: AgentsMdOptions = {
projectName: 'My App',
description: 'A custom application for testing',
template: 'minimal',
};
const result = await generateAgentsMd(options);
expect(result).toContain('A custom application for testing');
});
it('should include custom build and test commands', async () => {
const options: AgentsMdOptions = {
projectName: 'Custom Build Project',
buildCommand: 'yarn build',
testCommand: 'yarn test:unit',
template: 'minimal',
};
const result = await generateAgentsMd(options);
expect(result).toContain('yarn build');
expect(result).toContain('yarn test:unit');
});
it('should include default skills for minimal template', async () => {
const options: AgentsMdOptions = {
projectName: 'Minimal Skills',
template: 'minimal',
};
const result = await generateAgentsMd(options);
expect(result).toContain('$swarm-orchestration');
expect(result).toContain('$memory-management');
});
it('should include file organization section', async () => {
const options: AgentsMdOptions = {
projectName: 'Org Test',
template: 'minimal',
};
const result = await generateAgentsMd(options);
expect(result).toContain('/src');
expect(result).toContain('/tests');
expect(result).toContain('/docs');
});
});
describe('default template', () => {
it('should generate a default AGENTS.md with all sections', async () => {
const options: AgentsMdOptions = {
projectName: 'Default Project',
template: 'default',
};
const result = await generateAgentsMd(options);
expect(result).toContain('# Default Project');
expect(result).toContain('## Project Overview');
expect(result).toContain('## Quick Start');
expect(result).toContain('## Agent Coordination');
expect(result).toContain('## Code Standards');
expect(result).toContain('## Security');
expect(result).toContain('## Memory System');
});
it('should include tech stack', async () => {
const options: AgentsMdOptions = {
projectName: 'Tech Stack Test',
techStack: 'React, Node.js, PostgreSQL',
template: 'default',
};
const result = await generateAgentsMd(options);
expect(result).toContain('React, Node.js, PostgreSQL');
});
it('should include swarm configuration', async () => {
const options: AgentsMdOptions = {
projectName: 'Swarm Config',
template: 'default',
};
const result = await generateAgentsMd(options);
expect(result).toContain('Topology');
expect(result).toContain('hierarchical');
expect(result).toContain('Max Agents');
expect(result).toContain('raft');
});
it('should include agent types table', async () => {
const options: AgentsMdOptions = {
projectName: 'Agents Test',
template: 'default',
};
const result = await generateAgentsMd(options);
expect(result).toContain('researcher');
expect(result).toContain('architect');
expect(result).toContain('coder');
expect(result).toContain('tester');
expect(result).toContain('reviewer');
});
it('should include custom skills', async () => {
const options: AgentsMdOptions = {
projectName: 'Custom Skills',
skills: ['custom-skill', 'another-skill'],
template: 'default',
};
const result = await generateAgentsMd(options);
expect(result).toContain('$custom-skill');
expect(result).toContain('$another-skill');
expect(result).toContain('Custom skill');
});
it('should include built-in skill descriptions', async () => {
const options: AgentsMdOptions = {
projectName: 'Skill Descriptions',
skills: ['swarm-orchestration', 'memory-management'],
template: 'default',
};
const result = await generateAgentsMd(options);
expect(result).toContain('Multi-agent task coordination');
expect(result).toContain('Pattern storage and retrieval');
});
it('should include commit message format', async () => {
const options: AgentsMdOptions = {
projectName: 'Commit Test',
template: 'default',
};
const result = await generateAgentsMd(options);
expect(result).toContain('Co-Authored-By: claude-flow');
expect(result).toContain('feat');
expect(result).toContain('fix');
});
});
describe('full template', () => {
it('should include performance targets', async () => {
const options: AgentsMdOptions = {
projectName: 'Full Project',
template: 'full',
};
const result = await generateAgentsMd(options);
expect(result).toContain('## Performance Targets');
expect(result).toContain('HNSW Search');
expect(result).toContain('150x-12,500x faster');
});
it('should include testing section', async () => {
const options: AgentsMdOptions = {
projectName: 'Testing Project',
template: 'full',
};
const result = await generateAgentsMd(options);
expect(result).toContain('## Testing');
expect(result).toContain('test:integration');
expect(result).toContain('test:coverage');
expect(result).toContain('TDD London School');
});
it('should include MCP integration', async () => {
const options: AgentsMdOptions = {
projectName: 'MCP Project',
template: 'full',
};
const result = await generateAgentsMd(options);
expect(result).toContain('## MCP Integration');
expect(result).toContain('swarm_init');
expect(result).toContain('agent_spawn');
expect(result).toContain('memory_store');
});
it('should include hooks system', async () => {
const options: AgentsMdOptions = {
projectName: 'Hooks Project',
template: 'full',
};
const result = await generateAgentsMd(options);
expect(result).toContain('## Hooks System');
expect(result).toContain('pre-task');
expect(result).toContain('post-task');
expect(result).toContain('pre-edit');
expect(result).toContain('post-edit');
});
});
describe('enterprise template', () => {
it('should include governance section', async () => {
const options: AgentsMdOptions = {
projectName: 'Enterprise Project',
template: 'enterprise',
};
const result = await generateAgentsMd(options);
expect(result).toContain('## Governance');
expect(result).toContain('Approval Workflow');
expect(result).toContain('Audit Trail');
expect(result).toContain('Compliance');
});
it('should include compliance standards', async () => {
const options: AgentsMdOptions = {
projectName: 'Compliance Project',
template: 'enterprise',
};
const result = await generateAgentsMd(options);
expect(result).toContain('SOC2');
expect(result).toContain('GDPR');
expect(result).toContain('PCI-DSS');
});
it('should include incident response', async () => {
const options: AgentsMdOptions = {
projectName: 'Incident Response',
template: 'enterprise',
};
const result = await generateAgentsMd(options);
expect(result).toContain('## Incident Response');
expect(result).toContain('Security Issue');
expect(result).toContain('Production Bug');
});
});
describe('template fallback', () => {
it('should use default template when no template specified', async () => {
const options: AgentsMdOptions = {
projectName: 'No Template',
};
const result = await generateAgentsMd(options);
expect(result).toContain('## Agent Coordination');
expect(result).toContain('## Memory System');
});
it('should use default template for invalid template value', async () => {
const options: AgentsMdOptions = {
projectName: 'Invalid Template',
template: 'invalid-template' as any,
};
const result = await generateAgentsMd(options);
expect(result).toContain('## Agent Coordination');
});
});
});
// =============================================================================
// SKILL.md Generator Tests
// =============================================================================
describe('generateSkillMd', () => {
describe('basic skill generation', () => {
it('should generate valid YAML frontmatter', async () => {
const options: SkillMdOptions = {
name: 'test-skill',
description: 'A test skill for testing',
};
const result = await generateSkillMd(options);
expect(result).toMatch(/^---\n/);
expect(result).toContain('name: test-skill');
expect(result).toContain('description: >');
expect(result).toContain('A test skill for testing');
expect(result).toMatch(/---\n\n# Test Skill Skill/);
});
it('should include Purpose section', async () => {
const options: SkillMdOptions = {
name: 'purpose-skill',
description: 'Skill with a clear purpose',
};
const result = await generateSkillMd(options);
expect(result).toContain('## Purpose');
expect(result).toContain('Skill with a clear purpose');
});
it('should include When to Trigger section', async () => {
const options: SkillMdOptions = {
name: 'trigger-skill',
description: 'Skill with triggers',
triggers: ['condition one', 'condition two', 'condition three'],
};
const result = await generateSkillMd(options);
expect(result).toContain('## When to Trigger');
expect(result).toContain('- condition one');
expect(result).toContain('- condition two');
expect(result).toContain('- condition three');
});
it('should include When to Skip section', async () => {
const options: SkillMdOptions = {
name: 'skip-skill',
description: 'Skill with skip conditions',
skipWhen: ['skip condition A', 'skip condition B'],
};
const result = await generateSkillMd(options);
expect(result).toContain('## When to Skip');
expect(result).toContain('- skip condition A');
expect(result).toContain('- skip condition B');
});
it('should include Best Practices section', async () => {
const options: SkillMdOptions = {
name: 'best-practices',
description: 'Skill with best practices',
};
const result = await generateSkillMd(options);
expect(result).toContain('## Best Practices');
expect(result).toContain('Check memory for existing patterns');
expect(result).toContain('hierarchical topology');
});
});
describe('skill with commands', () => {
it('should generate Commands section', async () => {
const options: SkillMdOptions = {
name: 'command-skill',
description: 'Skill with commands',
commands: [
{
name: 'Initialize',
description: 'Initialize the skill',
command: 'npx skill init',
},
],
};
const result = await generateSkillMd(options);
expect(result).toContain('## Commands');
expect(result).toContain('### Initialize');
expect(result).toContain('Initialize the skill');
expect(result).toContain('```bash\nnpx skill init\n```');
});
it('should include command examples', async () => {
const options: SkillMdOptions = {
name: 'example-skill',
description: 'Skill with command examples',
commands: [
{
name: 'Run Task',
description: 'Run a specific task',
command: 'npx skill run --task [name]',
example: 'npx skill run --task build',
},
],
};
const result = await generateSkillMd(options);
expect(result).toContain('**Example:**');
expect(result).toContain('npx skill run --task build');
});
it('should handle multiple commands', async () => {
const options: SkillMdOptions = {
name: 'multi-command',
description: 'Skill with multiple commands',
commands: [
{ name: 'Cmd1', description: 'First command', command: 'cmd1' },
{ name: 'Cmd2', description: 'Second command', command: 'cmd2' },
{ name: 'Cmd3', description: 'Third command', command: 'cmd3' },
],
};
const result = await generateSkillMd(options);
expect(result).toContain('### Cmd1');
expect(result).toContain('### Cmd2');
expect(result).toContain('### Cmd3');
});
});
describe('skill with scripts', () => {
it('should generate Scripts section as table', async () => {
const options: SkillMdOptions = {
name: 'script-skill',
description: 'Skill with scripts',
scripts: [
{ name: 'setup', path: './scripts/setup.sh', description: 'Setup script' },
{ name: 'cleanup', path: './scripts/cleanup.sh', description: 'Cleanup script' },
],
};
const result = await generateSkillMd(options);
expect(result).toContain('## Scripts');
expect(result).toContain('| Script | Path | Description |');
expect(result).toContain('| `setup` | `./scripts/setup.sh` | Setup script |');
expect(result).toContain('| `cleanup` | `./scripts/cleanup.sh` | Cleanup script |');
});
});
describe('skill with references', () => {
it('should generate References section as table', async () => {
const options: SkillMdOptions = {
name: 'ref-skill',
description: 'Skill with references',
references: [
{ name: 'README', path: './README.md', description: 'Main documentation' },
{ name: 'API', path: './docs/api.md' },
],
};
const result = await generateSkillMd(options);
expect(result).toContain('## References');
expect(result).toContain('| Document | Path | Description |');
expect(result).toContain('| `README` | `./README.md` | Main documentation |');
expect(result).toContain('| `API` | `./docs/api.md` | |');
});
});
describe('skill name formatting', () => {
it('should format kebab-case names to Title Case', async () => {
const options: SkillMdOptions = {
name: 'my-complex-skill-name',
description: 'Testing name formatting',
};
const result = await generateSkillMd(options);
expect(result).toContain('# My Complex Skill Name Skill');
});
it('should handle single-word names', async () => {
const options: SkillMdOptions = {
name: 'simple',
description: 'Simple skill',
};
const result = await generateSkillMd(options);
expect(result).toContain('# Simple Skill');
});
});
});
describe('generateBuiltInSkill', () => {
it('should generate swarm-orchestration skill', async () => {
const result = await generateBuiltInSkill('swarm-orchestration');
expect(result.skillMd).toContain('name: swarm-orchestration');
expect(result.skillMd).toContain('Multi-agent swarm coordination');
expect(result.skillMd).toContain('Initialize Swarm');
expect(result.skillMd).toContain('npx ruflo swarm init');
});
it('should generate memory-management skill', async () => {
const result = await generateBuiltInSkill('memory-management');
expect(result.skillMd).toContain('name: memory-management');
expect(result.skillMd).toContain('AgentDB memory system');
expect(result.skillMd).toContain('Store Pattern');
expect(result.skillMd).toContain('Semantic Search');
});
it('should generate sparc-methodology skill', async () => {
const result = await generateBuiltInSkill('sparc-methodology');
expect(result.skillMd).toContain('name: sparc-methodology');
expect(result.skillMd).toContain('SPARC development workflow');
expect(result.skillMd).toContain('Specification Phase');
expect(result.skillMd).toContain('Architecture Phase');
});
it('should generate security-audit skill', async () => {
const result = await generateBuiltInSkill('security-audit');
expect(result.skillMd).toContain('name: security-audit');
expect(result.skillMd).toContain('security scanning');
expect(result.skillMd).toContain('Full Security Scan');
expect(result.skillMd).toContain('--depth full');
});
it('should generate performance-analysis skill', async () => {
const result = await generateBuiltInSkill('performance-analysis');
expect(result.skillMd).toContain('name: performance-analysis');
expect(result.skillMd).toContain('Performance profiling');
expect(result.skillMd).toContain('Run Benchmark');
expect(result.skillMd).toContain('Profile Code');
});
it('should generate github-automation skill', async () => {
const result = await generateBuiltInSkill('github-automation');
expect(result.skillMd).toContain('name: github-automation');
expect(result.skillMd).toContain('GitHub workflow automation');
expect(result.skillMd).toContain('Create Pull Request');
expect(result.skillMd).toContain('gh pr create');
});
it('should throw for unknown skill', async () => {
await expect(generateBuiltInSkill('unknown-skill')).rejects.toThrow(
'Unknown built-in skill: unknown-skill'
);
});
it('should return generated scripts for skills with scripts', async () => {
const result = await generateBuiltInSkill('swarm-orchestration');
// Scripts are now generated for skills that have them
expect(Object.keys(result.scripts).length).toBeGreaterThan(0);
expect(result.references).toEqual({});
});
it('should generate valid bash scripts', async () => {
const result = await generateBuiltInSkill('memory-management');
// Check that scripts are generated and contain bash shebang
for (const script of Object.values(result.scripts)) {
expect(script).toContain('#!/bin/bash');
expect(script).toContain('set -e');
}
});
});
// =============================================================================
// config.toml Generator Tests
// =============================================================================
describe('generateConfigToml', () => {
describe('default configuration', () => {
it('should generate valid TOML with header', async () => {
const result = await generateConfigToml();
expect(result).toContain('# Claude Flow V3 - Codex Configuration');
expect(result).toContain('# Generated by: @claude-flow/codex');
expect(result).toContain('# Documentation: https://github.com/ruvnet/ruflo');
});
it('should include core settings section', async () => {
const result = await generateConfigToml();
expect(result).toContain('# Core Settings');
expect(result).toContain('model = "gpt-5.3-codex"');
expect(result).toContain('approval_policy = "on-request"');
expect(result).toContain('sandbox_mode = "workspace-write"');
expect(result).toContain('web_search = "cached"');
});
it('should include project documentation settings', async () => {
const result = await generateConfigToml();
expect(result).toContain('# Project Documentation');
expect(result).toContain('project_doc_max_bytes = 65536');
expect(result).toContain('project_doc_fallback_filenames');
expect(result).toContain('"AGENTS.md"');
});
it('should include features section', async () => {
const result = await generateConfigToml();
expect(result).toContain('[features]');
expect(result).toContain('child_agents_md = true');
expect(result).toContain('shell_snapshot = true');
expect(result).toContain('request_rule = true');
expect(result).toContain('remote_compaction = true');
});
it('should include default ruflo MCP server', async () => {
const result = await generateConfigToml();
expect(result).toContain('[mcp_servers.ruflo]');
expect(result).toContain('command = "npx"');
expect(result).toContain('args = ["-y", "ruflo@latest", "mcp", "start"]');
expect(result).toContain('enabled = true');
});
it('should include default profiles', async () => {
const result = await generateConfigToml();
expect(result).toContain('[profiles.dev]');
expect(result).toContain('approval_policy = "never"');
expect(result).toContain('sandbox_mode = "danger-full-access"');
expect(result).toContain('[profiles.safe]');
expect(result).toContain('sandbox_mode = "read-only"');
expect(result).toContain('[profiles.ci]');
expect(result).toContain('sandbox_mode = "workspace-write"');
});
it('should include history section', async () => {
const result = await generateConfigToml();
expect(result).toContain('[history]');
expect(result).toContain('persistence = "save-all"');
});
it('should include shell environment policy', async () => {
const result = await generateConfigToml();
expect(result).toContain('[shell_environment_policy]');
expect(result).toContain('inherit = "core"');
expect(result).toContain('exclude = ["*_KEY", "*_SECRET", "*_TOKEN", "*_PASSWORD"]');
});
it('should include sandbox workspace settings', async () => {
const result = await generateConfigToml();
expect(result).toContain('[sandbox_workspace_write]');
expect(result).toContain('writable_roots = []');
expect(result).toContain('network_access = true');
expect(result).toContain('exclude_slash_tmp = false');
});
});
describe('custom model and policies', () => {
it('should accept custom model', async () => {
const options: ConfigTomlOptions = {
model: 'gpt-4o-mini',
};
const result = await generateConfigToml(options);
expect(result).toContain('model = "gpt-4o-mini"');
});
it('should accept custom approval policy', async () => {
const options: ConfigTomlOptions = {
approvalPolicy: 'never',
};
const result = await generateConfigToml(options);
expect(result).toContain('approval_policy = "never"');
});
it('should accept custom sandbox mode', async () => {
const options: ConfigTomlOptions = {
sandboxMode: 'read-only',
};
const result = await generateConfigToml(options);
expect(result).toContain('sandbox_mode = "read-only"');
});
it('should accept custom web search mode', async () => {
const options: ConfigTomlOptions = {
webSearch: 'live',
};
const result = await generateConfigToml(options);
expect(result).toContain('web_search = "live"');
});
});
describe('custom features', () => {
it('should allow disabling features', async () => {
const options: ConfigTomlOptions = {
features: {
childAgentsMd: false,
shellSnapshot: false,
requestRule: false,
remoteCompaction: false,
},
};
const result = await generateConfigToml(options);
expect(result).toContain('child_agents_md = false');
expect(result).toContain('shell_snapshot = false');
expect(result).toContain('request_rule = false');
expect(result).toContain('remote_compaction = false');
});
});
describe('MCP servers configuration', () => {
it('should add custom MCP servers', async () => {
const options: ConfigTomlOptions = {
mcpServers: [
{
name: 'custom-server',
command: 'node',
args: ['./server.js'],
enabled: true,
toolTimeout: 60,
},
],
};
const result = await generateConfigToml(options);
expect(result).toContain('[mcp_servers.custom-server]');
expect(result).toContain('command = "node"');
expect(result).toContain('args = ["./server.js"]');
expect(result).toContain('tool_timeout_sec = 60');
});
it('should add MCP server with environment variables', async () => {
const options: ConfigTomlOptions = {
mcpServers: [
{
name: 'env-server',
command: 'node',
args: ['./server.js'],
env: {
NODE_ENV: 'production',
API_KEY: '${API_KEY}',
},
},
],
};
const result = await generateConfigToml(options);
expect(result).toContain('[mcp_servers.env-server.env]');
expect(result).toContain('NODE_ENV = "production"');
expect(result).toContain('API_KEY = "${API_KEY}"');
});
it('should not duplicate claude-flow server if already specified', async () => {
const options: ConfigTomlOptions = {
mcpServers: [
{
name: 'claude-flow',
command: 'custom-claude-flow',
args: ['--custom'],
},
],
};
const result = await generateConfigToml(options);
const matches = result.match(/\[mcp_servers\.claude-flow\]/g);
expect(matches).toHaveLength(1);
expect(result).toContain('command = "custom-claude-flow"');
});
});
describe('skills configuration', () => {
it('should add skill configurations', async () => {
const options: ConfigTomlOptions = {
skills: [
{ path: './.agents/skills/custom-skill/', enabled: true },
{ path: './.agents/skills/another-skill/', enabled: false },
],
};
const result = await generateConfigToml(options);
expect(result).toContain('# Skills Configuration');
expect(result).toContain('[[skills.config]]');
expect(result).toContain('path = "./.agents/skills/custom-skill/"');
expect(result).toContain('enabled = true');
expect(result).toContain('path = "./.agents/skills/another-skill/"');
expect(result).toContain('enabled = false');
});
});
describe('custom profiles', () => {
it('should merge custom profiles with defaults', async () => {
const options: ConfigTomlOptions = {
profiles: {
staging: {
approvalPolicy: 'on-failure',
sandboxMode: 'workspace-write',
webSearch: 'cached',
},
},
};
const result = await generateConfigToml(options);
expect(result).toContain('[profiles.dev]');
expect(result).toContain('[profiles.safe]');
expect(result).toContain('[profiles.ci]');
expect(result).toContain('[profiles.staging]');
expect(result).toContain('approval_policy = "on-failure"');
});
});
describe('history persistence', () => {
it('should allow custom history persistence', async () => {
const options: ConfigTomlOptions = {
historyPersistence: 'none',
};
const result = await generateConfigToml(options);
expect(result).toContain('persistence = "none"');
});
});
});
describe('generateMinimalConfigToml', () => {
it('should generate minimal config', async () => {
const result = await generateMinimalConfigToml();
expect(result).toContain('# Claude Flow V3 - Minimal Codex Configuration');
expect(result).toContain('model = "gpt-5.3-codex"');
expect(result).toContain('approval_policy = "on-request"');
expect(result).toContain('sandbox_mode = "workspace-write"');
expect(result).toContain('[mcp_servers.ruflo]');
});
it('should accept custom options', async () => {
const result = await generateMinimalConfigToml({
model: 'custom-model',
approvalPolicy: 'never',
sandboxMode: 'danger-full-access',
});
expect(result).toContain('model = "custom-model"');
expect(result).toContain('approval_policy = "never"');
expect(result).toContain('sandbox_mode = "danger-full-access"');
});
it('should be much shorter than full config', async () => {
const minimal = await generateMinimalConfigToml();
const full = await generateConfigToml();
expect(minimal.length).toBeLessThan(full.length / 3);
});
});
describe('generateCIConfigToml', () => {
it('should generate CI-specific config', async () => {
const result = await generateCIConfigToml();
expect(result).toContain('# Claude Flow V3 - CI/CD Pipeline Configuration');
expect(result).toContain('approval_policy = "never"');
expect(result).toContain('web_search = "disabled"');
});
it('should disable shell snapshot for CI', async () => {
const result = await generateCIConfigToml();
expect(result).toContain('shell_snapshot = false');
expect(result).toContain('remote_compaction = false');
});
it('should disable history persistence', async () => {
const result = await generateCIConfigToml();
expect(result).toContain('persistence = "none"');
});
});