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(cli): keep @ruvector/rvagent-wasm out of optionalDependencies (guard #2561); test the not-installed message without module mocking

r2e12025f1808
diff --git a/v3/@claude-flow/cli/__tests__/agent-wasm-not-installed-3979.test.ts b/v3/@claude-flow/cli/__tests__/agent-wasm-not-installed-3979.test.ts
index 33177853d8..e15d09d099 100644
--- a/v3/@claude-flow/cli/__tests__/agent-wasm-not-installed-3979.test.ts
+++ b/v3/@claude-flow/cli/__tests__/agent-wasm-not-installed-3979.test.ts
@@ -1,59 +1,49 @@
// #3979 item 1: `ruflo mcp exec -t wasm_gallery_list` on a global install failed with
// Failed to initialize @ruvector/rvagent-wasm: Error [ERR_MODULE_NOT_FOUND]: Cannot find package ...
-// because (a) the package is imported by dist/src/ruvector/agent-wasm.js but was not
-// declared in the CLI's package.json, so `npm i -g ruflo` never installed it, and
-// (b) when it is missing the error is a raw module-resolution trace rather than a
-// plain "not installed" message with the fix. Both are checked here.
+// a raw module-resolution trace. It is now "not installed" with the fix. The package stays OPTIONAL
+// and is deliberately NOT in the CLI's optionalDependencies (guard no-cli-optdep-bloat-2561).
+// The mapping is tested directly (no module mocking), so it does not depend on the test runner's
+// mock-factory error wrapping.
-import { describe, it, expect, vi, afterEach } from 'vitest';
+import { describe, it, expect } from 'vitest';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
+import { agentWasmLoadError, isMissingAgentWasm, AGENT_WASM_NOT_INSTALLED_MESSAGE } from '../src/ruvector/agent-wasm.js';
const pkg = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf8'));
-afterEach(() => {
- vi.resetModules();
- vi.doUnmock('@ruvector/rvagent-wasm');
-});
-
-describe('@ruvector/rvagent-wasm packaging (#3979 item 1)', () => {
- it('is declared as an optional dependency so a global install fetches it', () => {
- expect(pkg.optionalDependencies?.['@ruvector/rvagent-wasm']).toBeTruthy();
- // Optional, never a hard dependency: ruflo must still install and run without it.
+describe('@ruvector/rvagent-wasm stays optional (#3979 item 1, #2561)', () => {
+ it('is not a dependency or optionalDependency of the CLI (bloat guard)', () => {
expect(pkg.dependencies?.['@ruvector/rvagent-wasm']).toBeUndefined();
+ expect(pkg.optionalDependencies?.['@ruvector/rvagent-wasm']).toBeUndefined();
});
});
-describe('initAgentWasm() when @ruvector/rvagent-wasm is missing (#3979 item 1)', () => {
- it('says the package is not installed and how to install it, instead of a raw resolution trace', async () => {
- vi.doMock('@ruvector/rvagent-wasm', () => {
- throw Object.assign(new Error("Cannot find package '@ruvector/rvagent-wasm' imported from /x/agent-wasm.js"), {
- code: 'ERR_MODULE_NOT_FOUND',
- });
- });
- const mod = await import('../src/ruvector/agent-wasm.js');
-
- const err = await mod.initAgentWasm().then(() => null, (e: unknown) => e as Error);
- expect(err).toBeInstanceOf(Error);
- expect(err!.message).toMatch(/@ruvector\/rvagent-wasm is not installed/);
- expect(err!.message).toMatch(/npm install/);
- expect(err!.message).not.toMatch(/ERR_MODULE_NOT_FOUND|Cannot find package/);
+describe('agentWasmLoadError() (#3979 item 1)', () => {
+ const trace = "Cannot find package '@ruvector/rvagent-wasm' imported from /x/agent-wasm.js";
+
+ it.each([
+ ['ERR_MODULE_NOT_FOUND with a code', Object.assign(new Error(trace), { code: 'ERR_MODULE_NOT_FOUND' })],
+ ['MODULE_NOT_FOUND (CJS) with a code', Object.assign(new Error("Cannot find module '@ruvector/rvagent-wasm'"), { code: 'MODULE_NOT_FOUND' })],
+ ['a wrapper that dropped the code but kept the text', new Error(`[wrapper] ${trace}`)],
+ ])('says the package is not installed and how to install it: %s', (_name, err) => {
+ expect(isMissingAgentWasm(err)).toBe(true);
+ const out = agentWasmLoadError(err);
+ expect(out.message).toBe(AGENT_WASM_NOT_INSTALLED_MESSAGE);
+ expect(out.message).toMatch(/@ruvector\/rvagent-wasm is not installed/);
+ expect(out.message).toMatch(/npm install/);
+ expect(out.message).not.toMatch(/ERR_MODULE_NOT_FOUND|Cannot find package/);
});
- it('still reports a genuine initialization failure as one', async () => {
- vi.doMock('@ruvector/rvagent-wasm', () => ({
- WasmAgent: class {},
- initSync: () => {
- throw new Error('wasm bytes rejected');
- },
- }));
- const mod = await import('../src/ruvector/agent-wasm.js');
+ it('does not mistake a missing OTHER package for a missing rvagent-wasm', () => {
+ const other = Object.assign(new Error("Cannot find package 'left-pad' imported from /x.js"), { code: 'ERR_MODULE_NOT_FOUND' });
+ expect(isMissingAgentWasm(other)).toBe(false);
+ expect(agentWasmLoadError(other).message).toMatch(/^Failed to initialize @ruvector\/rvagent-wasm: /);
+ });
- const err = await mod.initAgentWasm().then(() => null, (e: unknown) => e as Error);
- expect(err).toBeInstanceOf(Error);
- // Either the package resolves here and init fails (Failed to initialize ...),
- // or it is genuinely absent in this checkout (not installed). It must never
- // be reported as the wrong one of the two.
- expect(err!.message).toMatch(/Failed to initialize @ruvector\/rvagent-wasm|@ruvector\/rvagent-wasm is not installed/);
+ it('still reports a genuine initialization failure as one', () => {
+ const out = agentWasmLoadError(new Error('wasm bytes rejected'));
+ expect(out.message).toMatch(/^Failed to initialize @ruvector\/rvagent-wasm: .*wasm bytes rejected/);
+ expect(out.message).not.toMatch(/is not installed/);
});
});
diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json
index fe542f2e82..57cb06ccfa 100644
--- a/v3/@claude-flow/cli/package.json
+++ b/v3/@claude-flow/cli/package.json
@@ -135,7 +135,6 @@
"@metaharness/radio": "~0.1.0",
"@metaharness/turn-credit": "~0.1.0",
"@napi-rs/keyring": "1.3.0",
- "@ruvector/rvagent-wasm": "^0.1.0",
"agentdb": "^3.0.0-alpha.20",
"agentic-flow": "^3.0.0-alpha.1",
"better-sqlite3": "^12.9.0",
diff --git a/v3/@claude-flow/cli/src/ruvector/agent-wasm.ts b/v3/@claude-flow/cli/src/ruvector/agent-wasm.ts
index 0928d4b3b1..831df0dfe2 100644
--- a/v3/@claude-flow/cli/src/ruvector/agent-wasm.ts
+++ b/v3/@claude-flow/cli/src/ruvector/agent-wasm.ts
@@ -66,12 +66,28 @@ export const AGENT_WASM_NOT_INSTALLED_MESSAGE =
'@ruvector/rvagent-wasm is not installed.\n' +
'Install it with: npm install @ruvector/rvagent-wasm (or npm install -g @ruvector/rvagent-wasm for a global ruflo)';
-/** True when err is the module-resolution failure for @ruvector/rvagent-wasm itself. */
-function isMissingAgentWasm(err: unknown): boolean {
+/**
+ * True when err is the module-resolution failure for @ruvector/rvagent-wasm itself.
+ * Decided by the error code OR its text, because wrappers (loaders, test harnesses)
+ * can drop `code` while keeping the message.
+ */
+export function isMissingAgentWasm(err: unknown): boolean {
const e = err as { code?: unknown; message?: unknown } | null;
const code = typeof e?.code === 'string' ? e.code : '';
const message = typeof e?.message === 'string' ? e.message : String(err);
- return (code === 'ERR_MODULE_NOT_FOUND' || code === 'MODULE_NOT_FOUND') && message.includes('@ruvector/rvagent-wasm');
+ if (!message.includes('@ruvector/rvagent-wasm')) return false;
+ return (
+ code === 'ERR_MODULE_NOT_FOUND' ||
+ code === 'MODULE_NOT_FOUND' ||
+ /ERR_MODULE_NOT_FOUND|MODULE_NOT_FOUND|Cannot find (package|module)/.test(message)
+ );
+}
+
+/** The error initAgentWasm() throws for a load failure: "not installed" with the fix, or a genuine init failure. */
+export function agentWasmLoadError(err: unknown): Error {
+ return isMissingAgentWasm(err)
+ ? new Error(AGENT_WASM_NOT_INSTALLED_MESSAGE)
+ : new Error(`Failed to initialize @ruvector/rvagent-wasm: ${err}`);
}
/**
@@ -103,10 +119,7 @@ export async function initAgentWasm(): Promise<void> {
} catch (err) {
// #3979 item 1: a missing optional package is "not installed", with the fix,
// not a raw ERR_MODULE_NOT_FOUND trace dressed up as an initialization failure.
- if (isMissingAgentWasm(err)) {
- throw new Error(AGENT_WASM_NOT_INSTALLED_MESSAGE);
- }
- throw new Error(`Failed to initialize @ruvector/rvagent-wasm: ${err}`);
+ throw agentWasmLoadError(err);
}
}
diff --git a/v3/pnpm-lock.yaml b/v3/pnpm-lock.yaml
index fbed05905d..c8973b44ff 100644
--- a/v3/pnpm-lock.yaml
+++ b/v3/pnpm-lock.yaml
@@ -228,9 +228,6 @@ importers:
'@napi-rs/keyring':
specifier: 1.3.0
version: 1.3.0
- '@ruvector/rvagent-wasm':
- specifier: ^0.1.0
- version: 0.1.0
agentdb:
specifier: ^3.0.0-alpha.20
version: 3.0.0-alpha.20(@types/[email protected])([email protected])
@@ -5809,12 +5806,6 @@ packages:
'@ruvector/ruvllm-linux-x64-gnu': 2.0.1
'@ruvector/ruvllm-win32-x64-msvc': 2.0.1
- /@ruvector/[email protected]:
- resolution: {integrity: sha512-zhcnU7XfBEfDwkDFscehq6qGU/TW4LNr287xHHXCuNsaTBPlb8YSnkuMNWg6BBIK/X+UdWAsyYESN5jbNQEaBQ==}
- requiresBuild: true
- dev: false
- optional: true
-
/@ruvector/[email protected]:
resolution: {integrity: sha512-vll3WJwDn3oOfy1PB10IG7/f3zBpFiMNHL2/2tdJmeRR8La/rSPJ0ZH5MDIsfleiVtaWzh9bvVCtVkZ6uo2jeg==}
cpu: [arm64]
@@ -13575,6 +13566,7 @@ packages:
optional: true
dev: false
+
resolution: {integrity: sha512-sAt8BhgNbzCtgGbt2OxmpuryO63ZoDk/sqaB/znQm94T4fCEsy/yV+7CdC1kJhOU9lboAEU7R3kquuycDoibVA==}
engines: {node: '>=10.0.0'}