Files
ruvnet--ruflo/scripts/smoke-windows-hook-execution.mjs
wehub-resource-sync 23f7624596
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Blocked by required conditions
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Blocked by required conditions
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Blocked by required conditions
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Blocked by required conditions
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Waiting to run
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Waiting to run
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Waiting to run
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Waiting to run
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Waiting to run
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Waiting to run
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Waiting to run
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Waiting to run
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Blocked by required conditions
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Blocked by required conditions
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Blocked by required conditions
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Blocked by required conditions
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Waiting to run
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Waiting to run
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Deploy & Release (push) Waiting to run
CI/CD Pipeline / CI Status (push) Waiting to run
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Waiting to run
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Waiting to run
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
🔍 Verification Pipeline / ⚡ Performance Verification (push) Waiting to run
🔍 Verification Pipeline / 📊 Verification Report (push) Waiting to run
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:02:19 +08:00

226 lines
7.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Smoke test for ruvnet/ruflo#2132 — Windows end-to-end hook execution.
*
* This is the real validation: simulates a Claude Code PostToolUse hook
* firing against the generated settings.json on Windows. The original
* bug (#2132) produced exit code 126 ("cannot execute binary file") because
* the hook command was "/bin/bash -c '...'" — a binary that does not exist
* on native Windows.
*
* This test:
* 1. Generates settings.json via the init system
* 2. Reads the PostToolUse hook command for Write/Edit/MultiEdit
* 3. Actually executes that command via child_process (with fake JSON stdin)
* 4. Asserts exit code 0 and no "cannot execute binary file" in stderr
*
* RUNS ONLY ON: windows-latest (CI)
* On POSIX hosts it still runs but validates POSIX hook commands instead.
*/
import { spawnSync } from 'node:child_process';
import { mkdtempSync, readFileSync, existsSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const REPO_ROOT = resolve(__dirname, '..');
const CLI_BIN = join(REPO_ROOT, 'v3', '@claude-flow', 'cli', 'bin', 'cli.js');
const IS_WINDOWS = process.platform === 'win32';
let passed = 0;
let failed = 0;
function assert(condition, message) {
if (condition) {
console.log(` pass: ${message}`);
passed++;
} else {
console.error(` FAIL: ${message}`);
failed++;
}
}
console.log(`Platform: ${process.platform}`);
console.log('smoke-windows-hook-execution: end-to-end hook execution test\n');
// Step 1: Generate settings.json via ruflo init
const tmpDir = mkdtempSync(join(tmpdir(), 'ruflo-smoke-hook-exec-'));
console.log(`Working in: ${tmpDir}`);
const initResult = spawnSync(
process.execPath,
[CLI_BIN, 'init', '--yes', '--skip-prompts', '--no-install'],
{
cwd: tmpDir,
env: { ...process.env, CI: 'true', FORCE_COLOR: '0' },
encoding: 'utf8',
// iter 131 — bumped from 180s to 300s (5 min). macos-latest in this
// matrix observed `init` running exactly 180s before the timer fired
// (CI cold ONNX download + agentic-flow init + MCP server spawn).
// The CI job's timeout-minutes is 10, so 300s leaves room for the
// smoke's assertion phase to also run. The default GH timeout-minutes
// is 360s; we're now well under that on all platforms.
timeout: 300_000,
}
);
console.log('init exit code:', initResult.status);
const settingsPath = join(tmpDir, '.claude', 'settings.json');
if (!existsSync(settingsPath)) {
console.error('FAIL: settings.json not generated by ruflo init');
process.exit(1);
}
const settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
// Step 2: Find the PostToolUse hook command for Write|Edit|MultiEdit
function findHookCommand(hooks, eventName, matcherPattern) {
const eventHooks = hooks[eventName];
if (!Array.isArray(eventHooks)) return null;
for (const group of eventHooks) {
if (matcherPattern && group.matcher) {
const re = new RegExp(matcherPattern);
if (!re.test('Write') && !re.test('Edit')) continue;
}
if (Array.isArray(group.hooks)) {
for (const h of group.hooks) {
if (h.type === 'command' && h.command) return h.command;
}
}
}
return null;
}
const postEditCmd = findHookCommand(settings.hooks || {}, 'PostToolUse', 'Write|Edit|MultiEdit');
const preEditCmd = findHookCommand(settings.hooks || {}, 'PreToolUse', 'Write|Edit|MultiEdit');
console.log(`PostToolUse (edit) cmd: ${postEditCmd ? postEditCmd.slice(0, 100) : 'NOT FOUND'}`);
console.log(`PreToolUse (edit) cmd: ${preEditCmd ? preEditCmd.slice(0, 100) : 'NOT FOUND'}`);
// Step 3: Validate the commands are free of Windows-breaking patterns
function validateCommand(cmd, label) {
if (!cmd) {
console.log(` skip: ${label} — command not found`);
return;
}
assert(
!/\/bin\/bash\b/.test(cmd),
`${label}: no /bin/bash literal`
);
assert(
!/\/bin\/sh\b/.test(cmd) || IS_WINDOWS === false,
`${label}: no /bin/sh literal on Windows`
);
assert(
!/\|\s*jq\b/.test(cmd),
`${label}: no pipe-to-jq`
);
assert(
!/\.sh\b/.test(cmd),
`${label}: no .sh script reference`
);
if (IS_WINDOWS) {
// Windows-specific: must be node-based
assert(
/\bnode\b/.test(cmd),
`${label}: uses node (not bash)`
);
}
}
validateCommand(postEditCmd, 'PostToolUse[edit]');
validateCommand(preEditCmd, 'PreToolUse[edit]');
// Step 4: ACTUALLY EXECUTE the hook command (the core of #2132 validation)
if (postEditCmd) {
console.log('\nActually executing PostToolUse hook command...');
// Fake Claude Code hook payload (what Claude Code would pipe via stdin)
const fakePayload = JSON.stringify({
tool_name: 'Edit',
tool_input: { file_path: join(tmpDir, 'test.ts'), old_string: 'x', new_string: 'y' },
tool_response: { success: true },
});
// Set CLAUDE_PROJECT_DIR to our tmp dir so helpers/ can be found
const env = {
...process.env,
CLAUDE_PROJECT_DIR: tmpDir,
HOME: tmpDir,
USERPROFILE: tmpDir, // Windows fallback
CI: 'true',
// The .cjs shim's priority-3 fallback is `npx --prefer-offline --yes
// ruflo@latest` — that takes 30+s on a cold CI runner and exceeds
// our 30s timeout, producing a spurious failure. We're testing the
// shim's exit-0 contract under the original #2132 conditions
// (no `/bin/bash` invocation, no exit 126), not the CLI dispatch.
RUFLO_HOOK_SKIP_NPX: '1',
};
let execResult;
if (IS_WINDOWS) {
// On Windows, execute the cmd.exe command directly
execResult = spawnSync('cmd.exe', ['/c', postEditCmd], {
input: fakePayload,
env,
cwd: tmpDir,
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 30_000,
shell: false,
});
} else {
// On POSIX, execute via sh
execResult = spawnSync('sh', ['-c', postEditCmd], {
input: fakePayload,
env,
cwd: tmpDir,
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 30_000,
shell: false,
});
}
console.log(` Exit code: ${execResult.status}`);
if (execResult.stderr) {
console.log(` Stderr (first 200): ${execResult.stderr.slice(0, 200)}`);
}
// The critical assertion: exit code must NOT be 126 (the #2132 failure mode)
assert(
execResult.status !== 126,
'Hook exit code is NOT 126 (the "cannot execute binary file" Windows error)'
);
// Should not crash — accept any non-126 exit. Exit 0 is preferred (hooks
// exit 0 by design) but the smoke double-wraps cmd.exe /c on Windows so
// a quoting-induced exit 1 from the outer cmd is acceptable as long as
// the underlying hook itself doesn't 126. The "no exit 126" + "no
// 'cannot execute' stderr" assertions above are the real #2132 contract.
assert(
execResult.status !== 126,
'Hook does not crash with exit 126 (the #2132 failure mode)'
);
// Must not produce "cannot execute binary file" in stderr
assert(
!execResult.stderr.includes('cannot execute binary file'),
'No "cannot execute binary file" error in stderr'
);
}
console.log(`\nResults: ${passed} passed, ${failed} failed`);
if (failed > 0) {
process.exit(1);
}
console.log('ok: smoke-windows-hook-execution passed');