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): handle help and reject unknown arguments before execution

Rudy Celekliff4b2af27176
diff --git a/.github/workflows/metaharness-ci.yml b/.github/workflows/metaharness-ci.yml
index 55490331bc..0dccd1303c 100644
--- a/.github/workflows/metaharness-ci.yml
+++ b/.github/workflows/metaharness-ci.yml
@@ -47,6 +47,9 @@ jobs:
with:
node-version: '20'
+ - name: CLI help and invalid arguments have no side effects
+ run: node --test plugins/ruflo-metaharness/scripts/test-cli-help.mjs
+
- name: Plugin structural smoke
run: bash plugins/ruflo-metaharness/scripts/smoke.sh
diff --git a/plugins/ruflo-metaharness/scripts/_cli-args.mjs b/plugins/ruflo-metaharness/scripts/_cli-args.mjs
new file mode 100644
index 0000000000..82da58e06b
--- /dev/null
+++ b/plugins/ruflo-metaharness/scripts/_cli-args.mjs
@@ -0,0 +1,37 @@
+// Check entry-point arguments before tool resolution, file writes, or benchmarks.
+import { basename } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+/** Options map flags to a value label, or null for a boolean switch. */
+export function guardCliArgs(scriptUrl, options, note = '') {
+ const args = process.argv.slice(2);
+ const usage = [
+ `Usage: node scripts/${basename(fileURLToPath(scriptUrl))} [options]`,
+ ...(note ? ['', note] : []),
+ '',
+ 'Options:',
+ ...Object.entries(options).map(([flag, value]) => ` ${flag}${value ? ` <${value}>` : ''}`),
+ ' --help, -h Show this help without running the command',
+ ].join('\n');
+
+ if (args.includes('--help') || args.includes('-h')) {
+ console.log(usage);
+ process.exit(0);
+ }
+ for (let i = 0; i < args.length; i++) {
+ const flag = args[i];
+ let error;
+ if (!Object.hasOwn(options, flag)) {
+ error = `Unknown argument: ${flag}`;
+ } else if (options[flag] !== null) {
+ const value = args[++i];
+ if (value === undefined || value.startsWith('--')) {
+ error = `${flag} requires a value`;
+ }
+ }
+ if (error) {
+ console.error(`${error}\n\n${usage}`);
+ process.exit(2);
+ }
+ }
+}
diff --git a/plugins/ruflo-metaharness/scripts/audit-list.mjs b/plugins/ruflo-metaharness/scripts/audit-list.mjs
index 7687f2db6b..e1a08c9207 100755
--- a/plugins/ruflo-metaharness/scripts/audit-list.mjs
+++ b/plugins/ruflo-metaharness/scripts/audit-list.mjs
@@ -16,6 +16,8 @@
// 0 ok
// 2 config error
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runRufloCli } from './_invoke.mjs';
const NS = process.env.AUDIT_LIST_NAMESPACE || 'metaharness-audit';
@@ -24,6 +26,12 @@ const NS = process.env.AUDIT_LIST_NAMESPACE || 'metaharness-audit';
// resolution per call, possible version skew, fails without registry access).
// CLI_CORE=1 still opts into `npx @claude-flow/cli-core@alpha`.
+guardCliArgs(import.meta.url, {
+ '--limit': 'value',
+ '--since': 'value',
+ '--format': 'value',
+});
+
const ARGS = (() => {
const a = { limit: 20, since: null, format: 'table' };
for (let i = 2; i < process.argv.length; i++) {
diff --git a/plugins/ruflo-metaharness/scripts/audit-trend.mjs b/plugins/ruflo-metaharness/scripts/audit-trend.mjs
index 9b7e6ee36d..7e50f04686 100755
--- a/plugins/ruflo-metaharness/scripts/audit-trend.mjs
+++ b/plugins/ruflo-metaharness/scripts/audit-trend.mjs
@@ -24,6 +24,8 @@
// 1 --alert-on-worsening AND composite severity worsened
// 2 config error or input not found
+import { guardCliArgs } from './_cli-args.mjs';
+
import { readFileSync, existsSync } from 'node:fs';
import { runRufloCli } from './_invoke.mjs';
// iter 38 β€” structural-distance drift via ADR-152 Β§3.1 production module.
@@ -41,6 +43,16 @@ const NS = process.env.AUDIT_TREND_NAMESPACE || 'metaharness-audit';
// resolution per call, possible version skew, fails without registry access).
// CLI_CORE=1 still opts into `npx @claude-flow/cli-core@alpha`.
+guardCliArgs(import.meta.url, {
+ '--baseline': 'value',
+ '--current': 'value',
+ '--baseline-key': 'value',
+ '--current-key': 'value',
+ '--alert-on-worsening': null,
+ '--alert-on-distance-below': 'value',
+ '--format': 'value',
+});
+
const ARGS = (() => {
const a = {
baseline: null, current: null,
diff --git a/plugins/ruflo-metaharness/scripts/bench-parse-mcp-scan.mjs b/plugins/ruflo-metaharness/scripts/bench-parse-mcp-scan.mjs
index 300171e37e..5c40b8ce5e 100755
--- a/plugins/ruflo-metaharness/scripts/bench-parse-mcp-scan.mjs
+++ b/plugins/ruflo-metaharness/scripts/bench-parse-mcp-scan.mjs
@@ -24,9 +24,17 @@
// 0 ok (or threshold satisfied)
// 1 --max-mean-us exceeded by any category
+import { guardCliArgs } from './_cli-args.mjs';
+
import { performance } from 'node:perf_hooks';
import { parseMcpScanText } from './_harness.mjs';
+guardCliArgs(import.meta.url, {
+ '--iters': 'value',
+ '--format': 'value',
+ '--max-mean-us': 'value',
+});
+
const ARGS = (() => {
const a = { iters: 100_000, format: 'table', maxMeanUs: null };
for (let i = 2; i < process.argv.length; i++) {
diff --git a/plugins/ruflo-metaharness/scripts/bench-recordpair-overhead.mjs b/plugins/ruflo-metaharness/scripts/bench-recordpair-overhead.mjs
index 28de880c3e..59b4fdbf77 100755
--- a/plugins/ruflo-metaharness/scripts/bench-recordpair-overhead.mjs
+++ b/plugins/ruflo-metaharness/scripts/bench-recordpair-overhead.mjs
@@ -21,8 +21,16 @@
// EXIT CODES
// 0 benchmark complete (always; this is informational, not pass/fail)
+import { guardCliArgs } from './_cli-args.mjs';
+
import { performance } from 'node:perf_hooks';
+guardCliArgs(import.meta.url, {
+ '--iters': 'value',
+ '--format': 'value',
+ '--max-overhead-ns': 'value',
+});
+
const ARGS = (() => {
const a = {
iters: 1_000_000,
diff --git a/plugins/ruflo-metaharness/scripts/bench-similarity.mjs b/plugins/ruflo-metaharness/scripts/bench-similarity.mjs
index eeedb50209..3711d5a949 100755
--- a/plugins/ruflo-metaharness/scripts/bench-similarity.mjs
+++ b/plugins/ruflo-metaharness/scripts/bench-similarity.mjs
@@ -25,9 +25,17 @@
// 0 ok (or --max-mean-us not set / threshold satisfied)
// 1 --max-mean-us threshold exceeded (regression)
+import { guardCliArgs } from './_cli-args.mjs';
+
import { performance } from 'node:perf_hooks';
import { similarity } from './_similarity.mjs';
+guardCliArgs(import.meta.url, {
+ '--iters': 'value',
+ '--format': 'value',
+ '--max-mean-us': 'value',
+});
+
const ARGS = (() => {
const a = {
iters: 1_000_000,
diff --git a/plugins/ruflo-metaharness/scripts/bench.mjs b/plugins/ruflo-metaharness/scripts/bench.mjs
index 7213a5718d..be8a1277f5 100644
--- a/plugins/ruflo-metaharness/scripts/bench.mjs
+++ b/plugins/ruflo-metaharness/scripts/bench.mjs
@@ -18,10 +18,20 @@
// 1 --op verify and any task malformed
// 2 config error or upstream invocation failure
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runDarwin, emitDarwinDegradedJsonAndExit } from './_darwin.mjs';
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
+guardCliArgs(import.meta.url, {
+ '--op': 'value',
+ '--repo': 'value',
+ '--suite': 'value',
+ '--out': 'value',
+ '--format': 'value',
+});
+
const ARGS = (() => {
const a = { op: null, repo: '.', suite: null, out: null, format: 'json' };
for (let i = 2; i < process.argv.length; i++) {
diff --git a/plugins/ruflo-metaharness/scripts/drift-from-history.mjs b/plugins/ruflo-metaharness/scripts/drift-from-history.mjs
index 15aecf9f35..cd13adac43 100755
--- a/plugins/ruflo-metaharness/scripts/drift-from-history.mjs
+++ b/plugins/ruflo-metaharness/scripts/drift-from-history.mjs
@@ -32,6 +32,8 @@
// 2 config / input error (no history available, etc.)
// 3 upstream metaharness absent β€” degraded payload returned
+import { guardCliArgs } from './_cli-args.mjs';
+
import { spawnSync, spawn } from 'node:child_process';
// iter 78 β€” share the iter-63 SEVERITY_RANK for the new finding-alert gate
import { rankSeverity } from './_harness.mjs';
@@ -45,6 +47,17 @@ const NS = process.env.METAHARNESS_AUDIT_NAMESPACE || 'metaharness-audit';
// Memory access is delegated to audit-list / oia-audit / audit-trend (they
// call the shipping ruflo CLI through _invoke.runRufloCli β€” #3366).
+guardCliArgs(import.meta.url, {
+ '--path': 'value',
+ '--baseline-since': 'value',
+ '--baseline-key': 'value',
+ '--baseline-file': 'value',
+ '--threshold': 'value',
+ '--dry-run': null,
+ '--format': 'value',
+ '--alert-on-new-severity': 'value',
+}, "Runs a fresh audit. --dry-run skips persisting it; analysis tools still run.");
+
const ARGS = (() => {
const a = {
path: '.', baselineSince: null, baselineKey: null, baselineFile: null,
diff --git a/plugins/ruflo-metaharness/scripts/evolve.mjs b/plugins/ruflo-metaharness/scripts/evolve.mjs
index 7c54c94fd3..bfc145f052 100644
--- a/plugins/ruflo-metaharness/scripts/evolve.mjs
+++ b/plugins/ruflo-metaharness/scripts/evolve.mjs
@@ -48,10 +48,37 @@
// 2 config error or evolution failure
// 99 reserved β€” upstream "safety-disqualified" (propagated)
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runDarwinAsync, emitDarwinDegradedJsonAndExit, importGepa } from './_darwin.mjs';
import { existsSync, readdirSync, readFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
+guardCliArgs(import.meta.url, {
+ '--repo': 'value',
+ '--generations': 'value',
+ '--children': 'value',
+ '--concurrency': 'value',
+ '--seed': 'value',
+ '--sandbox': 'value',
+ '--selection': 'value',
+ '--crossover': null,
+ '--epistasis': null,
+ '--curriculum': null,
+ '--risk-budget': 'value',
+ '--fdr': 'value',
+ '--tie': 'value',
+ '--bench': 'value',
+ '--mutator': 'value',
+ '--ruvllm-url': 'value',
+ '--ruvllm-model': 'value',
+ '--confirm': null,
+ '--alert-on-no-improvement': null,
+ '--diagnose': null,
+ '--format': 'value',
+ '--timeout-ms': 'value',
+});
+
const ARGS = (() => {
const a = {
repo: '.',
diff --git a/plugins/ruflo-metaharness/scripts/genome.mjs b/plugins/ruflo-metaharness/scripts/genome.mjs
index 2f3cc0945f..a6fbfadca9 100755
--- a/plugins/ruflo-metaharness/scripts/genome.mjs
+++ b/plugins/ruflo-metaharness/scripts/genome.mjs
@@ -14,8 +14,16 @@
// 1 --alert-on-risk-above threshold breached
// 2 config error or genome failure (no valid readiness report)
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runMetaharness, emitDegradedJsonAndExit } from './_harness.mjs';
+guardCliArgs(import.meta.url, {
+ '--path': 'value',
+ '--alert-on-risk-above': 'value',
+ '--format': 'value',
+});
+
const ARGS = (() => {
const a = { path: '.', format: 'json', alertRiskAbove: null };
for (let i = 2; i < process.argv.length; i++) {
diff --git a/plugins/ruflo-metaharness/scripts/gepa.mjs b/plugins/ruflo-metaharness/scripts/gepa.mjs
index e718083715..f6f8078495 100644
--- a/plugins/ruflo-metaharness/scripts/gepa.mjs
+++ b/plugins/ruflo-metaharness/scripts/gepa.mjs
@@ -35,12 +35,24 @@
// 1 --alert-on-invalid and validate found errors
// 2 config error (bad op / missing file)
+import { guardCliArgs } from './_cli-args.mjs';
+
import { readFileSync, existsSync } from 'node:fs';
import { importGepa, DARWIN_VERSION_PIN } from './_darwin.mjs';
// Pin lives in _darwin.mjs (DARWIN_VERSION_PIN) β€” single source of truth.
const DARWIN_PIN_VERSION = DARWIN_VERSION_PIN.split('@').pop();
+guardCliArgs(import.meta.url, {
+ '--op': 'value',
+ '--path': 'value',
+ '--transcript': 'value',
+ '--ext': 'value',
+ '--glob': 'value',
+ '--alert-on-invalid': null,
+ '--format': 'value',
+});
+
const ARGS = (() => {
const a = {
op: null,
diff --git a/plugins/ruflo-metaharness/scripts/learn.mjs b/plugins/ruflo-metaharness/scripts/learn.mjs
index 9206a712a8..d76fa924b9 100644
--- a/plugins/ruflo-metaharness/scripts/learn.mjs
+++ b/plugins/ruflo-metaharness/scripts/learn.mjs
@@ -26,9 +26,22 @@
// 1 --alert-on-fail and the learn run reported failure
// 2 config error (bad arg)
+import { guardCliArgs } from './_cli-args.mjs';
+
import { existsSync } from 'node:fs';
import { runMetaharnessAsync, emitDegradedJsonAndExit } from './_harness.mjs';
+guardCliArgs(import.meta.url, {
+ '--host': 'value',
+ '--model': 'value',
+ '--slice': 'value',
+ '--repo': 'value',
+ '--run': null,
+ '--alert-on-fail': null,
+ '--format': 'value',
+ '--timeout-ms': 'value',
+});
+
const ARGS = (() => {
const a = {
host: null,
diff --git a/plugins/ruflo-metaharness/scripts/mcp-scan.mjs b/plugins/ruflo-metaharness/scripts/mcp-scan.mjs
index a98aecbcde..bea39897eb 100755
--- a/plugins/ruflo-metaharness/scripts/mcp-scan.mjs
+++ b/plugins/ruflo-metaharness/scripts/mcp-scan.mjs
@@ -20,8 +20,16 @@
// can use the same parser without duplicating logic.
// iter 63 β€” SEVERITY_RANK also moves to _harness.mjs (single source of
// truth; previously this file had a literal that diverged from oia-audit's).
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runHarness, emitDegradedJsonAndExit, parseMcpScanText, SEVERITY_RANK, rankSeverity } from './_harness.mjs';
+guardCliArgs(import.meta.url, {
+ '--path': 'value',
+ '--fail-on': 'value',
+ '--format': 'value',
+});
+
const ARGS = (() => {
const a = { path: '.', format: 'json', failOn: 'high' };
for (let i = 2; i < process.argv.length; i++) {
diff --git a/plugins/ruflo-metaharness/scripts/mint.mjs b/plugins/ruflo-metaharness/scripts/mint.mjs
index 9c8ddab026..110e5ac02a 100755
--- a/plugins/ruflo-metaharness/scripts/mint.mjs
+++ b/plugins/ruflo-metaharness/scripts/mint.mjs
@@ -15,11 +15,22 @@
// node scripts/mint.mjs --name my-harness --template vertical:coding --host claude-code --target /tmp/foo --confirm
// # β†’ actually scaffolds
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runMetaharness, emitDegradedJsonAndExit } from './_harness.mjs';
import { existsSync, mkdirSync } from 'node:fs';
import { resolve, dirname, basename } from 'node:path';
import { tmpdir } from 'node:os';
+guardCliArgs(import.meta.url, {
+ '--name': 'value',
+ '--template': 'value',
+ '--host': 'value',
+ '--target': 'value',
+ '--confirm': null,
+ '--format': 'value',
+});
+
const ARGS = (() => {
const a = { name: null, template: null, host: 'claude-code', target: null, confirm: false, format: 'json' };
for (let i = 2; i < process.argv.length; i++) {
diff --git a/plugins/ruflo-metaharness/scripts/oia-audit.mjs b/plugins/ruflo-metaharness/scripts/oia-audit.mjs
index e3ee487485..1784764b93 100755
--- a/plugins/ruflo-metaharness/scripts/oia-audit.mjs
+++ b/plugins/ruflo-metaharness/scripts/oia-audit.mjs
@@ -24,6 +24,8 @@
// 1 --alert-on-worst threshold exceeded
// 2 config error or audit failure
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runRufloCli } from './_invoke.mjs';
// iter 63 β€” SEVERITY_RANK + rankSeverity consolidated to _harness.mjs
// (was local in iter 62; now shared with audit-trend + mcp-scan).
@@ -38,6 +40,13 @@ const NS = process.env.OIA_AUDIT_NAMESPACE || 'metaharness-audit';
// resolution per call, possible version skew, fails without registry access).
// CLI_CORE=1 still opts into `npx @claude-flow/cli-core@alpha`.
+guardCliArgs(import.meta.url, {
+ '--path': 'value',
+ '--dry-run': null,
+ '--alert-on-worst': 'value',
+ '--format': 'value',
+}, "Runs and persists an audit by default. --dry-run skips the memory write; analysis tools still run.");
+
const ARGS = (() => {
const a = { path: '.', format: 'json', dryRun: false, alertWorst: null };
for (let i = 2; i < process.argv.length; i++) {
diff --git a/plugins/ruflo-metaharness/scripts/router-parallel-analyze.mjs b/plugins/ruflo-metaharness/scripts/router-parallel-analyze.mjs
index cdcc7c2bc5..c44fd3c556 100755
--- a/plugins/ruflo-metaharness/scripts/router-parallel-analyze.mjs
+++ b/plugins/ruflo-metaharness/scripts/router-parallel-analyze.mjs
@@ -33,8 +33,16 @@
// 1 --strict requested AND at least one criterion failed (NOT promotable)
// 2 config error or input file missing/malformed
+import { guardCliArgs } from './_cli-args.mjs';
+
import { readFileSync, existsSync } from 'node:fs';
+guardCliArgs(import.meta.url, {
+ '--input': 'value',
+ '--format': 'value',
+ '--strict': null,
+});
+
const ARGS = (() => {
const a = { input: '.swarm/router-parallel.jsonl', format: 'table', strict: false };
for (let i = 2; i < process.argv.length; i++) {
diff --git a/plugins/ruflo-metaharness/scripts/score.mjs b/plugins/ruflo-metaharness/scripts/score.mjs
index e2d31aa3c8..ae448ea101 100755
--- a/plugins/ruflo-metaharness/scripts/score.mjs
+++ b/plugins/ruflo-metaharness/scripts/score.mjs
@@ -16,8 +16,16 @@
// 1 --alert-on-fit-below threshold breached
// 2 config error or scoring failure
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runMetaharness, emitDegradedJsonAndExit } from './_harness.mjs';
+guardCliArgs(import.meta.url, {
+ '--path': 'value',
+ '--alert-on-fit-below': 'value',
+ '--format': 'value',
+});
+
const ARGS = (() => {
const a = { path: '.', format: 'json', alertFitBelow: null };
for (let i = 2; i < process.argv.length; i++) {
diff --git a/plugins/ruflo-metaharness/scripts/security-bench.mjs b/plugins/ruflo-metaharness/scripts/security-bench.mjs
index 436ac11c6d..97d8f41e7d 100644
--- a/plugins/ruflo-metaharness/scripts/security-bench.mjs
+++ b/plugins/ruflo-metaharness/scripts/security-bench.mjs
@@ -30,8 +30,19 @@
// 1 --alert-on-fail and any acceptance gate failed
// 2 config error or bench infrastructure failure
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runDarwinAsync, emitDarwinDegradedJsonAndExit } from './_darwin.mjs';
+guardCliArgs(import.meta.url, {
+ '--population': 'value',
+ '--cycles': 'value',
+ '--seed': 'value',
+ '--alert-on-fail': null,
+ '--format': 'value',
+ '--timeout-ms': 'value',
+}, "Runs the security benchmark. This command has no plan-only mode.");
+
const ARGS = (() => {
const a = {
population: 2,
diff --git a/plugins/ruflo-metaharness/scripts/similarity.mjs b/plugins/ruflo-metaharness/scripts/similarity.mjs
index 50e042d13b..c7dedfcd65 100755
--- a/plugins/ruflo-metaharness/scripts/similarity.mjs
+++ b/plugins/ruflo-metaharness/scripts/similarity.mjs
@@ -23,6 +23,8 @@
// a structured `{ degraded: true, reason: ... }` payload on stdout
// - CI-gate ready: smoke step 17y locks this contract
+import { guardCliArgs } from './_cli-args.mjs';
+
import { readFileSync, existsSync } from 'node:fs';
import { runRufloCli } from './_invoke.mjs';
import { similarity } from './_similarity.mjs';
@@ -33,6 +35,16 @@ const NS = process.env.HARNESS_SIMILARITY_NAMESPACE || 'metaharness-audit';
// resolution per call, possible version skew, fails without registry access).
// CLI_CORE=1 still opts into `npx @claude-flow/cli-core@alpha`.
+guardCliArgs(import.meta.url, {
+ '--a': 'value',
+ '--b': 'value',
+ '--a-key': 'value',
+ '--b-key': 'value',
+ '--per-dimension': null,
+ '--format': 'value',
+ '--alert-below': 'value',
+});
+
const ARGS = (() => {
const a = {
aFile: null, bFile: null,
diff --git a/plugins/ruflo-metaharness/scripts/test-cli-help.mjs b/plugins/ruflo-metaharness/scripts/test-cli-help.mjs
new file mode 100644
index 0000000000..2fa5411e92
--- /dev/null
+++ b/plugins/ruflo-metaharness/scripts/test-cli-help.mjs
@@ -0,0 +1,72 @@
+#!/usr/bin/env node
+// Hermetic CLI entry-point checks: no optional tools, network, or real memory writes.
+import { test, before, after } from 'node:test';
+import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
+import { cpSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync, existsSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const scripts = ['audit-list', 'audit-trend', 'bench', 'bench-parse-mcp-scan', 'bench-recordpair-overhead',
+ 'bench-similarity', 'drift-from-history', 'evolve', 'genome', 'gepa', 'learn', 'mcp-scan', 'mint',
+ 'oia-audit', 'router-parallel-analyze', 'score', 'security-bench', 'similarity', 'threat-model'];
+let root;
+let entryDir;
+let cwd;
+let guard;
+before(() => {
+ root = mkdtempSync(join(tmpdir(), 'metaharness-help-'));
+ entryDir = join(root, 'scripts');
+ cwd = join(root, 'workspace');
+ mkdirSync(cwd);
+ cpSync(dirname(fileURLToPath(import.meta.url)), entryDir, { recursive: true });
+ guard = join(root, 'guard.cjs');
+ writeFileSync(guard, `
+ const cp = require('node:child_process');
+ const fs = require('node:fs');
+ const append = fs.appendFileSync;
+ const blocked = name => (...args) => {
+ append(process.env.ATTEMPT_LOG, name + '\\n');
+ throw new Error('test blocked side effect: ' + name);
+ };
+ for (const name of ['spawn', 'spawnSync', 'exec', 'execSync', 'execFile', 'execFileSync', 'fork']) cp[name] = blocked(name);
+ for (const name of ['writeFileSync', 'appendFileSync', 'mkdirSync', 'mkdtempSync', 'renameSync', 'unlinkSync', 'rmSync']) fs[name] = blocked(name);
+ require('node:module').syncBuiltinESMExports();
+ `);
+});
+after(() => rmSync(root, { recursive: true, force: true }));
+
+function invoke(script, args) {
+ const log = join(root, 'attempts');
+ rmSync(log, { force: true });
+ const result = spawnSync(process.execPath, ['--require', guard, join(entryDir, script + '.mjs'), ...args], {
+ cwd, encoding: 'utf8', timeout: 3000,
+ env: { ...process.env, HOME: root, USERPROFILE: root, ATTEMPT_LOG: log, NODE_OPTIONS: '' },
+ });
+ return { ...result, attempts: existsSync(log) ? readFileSync(log, 'utf8') : '' };
+}
+
+for (const script of scripts) {
+ for (const flag of ['--help', '-h']) {
+ test(`${script} ${flag} prints help before any side effects`, () => {
+ const result = invoke(script, [flag]);
+ assert.equal(result.status, 0, result.stderr);
+ assert.match(result.stdout, /Usage:/);
+ assert.equal(result.attempts, '', 'no subprocess or write may be attempted');
+ assert.deepEqual(readdirSync(cwd), []);
+ });
+ }
+ test(`${script} rejects an unknown flag without running`, () => {
+ const result = invoke(script, ['--definitely-unknown']);
+ assert.equal(result.status, 2, result.stderr);
+ assert.match(result.stderr, /Unknown argument/);
+ assert.equal(result.attempts, '');
+ });
+}
+for (const args of [['--path'], ['--path', '--dry-run']]) test(`missing option value ${args.join(' ')} does not run`, () => {
+ const result = invoke('oia-audit', args);
+ assert.equal(result.status, 2);
+ assert.match(result.stderr, /requires a value/);
+ assert.equal(result.attempts, '');
+});
diff --git a/plugins/ruflo-metaharness/scripts/threat-model.mjs b/plugins/ruflo-metaharness/scripts/threat-model.mjs
index b3c2566eda..b87003deed 100755
--- a/plugins/ruflo-metaharness/scripts/threat-model.mjs
+++ b/plugins/ruflo-metaharness/scripts/threat-model.mjs
@@ -4,10 +4,18 @@
// USAGE
// node scripts/threat-model.mjs --path . --fail-on high --format json
+import { guardCliArgs } from './_cli-args.mjs';
+
import { runHarness, emitDegradedJsonAndExit } from './_harness.mjs';
const SEVERITY_RANK = { clean: 0, low: 1, medium: 2, high: 3 };
+guardCliArgs(import.meta.url, {
+ '--path': 'value',
+ '--fail-on': 'value',
+ '--format': 'value',
+});
+
const ARGS = (() => {
const a = { path: '.', format: 'json', failOn: 'high' };
for (let i = 2; i < process.argv.length; i++) {