Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

fix(metaharness): oia-audit fingerprint uses metaharness CLI shape (iter 47)

ruvf0400fef015a
diff --git a/plugins/ruflo-metaharness/scripts/oia-audit.mjs b/plugins/ruflo-metaharness/scripts/oia-audit.mjs
index cf0537ac77..3822eaf761 100755
--- a/plugins/ruflo-metaharness/scripts/oia-audit.mjs
+++ b/plugins/ruflo-metaharness/scripts/oia-audit.mjs
@@ -25,7 +25,7 @@
// 2 config error or audit failure
import { spawnSync } from 'node:child_process';
-import { runHarness, emitDegradedJsonAndExit } from './_harness.mjs';
+import { runHarness, runMetaharness, emitDegradedJsonAndExit } from './_harness.mjs';
const SEVERITY_RANK = { clean: 0, low: 1, medium: 2, high: 3 };
const NS = process.env.OIA_AUDIT_NAMESPACE || 'metaharness-audit';
@@ -45,8 +45,13 @@ const ARGS = (() => {
return a;
})();
-function runOne(args, label) {
- const r = runHarness(args);
+// iter 47 β€” the `harness` and `metaharness` CLIs both have `score` /
+// `genome` subcommands but with DIFFERENT output schemas. For the
+// fingerprint to be consumable by _similarity.mjs (which expects the
+// metaharness CLI shape: harnessFit/compileConfidence/agent_topology),
+// we need to dispatch to runMetaharness for score+genome, not runHarness.
+function runOne(args, label, engine = 'harness') {
+ const r = engine === 'metaharness' ? runMetaharness(args) : runHarness(args);
return {
label,
exitCode: r.exitCode,
@@ -84,11 +89,13 @@ function main() {
const oia = runOne(['oia-manifest', ARGS.path], 'oia-manifest');
const tm = runOne(['threat-model', ARGS.path], 'threat-model');
const mcp = runOne(['mcp-scan', ARGS.path], 'mcp-scan');
- // iter 38 β€” bundle score + genome so audit-trend can compute structural
- // distance via _similarity.mjs (ADR-152 Β§3.1 dep). Both are pure-read
- // and degrade gracefully like the other three.
- const score = runOne(['score', ARGS.path], 'score');
- const genome = runOne(['genome', ARGS.path], 'genome');
+ // iter 38 + iter 47 β€” bundle score + genome so audit-trend can compute
+ // structural distance via _similarity.mjs. Both use the `metaharness`
+ // CLI (not `harness`) because the two binaries have different schemas
+ // for the same subcommand names; only the metaharness CLI emits the
+ // shape similarity() expects (harnessFit/agent_topology/etc).
+ const score = runOne(['score', ARGS.path], 'score', 'metaharness');
+ const genome = runOne(['genome', ARGS.path], 'genome', 'metaharness');
// If all FIVE say "metaharness not available", surface the degraded
// payload exactly once and exit 0 (architectural constraint #3).
diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.sh
index ec60df5a55..7aca197c3f 100755
--- a/plugins/ruflo-metaharness/scripts/smoke.sh
+++ b/plugins/ruflo-metaharness/scripts/smoke.sh
@@ -191,6 +191,31 @@ grep -q "execCli(\[\s*'-y'\s*,\s*'metaharness@latest'" "$F" 2>/dev/null || \
grep -q "cwd: opts" "$F" || miss="$miss no-cwd-passthrough"
[[ -z "$miss" ]] && ok || bad "$miss"
+step "17z10. end-to-end pipeline roundtrip (iter 47 β€” caught iter-38 schema bug)"
+F="$ROOT/scripts/test-pipeline-roundtrip.mjs"
+miss=""
+[[ -x "$F" ]] || miss="$miss not-executable"
+node --check "$F" 2>/dev/null || miss="$miss syntax-error"
+# Five stages (anti-shrink guard)
+for stage in 'Stage 1' 'Stage 2' 'Stage 3' 'Stage 4' 'Stage 5'; do
+ grep -q "$stage" "$F" || miss="$miss missing-${stage// /-}"
+done
+# Asserts the critical invariant: self-roundtrip overall === 1
+grep -q "self-roundtrip overall === 1" "$F" 2>/dev/null || miss="$miss no-self-match-assert"
+# Distinguishes "test cannot run" (exit 2) from "test failed" (exit 1)
+grep -q "process.exit(2)" "$F" 2>/dev/null || miss="$miss no-cannot-run-exit"
+# oia-audit fix is in place: dispatches metaharness for score+genome
+OIA="$ROOT/scripts/oia-audit.mjs"
+grep -q "score', 'metaharness'" "$OIA" 2>/dev/null || miss="$miss no-metaharness-engine-score"
+grep -q "genome', 'metaharness'" "$OIA" 2>/dev/null || miss="$miss no-metaharness-engine-genome"
+grep -q "runMetaharness" "$OIA" 2>/dev/null || miss="$miss no-runMetaharness-import"
+# Runtime: the roundtrip test must pass when metaharness is installed,
+# or exit 2 (test-cannot-run) when it isn't. Both are smoke-green.
+node "$F" >/dev/null 2>&1
+CODE=$?
+[[ "$CODE" == "0" || "$CODE" == "2" ]] || miss="$miss roundtrip-test-failed:$CODE"
+[[ -z "$miss" ]] && ok || bad "$miss"
+
step "17z9. MCP success-semantic footnote + audit_trend file inputs (iter 46)"
miss=""
WRAPPER="$ROOT/../../v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts"
diff --git a/plugins/ruflo-metaharness/scripts/test-pipeline-roundtrip.mjs b/plugins/ruflo-metaharness/scripts/test-pipeline-roundtrip.mjs
new file mode 100755
index 0000000000..d8e0eebc07
--- /dev/null
+++ b/plugins/ruflo-metaharness/scripts/test-pipeline-roundtrip.mjs
@@ -0,0 +1,194 @@
+#!/usr/bin/env node
+// test-pipeline-roundtrip.mjs β€” end-to-end test of the ADR-152 Β§3.1
+// cross-pipeline integration shipped iters 36β†’46.
+//
+// THE GAP THIS CLOSES
+// Every prior iter test exercised ONE surface in isolation:
+// iter 35: spike β€” synthetic LEGAL/SUPPORT/DEVOPS fixtures
+// iter 37: MCP runtime test β€” fake mem keys
+// iter 38: audit-trend β€” hand-written audit JSON
+// iter 39: unit tests β€” pure-function arithmetic
+// iter 41: bench β€” synthetic payloads
+// iter 43: Phase 4 β€” file-path fixtures
+// iter 46: audit_trend file inputs β€” same fixtures
+//
+// None of these proved the FULL chain works end-to-end with no
+// synthetic data. This test does.
+//
+// THE PIPELINE BEING TESTED
+// 1. oia-audit --dry-run --path . (real run against ruflo)
+// 2. The audit record's fingerprint{score,genome}
+// 3. audit-trend --baseline {same-record} --current {same-record}
+// 4. delta.structuralDistance.verdict === 'near-identical'
+// 5. delta.structuralDistance.overall === 1
+//
+// USAGE
+// node scripts/test-pipeline-roundtrip.mjs
+// node scripts/test-pipeline-roundtrip.mjs --format json
+//
+// EXIT CODES
+// 0 full chain works
+// 1 some assertion failed
+// 2 oia-audit degraded (upstream metaharness absent β€” test cannot run)
+//
+// ADR-150 ARCHITECTURAL CONSTRAINT BEHAVIOR
+// If oia-audit returns {degraded:true} (no upstream metaharness), the
+// test exits 2 with a clear message β€” this is the "test cannot run"
+// case, NOT a "test failed" case. CI infrastructure can distinguish.
+
+import { spawnSync } from 'node:child_process';
+import { mkdtempSync, writeFileSync, readFileSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, dirname } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const SCRIPTS_DIR = dirname(fileURLToPath(import.meta.url));
+const REPO_ROOT = dirname(dirname(dirname(SCRIPTS_DIR))); // up out of plugins/ruflo-metaharness/scripts
+
+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++; }
+}
+
+function runNode(scriptName, args, timeoutMs = 60_000) {
+ const p = spawnSync('node', [join(SCRIPTS_DIR, scriptName), ...args], {
+ encoding: 'utf-8',
+ timeout: timeoutMs,
+ cwd: REPO_ROOT,
+ });
+ return { stdout: p.stdout || '', stderr: p.stderr || '', status: p.status ?? -1 };
+}
+
+// ──────────────────────────────────────────────────────────────────
+console.log(`# test-pipeline-roundtrip β€” ADR-152 Β§3.1 end-to-end (iter 47)\n`);
+
+const tmp = mkdtempSync(join(tmpdir(), 'pipeline-roundtrip-'));
+
+try {
+ // ──────────────────────────────────────────────────────────────
+ // STAGE 1: oia-audit --dry-run against ruflo repo itself
+ // ──────────────────────────────────────────────────────────────
+ console.log('Stage 1 β€” oia-audit --dry-run against ruflo repo');
+ const auditRun = runNode('oia-audit.mjs', ['--path', REPO_ROOT, '--dry-run', '--format', 'json'], 90_000);
+
+ // Extract the JSON object from stdout (script may emit some prelude)
+ const auditMatch = /\{[\s\S]*\}/.exec(auditRun.stdout);
+ if (!auditMatch) {
+ console.log(` βœ— oia-audit produced no JSON; stderr:\n${auditRun.stderr.slice(0, 500)}`);
+ process.exit(1);
+ }
+ const audit = JSON.parse(auditMatch[0]);
+
+ // If oia-audit reports degraded (no upstream metaharness installed), skip
+ // β€” this test cannot run without real score/genome output.
+ if (audit.degraded === true) {
+ console.log(` ⊘ oia-audit reports degraded β€” upstream metaharness absent`);
+ console.log(` This test exercises real metaharness output; cannot run.`);
+ console.log(` reason: ${audit.reason}`);
+ process.exit(2);
+ }
+
+ assert(typeof audit === 'object' && audit !== null,
+ 'oia-audit produced a JSON object');
+ assert(typeof audit.composite === 'object',
+ 'oia-audit has composite worst-severity');
+ assert(typeof audit.components === 'object',
+ 'oia-audit has components bundle');
+
+ // iter 38 β€” fingerprint must be present
+ assert(typeof audit.fingerprint === 'object' && audit.fingerprint !== null,
+ 'oia-audit emits fingerprint field (iter 38)');
+ if (!audit.fingerprint?.score || !audit.fingerprint?.genome) {
+ console.log(` ⊘ fingerprint partial; score+genome may have degraded individually`);
+ console.log(` fingerprint: ${JSON.stringify(audit.fingerprint).slice(0, 200)}`);
+ process.exit(2);
+ }
+ assert(typeof audit.fingerprint.score?.harnessFit === 'number',
+ 'fingerprint.score has harnessFit');
+ assert(Array.isArray(audit.fingerprint.genome?.agent_topology),
+ 'fingerprint.genome has agent_topology array');
+
+ // ──────────────────────────────────────────────────────────────
+ // STAGE 2: persist the audit record as both baseline and current
+ // ──────────────────────────────────────────────────────────────
+ console.log('\nStage 2 β€” write audit record to baseline + current paths');
+ const basePath = join(tmp, 'baseline.json');
+ const currPath = join(tmp, 'current.json');
+ writeFileSync(basePath, JSON.stringify(audit));
+ writeFileSync(currPath, JSON.stringify(audit));
+ assert(readFileSync(basePath, 'utf-8').length > 100, 'baseline file written');
+ assert(readFileSync(currPath, 'utf-8').length > 100, 'current file written');
+
+ // ──────────────────────────────────────────────────────────────
+ // STAGE 3: audit-trend reading the same audit twice
+ // ──────────────────────────────────────────────────────────────
+ console.log('\nStage 3 β€” audit-trend against self (must report near-identical)');
+ const trendRun = runNode('audit-trend.mjs', [
+ '--baseline', basePath,
+ '--current', currPath,
+ '--format', 'json',
+ ]);
+
+ const trendMatch = /\{[\s\S]*\}/.exec(trendRun.stdout);
+ assert(trendMatch !== null, 'audit-trend produced JSON');
+ const trend = JSON.parse(trendMatch[0]);
+
+ assert(typeof trend.delta?.structuralDistance === 'object',
+ 'trend exposes delta.structuralDistance');
+ const sd = trend.delta.structuralDistance;
+ assert(sd.verdict === 'near-identical',
+ `self-roundtrip verdict === near-identical (got ${sd.verdict})`);
+ assert(sd.overall === 1,
+ `self-roundtrip overall === 1 (got ${sd.overall})`);
+ assert(sd.distance === 0,
+ `self-roundtrip distance === 0 (got ${sd.distance})`);
+
+ // ──────────────────────────────────────────────────────────────
+ // STAGE 4: alert-on-distance-below should NOT trigger on self-match
+ // ──────────────────────────────────────────────────────────────
+ console.log('\nStage 4 β€” distance alert does not trigger on self-match');
+ const noAlertRun = runNode('audit-trend.mjs', [
+ '--baseline', basePath,
+ '--current', currPath,
+ '--alert-on-distance-below', '0.5',
+ '--format', 'json',
+ ]);
+ assert(noAlertRun.status === 0,
+ `alert at threshold 0.5 does NOT fire on self-match (exit 0, got ${noAlertRun.status})`);
+
+ // Now flip: any threshold above 1 must trigger
+ console.log('\nStage 5 β€” distance alert triggers when threshold > self-match');
+ const alertRun = runNode('audit-trend.mjs', [
+ '--baseline', basePath,
+ '--current', currPath,
+ '--alert-on-distance-below', '1.01',
+ '--format', 'json',
+ ]);
+ assert(alertRun.status === 1,
+ `alert at threshold 1.01 fires on self-match (exit 1, got ${alertRun.status})`);
+
+} finally {
+ try { rmSync(tmp, { recursive: true, force: true }); } catch { /* ignore */ }
+}
+
+// ──────────────────────────────────────────────────────────────────
+const summary = { passed, failed, total: passed + failed, failures };
+
+console.log(`\n${passed} passed, ${failed} failed`);
+if (ARGS.format === 'json') console.log(JSON.stringify(summary, null, 2));
+if (failed > 0) {
+ console.log('\nFailures:');
+ for (const f of failures) console.log(` - ${f}`);
+ process.exit(1);
+}
+console.log('\nβœ“ Full ADR-152 Β§3.1 pipeline works end-to-end with real metaharness output.');