mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 22:28:10 +09:00
* 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>
737 lines
22 KiB
TypeScript
737 lines
22 KiB
TypeScript
/**
|
|
* @claude-flow/codex - Migration Tests
|
|
*
|
|
* Tests for Claude Code to Codex migration functions
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import {
|
|
analyzeClaudeMd,
|
|
migrateFromClaudeCode,
|
|
convertSkillSyntax,
|
|
convertSettingsToToml,
|
|
generateMigrationReport,
|
|
FEATURE_MAPPINGS,
|
|
} from '../src/migrations/index.js';
|
|
import type { MigrationResult } from '../src/types.js';
|
|
|
|
// =============================================================================
|
|
// Sample CLAUDE.md Content for Testing
|
|
// =============================================================================
|
|
|
|
const SAMPLE_CLAUDE_MD = `# Claude Flow V3 Project
|
|
|
|
## Behavioral Rules (Always Enforced)
|
|
|
|
- Do what has been asked; nothing more, nothing less
|
|
- NEVER create files unless they're absolutely necessary
|
|
- ALWAYS prefer editing an existing file to creating a new one
|
|
- NEVER proactively create documentation files
|
|
|
|
## File Organization
|
|
|
|
- Use \`/src\` for source code files
|
|
- Use \`/tests\` for test files
|
|
- Use \`/docs\` for documentation
|
|
|
|
## Swarm Orchestration
|
|
|
|
Use /swarm-init to initialize the swarm.
|
|
Run /security-scan for security checks.
|
|
|
|
The /memory-store command stores patterns.
|
|
|
|
## Hooks
|
|
|
|
Use pre-task hooks before starting work.
|
|
Use post-task hooks after completion.
|
|
The session-start hook initializes context.
|
|
|
|
## Advanced
|
|
|
|
Run \`claude -p "analyze code"\` for headless analysis.
|
|
Use TodoWrite for task tracking.
|
|
EnterPlanMode for planning complex tasks.
|
|
`;
|
|
|
|
const SAMPLE_CLAUDE_MD_WITH_SKILLS = `# Skill Project
|
|
|
|
## Skills
|
|
|
|
- /code-review - Review code changes
|
|
- /test-generation - Generate tests
|
|
- /performance-analysis - Analyze performance
|
|
- /security-audit - Security checks
|
|
|
|
## Commands
|
|
|
|
Run /deploy for deployment.
|
|
Use /rollback if needed.
|
|
`;
|
|
|
|
// =============================================================================
|
|
// analyzeClaudeMd Tests
|
|
// =============================================================================
|
|
|
|
describe('analyzeClaudeMd', () => {
|
|
describe('section extraction', () => {
|
|
it('should extract all level-2 sections', async () => {
|
|
const result = await analyzeClaudeMd(SAMPLE_CLAUDE_MD);
|
|
|
|
expect(result.sections).toContain('Behavioral Rules (Always Enforced)');
|
|
expect(result.sections).toContain('File Organization');
|
|
expect(result.sections).toContain('Swarm Orchestration');
|
|
expect(result.sections).toContain('Hooks');
|
|
expect(result.sections).toContain('Advanced');
|
|
});
|
|
|
|
it('should handle CLAUDE.md with no level-2 sections', async () => {
|
|
const content = `# Simple Project
|
|
|
|
Just a description with no level-2 sections.
|
|
`;
|
|
|
|
const result = await analyzeClaudeMd(content);
|
|
|
|
// The sections array should be empty or not contain level-2 section titles
|
|
// Since there are no ## headings, we should have no sections or only the H1
|
|
expect(result.sections.length).toBeLessThanOrEqual(1);
|
|
});
|
|
});
|
|
|
|
describe('skill extraction', () => {
|
|
it('should extract skill references', async () => {
|
|
const result = await analyzeClaudeMd(SAMPLE_CLAUDE_MD);
|
|
|
|
expect(result.skills).toContain('swarm-init');
|
|
expect(result.skills).toContain('security-scan');
|
|
expect(result.skills).toContain('memory-store');
|
|
});
|
|
|
|
it('should extract multiple skills without duplicates', async () => {
|
|
const content = `# Project
|
|
|
|
Use /skill-a and /skill-b.
|
|
Also run /skill-a again.
|
|
Then /skill-c.
|
|
`;
|
|
|
|
const result = await analyzeClaudeMd(content);
|
|
|
|
expect(result.skills).toContain('skill-a');
|
|
expect(result.skills).toContain('skill-b');
|
|
expect(result.skills).toContain('skill-c');
|
|
expect(result.skills.filter(s => s === 'skill-a')).toHaveLength(1);
|
|
});
|
|
|
|
it('should extract skills from skill-heavy document', async () => {
|
|
const result = await analyzeClaudeMd(SAMPLE_CLAUDE_MD_WITH_SKILLS);
|
|
|
|
expect(result.skills).toContain('code-review');
|
|
expect(result.skills).toContain('test-generation');
|
|
expect(result.skills).toContain('performance-analysis');
|
|
expect(result.skills).toContain('security-audit');
|
|
expect(result.skills).toContain('deploy');
|
|
expect(result.skills).toContain('rollback');
|
|
});
|
|
});
|
|
|
|
describe('hook extraction', () => {
|
|
it('should detect referenced hooks', async () => {
|
|
const result = await analyzeClaudeMd(SAMPLE_CLAUDE_MD);
|
|
|
|
expect(result.hooks).toContain('pre-task');
|
|
expect(result.hooks).toContain('post-task');
|
|
expect(result.hooks).toContain('session-start');
|
|
});
|
|
|
|
it('should handle document with no hooks', async () => {
|
|
const content = `# No Hooks Project
|
|
|
|
Just a simple project with no hook references.
|
|
`;
|
|
|
|
const result = await analyzeClaudeMd(content);
|
|
|
|
expect(result.hooks).toHaveLength(0);
|
|
});
|
|
|
|
it('should detect all hook types', async () => {
|
|
const content = `# All Hooks
|
|
|
|
Use pre-task before work.
|
|
Use post-task after work.
|
|
Use pre-edit before editing.
|
|
Use post-edit after editing.
|
|
Use session-start at startup.
|
|
Use session-end at shutdown.
|
|
`;
|
|
|
|
const result = await analyzeClaudeMd(content);
|
|
|
|
expect(result.hooks).toContain('pre-task');
|
|
expect(result.hooks).toContain('post-task');
|
|
expect(result.hooks).toContain('pre-edit');
|
|
expect(result.hooks).toContain('post-edit');
|
|
expect(result.hooks).toContain('session-start');
|
|
expect(result.hooks).toContain('session-end');
|
|
});
|
|
});
|
|
|
|
describe('custom instructions extraction', () => {
|
|
it('should extract behavioral rules', async () => {
|
|
const result = await analyzeClaudeMd(SAMPLE_CLAUDE_MD);
|
|
|
|
expect(result.customInstructions).toContain(
|
|
'Do what has been asked; nothing more, nothing less'
|
|
);
|
|
expect(result.customInstructions).toContain(
|
|
'NEVER create files unless they\'re absolutely necessary'
|
|
);
|
|
});
|
|
|
|
it('should handle document without Behavioral Rules section', async () => {
|
|
const content = `# Simple Project
|
|
|
|
## Quick Start
|
|
|
|
npm install
|
|
`;
|
|
|
|
const result = await analyzeClaudeMd(content);
|
|
|
|
expect(result.customInstructions).toHaveLength(0);
|
|
});
|
|
});
|
|
|
|
describe('warnings generation', () => {
|
|
it('should warn about EnterPlanMode usage', async () => {
|
|
const result = await analyzeClaudeMd(SAMPLE_CLAUDE_MD);
|
|
|
|
expect(result.warnings.some(w => w.includes('EnterPlanMode'))).toBe(true);
|
|
});
|
|
|
|
it('should warn about claude -p usage', async () => {
|
|
const result = await analyzeClaudeMd(SAMPLE_CLAUDE_MD);
|
|
|
|
expect(result.warnings.some(w => w.includes('claude -p'))).toBe(true);
|
|
});
|
|
|
|
it('should warn about TodoWrite usage', async () => {
|
|
const result = await analyzeClaudeMd(SAMPLE_CLAUDE_MD);
|
|
|
|
expect(result.warnings.some(w => w.includes('TodoWrite'))).toBe(true);
|
|
});
|
|
|
|
it('should not generate warnings for clean CLAUDE.md', async () => {
|
|
const content = `# Clean Project
|
|
|
|
## Setup
|
|
|
|
npm install
|
|
|
|
## Code Standards
|
|
|
|
- Keep files small
|
|
- Use typed interfaces
|
|
`;
|
|
|
|
const result = await analyzeClaudeMd(content);
|
|
|
|
expect(result.warnings).toHaveLength(0);
|
|
});
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// migrateFromClaudeCode Tests
|
|
// =============================================================================
|
|
|
|
describe('migrateFromClaudeCode', () => {
|
|
describe('successful migration', () => {
|
|
it('should return success result', async () => {
|
|
const result = await migrateFromClaudeCode({
|
|
sourcePath: '/project/CLAUDE.md',
|
|
targetPath: '/project',
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
it('should generate AGENTS.md path', async () => {
|
|
const result = await migrateFromClaudeCode({
|
|
sourcePath: '/project/CLAUDE.md',
|
|
targetPath: '/project',
|
|
});
|
|
|
|
expect(result.agentsMdPath).toBe('/project/AGENTS.md');
|
|
});
|
|
|
|
it('should generate config.toml path', async () => {
|
|
const result = await migrateFromClaudeCode({
|
|
sourcePath: '/project/CLAUDE.md',
|
|
targetPath: '/project',
|
|
});
|
|
|
|
expect(result.configTomlPath).toBe('/project/.agents/config.toml');
|
|
});
|
|
|
|
it('should create default skills when generateSkills is true', async () => {
|
|
const result = await migrateFromClaudeCode({
|
|
sourcePath: '/project/CLAUDE.md',
|
|
targetPath: '/project',
|
|
generateSkills: true,
|
|
});
|
|
|
|
expect(result.skillsCreated).toContain('swarm-orchestration');
|
|
expect(result.skillsCreated).toContain('memory-management');
|
|
expect(result.skillsCreated).toContain('security-audit');
|
|
});
|
|
|
|
it('should not create skills when generateSkills is false', async () => {
|
|
const result = await migrateFromClaudeCode({
|
|
sourcePath: '/project/CLAUDE.md',
|
|
targetPath: '/project',
|
|
generateSkills: false,
|
|
});
|
|
|
|
expect(result.skillsCreated).toHaveLength(0);
|
|
});
|
|
|
|
it('should include feature mappings', async () => {
|
|
const result = await migrateFromClaudeCode({
|
|
sourcePath: '/project/CLAUDE.md',
|
|
targetPath: '/project',
|
|
});
|
|
|
|
expect(result.mappings).toBeDefined();
|
|
expect(result.mappings!.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should include migration warnings', async () => {
|
|
const result = await migrateFromClaudeCode({
|
|
sourcePath: '/project/CLAUDE.md',
|
|
targetPath: '/project',
|
|
});
|
|
|
|
expect(result.warnings).toBeDefined();
|
|
expect(result.warnings!.some(w => w.includes('skill invocation syntax'))).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('migration options', () => {
|
|
it('should respect preserveComments option', async () => {
|
|
const result = await migrateFromClaudeCode({
|
|
sourcePath: '/project/CLAUDE.md',
|
|
targetPath: '/project',
|
|
preserveComments: true,
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
it('should use custom target path', async () => {
|
|
const result = await migrateFromClaudeCode({
|
|
sourcePath: '/old/CLAUDE.md',
|
|
targetPath: '/new/project',
|
|
});
|
|
|
|
expect(result.agentsMdPath).toBe('/new/project/AGENTS.md');
|
|
expect(result.configTomlPath).toBe('/new/project/.agents/config.toml');
|
|
});
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// convertSkillSyntax Tests
|
|
// =============================================================================
|
|
|
|
describe('convertSkillSyntax', () => {
|
|
it('should convert /skill-name to $skill-name', () => {
|
|
const content = 'Use /swarm-init to start.';
|
|
const result = convertSkillSyntax(content);
|
|
|
|
expect(result).toBe('Use $swarm-init to start.');
|
|
});
|
|
|
|
it('should convert multiple skill references', () => {
|
|
const content = 'Run /skill-a then /skill-b and finally /skill-c.';
|
|
const result = convertSkillSyntax(content);
|
|
|
|
expect(result).toBe('Run $skill-a then $skill-b and finally $skill-c.');
|
|
});
|
|
|
|
it('should preserve URLs (improved regex)', () => {
|
|
const content = 'Visit https://example.com/path for more info.';
|
|
const result = convertSkillSyntax(content);
|
|
|
|
// The improved regex should not convert paths within URLs
|
|
// as it excludes patterns preceded by alphanumeric/underscore/dot/slash chars
|
|
expect(result).toBe(content);
|
|
});
|
|
|
|
it('should handle complex skill names', () => {
|
|
const content = '/multi-word-skill-name and /a1b2c3';
|
|
const result = convertSkillSyntax(content);
|
|
|
|
expect(result).toBe('$multi-word-skill-name and $a1b2c3');
|
|
});
|
|
|
|
it('should preserve surrounding text', () => {
|
|
const content = 'Before /skill after';
|
|
const result = convertSkillSyntax(content);
|
|
|
|
expect(result).toBe('Before $skill after');
|
|
});
|
|
|
|
it('should handle content with no skills', () => {
|
|
const content = 'No skills here, just regular text.';
|
|
const result = convertSkillSyntax(content);
|
|
|
|
expect(result).toBe('No skills here, just regular text.');
|
|
});
|
|
|
|
it('should convert skills at line start', () => {
|
|
const content = '/skill-at-start\nMore text';
|
|
const result = convertSkillSyntax(content);
|
|
|
|
expect(result).toBe('$skill-at-start\nMore text');
|
|
});
|
|
|
|
it('should convert skills at line end', () => {
|
|
const content = 'Run the command /skill-at-end';
|
|
const result = convertSkillSyntax(content);
|
|
|
|
expect(result).toBe('Run the command $skill-at-end');
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// convertSettingsToToml Tests
|
|
// =============================================================================
|
|
|
|
describe('convertSettingsToToml', () => {
|
|
it('should include migration header', () => {
|
|
const result = convertSettingsToToml({});
|
|
|
|
expect(result).toContain('# Migrated from settings.json');
|
|
});
|
|
|
|
it('should convert model setting', () => {
|
|
const settings = {
|
|
model: 'claude-3-opus',
|
|
};
|
|
|
|
const result = convertSettingsToToml(settings);
|
|
|
|
expect(result).toContain('model = "claude-3-opus"');
|
|
});
|
|
|
|
it('should convert autoApprove true to never policy', () => {
|
|
const settings = {
|
|
permissions: {
|
|
autoApprove: true,
|
|
},
|
|
};
|
|
|
|
const result = convertSettingsToToml(settings);
|
|
|
|
expect(result).toContain('approval_policy = "never"');
|
|
});
|
|
|
|
it('should convert autoApprove read-only', () => {
|
|
const settings = {
|
|
permissions: {
|
|
autoApprove: 'read-only',
|
|
},
|
|
};
|
|
|
|
const result = convertSettingsToToml(settings);
|
|
|
|
expect(result).toContain('approval_policy = "on-request"');
|
|
expect(result).toContain('sandbox_mode = "read-only"');
|
|
});
|
|
|
|
it('should use on-request as default approval policy', () => {
|
|
const settings = {
|
|
permissions: {
|
|
autoApprove: false,
|
|
},
|
|
};
|
|
|
|
const result = convertSettingsToToml(settings);
|
|
|
|
expect(result).toContain('approval_policy = "on-request"');
|
|
});
|
|
|
|
it('should convert MCP servers', () => {
|
|
const settings = {
|
|
mcpServers: {
|
|
'claude-flow': {
|
|
command: 'npx',
|
|
args: ['-y', '@claude-flow/cli'],
|
|
},
|
|
'custom-server': {
|
|
command: 'node',
|
|
args: ['./server.js', '--port', '3000'],
|
|
},
|
|
},
|
|
};
|
|
|
|
const result = convertSettingsToToml(settings);
|
|
|
|
expect(result).toContain('[mcp_servers.claude-flow]');
|
|
expect(result).toContain('command = "npx"');
|
|
expect(result).toContain('args = ["-y", "@claude-flow/cli"]');
|
|
expect(result).toContain('[mcp_servers.custom-server]');
|
|
expect(result).toContain('command = "node"');
|
|
});
|
|
|
|
it('should add default ruflo server when no mcpServers', () => {
|
|
const settings = {
|
|
model: 'gpt-4',
|
|
};
|
|
|
|
const result = convertSettingsToToml(settings);
|
|
|
|
// The implementation adds a default ruflo server when none specified
|
|
expect(result).toContain('[mcp_servers.ruflo]');
|
|
expect(result).toContain('command = "npx"');
|
|
});
|
|
|
|
it('should handle empty settings', () => {
|
|
const result = convertSettingsToToml({});
|
|
|
|
expect(result).toContain('# Migrated from settings.json');
|
|
expect(result.split('\n').length).toBeGreaterThan(1);
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// generateMigrationReport Tests
|
|
// =============================================================================
|
|
|
|
describe('generateMigrationReport', () => {
|
|
describe('successful migration report', () => {
|
|
it('should show success status', () => {
|
|
const result: MigrationResult = {
|
|
success: true,
|
|
agentsMdPath: '/project/AGENTS.md',
|
|
configTomlPath: '/project/.agents/config.toml',
|
|
skillsCreated: ['swarm-orchestration', 'memory-management'],
|
|
mappings: FEATURE_MAPPINGS,
|
|
warnings: ['Check skill syntax'],
|
|
};
|
|
|
|
const report = generateMigrationReport(result);
|
|
|
|
expect(report).toContain('# Migration Report');
|
|
expect(report).toContain('**Status**: Success');
|
|
});
|
|
|
|
it('should list generated files', () => {
|
|
const result: MigrationResult = {
|
|
success: true,
|
|
agentsMdPath: '/project/AGENTS.md',
|
|
configTomlPath: '/project/.agents/config.toml',
|
|
};
|
|
|
|
const report = generateMigrationReport(result);
|
|
|
|
expect(report).toContain('## Generated Files');
|
|
expect(report).toContain('AGENTS.md:');
|
|
expect(report).toContain('/project/AGENTS.md');
|
|
expect(report).toContain('config.toml:');
|
|
expect(report).toContain('/project/.agents/config.toml');
|
|
});
|
|
|
|
it('should list created skills', () => {
|
|
const result: MigrationResult = {
|
|
success: true,
|
|
skillsCreated: ['skill-a', 'skill-b', 'skill-c'],
|
|
};
|
|
|
|
const report = generateMigrationReport(result);
|
|
|
|
expect(report).toContain('## Skills Created');
|
|
// Skills are formatted with $ prefix in backticks
|
|
expect(report).toContain('$skill-a');
|
|
expect(report).toContain('$skill-b');
|
|
expect(report).toContain('$skill-c');
|
|
});
|
|
|
|
it('should include feature mappings table', () => {
|
|
const result: MigrationResult = {
|
|
success: true,
|
|
mappings: [
|
|
{ claudeCode: 'CLAUDE.md', codex: 'AGENTS.md', status: 'mapped', notes: 'Main file' },
|
|
{ claudeCode: '/skill', codex: '$skill', status: 'mapped', notes: 'Syntax change' },
|
|
],
|
|
};
|
|
|
|
const report = generateMigrationReport(result);
|
|
|
|
expect(report).toContain('## Feature Mappings');
|
|
// Table now includes Notes column
|
|
expect(report).toContain('| Claude Code | Codex | Status | Notes |');
|
|
expect(report).toContain('CLAUDE.md');
|
|
expect(report).toContain('AGENTS.md');
|
|
expect(report).toContain('mapped');
|
|
});
|
|
|
|
it('should include warnings', () => {
|
|
const result: MigrationResult = {
|
|
success: true,
|
|
warnings: ['Warning 1', 'Warning 2'],
|
|
};
|
|
|
|
const report = generateMigrationReport(result);
|
|
|
|
expect(report).toContain('## Warnings');
|
|
expect(report).toContain('- Warning 1');
|
|
expect(report).toContain('- Warning 2');
|
|
});
|
|
});
|
|
|
|
describe('failed migration report', () => {
|
|
it('should show failed status', () => {
|
|
const result: MigrationResult = {
|
|
success: false,
|
|
warnings: ['Migration failed: File not found'],
|
|
};
|
|
|
|
const report = generateMigrationReport(result);
|
|
|
|
expect(report).toContain('**Status**: Failed');
|
|
});
|
|
|
|
it('should include error warnings', () => {
|
|
const result: MigrationResult = {
|
|
success: false,
|
|
warnings: ['Error: Could not read source file'],
|
|
};
|
|
|
|
const report = generateMigrationReport(result);
|
|
|
|
expect(report).toContain('## Warnings');
|
|
expect(report).toContain('Error: Could not read source file');
|
|
});
|
|
});
|
|
|
|
describe('minimal report', () => {
|
|
it('should handle minimal result', () => {
|
|
const result: MigrationResult = {
|
|
success: true,
|
|
};
|
|
|
|
const report = generateMigrationReport(result);
|
|
|
|
expect(report).toContain('# Migration Report');
|
|
expect(report).toContain('**Status**: Success');
|
|
expect(report).not.toContain('## Generated Files');
|
|
expect(report).not.toContain('## Skills Created');
|
|
});
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// FEATURE_MAPPINGS Tests
|
|
// =============================================================================
|
|
|
|
describe('FEATURE_MAPPINGS', () => {
|
|
it('should contain CLAUDE.md to AGENTS.md mapping', () => {
|
|
const mapping = FEATURE_MAPPINGS.find(m => m.claudeCode === 'CLAUDE.md');
|
|
|
|
expect(mapping).toBeDefined();
|
|
expect(mapping!.codex).toBe('AGENTS.md');
|
|
expect(mapping!.status).toBe('mapped');
|
|
});
|
|
|
|
it('should contain skill invocation syntax mapping', () => {
|
|
const mapping = FEATURE_MAPPINGS.find(m => m.claudeCode === '/skill-name');
|
|
|
|
expect(mapping).toBeDefined();
|
|
expect(mapping!.codex).toBe('$skill-name');
|
|
expect(mapping!.status).toBe('mapped');
|
|
});
|
|
|
|
it('should contain MCP servers mapping', () => {
|
|
const mapping = FEATURE_MAPPINGS.find(m => m.claudeCode === 'MCP servers');
|
|
|
|
expect(mapping).toBeDefined();
|
|
expect(mapping!.codex).toBe('[mcp_servers]');
|
|
expect(mapping!.status).toBe('mapped');
|
|
});
|
|
|
|
it('should mark EnterPlanMode as unsupported', () => {
|
|
const mapping = FEATURE_MAPPINGS.find(m => m.claudeCode === 'EnterPlanMode');
|
|
|
|
expect(mapping).toBeDefined();
|
|
expect(mapping!.status).toBe('unsupported');
|
|
});
|
|
|
|
it('should mark hooks as partial', () => {
|
|
const mapping = FEATURE_MAPPINGS.find(m => m.claudeCode === 'hooks system');
|
|
|
|
expect(mapping).toBeDefined();
|
|
expect(mapping!.status).toBe('partial');
|
|
});
|
|
|
|
it('should include notes for all mappings', () => {
|
|
for (const mapping of FEATURE_MAPPINGS) {
|
|
expect(mapping.notes).toBeDefined();
|
|
expect(mapping.notes!.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
it('should have at least 8 mappings', () => {
|
|
expect(FEATURE_MAPPINGS.length).toBeGreaterThanOrEqual(8);
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// Integration Tests
|
|
// =============================================================================
|
|
|
|
describe('migration integration', () => {
|
|
it('should analyze and migrate consistently', async () => {
|
|
const content = `# Test Project
|
|
|
|
## Behavioral Rules
|
|
|
|
- Rule one
|
|
- Rule two
|
|
|
|
## Skills
|
|
|
|
Use /skill-a and /skill-b.
|
|
|
|
## Hooks
|
|
|
|
Use pre-task hooks.
|
|
`;
|
|
|
|
const analysis = await analyzeClaudeMd(content);
|
|
const migration = await migrateFromClaudeCode({
|
|
sourcePath: '/test/CLAUDE.md',
|
|
targetPath: '/test',
|
|
});
|
|
|
|
expect(analysis.skills).toContain('skill-a');
|
|
expect(analysis.skills).toContain('skill-b');
|
|
expect(analysis.hooks).toContain('pre-task');
|
|
expect(migration.success).toBe(true);
|
|
});
|
|
|
|
it('should convert analyzed content correctly', async () => {
|
|
const content = 'Use /swarm-orchestration and /memory-management.';
|
|
const converted = convertSkillSyntax(content);
|
|
const analysis = await analyzeClaudeMd(content);
|
|
|
|
expect(converted).toContain('$swarm-orchestration');
|
|
expect(converted).toContain('$memory-management');
|
|
expect(analysis.skills).toContain('swarm-orchestration');
|
|
expect(analysis.skills).toContain('memory-management');
|
|
});
|
|
});
|