mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 06:21:59 +09:00
Merge pull request #4830 from MentaNew/fix/embeddings-init-zero
Fix/embeddings init zero
This commit is contained in:
2 files changed
+33
-3
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
|
||||
@@ -18,6 +18,7 @@ vi.mock('../src/memory/memory-initializer.js', () => ({
|
||||
const { embeddingsTools } = await import('../src/mcp-tools/embeddings-tools.js');
|
||||
const init = embeddingsTools.find(tool => tool.name === 'embeddings_init')!;
|
||||
const search = embeddingsTools.find(tool => tool.name === 'embeddings_search')!;
|
||||
const neural = embeddingsTools.find(tool => tool.name === 'embeddings_neural')!;
|
||||
|
||||
let originalCwd: string;
|
||||
let workdir: string;
|
||||
@@ -48,3 +49,31 @@ describe('embeddings_search threshold', () => {
|
||||
expect(result.metadata.threshold).toBe(0.5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('embeddings_neural init', () => {
|
||||
it('honours an explicit 0 for decayRate and driftThreshold', async () => {
|
||||
const result = await neural.handler({ action: 'init', decayRate: 0, driftThreshold: 0 }) as any;
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.neural.decayRate).toBe(0);
|
||||
expect(result.neural.driftThreshold).toBe(0);
|
||||
});
|
||||
|
||||
it('persists the 0 values to the embeddings config', async () => {
|
||||
await neural.handler({ action: 'init', decayRate: 0, driftThreshold: 0 });
|
||||
const saved = JSON.parse(readFileSync(join(workdir, '.claude-flow', 'embeddings.json'), 'utf-8'));
|
||||
expect(saved.neural.decayRate).toBe(0);
|
||||
expect(saved.neural.driftThreshold).toBe(0);
|
||||
});
|
||||
|
||||
it('still defaults to 0.3 and 0.01 when the values are omitted', async () => {
|
||||
const result = await neural.handler({ action: 'init' }) as any;
|
||||
expect(result.neural.driftThreshold).toBe(0.3);
|
||||
expect(result.neural.decayRate).toBe(0.01);
|
||||
});
|
||||
|
||||
it('keeps non-zero values as given', async () => {
|
||||
const result = await neural.handler({ action: 'init', decayRate: 0.05, driftThreshold: 0.7 }) as any;
|
||||
expect(result.neural.decayRate).toBe(0.05);
|
||||
expect(result.neural.driftThreshold).toBe(0.7);
|
||||
});
|
||||
});
|
||||
@@ -636,8 +636,9 @@ export const embeddingsTools: MCPTool[] = [
|
||||
case 'init':
|
||||
config.neural = {
|
||||
enabled: true,
|
||||
driftThreshold: (input.driftThreshold as number) || 0.3,
|
||||
decayRate: (input.decayRate as number) || 0.01,
|
||||
// `??`, not `||`: an explicit 0 is a valid value for both.
|
||||
driftThreshold: (input.driftThreshold as number) ?? 0.3,
|
||||
decayRate: (input.decayRate as number) ?? 0.01,
|
||||
ruvector: {
|
||||
enabled: true,
|
||||
sona: true,
|
||||
|
||||
Reference in new issue
Block a user