π The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
test(metaharness): MCP tool runtime contract β 65 assertions across 7 tools (iter 23)
ruv3ce5a6c896b1
diff --git a/.github/workflows/metaharness-ci.yml b/.github/workflows/metaharness-ci.ymlindex 2785f39c14..accc79a0a2 100644--- a/.github/workflows/metaharness-ci.yml+++ b/.github/workflows/metaharness-ci.yml@@ -129,6 +129,19 @@ jobs:# promotable and non-promotable paths.run: node plugins/ruflo-metaharness/scripts/test-parallel-pipeline.mjs+ - name: MCP tool runtime contract test (ADR-150 iter 23)+ # Builds the CLI dist, imports metaharnessTools, invokes every+ # handler with minimal input, asserts each returns the+ # {success, data, degraded, exitCode} contract without throwing.+ # 65 assertions across 7 tools. Slow path (~50s) due to npx+ # warmup; runs only on PRs that touched the MCP wiring.+ run: |+ cd v3/@claude-flow/cli+ npm install --no-audit --no-fund --ignore-scripts --silent+ npm run build+ cd ../../..+ node plugins/ruflo-metaharness/scripts/test-mcp-tools.mjs+eject-dryrun:# ADR-150 Phase 2 β verify `ruflo eject` dry-run produces a valid# plan against the ruflo repo itself, AND that the safety gatediff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.shindex 91aea0b164..df99a6d1ee 100755--- a/plugins/ruflo-metaharness/scripts/smoke.sh+++ b/plugins/ruflo-metaharness/scripts/smoke.sh@@ -170,6 +170,24 @@ if (!od.metaharness) { console.error('missing metaharness in optionalDependencieif (j.dependencies && j.dependencies.metaharness) { console.error('metaharness leaked into dependencies'); process.exit(1); }" 2>/dev/null && ok || bad "ruflo wrapper missing metaharness optionalDep"+step "17o. test-mcp-tools runtime contract test (ADR-150 β iter 23)"+F="$ROOT/scripts/test-mcp-tools.mjs"+miss=""+[[ -x "$F" ]] || miss="$miss not-executable"+node --check "$F" 2>/dev/null || miss="$miss syntax-error"+# Asserts the runtime contract literally: { success, data, degraded, exitCode }+grep -q "result has 'success'" "$F" || miss="$miss no-success-assertion"+grep -q "result has 'data'" "$F" || miss="$miss no-data-assertion"+grep -q "result has 'degraded'" "$F" || miss="$miss no-degraded-assertion"+grep -q "result has 'exitCode'" "$F" || miss="$miss no-exitcode-assertion"+# All 7 tool names enumerated+for tool in metaharness_score metaharness_genome metaharness_mcp_scan metaharness_threat_model metaharness_oia_audit metaharness_audit_list metaharness_audit_trend; do+ grep -q "${tool}" "$F" || miss="$miss missing-${tool}"+done+# Graceful skip when dist absent (so the script is smoke-runnable pre-build)+grep -q "SKIPPED" "$F" || miss="$miss no-skip-doc"+[[ -z "$miss" ]] && ok || bad "$miss"+step "17n. CLAUDE.md documents MetaHarness integration (ADR-150 discoverability β iter 22)"F="$ROOT/../../CLAUDE.md"miss=""diff --git a/plugins/ruflo-metaharness/scripts/test-mcp-tools.mjs b/plugins/ruflo-metaharness/scripts/test-mcp-tools.mjsnew file mode 100755index 0000000000..56d75d5edc--- /dev/null+++ b/plugins/ruflo-metaharness/scripts/test-mcp-tools.mjs@@ -0,0 +1,161 @@+#!/usr/bin/env node+// test-mcp-tools.mjs β runtime test for the iter-20/21 MCP tool registry.+//+// tsc proves the metaharness-tools.ts module COMPILES; structural smoke+// proves the source DECLARES the right tool names. Neither proves the+// HANDLERS actually run without throwing. This test imports the compiled+// module and invokes every tool's handler with minimal inputs.+//+// CONTRACT EACH TOOL MUST SATISFY+// - handler is callable as `await tool.handler({ ... })`+// - returns an object with keys: success, data, degraded, exitCode+// - never throws (even with bad/missing optional dep β graceful)+// - handler honors the 120s subprocess timeout (no hang)+//+// USAGE+// node scripts/test-mcp-tools.mjs # default+// node scripts/test-mcp-tools.mjs --format json+//+// EXIT CODES+// 0 all tools satisfy the contract+// 1 at least one tool failed+// 2 setup error (compiled dist not present)++import { existsSync } from 'node:fs';+import { dirname, join, resolve } from 'node:path';+import { fileURLToPath } from 'node:url';++const SCRIPTS_DIR = dirname(fileURLToPath(import.meta.url));+const ARGS = (() => {+ const a = { format: 'table' };+ for (let i = 2; i < process.argv.length; i++) {+ if (process.argv[i] === '--format') a.format = process.argv[++i];+ }+ return a;+})();++let passed = 0, failed = 0;+const failures = [];++function assert(cond, label) {+ if (cond) { console.log(` β ${label}`); passed++; }+ else { console.log(` β ${label}`); failures.push(label); failed++; }+}++async function main() {+ // Locate the compiled dist of metaharness-tools.+ const distPath = resolve(SCRIPTS_DIR, '..', '..', '..',+ 'v3', '@claude-flow', 'cli', 'dist', 'src', 'mcp-tools', 'metaharness-tools.js');++ if (!existsSync(distPath)) {+ console.log(`# test-mcp-tools β SKIPPED`);+ console.log('');+ console.log(`Compiled dist not present: ${distPath}`);+ console.log(`Build the CLI first:`);+ console.log(` cd v3/@claude-flow/cli && npm run build`);+ console.log('');+ console.log(`Exit 0 β this script is meaningfully runnable only post-build.`);+ process.exit(0);+ }++ let mod;+ try {+ mod = await import(distPath);+ } catch (e) {+ console.error(`test-mcp-tools: failed to import ${distPath}: ${e.message}`);+ process.exit(2);+ }++ const tools = mod.metaharnessTools;+ console.log(`# test-mcp-tools β runtime contract\n`);++ // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+ // PHASE 1 β module exports the right shape+ // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+ console.log('Phase 1 β module shape');+ assert(Array.isArray(tools), 'metaharnessTools is an array');+ assert(tools.length === 7, `7 tools registered (got ${tools.length})`);++ const expectedNames = new Set([+ 'metaharness_score',+ 'metaharness_genome',+ 'metaharness_mcp_scan',+ 'metaharness_threat_model',+ 'metaharness_oia_audit',+ 'metaharness_audit_list',+ 'metaharness_audit_trend',+ ]);+ const actualNames = new Set(tools.map((t) => t.name));+ for (const name of expectedNames) {+ assert(actualNames.has(name), `${name} registered`);+ }++ // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+ // PHASE 2 β every tool has the required MCP shape+ // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+ console.log('\nPhase 2 β per-tool shape');+ for (const tool of tools) {+ const ok = typeof tool.name === 'string'+ && typeof tool.description === 'string'+ && typeof tool.category === 'string'+ && typeof tool.handler === 'function'+ && typeof tool.inputSchema === 'object';+ assert(ok, `${tool.name} has {name, description, category, handler, inputSchema}`);+ assert(tool.category === 'metaharness', `${tool.name} category === 'metaharness'`);+ }++ // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+ // PHASE 3 β handlers callable + return contract shape+ //+ // We invoke each handler with minimal valid input. The handlers may+ // succeed (if metaharness is installed) or report degraded (if not).+ // EITHER way, they must return { success, data, degraded, exitCode }+ // without throwing.+ // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+ console.log('\nPhase 3 β handler invocations (allow up to 30s each)');+ for (const tool of tools) {+ // Construct minimal valid input per tool.+ let input = {};+ if (tool.name === 'metaharness_audit_trend') {+ // Requires baselineKey + currentKey β use fake keys that won't+ // resolve so we exercise the not-found path.+ input = { baselineKey: 'audit-fake-base', currentKey: 'audit-fake-curr' };+ }++ // 30s budget per tool β slow path is npx warmup+ const handlerPromise = tool.handler(input);+ const timeoutPromise = new Promise((_, reject) =>+ setTimeout(() => reject(new Error('30s handler timeout')), 30_000));++ let result;+ let threw = false;+ try {+ result = await Promise.race([handlerPromise, timeoutPromise]);+ } catch (e) {+ threw = true;+ console.log(` [${tool.name}] handler threw: ${e.message.slice(0, 80)}`);+ }++ assert(!threw, `${tool.name} handler did not throw`);+ if (!threw && result) {+ assert(typeof result === 'object', `${tool.name} returns object`);+ assert('success' in result, `${tool.name} result has 'success'`);+ assert('data' in result, `${tool.name} result has 'data'`);+ assert('degraded' in result, `${tool.name} result has 'degraded'`);+ assert('exitCode' in result, `${tool.name} result has 'exitCode'`);+ }+ }++ console.log(`\n${passed} passed, ${failed} failed`);+ if (failed > 0) {+ console.log('\nFailures:');+ for (const f of failures) console.log(` - ${f}`);+ process.exit(1);+ }+ console.log('\nβ All 7 MCP tools satisfy the runtime contract.');+}++main().catch((e) => {+ console.error('test-mcp-tools crashed:', e.message || e);+ process.exit(2);+});