mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-05 06:56:22 +09:00
Merge pull request #4949 from ruvnet/test/4930-darwin-parity-diagnostics
test(metaharness): diagnose bench parity flake, fix 404-in-digest degraded misclassification (#4930)
This commit is contained in:
6 files changed
+90
-14
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -272,10 +277,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.`,
|
||||
|
||||
@@ -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-<pin> 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) }),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<string, unknown> };
|
||||
const s = sub.json as { success: boolean; data: Record<string, unknown> };
|
||||
expect(p.success).toBe(s.success);
|
||||
@@ -109,7 +127,38 @@ 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);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* #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' });
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user