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

test(metaharness): unit tests for iter-63 rankSeverity + rollup (iter 64)

ruvf1f20b59c1b3
diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.sh
index b4f4032846..8e3d71d673 100755
--- a/plugins/ruflo-metaharness/scripts/smoke.sh
+++ b/plugins/ruflo-metaharness/scripts/smoke.sh
@@ -191,6 +191,19 @@ 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 "17z27. rankSeverity + rollup unit tests (iter 64 β€” locks iter-63 fix)"
+miss=""
+F="$ROOT/scripts/test-similarity.mjs"
+grep -q "Phase 9 β€” iter-63 shared SEVERITY_RANK" "$F" 2>/dev/null || miss="$miss no-phase-9"
+grep -q "SEVERITY_RANK frozen" "$F" 2>/dev/null || miss="$miss no-freeze-test"
+grep -q "rankSeverity case-insensitive" "$F" 2>/dev/null || miss="$miss no-case-insensitive-test"
+grep -q "rankSeverity(null)" "$F" 2>/dev/null || miss="$miss no-null-test"
+grep -q "rollup warn-only elevates to warn" "$F" 2>/dev/null || miss="$miss no-warn-rollup-test"
+grep -q "rollup with critical elevates above info" "$F" 2>/dev/null || miss="$miss no-critical-rollup-test"
+# Runtime: test passes (now 75+ assertions)
+node "$F" >/dev/null 2>&1 || miss="$miss runtime-fails"
+[[ -z "$miss" ]] && ok || bad "$miss"
+
step "17z26. SEVERITY_RANK consolidated to _harness.mjs (iter 63)"
miss=""
HARNESS="$ROOT/scripts/_harness.mjs"
diff --git a/plugins/ruflo-metaharness/scripts/test-similarity.mjs b/plugins/ruflo-metaharness/scripts/test-similarity.mjs
index d3ade40429..4081435af2 100755
--- a/plugins/ruflo-metaharness/scripts/test-similarity.mjs
+++ b/plugins/ruflo-metaharness/scripts/test-similarity.mjs
@@ -24,6 +24,8 @@
import {
projectToVec, cosine, categoricalAgreement, jaccard, similarity,
} from './_similarity.mjs';
+// iter 64 β€” also test the iter-63 shared severity primitives
+import { SEVERITY_RANK, rankSeverity } from './_harness.mjs';
const ARGS = (() => {
const a = { format: 'table' };
@@ -193,6 +195,52 @@ assert(sLS.components.categorical === 0.75,
assert(sLS.components.jaccard === 0.2857,
`LEGAL Γ— SUPPORT jaccard must be 0.2857 (got ${sLS.components.jaccard})`);
+console.log('\nPhase 9 β€” iter-63 shared SEVERITY_RANK + rankSeverity()');
+// Known severities β€” full vocab the iter-50 parser produces
+assert(SEVERITY_RANK.clean === 0, 'rank.clean === 0');
+assert(SEVERITY_RANK.info === 0, 'rank.info === 0 (informational, no harm)');
+assert(SEVERITY_RANK.low === 1, 'rank.low === 1');
+assert(SEVERITY_RANK.medium === 2, 'rank.medium === 2');
+assert(SEVERITY_RANK.warn === 2, 'rank.warn === 2 (warn β‰ˆ medium)');
+assert(SEVERITY_RANK.high === 3, 'rank.high === 3');
+assert(SEVERITY_RANK.error === 3, 'rank.error === 3 (error β‰ˆ high)');
+assert(SEVERITY_RANK.critical === 4, 'rank.critical === 4 (elevated above high)');
+
+// Object.freeze blocks mutation β€” anti-tamper guard
+const before = SEVERITY_RANK.high;
+let mutated = false;
+try { SEVERITY_RANK.high = 999; mutated = SEVERITY_RANK.high !== before; } catch { /* strict mode throws */ }
+assert(!mutated, 'SEVERITY_RANK frozen β€” mutation does not stick');
+
+// rankSeverity safe accessor
+assert(rankSeverity('info') === 0, 'rankSeverity("info") === 0');
+assert(rankSeverity('CRITICAL') === 4, 'rankSeverity case-insensitive ("CRITICAL" β†’ 4)');
+assert(rankSeverity('Warn') === 2, 'rankSeverity case-insensitive ("Warn" β†’ 2)');
+assert(rankSeverity('unknown') === 0, 'rankSeverity("unknown") === 0 (no NaN)');
+assert(rankSeverity(null) === 0, 'rankSeverity(null) === 0');
+assert(rankSeverity(undefined) === 0, 'rankSeverity(undefined) === 0');
+assert(rankSeverity('') === 0, 'rankSeverity("") === 0');
+assert(rankSeverity(' high ') === 0,
+ 'rankSeverity does not strip whitespace (returns 0 for non-normalized input)');
+
+// Rollup pattern mirrors oia-audit's reduce
+function rollup(findings) {
+ return findings.reduce((acc, f) => {
+ const s = String(f.severity || 'low').toLowerCase();
+ return rankSeverity(s) > rankSeverity(acc) ? s : acc;
+ }, 'clean');
+}
+assert(rollup([{ severity: 'info' }]) === 'clean',
+ 'rollup info-only stays clean');
+assert(rollup([{ severity: 'warn' }]) === 'warn',
+ 'rollup warn-only elevates to warn (was NaN-ignored pre-iter-63)');
+assert(rollup([{ severity: 'critical' }, { severity: 'info' }]) === 'critical',
+ 'rollup with critical elevates above info');
+assert(rollup([{ severity: 'low' }, { severity: 'warn' }, { severity: 'high' }, { severity: 'critical' }]) === 'critical',
+ 'rollup picks max across mixed severities');
+assert(rollup([{ severity: 'unknown-strange-value' }]) === 'clean',
+ 'rollup with unknown severity stays clean (safe default)');
+
// ──────────────────────────────────────────────────────────────────
const summary = {
passed, failed,