From 0352da8033a50ff69b289c92803520cf73f5d77a Mon Sep 17 00:00:00 2001 From: r Date: Tue, 10 Nov 2026 13:07:04 -0500 Subject: [PATCH 1/4] test(metaharness): report darwin resolution path and subprocess tails on bench parity mismatch bench.mjs now adds a top-level darwinSource field to every JSON payload (library | cli-local | cli-cache | none). A degraded payload also carries the darwin CLI's exit code and stderr tail. Existing fields and exit codes are unchanged. runDarwin() returns the resolved bin source, and the shared degraded emitter takes optional extra diagnostic fields. darwin-inprocess-adr526 puts darwinSource, the degraded reason, and the stdout/stderr tails in the assertion message when the bench.mjs subprocess exit code is not the expected one. Refs #4930 Co-Authored-By: RuFlo --- plugins/ruflo-metaharness/scripts/_darwin.mjs | 4 +++ plugins/ruflo-metaharness/scripts/_invoke.mjs | 4 ++- plugins/ruflo-metaharness/scripts/bench.mjs | 20 +++++++++++-- .../__tests__/darwin-inprocess-adr526.test.ts | 28 +++++++++++++++---- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/plugins/ruflo-metaharness/scripts/_darwin.mjs b/plugins/ruflo-metaharness/scripts/_darwin.mjs index 0518d31751..2c3faf828e 100644 --- a/plugins/ruflo-metaharness/scripts/_darwin.mjs +++ b/plugins/ruflo-metaharness/scripts/_darwin.mjs @@ -156,6 +156,8 @@ export function runDarwin(args, opts = {}) { shell: false, }); const durationMs = Date.now() - start; + // #4930 — which bin ran (`local` install or `cache` install), for diagnostics. + const source = resolved.source; const stdout = r.stdout || ''; const stderr = r.stderr || ''; const classified = classifyDegraded(stderr, r.status, REASON_PREFIX); @@ -167,6 +169,7 @@ export function runDarwin(args, opts = {}) { durationMs, degraded: true, reason: classified.reason, + source, }; } return { @@ -175,6 +178,7 @@ export function runDarwin(args, opts = {}) { json: wantJson ? maybeParseJson(stdout) : null, durationMs, degraded: false, + source, }; } diff --git a/plugins/ruflo-metaharness/scripts/_invoke.mjs b/plugins/ruflo-metaharness/scripts/_invoke.mjs index 62ae6f11a0..33eabb343a 100644 --- a/plugins/ruflo-metaharness/scripts/_invoke.mjs +++ b/plugins/ruflo-metaharness/scripts/_invoke.mjs @@ -272,10 +272,12 @@ export async function importOptionalLibrary({ specifier, pkg, pinVersion, entryR * Build the per-package `emit*DegradedJsonAndExit(reason)` helper. Emits the * structured degraded payload and exits 0 — ADR-150 architectural constraint * rule #3: ruflo continues to function when MetaHarness is absent. + * `extra` (optional) adds diagnostic fields; it never overrides the fixed ones. */ export function makeDegradedEmitter(pkg, pinVersion) { - return function emitDegradedAndExit(reason) { + return function emitDegradedAndExit(reason, extra = {}) { const payload = { + ...extra, degraded: true, reason, hint: `Install with \`npm i -D ${pkg}@${pinVersion}\` (pinned range — this plugin never fetches @latest) or verify network access for the one-time cache install.`, diff --git a/plugins/ruflo-metaharness/scripts/bench.mjs b/plugins/ruflo-metaharness/scripts/bench.mjs index 628a729600..f944e37ba3 100644 --- a/plugins/ruflo-metaharness/scripts/bench.mjs +++ b/plugins/ruflo-metaharness/scripts/bench.mjs @@ -17,6 +17,14 @@ // 0 ok (or degraded — Darwin not available) // 1 --op verify and any task malformed // 2 config error or upstream invocation failure +// +// DIAGNOSTICS (#4930) +// Every JSON payload carries a top-level `darwinSource`: which darwin ran. +// library — bare import of @metaharness/darwin, verified in-process +// cli-local — darwin CLI from an installed copy next to this plugin +// cli-cache — darwin CLI from the one-time ~/.ruflo/darwin-cache- install +// none — darwin could not be resolved at all (degraded) +// A degraded payload also carries the upstream exit code and stderr tail. import { guardCliArgs } from './_cli-args.mjs'; @@ -80,6 +88,7 @@ async function verifyInProcess() { exitCode = check.ok ? 0 : 1; payload = { success: check.ok, + darwinSource: 'library', data: { op: 'verify', suiteId: suite.id, version: suite.version, tasks, hashOk: check.ok, hash: check.actual, stdoutTail: `Suite ${suite.id}@${suite.version}: ${tasks} tasks, hash ${check.ok ? 'OK' : 'MISMATCH'} (${String(check.actual).slice(0, 12)}…)\n`, @@ -89,7 +98,7 @@ async function verifyInProcess() { }; } catch (e) { exitCode = 1; - payload = { success: false, data: { op: 'verify', error: e?.message ?? String(e), durationMs: Date.now() - start }, generatedAt: new Date().toISOString() }; + payload = { success: false, darwinSource: 'library', data: { op: 'verify', error: e?.message ?? String(e), durationMs: Date.now() - start }, generatedAt: new Date().toISOString() }; } console.log(JSON.stringify(payload, null, 2)); process.exit(exitCode); @@ -104,15 +113,21 @@ async function main() { : ['bench', 'verify', resolve(ARGS.suite)]; const r = runDarwin(cliArgs, { timeoutMs: 60_000 }); + const darwinSource = r.source ? `cli-${r.source}` : 'none'; if (r.degraded) { - emitDarwinDegradedJsonAndExit(r.reason); + emitDarwinDegradedJsonAndExit(r.reason, { + darwinSource, + upstreamExitCode: r.exitCode, + stderrTail: String(r.stderr ?? '').slice(-1200), + }); return; } if (r.exitCode !== 0 && r.exitCode !== 1) { const payload = { success: false, + darwinSource, data: { exitCode: r.exitCode, stderrTail: r.stderr.slice(-400) }, generatedAt: new Date().toISOString(), }; @@ -122,6 +137,7 @@ async function main() { const payload = { success: r.exitCode === 0, + darwinSource, data: { op: ARGS.op, ...(r.json ?? { stdoutTail: r.stdout.slice(-2000) }), diff --git a/v3/@claude-flow/cli/__tests__/darwin-inprocess-adr526.test.ts b/v3/@claude-flow/cli/__tests__/darwin-inprocess-adr526.test.ts index 2d6c089552..5cba66678e 100644 --- a/v3/@claude-flow/cli/__tests__/darwin-inprocess-adr526.test.ts +++ b/v3/@claude-flow/cli/__tests__/darwin-inprocess-adr526.test.ts @@ -22,12 +22,30 @@ function findDarwinCli(): string { } const DARWIN_CLI = findDarwinCli(); -function runScript(name: string, args: string[]): { exitCode: number; json: unknown } { +interface ScriptRun { exitCode: number; json: unknown; stdout: string; stderr: string; signal: string | null } + +function runScript(name: string, args: string[]): ScriptRun { const r = spawnSync(process.execPath, [join(SCRIPTS, name), ...args, '--format', 'json'], { encoding: 'utf8', timeout: 60_000 }); - const m = /\{[\s\S]*\}/.exec(r.stdout ?? ''); + const stdout = r.stdout ?? ''; + const m = /\{[\s\S]*\}/.exec(stdout); let json: unknown = null; if (m) { try { json = JSON.parse(m[0]); } catch { /* null */ } } - return { exitCode: r.status ?? -1, json }; + return { exitCode: r.status ?? -1, json, stdout, stderr: r.stderr ?? '', signal: r.signal }; +} + +/** + * #4930 — failure message for a subprocess exit-code mismatch: which darwin + * the script resolved (`darwinSource`: library | cli-local | cli-cache | none), + * whether it reported itself degraded, and the stdout/stderr tails. + */ +function describeRun(label: string, r: ScriptRun): string { + const j = (r.json ?? {}) as { darwinSource?: unknown; degraded?: unknown; reason?: unknown }; + return [ + `${label}: exit ${r.exitCode}${r.signal ? ` (signal ${r.signal})` : ''}`, + `darwinSource=${String(j.darwinSource ?? 'unreported')} degraded=${String(j.degraded ?? false)}${j.reason ? ` reason=${String(j.reason)}` : ''}`, + `--- stdout tail ---\n${r.stdout.slice(-1500)}`, + `--- stderr tail ---\n${r.stderr.slice(-1500)}`, + ].join('\n'); } /** @@ -87,7 +105,7 @@ describe('ADR-526 darwin in-process parity', () => { const inProc = await benchVerify(suite); const sub = runScript('bench.mjs', ['--op', 'verify', '--suite', suite]); expect(inProc!.exitCode).toBe(0); - expect(sub.exitCode).toBe(0); + expect(sub.exitCode, describeRun('bench.mjs --op verify (good suite)', sub)).toBe(0); const p = inProc!.json as { success: boolean; data: Record }; const s = sub.json as { success: boolean; data: Record }; expect(p.success).toBe(s.success); @@ -109,7 +127,7 @@ describe('ADR-526 darwin in-process parity', () => { const inProc = await benchVerify(tampered); const sub = runScript('bench.mjs', ['--op', 'verify', '--suite', tampered]); expect(inProc!.exitCode).toBe(1); - expect(sub.exitCode).toBe(1); + expect(sub.exitCode, describeRun('bench.mjs --op verify (tampered suite)', sub)).toBe(1); expect((inProc!.json as { success: boolean }).success).toBe(false); }); }); From 0383c7e7b6bfe621d76c8406b73700e473ada5b0 Mon Sep 17 00:00:00 2001 From: r Date: Tue, 10 Nov 2026 13:11:09 -0500 Subject: [PATCH 2/4] fix(metaharness): do not classify a "404" inside a hex digest as darwin unavailable DEGRADED_RX matched any 404 substring. When bench.mjs cannot import darwin (CI's Test V3 Packages job installs only v3/ with pnpm, so the plugin script finds no @metaharness/darwin and runs the cached darwin CLI), darwin reports a tampered suite on stderr with both sha256 digests. A digest containing "404", about 3% of tampered suites, made classifyDegraded() report the tamper as "darwin not available", and the script exited 0 instead of 1. The 404 token now has to stand alone ("404 Not Found", "E404"). The regression test runs classifyDegraded on a tamper message whose digests contain 404, and checks that the npm 404 forms are still classified as unavailable. Refs #4930 Co-Authored-By: RuFlo --- plugins/ruflo-metaharness/scripts/_invoke.mjs | 7 ++++- .../__tests__/darwin-inprocess-adr526.test.ts | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plugins/ruflo-metaharness/scripts/_invoke.mjs b/plugins/ruflo-metaharness/scripts/_invoke.mjs index 33eabb343a..93d39b625c 100644 --- a/plugins/ruflo-metaharness/scripts/_invoke.mjs +++ b/plugins/ruflo-metaharness/scripts/_invoke.mjs @@ -58,7 +58,12 @@ const INSTALL_TIMEOUT_MS = 180_000; // npm install can be slow on cold cache // Superset of the three per-file regexes. `npm ERR` (from _redblue) is // included for everyone: an npm-level failure during a cached install or an // npx shim means "upstream unavailable", never a ruflo bug. -export const DEGRADED_RX = /could not determine executable|404|not installed|MODULE_NOT_FOUND|ENOTFOUND|getaddrinfo|ECONNREFUSED|ETIMEDOUT|npm ERR/i; +// +// `404` must be a whole token (`404 Not Found`, `E404`), never three digits +// inside a longer word (#4930): darwin's `bench verify` reports a tampered +// suite with both sha256 hex digests on stderr, and a digest containing +// "404" (~3% of tampered suites) turned exit 1 into degraded exit 0. +export const DEGRADED_RX = /could not determine executable|\bE?404\b|not installed|MODULE_NOT_FOUND|ENOTFOUND|getaddrinfo|ECONNREFUSED|ETIMEDOUT|npm ERR/i; /** * Classify a finished subprocess as degraded or healthy. diff --git a/v3/@claude-flow/cli/__tests__/darwin-inprocess-adr526.test.ts b/v3/@claude-flow/cli/__tests__/darwin-inprocess-adr526.test.ts index 5cba66678e..280608a7bf 100644 --- a/v3/@claude-flow/cli/__tests__/darwin-inprocess-adr526.test.ts +++ b/v3/@claude-flow/cli/__tests__/darwin-inprocess-adr526.test.ts @@ -131,3 +131,34 @@ describe('ADR-526 darwin in-process parity', () => { expect((inProc!.json as { success: boolean }).success).toBe(false); }); }); + +/** + * #4930 — the root cause of the flake. Where the plugin script cannot import + * darwin (CI's v3-only pnpm install), bench.mjs runs the darwin CLI, which + * prints both sha256 digests of a tampered suite to stderr. The degraded + * classifier matched any "404", so a digest containing it turned exit 1 into + * degraded exit 0. + */ +describe('#4930 degraded classification ignores "404" inside hex digests', () => { + type Classify = (stderr: string, exitCode: number | null, prefix: string) => { degraded: boolean; reason?: string }; + let classifyDegraded: Classify; + + beforeAll(async () => { + ({ classifyDegraded } = (await import(join(SCRIPTS, '_invoke.mjs'))) as { classifyDegraded: Classify }); + }); + + it('a tampered-suite error whose digests contain 404 is a real failure', () => { + const stderr = 'Error: benchmark suite tampered: taskHash 89e4265664cd17b0c2a1f404e8d1 != recomputed 404a1b2c3d4e5f60718293a4b5c6d7e8f9\n at loadSuite (file:///x/suite.js:50:15)\n'; + expect(classifyDegraded(stderr, 1, 'metaharness-darwin')).toEqual({ degraded: false }); + }); + + it('still treats npm 404s as unavailable', () => { + for (const stderr of [ + 'npm error code E404\nnpm error 404 Not Found - GET https://registry.npmjs.org/@metaharness%2fdarwin', + 'npm error code E404', + '404 Not Found', + ]) { + expect(classifyDegraded(stderr, 1, 'metaharness-darwin')).toEqual({ degraded: true, reason: 'metaharness-darwin-not-available' }); + } + }); +}); From 20ef74393566ae18b89a830203170d98c97038de Mon Sep 17 00:00:00 2001 From: r Date: Tue, 10 Nov 2026 14:07:30 -0500 Subject: [PATCH 3/4] chore(ruflo-metaharness): bump plugin to 0.5.1 Co-Authored-By: RuFlo --- plugins/ruflo-metaharness/.claude-plugin/plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ruflo-metaharness/.claude-plugin/plugin.json b/plugins/ruflo-metaharness/.claude-plugin/plugin.json index cbb5c62e46..3e8648b086 100644 --- a/plugins/ruflo-metaharness/.claude-plugin/plugin.json +++ b/plugins/ruflo-metaharness/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "ruflo-metaharness", "description": "MetaHarness integration for ruflo — surfaces score/genome/mint/mcp-scan/threat-model via skills; pairs with @metaharness/router (ADR-148/149) for cost-optimal model routing; honors ADR-150's architectural constraint that MetaHarness remains an optional augmentation, never a required runtime dependency. As a mod (ADR-445): confirms flywheel promotion, keeps secrets out of inputs, /metaharness-mod, and a status file the console shows", - "version": "0.5.0", + "version": "0.5.1", "repository": "https://github.com/ruvnet/ruflo", "author": { "name": "ruvnet", From 871f2ff35bdc507007c3363399b8e57d63175d24 Mon Sep 17 00:00:00 2001 From: r Date: Tue, 10 Nov 2026 14:57:47 -0500 Subject: [PATCH 4/4] test(ruflo-metaharness): smoke accepts any plugin version from 0.5.0 up The exact-match check broke on every ruflo-metaharness version bump. Co-Authored-By: RuFlo --- plugins/ruflo-metaharness/scripts/smoke.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.sh index e7e8b9dfd0..a6b355d932 100755 --- a/plugins/ruflo-metaharness/scripts/smoke.sh +++ b/plugins/ruflo-metaharness/scripts/smoke.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Structural smoke test for ruflo-metaharness v0.5.0 (ADR-150 Phase 1). +# Structural smoke test for ruflo-metaharness v0.5.0+ (ADR-150 Phase 1). set -u ROOT="$(cd "$(dirname "$0")/.." && pwd)" PASS=0 @@ -32,10 +32,10 @@ else bad "extraction-regex-rot: EXPECTED_TOOLS=$EXPECTED_TOOLS EXPECTED_SUBS=$EXPECTED_SUBS" fi -step "1. plugin.json declares 0.5.0 with adr-150 keywords" +step "1. plugin.json declares 0.5.0 or later with adr-150 keywords" v=$(grep -E '"version"' "$ROOT/.claude-plugin/plugin.json" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) -if [[ "$v" != "0.5.0" ]]; then - bad "expected 0.5.0, got '$v'" +if [[ -z "$v" || "$(printf "%s\n%s\n" 0.5.0 "$v" | sort -V | head -1)" != "0.5.0" ]]; then + bad "expected 0.5.0 or later, got '$v'" else miss="" for k in ruflo metaharness harness scorecard genome mcp-scan threat-model router adr-150 adr-148 adr-149 optional-dependency graceful-degradation subprocess phase-1-mvp; do